From acd9cecd669f1ab23d28de58e542d3949e6f846d Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 11 Sep 2018 18:26:10 -0700 Subject: [PATCH] improve path safety --- .../behavior/impl/PathingBehavior.java | 10 +++++-- .../java/baritone/pathing/path/IPath.java | 29 +------------------ .../baritone/pathing/path/PathExecutor.java | 13 +++++++++ 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/main/java/baritone/behavior/impl/PathingBehavior.java b/src/main/java/baritone/behavior/impl/PathingBehavior.java index f5c81acd8..8ce34ecc5 100644 --- a/src/main/java/baritone/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/behavior/impl/PathingBehavior.java @@ -40,7 +40,7 @@ import java.awt.*; import java.util.Collections; import java.util.Optional; -public class PathingBehavior extends Behavior { +public final class PathingBehavior extends Behavior { public static final PathingBehavior INSTANCE = new PathingBehavior(); @@ -66,7 +66,7 @@ public class PathingBehavior extends Behavior { @Override public void onTick(TickEvent event) { if (event.getType() == TickEvent.Type.OUT) { - this.cancel(); + softCancel(); // no player, so can't fix capabilities return; } if (current == null) { @@ -191,11 +191,15 @@ public class PathingBehavior extends Behavior { return Optional.ofNullable(current).map(PathExecutor::getPath); } - public void cancel() { + private void softCancel() { current = null; next = null; Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); AbstractNodeCostSearch.getCurrentlyRunning().ifPresent(AbstractNodeCostSearch::cancel); + } + + public void cancel() { + softCancel(); mc.playerController.setPlayerCapabilities(mc.player); } diff --git a/src/main/java/baritone/pathing/path/IPath.java b/src/main/java/baritone/pathing/path/IPath.java index 0db487d52..575aacb14 100644 --- a/src/main/java/baritone/pathing/path/IPath.java +++ b/src/main/java/baritone/pathing/path/IPath.java @@ -58,33 +58,6 @@ public interface IPath extends Helper { return positions().size(); } - /** - * What's the next step - * - * @param currentPosition the current position - * @return - */ - default Movement subsequentMovement(BlockPos currentPosition) { - List pos = positions(); - List movements = movements(); - for (int i = 0; i < pos.size(); i++) { - if (currentPosition.equals(pos.get(i))) { - return movements.get(i); - } - } - throw new UnsupportedOperationException(currentPosition + " not in path"); - } - - /** - * Determines whether or not a position is within this path. - * - * @param pos The position to check - * @return Whether or not the specified position is in this class - */ - default boolean isInPath(BlockPos pos) { - return positions().contains(pos); - } - default Tuple closestPathPos(double x, double y, double z) { double best = -1; BlockPos bestPos = null; @@ -146,7 +119,7 @@ public interface IPath extends Helper { } double factor = Baritone.settings().pathCutoffFactor.get(); int newLength = (int) (length() * factor); - //logDebug("Static cutoff " + length() + " to " + newLength); + logDebug("Static cutoff " + length() + " to " + newLength); return new CutoffPath(this, newLength); } } diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 93e12e093..ab132ca03 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -291,6 +291,19 @@ public class PathExecutor implements Helper { } Movement movement = path.movements().get(pathPosition); if (movement instanceof MovementDescend && pathPosition < path.length() - 2) { + BlockPos descendStart = movement.getSrc(); + BlockPos descendEnd = movement.getDest(); + BlockPos into = descendEnd.subtract(descendStart.down()).add(descendEnd); + if (into.getY() != descendEnd.getY()) { + throw new IllegalStateException(); // sanity check + } + for (int i = 0; i <= 2; i++) { + if (MovementHelper.avoidWalkingInto(BlockStateInterface.getBlock(into.up(i)))) { + logDebug("Sprinting would be unsafe"); + player().setSprinting(false); + return; + } + } Movement next = path.movements().get(pathPosition + 1); if (next instanceof MovementDescend) { if (next.getDirection().equals(movement.getDirection())) {