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.Rotation;
|
||||||
import baritone.api.utils.RotationUtils;
|
import baritone.api.utils.RotationUtils;
|
||||||
import baritone.api.utils.VecUtils;
|
import baritone.api.utils.VecUtils;
|
||||||
import baritone.utils.BlockBreakHelper;
|
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.Helper;
|
import baritone.utils.Helper;
|
||||||
import baritone.utils.InputOverrideHandler;
|
import baritone.utils.InputOverrideHandler;
|
||||||
import net.minecraft.block.BlockLiquid;
|
import net.minecraft.block.BlockLiquid;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
|
||||||
import net.minecraft.world.chunk.EmptyChunk;
|
import net.minecraft.world.chunk.EmptyChunk;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -115,52 +113,31 @@ public abstract class Movement implements IMovement, Helper, MovementHelper {
|
|||||||
@Override
|
@Override
|
||||||
public MovementStatus update() {
|
public MovementStatus update() {
|
||||||
player().capabilities.isFlying = false;
|
player().capabilities.isFlying = false;
|
||||||
MovementState latestState = updateState(currentState);
|
currentState = updateState(currentState);
|
||||||
if (MovementHelper.isLiquid(playerFeet())) {
|
if (MovementHelper.isLiquid(playerFeet())) {
|
||||||
latestState.setInput(Input.JUMP, true);
|
currentState.setInput(Input.JUMP, true);
|
||||||
}
|
}
|
||||||
if (player().isEntityInsideOpaqueBlock()) {
|
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
|
// 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(
|
Baritone.INSTANCE.getLookBehavior().updateTarget(
|
||||||
rotation,
|
rotation,
|
||||||
latestState.getTarget().hasToForceRotations()));
|
currentState.getTarget().hasToForceRotations()));
|
||||||
|
|
||||||
// TODO: calculate movement inputs from latestState.getGoal().position
|
// 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
|
// 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;
|
currentState.getInputStates().forEach((input, forced) -> {
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced);
|
Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced);
|
||||||
});
|
});
|
||||||
latestState.getInputStates().replaceAll((input, forced) -> false);
|
currentState.getInputStates().replaceAll((input, forced) -> false);
|
||||||
|
|
||||||
if (!this.didBreakLastTick) {
|
|
||||||
BlockBreakHelper.stopBreakingBlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
currentState = latestState;
|
|
||||||
|
|
||||||
// If the current status indicates a completed movement
|
// If the current status indicates a completed movement
|
||||||
if (currentState.getStatus().isComplete()) {
|
if (currentState.getStatus().isComplete()) {
|
||||||
onFinish(latestState);
|
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentState.getStatus();
|
return currentState.getStatus();
|
||||||
@ -218,14 +195,6 @@ public abstract class Movement implements IMovement, Helper, MovementHelper {
|
|||||||
return dest;
|
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
|
@Override
|
||||||
public void reset() {
|
public void reset() {
|
||||||
currentState = new MovementState().setStatus(MovementStatus.PREPPING);
|
currentState = new MovementState().setStatus(MovementStatus.PREPPING);
|
||||||
|
@ -20,6 +20,7 @@ package baritone.utils;
|
|||||||
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;
|
||||||
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Brady
|
* @author Brady
|
||||||
@ -32,6 +33,7 @@ public final class BlockBreakHelper implements Helper {
|
|||||||
* between attempts, then we re-initialize the breaking process.
|
* between attempts, then we re-initialize the breaking process.
|
||||||
*/
|
*/
|
||||||
private static BlockPos lastBlock;
|
private static BlockPos lastBlock;
|
||||||
|
private static boolean didBreakLastTick;
|
||||||
|
|
||||||
private BlockBreakHelper() {}
|
private BlockBreakHelper() {}
|
||||||
|
|
||||||
@ -48,7 +50,23 @@ public final class BlockBreakHelper implements Helper {
|
|||||||
public static void stopBreakingBlock() {
|
public static void stopBreakingBlock() {
|
||||||
if (mc.playerController != null) {
|
if (mc.playerController != null) {
|
||||||
mc.playerController.resetBlockRemoving();
|
mc.playerController.resetBlockRemoving();
|
||||||
}
|
}
|
||||||
lastBlock = null;
|
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;
|
package baritone.utils;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
|
import baritone.api.event.events.TickEvent;
|
||||||
import baritone.behavior.Behavior;
|
import baritone.behavior.Behavior;
|
||||||
import net.minecraft.client.settings.KeyBinding;
|
import net.minecraft.client.settings.KeyBinding;
|
||||||
import org.lwjgl.input.Keyboard;
|
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.
|
* An {@link Enum} representing the possible inputs that we may want to force.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user