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; } } } }