diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index e596df14..a23401dc 100644 --- a/src/main/java/baritone/Settings.java +++ b/src/main/java/baritone/Settings.java @@ -147,6 +147,13 @@ public class Settings { */ public Setting maxFallHeightBucket = new Setting<>(20); + /** + * Is it okay to sprint through a descend followed by a diagonal? + * The player overshoots the landing, but not enough to fall off. And the diagonal ensures that there isn't + * lava or anything that's !canWalkInto in that space, so it's technically safe, just a little sketchy. + */ + public Setting allowOvershootDiagonalDescend = new Setting<>(true); + /** * If your goal is a GoalBlock in an unloaded chunk, assume it's far enough away that the Y coord * doesn't matter yet, and replace it with a GoalXZ to the same place before calculating a path. diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 27cbb08e..5a3f26f5 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -104,7 +104,6 @@ public abstract class Movement implements Helper, MovementHelper { * @return Status */ public MovementStatus update() { - player().setSprinting(false); MovementState latestState = updateState(currentState); if (BlockStateInterface.isLiquid(playerFeet())) { latestState.setInput(Input.JUMP, true); @@ -269,6 +268,10 @@ public abstract class Movement implements Helper, MovementHelper { return state; } + public BlockPos getDirection() { + return getDest().subtract(getSrc()); + } + public List toBreakCached = null; public List toPlaceCached = null; public List toWalkIntoCached = null; diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 34c65ae6..fd033b78 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -158,7 +158,7 @@ public interface MovementHelper extends ActionCosts, Helper { return true; } - return (facing == playerFacing) == open; + return facing == playerFacing == open; } static boolean avoidWalkingInto(Block block) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 7bde41c7..cd29bdbf 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -17,12 +17,12 @@ package baritone.pathing.movement.movements; -import baritone.Baritone; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.utils.BlockStateInterface; +import baritone.utils.InputOverrideHandler; import net.minecraft.block.BlockMagma; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; @@ -65,8 +65,8 @@ public class MovementDiagonal extends Movement { state.setStatus(MovementState.MovementStatus.SUCCESS); return state; } - if (!BlockStateInterface.isLiquid(playerFeet()) && Baritone.settings().allowSprint.get()) { - player().setSprinting(true); + if (!BlockStateInterface.isLiquid(playerFeet())) { + state.setInput(InputOverrideHandler.Input.SPRINT, true); } MovementHelper.moveTowards(state, dest); return state; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index e92fc527..20b284e6 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -17,7 +17,6 @@ package baritone.pathing.movement.movements; -import baritone.Baritone; import baritone.behavior.impl.LookBehaviorUtils; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; @@ -190,8 +189,8 @@ public class MovementTraverse extends Movement { state.setStatus(MovementState.MovementStatus.SUCCESS); return state; } - if (wasTheBridgeBlockAlwaysThere && !BlockStateInterface.isLiquid(playerFeet()) && Baritone.settings().allowSprint.get()) { - player().setSprinting(true); + if (wasTheBridgeBlockAlwaysThere && !BlockStateInterface.isLiquid(playerFeet())) { + state.setInput(InputOverrideHandler.Input.SPRINT, true); } Block destDown = BlockStateInterface.get(dest.down()).getBlock(); if (ladder && (destDown instanceof BlockVine || destDown instanceof BlockLadder)) { diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 88a7126c..210544c4 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -22,6 +22,9 @@ import baritone.event.events.TickEvent; import baritone.pathing.movement.ActionCosts; import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementState; +import baritone.pathing.movement.movements.MovementDescend; +import baritone.pathing.movement.movements.MovementDiagonal; +import baritone.pathing.movement.movements.MovementTraverse; import baritone.utils.BlockStateInterface; import baritone.utils.Helper; import net.minecraft.client.entity.EntityPlayerSP; @@ -228,6 +231,7 @@ public class PathExecutor implements Helper { onTick(event); return true; } else { + sprintIfRequested(); ticksOnCurrent++; if (ticksOnCurrent > currentMovementInitialCostEstimate + Baritone.settings().movementTimeoutTicks.get()) { // only fail if the total time has exceeded the initial estimate @@ -245,6 +249,59 @@ public class PathExecutor implements Helper { return false; // movement is in progress } + private void sprintIfRequested() { + if (!Baritone.settings().allowSprint.get()) { + player().setSprinting(false); + return; + } + if (Baritone.INSTANCE.getInputOverrideHandler().isInputForcedDown(mc.gameSettings.keyBindSprint)) { + if (!player().isSprinting()) { + player().setSprinting(true); + } + return; + } + Movement movement = path.movements().get(pathPosition); + if (movement instanceof MovementDescend && pathPosition < path.length() - 2) { + Movement next = path.movements().get(pathPosition + 1); + if (next instanceof MovementDescend) { + if (next.getDirection().equals(movement.getDirection())) { + if (playerFeet().equals(movement.getDest())) { + pathPosition++; + Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); + } + if (!player().isSprinting()) { + player().setSprinting(true); + } + return; + } + } + if (next instanceof MovementTraverse) { + if (next.getDirection().down().equals(movement.getDirection())) { + if (playerFeet().equals(movement.getDest())) { + pathPosition++; + Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); + } + if (!player().isSprinting()) { + player().setSprinting(true); + } + return; + } + } + if (next instanceof MovementDiagonal && Baritone.settings().allowOvershootDiagonalDescend.get()) { + if (playerFeet().equals(movement.getDest())) { + pathPosition++; + Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); + } + if (!player().isSprinting()) { + player().setSprinting(true); + } + return; + } + displayChatMessageRaw("Turning off sprinting " + movement + " " + next + " " + movement.getDirection() + " " + next.getDirection().down() + " " + next.getDirection().down().equals(movement.getDirection())); + } + player().setSprinting(false); + } + public int getPosition() { return pathPosition; }