fixes to BlockBreakHelper

This commit is contained in:
Leijurv 2018-11-13 22:15:01 -08:00
parent c74ccaafbf
commit 57b60c734b
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 45 additions and 20 deletions

View File

@ -17,6 +17,9 @@
package baritone.utils; package baritone.utils;
import baritone.Baritone;
import baritone.api.BaritoneAPI;
import baritone.api.utils.IPlayerContext;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos; 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 * The last block that we tried to break, if this value changes
* between attempts, then we re-initialize the breaking process. * between attempts, then we re-initialize the breaking process.
*/ */
private static BlockPos lastBlock; private BlockPos lastBlock;
private static boolean didBreakLastTick; 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)) { if (!pos.equals(lastBlock)) {
mc.playerController.clickBlock(pos, side); playerContext.playerController().clickBlock(pos, side);
} }
if (mc.playerController.onPlayerDamageBlock(pos, side)) { if (playerContext.playerController().onPlayerDamageBlock(pos, side)) {
mc.player.swingArm(EnumHand.MAIN_HAND); playerContext.player().swingArm(EnumHand.MAIN_HAND);
} }
lastBlock = pos; lastBlock = pos;
} }
public static void stopBreakingBlock() { public void stopBreakingBlock() {
if (mc.playerController != null) { if (playerContext.playerController() != null) {
mc.playerController.resetBlockRemoving(); playerContext.playerController().resetBlockRemoving();
} }
lastBlock = null; lastBlock = null;
} }
public static boolean tick(boolean isLeftClick) { private boolean fakeBreak() {
RayTraceResult trace = mc.objectMouseOver; 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; 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 if (isLeftClick && isBlockTrace) {
// at a block, break the block without a direct game input manipulation.
if (mc.currentScreen != null && isLeftClick && isBlockTrace) {
tryBreakBlock(trace.getBlockPos(), trace.sideHit); tryBreakBlock(trace.getBlockPos(), trace.sideHit);
didBreakLastTick = true; didBreakLastTick = true;
} else if (didBreakLastTick) { } else if (didBreakLastTick) {
stopBreakingBlock(); stopBreakingBlock();
didBreakLastTick = false; didBreakLastTick = false;
} }
return !didBreakLastTick && isLeftClick; return false; // fakeBreak is true so no matter what we aren't forcing CLICK_LEFT
} }
} }

View File

@ -43,8 +43,11 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri
*/ */
private final Map<Input, Boolean> inputForceStateMap = new HashMap<>(); private final Map<Input, Boolean> inputForceStateMap = new HashMap<>();
private final BlockBreakHelper blockBreakHelper;
public InputOverrideHandler(Baritone baritone) { public InputOverrideHandler(Baritone baritone) {
super(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) { if (event.getType() == TickEvent.Type.OUT) {
return; return;
} }
if (Baritone.settings().leftClickWorkaround.get()) { boolean stillClick = blockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT.getKeyBinding()));
boolean stillClick = BlockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT.getKeyBinding())); setInputForceState(Input.CLICK_LEFT, stillClick);
setInputForceState(Input.CLICK_LEFT, stillClick);
}
} }
} }