fix blockbreakhelper toxic cloud in movement
This commit is contained in:
parent
a182c22d36
commit
527691a2ec
@ -24,14 +24,12 @@ import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.api.utils.RotationUtils;
|
||||
import baritone.api.utils.VecUtils;
|
||||
import baritone.utils.BlockBreakHelper;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.chunk.EmptyChunk;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -115,52 +113,31 @@ public abstract class Movement implements IMovement, Helper, MovementHelper {
|
||||
@Override
|
||||
public MovementStatus update() {
|
||||
player().capabilities.isFlying = false;
|
||||
MovementState latestState = updateState(currentState);
|
||||
currentState = updateState(currentState);
|
||||
if (MovementHelper.isLiquid(playerFeet())) {
|
||||
latestState.setInput(Input.JUMP, true);
|
||||
currentState.setInput(Input.JUMP, true);
|
||||
}
|
||||
if (player().isEntityInsideOpaqueBlock()) {
|
||||
latestState.setInput(Input.CLICK_LEFT, true);
|
||||
currentState.setInput(Input.CLICK_LEFT, true);
|
||||
}
|
||||
|
||||
// If the movement target has to force the new rotations, or we aren't using silent move, then force the rotations
|
||||
latestState.getTarget().getRotation().ifPresent(rotation ->
|
||||
currentState.getTarget().getRotation().ifPresent(rotation ->
|
||||
Baritone.INSTANCE.getLookBehavior().updateTarget(
|
||||
rotation,
|
||||
latestState.getTarget().hasToForceRotations()));
|
||||
currentState.getTarget().hasToForceRotations()));
|
||||
|
||||
// TODO: calculate movement inputs from latestState.getGoal().position
|
||||
// latestState.getTarget().position.ifPresent(null); NULL CONSUMER REALLY SHOULDN'T BE THE FINAL THING YOU SHOULD REALLY REPLACE THIS WITH ALMOST ACTUALLY ANYTHING ELSE JUST PLEASE DON'T LEAVE IT AS IT IS THANK YOU KANYE
|
||||
|
||||
this.didBreakLastTick = false;
|
||||
|
||||
latestState.getInputStates().forEach((input, forced) -> {
|
||||
if (Baritone.settings().leftClickWorkaround.get()) {
|
||||
RayTraceResult trace = mc.objectMouseOver;
|
||||
boolean isBlockTrace = trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK;
|
||||
boolean isLeftClick = forced && input == Input.CLICK_LEFT;
|
||||
|
||||
// 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) {
|
||||
BlockBreakHelper.tryBreakBlock(trace.getBlockPos(), trace.sideHit);
|
||||
this.didBreakLastTick = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
currentState.getInputStates().forEach((input, forced) -> {
|
||||
Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced);
|
||||
});
|
||||
latestState.getInputStates().replaceAll((input, forced) -> false);
|
||||
|
||||
if (!this.didBreakLastTick) {
|
||||
BlockBreakHelper.stopBreakingBlock();
|
||||
}
|
||||
|
||||
currentState = latestState;
|
||||
currentState.getInputStates().replaceAll((input, forced) -> false);
|
||||
|
||||
// If the current status indicates a completed movement
|
||||
if (currentState.getStatus().isComplete()) {
|
||||
onFinish(latestState);
|
||||
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
||||
}
|
||||
|
||||
return currentState.getStatus();
|
||||
@ -218,14 +195,6 @@ public abstract class Movement implements IMovement, Helper, MovementHelper {
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run cleanup on state finish and declare success.
|
||||
*/
|
||||
public void onFinish(MovementState state) {
|
||||
state.getInputStates().replaceAll((input, forced) -> false);
|
||||
state.getInputStates().forEach((input, forced) -> Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
currentState = new MovementState().setStatus(MovementStatus.PREPPING);
|
||||
|
@ -20,6 +20,7 @@ package baritone.utils;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
@ -32,6 +33,7 @@ public final class BlockBreakHelper implements Helper {
|
||||
* between attempts, then we re-initialize the breaking process.
|
||||
*/
|
||||
private static BlockPos lastBlock;
|
||||
private static boolean didBreakLastTick;
|
||||
|
||||
private BlockBreakHelper() {}
|
||||
|
||||
@ -51,4 +53,20 @@ public final class BlockBreakHelper implements Helper {
|
||||
}
|
||||
lastBlock = null;
|
||||
}
|
||||
|
||||
public static boolean tick(boolean isLeftClick) {
|
||||
RayTraceResult trace = mc.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) {
|
||||
tryBreakBlock(trace.getBlockPos(), trace.sideHit);
|
||||
didBreakLastTick = true;
|
||||
} else if (didBreakLastTick) {
|
||||
stopBreakingBlock();
|
||||
didBreakLastTick = false;
|
||||
}
|
||||
return !didBreakLastTick && isLeftClick;
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
package baritone.utils;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.event.events.TickEvent;
|
||||
import baritone.behavior.Behavior;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
@ -84,6 +85,17 @@ public final class InputOverrideHandler extends Behavior implements Helper {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onTick(TickEvent event) {
|
||||
if (event.getType() == TickEvent.Type.OUT) {
|
||||
return;
|
||||
}
|
||||
if (Baritone.settings().leftClickWorkaround.get()) {
|
||||
boolean stillClick = BlockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT.keyBinding));
|
||||
setInputForceState(Input.CLICK_LEFT, stillClick);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@link Enum} representing the possible inputs that we may want to force.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user