From 57b60c734bdb695f4315b2902bf2b84408115842 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 13 Nov 2018 22:15:01 -0800 Subject: [PATCH] fixes to BlockBreakHelper --- .../java/baritone/utils/BlockBreakHelper.java | 56 +++++++++++++------ .../baritone/utils/InputOverrideHandler.java | 9 +-- 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/main/java/baritone/utils/BlockBreakHelper.java b/src/main/java/baritone/utils/BlockBreakHelper.java index b1e9ae53..e384cf9c 100644 --- a/src/main/java/baritone/utils/BlockBreakHelper.java +++ b/src/main/java/baritone/utils/BlockBreakHelper.java @@ -17,6 +17,9 @@ package baritone.utils; +import baritone.Baritone; +import baritone.api.BaritoneAPI; +import baritone.api.utils.IPlayerContext; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; @@ -32,41 +35,62 @@ public final class BlockBreakHelper implements Helper { * The last block that we tried to break, if this value changes * between attempts, then we re-initialize the breaking process. */ - private static BlockPos lastBlock; - private static boolean didBreakLastTick; + private BlockPos lastBlock; + private boolean didBreakLastTick; - private BlockBreakHelper() {} + private IPlayerContext playerContext; - public static void tryBreakBlock(BlockPos pos, EnumFacing side) { + public BlockBreakHelper(IPlayerContext playerContext) { + this.playerContext = playerContext; + } + + public void tryBreakBlock(BlockPos pos, EnumFacing side) { if (!pos.equals(lastBlock)) { - mc.playerController.clickBlock(pos, side); + playerContext.playerController().clickBlock(pos, side); } - if (mc.playerController.onPlayerDamageBlock(pos, side)) { - mc.player.swingArm(EnumHand.MAIN_HAND); + if (playerContext.playerController().onPlayerDamageBlock(pos, side)) { + playerContext.player().swingArm(EnumHand.MAIN_HAND); } lastBlock = pos; } - public static void stopBreakingBlock() { - if (mc.playerController != null) { - mc.playerController.resetBlockRemoving(); + public void stopBreakingBlock() { + if (playerContext.playerController() != null) { + playerContext.playerController().resetBlockRemoving(); } lastBlock = null; } - public static boolean tick(boolean isLeftClick) { - RayTraceResult trace = mc.objectMouseOver; + private boolean fakeBreak() { + if (playerContext != BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext()) { + // for a non primary player, we need to fake break always, CLICK_LEFT has no effect + return true; + } + if (!Baritone.settings().leftClickWorkaround.get()) { + // if this setting is false, we CLICK_LEFT regardless of gui status + return false; + } + return mc.currentScreen != null; + } + + public boolean tick(boolean isLeftClick) { + if (!fakeBreak()) { + if (didBreakLastTick) { + stopBreakingBlock(); + } + return isLeftClick; + } + + RayTraceResult trace = mc.objectMouseOver; // TODO per-player objectMouseOver boolean isBlockTrace = trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK; - // If we're forcing left click, we're in a gui screen, and we're looking - // at a block, break the block without a direct game input manipulation. - if (mc.currentScreen != null && isLeftClick && isBlockTrace) { + if (isLeftClick && isBlockTrace) { tryBreakBlock(trace.getBlockPos(), trace.sideHit); didBreakLastTick = true; } else if (didBreakLastTick) { stopBreakingBlock(); didBreakLastTick = false; } - return !didBreakLastTick && isLeftClick; + return false; // fakeBreak is true so no matter what we aren't forcing CLICK_LEFT } } diff --git a/src/main/java/baritone/utils/InputOverrideHandler.java b/src/main/java/baritone/utils/InputOverrideHandler.java index 228a3e86..3670a044 100755 --- a/src/main/java/baritone/utils/InputOverrideHandler.java +++ b/src/main/java/baritone/utils/InputOverrideHandler.java @@ -43,8 +43,11 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri */ private final Map inputForceStateMap = new HashMap<>(); + private final BlockBreakHelper blockBreakHelper; + public InputOverrideHandler(Baritone baritone) { super(baritone); + this.blockBreakHelper = new BlockBreakHelper(baritone.getPlayerContext()); } /** @@ -109,9 +112,7 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri if (event.getType() == TickEvent.Type.OUT) { return; } - if (Baritone.settings().leftClickWorkaround.get()) { - boolean stillClick = BlockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT.getKeyBinding())); - setInputForceState(Input.CLICK_LEFT, stillClick); - } + boolean stillClick = blockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT.getKeyBinding())); + setInputForceState(Input.CLICK_LEFT, stillClick); } }