From b45fcaa9972752fd83173302286837dcda026934 Mon Sep 17 00:00:00 2001 From: p1k0chu Date: Tue, 22 Oct 2024 22:58:13 +0300 Subject: [PATCH 1/3] player could be null here --- common/src/main/java/pro/mikey/autoclicker/AutoClicker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/pro/mikey/autoclicker/AutoClicker.java b/common/src/main/java/pro/mikey/autoclicker/AutoClicker.java index bee5c98..c336358 100644 --- a/common/src/main/java/pro/mikey/autoclicker/AutoClicker.java +++ b/common/src/main/java/pro/mikey/autoclicker/AutoClicker.java @@ -236,7 +236,7 @@ private void attemptMobAttack(MinecraftClient mc, Holding key) { } HitResult rayTrace = mc.crosshairTarget; - if (rayTrace instanceof EntityHitResult && mc.interactionManager != null) { + if (rayTrace instanceof EntityHitResult && mc.interactionManager != null && mc.player != null) { if(!(config.getLeftClick().isRespectShield() && isShielding(mc.player))) { mc.interactionManager.attackEntity(mc.player, ((EntityHitResult) rayTrace).getEntity()); if (mc.player != null) { From 900c49330b3f09f2c3214e16d01375f9d065ee3c Mon Sep 17 00:00:00 2001 From: p1k0chu Date: Wed, 23 Oct 2024 01:37:10 +0300 Subject: [PATCH 2/3] fixes AdvancedXRay/Auto-Clicker#72 --- .../pro/mikey/autoclicker/AutoClicker.java | 73 +++++++++++++++++-- 1 file changed, 68 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/pro/mikey/autoclicker/AutoClicker.java b/common/src/main/java/pro/mikey/autoclicker/AutoClicker.java index c336358..ae87742 100644 --- a/common/src/main/java/pro/mikey/autoclicker/AutoClicker.java +++ b/common/src/main/java/pro/mikey/autoclicker/AutoClicker.java @@ -10,8 +10,10 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.item.ShieldItem; import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; import net.minecraft.util.Formatting; import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.hit.HitResult; import org.apache.logging.log4j.LogManager; @@ -187,12 +189,15 @@ private void handleActiveHolding(MinecraftClient mc, Holding key) { key.resetTimeout(); } - // Press the button twice by toggling 1 and 0 - key.getKey().setPressed(key.getTimeout() == 1); - - if (key.getKey().isPressed()) { - this.attemptMobAttack(mc, key); + // simulate the actual button press only if its jumping + if(key == jumpHolding) { + // Press the button twice by toggling 1 and 0 + key.getKey().setPressed(key.getTimeout() == 1); } + // for left click, attempt to attack the mob + this.attemptMobAttack(mc, key); + // for right click, attempt to interact with block or mob + this.attemptUse(mc, key); } key.decreaseTimeout(); } else { @@ -229,6 +234,64 @@ private void handleActiveHolding(MinecraftClient mc, Holding key) { } } + /** + * Attempts to use items in main hand, and if it couldn't, tries offhand. + */ + private void attemptUse(MinecraftClient mc, Holding key) { + // don't interact on left click + if(key.getKey() != rightHolding.getKey() || mc.interactionManager == null || mc.player == null) { + return; + } + + HitResult rayTrace = mc.crosshairTarget; + if(rayTrace == null) { + return; + } + + // try with both hands + for(var hand : Hand.values()) { + if (rayTrace.getType() == HitResult.Type.ENTITY && rayTrace instanceof EntityHitResult) { + // interact with entity + ActionResult result = mc.interactionManager.interactEntity(mc.player, ((EntityHitResult) rayTrace).getEntity(), hand); + if (result.isAccepted()) { + if (result.shouldSwingHand()) { + mc.player.swingHand(hand); + } + return; + } + } else if (rayTrace.getType() == HitResult.Type.BLOCK) { + // interact with block + ActionResult result = mc.interactionManager.interactBlock(mc.player, hand, (BlockHitResult) rayTrace); + if (result.isAccepted()) { + if (result.shouldSwingHand()) { + mc.player.swingHand(hand); + } + return; + } else { + // if you cant interact with block, you could use a water bucket on it + ActionResult result1 = mc.interactionManager.interactItem(mc.player, hand); + if(result1.isAccepted()) { + if(result.shouldSwingHand()) { + mc.player.swingHand(hand); + } + return; + } + } + } else if (rayTrace.getType() == HitResult.Type.MISS) { + // no blocks and entities to interact with + // attempt to use an item (e.g. ender pearl) + ActionResult result = mc.interactionManager.interactItem(mc.player, hand); + if (result.isAccepted()) { + if (result.shouldSwingHand()) { + // cosmetic swing + mc.player.swingHand(hand); + } + return; + } + } + } + } + private void attemptMobAttack(MinecraftClient mc, Holding key) { // Don't attack on a right click if (key.getKey() != leftHolding.getKey()) { From 006a37bb4bd5151539022ada04d58642b35de5ab Mon Sep 17 00:00:00 2001 From: p1k0chu Date: Wed, 23 Oct 2024 01:42:45 +0300 Subject: [PATCH 3/3] fixed bug when using items and attacking simultaneously --- common/src/main/java/pro/mikey/autoclicker/AutoClicker.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/src/main/java/pro/mikey/autoclicker/AutoClicker.java b/common/src/main/java/pro/mikey/autoclicker/AutoClicker.java index ae87742..a407b99 100644 --- a/common/src/main/java/pro/mikey/autoclicker/AutoClicker.java +++ b/common/src/main/java/pro/mikey/autoclicker/AutoClicker.java @@ -305,6 +305,8 @@ private void attemptMobAttack(MinecraftClient mc, Holding key) { if (mc.player != null) { mc.player.swingHand(Hand.MAIN_HAND); } + // it's impossible in vanilla minecraft to attack and use item at the same time + mc.interactionManager.stopUsingItem(mc.player); } } }