diff --git a/src/openonyx/features/combat/BedTarget.java b/src/openonyx/features/combat/BedTarget.java new file mode 100644 index 0000000..9043de8 --- /dev/null +++ b/src/openonyx/features/combat/BedTarget.java @@ -0,0 +1,6 @@ +package openonyx.features.combat; + +import net.minecraft.util.BlockPos; + +record BedTarget(BlockPos pos, String block, int index, double distance) { +} diff --git a/src/openonyx/features/combat/BedTracker.java b/src/openonyx/features/combat/BedTracker.java new file mode 100644 index 0000000..4aa7757 --- /dev/null +++ b/src/openonyx/features/combat/BedTracker.java @@ -0,0 +1,124 @@ +package openonyx.features.combat; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import meteordevelopment.orbit.EventHandler; +import net.minecraft.block.BlockBed; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S02PacketChat; +import net.minecraft.network.play.server.S08PacketPlayerPosLook; +import net.minecraft.util.BlockPos; +import openonyx.configuration.internal.PacketDirection; +import openonyx.configuration.internal.PacketEvent; +import openonyx.configuration.internal.PreTickEvent; +import openonyx.configuration.internal.WorldChangeEvent; +import openonyx.core.MinecraftAccess; +import openonyx.utilities.Timer; + +public final class BedTracker implements MinecraftAccess { + private final Set blockPosList = new HashSet<>(); + private final Timer timer = new Timer(); + public static final BedTracker INSTANCE = new BedTracker(); + private static final long I = 3000L; + private static final int d = 15; + private BlockPos blockPos; + private boolean f; + private static final int H = 35; + private boolean e; + + public boolean L(BlockPos blockPos) { + return this.blockPosList.contains(blockPosx); + } + + @EventHandler + public void onPreTick(PreTickEvent preTickEvent) { + if (this.f && this.timer.hasElapsed(3000L)) { + this.f = false; + this.d(); + } + } + + public BlockPos L() { + BedTracker bedTracker1 = this; + if (mc.thePlayer != null && mc.theWorld != null && !bedTracker1.blockPosList.isEmpty()) { + BlockPos blockPosx = new BlockPos(mc.thePlayer); + BlockPos blockPos2 = null; + double dx = Double.MAX_VALUE; + Iterator iterator = bedTracker1.blockPosList.iterator(); + + label25: + while (true) { + for (Iterator iterator1 = iterator; iterator1.hasNext(); iterator1 = iterator) { + BlockPos blockPos1 = (BlockPos)iterator.next(); + if (mc.theWorld.getBlockState(blockPos1).getBlock() instanceof BlockBed) { + double ex; + if ((ex = blockPos1.distanceSq(blockPosx.getX(), blockPosx.getY(), blockPosx.getZ())) < dx) { + dx = ex; + blockPos2 = blockPos1; + } + continue label25; + } + } + + return blockPos2; + } + } else { + return null; + } + } + + private void d() { + BedTracker bedTracker1 = this; + if (bedTracker1.blockPos != null && mc.theWorld != null) { + int i; + int j; + for (int n = i = -35; n <= 35; n = ++i) { + int k; + for (int l = j = -15; l <= 15; l = ++j) { + for (int m = k = -35; m <= 35; m = ++k) { + BlockPos blockPosx = bedTracker1.blockPos.add(i, j, k); + if (mc.theWorld.getBlockState(blockPosx).getBlock() instanceof BlockBed) { + bedTracker1.blockPosList.add(blockPosx); + } + } + } + } + } + } + + @EventHandler + public void onPacket(PacketEvent packetEvent) { + if (packetEvent.getPacketDirection() == PacketDirection.INCOMING) { + Packet packet; + if ((packet = packetEvent.getPacket()) instanceof S02PacketChat) { + String string; + if ((string = ((S02PacketChat)packet).getChatComponent().getUnformattedText()).contains("Protect your bed and destroy the enemy bed") + || string.contains("Destroy the enemy bed and then eliminate them")) { + this.e = true; + return; + } + } else if (packet instanceof S08PacketPlayerPosLook s08PacketPlayerPosLook && this.e) { + this.e = false; + this.blockPos = new BlockPos(s08PacketPlayerPosLook.getX(), s08PacketPlayerPosLook.getY(), s08PacketPlayerPosLook.getZ()); + this.f = true; + this.timer.reset(); + } + } + } + + @EventHandler + public void onWorldChange(WorldChangeEvent worldChangeEvent) { + this.L(); + } + + private void L() { + this.blockPosList.clear(); + this.e = false; + this.f = false; + this.blockPos = null; + } + + private BedTracker() { + } +} diff --git a/src/openonyx/features/combat/CombatController.java b/src/openonyx/features/combat/CombatController.java new file mode 100644 index 0000000..7b8fa64 --- /dev/null +++ b/src/openonyx/features/combat/CombatController.java @@ -0,0 +1,378 @@ +package openonyx.features.combat; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemSword; +import net.minecraft.network.Packet; +import net.minecraft.network.play.client.C02PacketUseEntity; +import net.minecraft.network.play.client.C03PacketPlayer; +import net.minecraft.network.play.client.C07PacketPlayerDigging; +import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement; +import net.minecraft.network.play.client.C09PacketHeldItemChange; +import net.minecraft.network.play.client.C0APacketAnimation; +import net.minecraft.network.play.client.C07PacketPlayerDigging.Action; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; +import openonyx.configuration.internal.PacketEvent; +import openonyx.core.MinecraftAccess; +import openonyx.utilities.Timer; + +public class CombatController implements MinecraftAccess { + private volatile boolean C; + private final Timer timer; + private boolean D; + private boolean c; + private boolean a; + private EntityLivingBase entityLivingBase; + private boolean g; + private boolean M; + private boolean L; + private boolean j; + private boolean m; + private boolean h; + private static final long l = 329L; + private volatile int I; + private boolean d; + private int i; + private static final int f = 2; + private boolean H; + private final List packets; + + public void e() { + if (this.h) { + switch (this.i) { + case 7: + while (false) { + } + + this.L(); + this.i = 10; + return; + case 8: + this.L(); + this.d(); + this.I(); + this.i = 9; + return; + case 11: + this.d(); + this.I(); + this.i = 0; + case 9: + case 10: + } + } + } + + public void L(PacketEvent packetEvent) { + CombatController combatController1 = this; + if (!combatController1.D) { + if (!packetEvent.isCancelled()) { + Packet packet = packetEvent.getPacket(); + if (mc.isCallingFromMinecraftThread()) { + combatController1.d(packet); + if (combatController1.c) { + combatController1.packets.add(packet); + packetEvent.cancel(); + } + } + } + } + } + + public void L(boolean bl) { + if (bl) { + this.I = 0; + } + + if (this.a) { + this.d(); + this.c = false; + this.a = false; + } + + if (mc.thePlayer == null) { + this.l(); + } else if (!isHoldingSword()) { + this.k(); + this.h = false; + this.L = false; + this.entityLivingBase = null; + } else { + if (this.m) { + this.D(); + } + + if (!this.h || !this.D() || this.h()) { + if (this.I <= 0) { + this.k(); + } + + this.h = false; + this.L = false; + this.entityLivingBase = null; + } + } + } + + private boolean h() { + if (!this.D()) { + return true; + } else if (isHoldingSword() && !this.d && !this.H && !this.j) { + this.L(new C07PacketPlayerDigging(Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, EnumFacing.DOWN)); + this.L = false; + return true; + } else { + return false; + } + } + + private void k() { + if (this.g) { + this.g = false; + if (mc.thePlayer != null) { + mc.thePlayer.stopUsingItem(); + } + } + } + + public CombatController() { + int ix = 2 ^ 3; + super(); + this.C = (boolean)ix; + this.packets = new CopyOnWriteArrayList<>(); + this.timer = new Timer(System.currentTimeMillis()); + } + + public void F() { + this.I = 2; + } + + public boolean L(EntityLivingBase entityLivingBase, Runnable runnable) { + if (this.m) { + int ix = --1; + int jx = --1; + this.D(); + this.L((boolean)jx); + return (boolean)ix; + } + + if (this.g && !mc.thePlayer.isUsingItem()) { + this.g = false; + } + + if (this.I > 0) { + this.I--; + if (this.I > 0) { + this.L(false); + return false; + } + } + + this.entityLivingBase = entityLivingBasex; + if (!this.h) { + this.L = !this.g && mc.thePlayer.isUsingItem(); + this.i = this.L ? 0 : 1; + this.h = true; + this.h(); + } + + CombatController combatController1; + label111: { + if (this.i == 0 || this.i == 3 || this.i == 5) { + this.I(); + if (this.i != 0) { + if (this.i == 3) { + combatController1 = this; + this.i = 6; + } else { + combatController1 = this; + this.i = 1; + } + break label111; + } + + if (this.h()) { + combatController1 = this; + this.i = 3; + break label111; + } + } else if (this.i == 1 || this.i == 6) { + this.i = 2; + } + + combatController1 = this; + } + + if (combatController1.i == 10) { + this.i = 11; + } else if (this.i == 9) { + this.i = 0; + } else { + boolean bl = this.timer.elapsed() >= 329L; + if (this.i == 2 || this.i == 5 || this.i == 6 || bl) { + boolean bl1 = this.L(runnable); + if (this.i != 5 && this.i != 6 && (bl1 || bl)) { + this.i = 7; + } + } + } + + return true; + } + + public void l() { + this.packets.clear(); + this.c = false; + this.a = false; + this.D = false; + this.h = false; + this.L = false; + this.i = 0; + this.I = 0; + this.entityLivingBase = null; + this.g = false; + this.C = true; + this.m = false; + this.D(); + this.timer.reset(); + } + + private void d(Packet packet) { + if (packet instanceof C02PacketUseEntity) { + C02PacketUseEntity c02PacketUseEntity; + C02PacketUseEntity c02PacketUseEntity1 = c02PacketUseEntity = (C02PacketUseEntity)packet; + this.j = true; + if (c02PacketUseEntity1.getAction() != net.minecraft.network.play.client.C02PacketUseEntity.Action.ATTACK || c02PacketUseEntity.getHitVec() != null) { + this.d = true; + } + } + + if (packet instanceof C07PacketPlayerDigging) { + this.H = true; + } + + if (packet instanceof C08PacketPlayerBlockPlacement) { + this.d = true; + } + + if (packet instanceof C09PacketHeldItemChange c09PacketHeldItemChange + && mc.thePlayer != null + && c09PacketHeldItemChange.getSlotId() != mc.thePlayer.inventory.currentItem) { + this.H = true; + } + + if (packet instanceof C0APacketAnimation) { + this.M = true; + } + + if (packet instanceof C03PacketPlayer) { + this.C = true; + this.j = false; + this.d = false; + this.H = false; + this.M = false; + } + } + + private boolean L(Runnable runnable) { + if (!this.D() && !this.M && !this.H && !this.d) { + runnable.run(); + return true; + } else { + return false; + } + } + + private void h() { + CombatController combatController1 = this; + ItemStack itemStack; + if ((itemStack = mc.thePlayer.getHeldItem()) != null) { + mc.thePlayer.setItemInUse(itemStack, itemStack.getMaxItemUseDuration()); + combatController1.g = true; + } + } + + private void I() { + this.c = true; + this.a = true; + } + + public static boolean isHoldingSword() { + ItemStack itemStack; + return mc.thePlayer == null ? false : (itemStack = mc.thePlayer.getHeldItem()) != null && itemStack.getItem() instanceof ItemSword; + } + + public void i() { + this.m = !this.C; + this.C = false; + } + + public boolean i() { + return this.h || this.g; + } + + private void L(Packet packet) { + if (mc.getNetHandler() != null) { + mc.getNetHandler().addToSendQueue(packet); + } + } + + private boolean D() { + return this.h ? this.L : mc.thePlayer.isUsingItem(); + } + + private void D() { + this.j = false; + this.d = false; + this.H = false; + this.M = false; + } + + // $VF: Could not inline inconsistent finally blocks + // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!) + private void d() { + CombatController combatController1 = this; + combatController1.timer.reset(); + combatController1.D(); + if (!combatController1.packets.isEmpty()) { + ArrayList arrayList = new ArrayList<>(combatController1.packets); + combatController1.packets.clear(); + if (mc.getNetHandler() != null) { + combatController1.D = true; + + try { + mc.getNetHandler().getNetworkManager().sendGrouped(arrayList); + } catch (Throwable throwable) { + combatController1.D = false; + throw throwable; + } + + combatController1.D = false; + } + } + } + + public boolean d() { + return (this.h || this.g) && !this.L; + } + + public boolean L() { + return mc.thePlayer == null ? false : !this.D() && !this.M && !this.H && !this.d; + } + + private void L() { + CombatController combatController1 = this; + if (!combatController1.D()) { + if (isHoldingSword()) { + ItemStack itemStack = mc.thePlayer.getHeldItem(); + combatController1.L(new C08PacketPlayerBlockPlacement(itemStack)); + combatController1.h(); + combatController1.L = true; + } + } + } +} diff --git a/src/openonyx/features/combat/DefensePattern.java b/src/openonyx/features/combat/DefensePattern.java new file mode 100644 index 0000000..b588904 --- /dev/null +++ b/src/openonyx/features/combat/DefensePattern.java @@ -0,0 +1,39 @@ +package openonyx.features.combat; + +import openonyx.history.DisplayNamed; + +public enum DefensePattern implements DisplayNamed { + END_GLASS_NO_CORNERS("EndGlassNoCorners"), + WOOD_WOOL_CORNERS("WoodWoolCorners"), + WOOL_1_LAYER("Wool1Layer"), + END_WOOL_CORNERS("EndWoolCorners"), + END_WOOL_CORNERS_2("EndWoolCorners2"), + END_WOOD_LONG_CORNERS("EndWoodLongCorners"), + END_GLASS_WOOL("EndGlassWool"), + END_WOOL_LONG("EndWoolLong"); + + private final String H; + + DefensePattern(String string1) { + this.H = string1; + } + + @Override + public String getDisplayName() { + return this.H; + } + + private static DefensePattern[] L() { + DefensePattern[] defensePatterns = new DefensePattern[8]; + boolean bl = true; + defensePatterns[0] = END_WOOL_CORNERS; + defensePatterns[1] = END_WOOL_CORNERS_2; + defensePatterns[2] = END_GLASS_NO_CORNERS; + defensePatterns[3] = WOOD_WOOL_CORNERS; + defensePatterns[4] = END_GLASS_WOOL; + defensePatterns[5] = WOOL_1_LAYER; + defensePatterns[6] = END_WOOD_LONG_CORNERS; + defensePatterns[7] = END_WOOL_LONG; + return defensePatterns; + } +} diff --git a/src/openonyx/features/combat/DefenseStep.java b/src/openonyx/features/combat/DefenseStep.java new file mode 100644 index 0000000..7e85c81 --- /dev/null +++ b/src/openonyx/features/combat/DefenseStep.java @@ -0,0 +1,6 @@ +package openonyx.features.combat; + +import net.minecraft.util.BlockPos; + +public record DefenseStep(String block, BlockPos offset) { +}