diff --git a/src/main/java/com/breelock/autoclicky/AutoClicky.java b/src/main/java/com/breelock/autoclicky/AutoClicky.java index 461c864..22ddc85 100644 --- a/src/main/java/com/breelock/autoclicky/AutoClicky.java +++ b/src/main/java/com/breelock/autoclicky/AutoClicky.java @@ -13,7 +13,6 @@ import net.minecraft.text.LiteralText; import net.minecraft.text.TranslatableText; - import org.lwjgl.glfw.GLFW; import org.apache.logging.log4j.LogManager; diff --git a/src/main/java/com/breelock/autoclicky/PlayerMethods.java b/src/main/java/com/breelock/autoclicky/PlayerMethods.java index 5e0f1e4..6743435 100644 --- a/src/main/java/com/breelock/autoclicky/PlayerMethods.java +++ b/src/main/java/com/breelock/autoclicky/PlayerMethods.java @@ -18,12 +18,6 @@ public static void attack(MinecraftClient client, boolean isNewPvP) { boolean isInLava = client.world.getBlockState(new BlockPos(client.player.getX(), client.player.getY(), client.player.getZ())).getBlock() == Blocks.LAVA || client.player.isSubmergedIn(FluidTags.LAVA); boolean isOnGround = client.player.isOnGround() && !client.player.isTouchingWater() && !isInLava; - if (client.player.isUsingItem()) { - if (isNewPvP && ModConfig.NewPvP.interrupt || !isNewPvP && ModConfig.OldPvP.interrupt) - client.interactionManager.stopUsingItem(client.player); - else - return; - } if (isNewPvP) { if (ModConfig.NewPvP.onlyEntity) { if (client.crosshairTarget.getType() == HitResult.Type.ENTITY) { @@ -31,8 +25,10 @@ public static void attack(MinecraftClient client, boolean isNewPvP) { client.player.jump(); if (client.player.getAttackCooldownProgress(0.0F) >= 1.0F) { - if (!isOnGround && client.player.getVelocity().y < -0.1 || client.player.isOnGround() || client.player.abilities.flying || client.player.isTouchingWater() || isInLava) + if (!isOnGround && client.player.getVelocity().y < -0.1 || client.player.isOnGround() || client.player.abilities.flying || client.player.isTouchingWater() || isInLava) { + if (interrupt(client, true)) return; PlayerMethods.attackEntity(client); + } } } } @@ -41,6 +37,8 @@ public static void attack(MinecraftClient client, boolean isNewPvP) { client.player.jump(); if (client.player.getAttackCooldownProgress(0.0F) >= 1.0F) { + if (interrupt(client, true)) return; + if (client.crosshairTarget.getType() == HitResult.Type.ENTITY) { if (!isOnGround && client.player.getVelocity().y < -0.1 || client.player.isOnGround() || client.player.abilities.flying || client.player.isTouchingWater() || isInLava) PlayerMethods.attackEntity(client); @@ -55,14 +53,18 @@ else if (client.crosshairTarget.getType() == HitResult.Type.MISS) { } } else { - if (client.crosshairTarget.getType() == HitResult.Type.ENTITY && ModConfig.NewPvP.autoJump && client.player.isOnGround() && !client.player.isTouchingWater() && !isInLava) + if (client.crosshairTarget.getType() == HitResult.Type.ENTITY && ModConfig.OldPvP.autoJump && client.player.isOnGround() && !client.player.isTouchingWater() && !isInLava) client.player.jump(); if (ModConfig.OldPvP.onlyEntity) { - if (client.crosshairTarget.getType() == HitResult.Type.ENTITY) + if (client.crosshairTarget.getType() == HitResult.Type.ENTITY) { + if (interrupt(client, false)) return; PlayerMethods.attackEntity(client); + } } else { + if (interrupt(client, false)) return; + if (client.crosshairTarget.getType() == HitResult.Type.ENTITY) PlayerMethods.attackEntity(client); else if (client.crosshairTarget.getType() == HitResult.Type.BLOCK) @@ -93,6 +95,17 @@ else if (client.crosshairTarget.getType() == HitResult.Type.BLOCK) { } } + private static boolean interrupt(MinecraftClient client, boolean isNewPvP) { + if (client != null && client.player != null && client.interactionManager != null && client.player.isUsingItem()) { + if (isNewPvP && ModConfig.NewPvP.interrupt || !isNewPvP && ModConfig.OldPvP.interrupt) + client.interactionManager.stopUsingItem(client.player); + else + return true; + } + + return false; + } + private static void resetAttackCooldown(MinecraftClient client) { if (client.player != null) { client.player.resetLastAttackedTicks(); diff --git a/src/main/java/com/breelock/autoclicky/pages/NewCombat.java b/src/main/java/com/breelock/autoclicky/pages/NewCombat.java index 786660d..7d428fd 100644 --- a/src/main/java/com/breelock/autoclicky/pages/NewCombat.java +++ b/src/main/java/com/breelock/autoclicky/pages/NewCombat.java @@ -108,7 +108,7 @@ protected void applyValue() { // Exit without saving button this.addButton(new ButtonWidget(centerX - buttonWidth - 5, startY + 5 * spacing, buttonWidth, 20, new LiteralText(new TranslatableText("gui.autoclicky.cancel").getString()), button -> { - this.client.openScreen(null); // Close the screen without saving + this.client.openScreen(null); // Close the screen })); } } diff --git a/src/main/java/com/breelock/autoclicky/pages/OldCombat.java b/src/main/java/com/breelock/autoclicky/pages/OldCombat.java index d9de30d..d8fe33b 100644 --- a/src/main/java/com/breelock/autoclicky/pages/OldCombat.java +++ b/src/main/java/com/breelock/autoclicky/pages/OldCombat.java @@ -130,7 +130,7 @@ protected void applyValue() { // Exit without saving button this.addButton(new ButtonWidget(centerX - buttonWidth - 5, startY + 5 * spacing, buttonWidth, 20, new LiteralText(new TranslatableText("gui.autoclicky.cancel").getString()), button -> { - this.client.openScreen(null); // Close the screen without saving + this.client.openScreen(null); // Close the screen })); }