diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index d7d23c59e..78c2d4b34 100644 --- a/src/main/java/baritone/Settings.java +++ b/src/main/java/baritone/Settings.java @@ -185,7 +185,12 @@ public class Settings { /** * Pathing can never take longer than this */ - public Setting pathTimeoutMS = new Setting<>(4000L); + public Setting pathTimeoutMS = new Setting<>(2000L); + + /** + * Planning ahead while executing a segment can never take longer than this + */ + public Setting planAheadTimeoutMS = new Setting<>(4000L); /** * For debugging, consider nodes much much slower diff --git a/src/main/java/baritone/behavior/impl/PathingBehavior.java b/src/main/java/baritone/behavior/impl/PathingBehavior.java index 075d8d6f4..fa651a87f 100644 --- a/src/main/java/baritone/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/behavior/impl/PathingBehavior.java @@ -324,9 +324,15 @@ public class PathingBehavior extends Behavior { goal = new GoalXZ(pos.getX(), pos.getZ()); } } + long timeout; + if (current == null) { + timeout = Baritone.settings().pathTimeoutMS.get(); + } else { + timeout = Baritone.settings().planAheadTimeoutMS.get(); + } try { IPathFinder pf = new AStarPathFinder(start, goal, previous.map(IPath::positions)); - return pf.calculate(); + return pf.calculate(timeout); } catch (Exception e) { displayChatMessageRaw("Pathing exception: " + e); e.printStackTrace(); diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 0af6f0feb..fa8b5076e 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -55,7 +55,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { } @Override - protected Optional calculate0() { + protected Optional calculate0(long timeout) { startNode = getNodeAtPosition(start); startNode.cost = 0; startNode.combinedCost = startNode.estimatedCostToGoal; @@ -74,7 +74,10 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { ChunkProviderClient chunkProvider = Minecraft.getMinecraft().world.getChunkProvider(); long startTime = System.nanoTime() / 1000000L; boolean slowPath = Baritone.settings().slowPath.get(); - long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS : Baritone.settings().pathTimeoutMS).get(); + if (slowPath) { + displayChatMessageRaw("slowPath is on, path timeout will be " + Baritone.settings().slowPathTimeoutMS.get() + "ms instead of " + timeout + "ms"); + } + long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS.get() : timeout); //long lastPrintout = 0; int numNodes = 0; int numMovementsConsidered = 0; diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index 3960a376f..5804cb1a0 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -76,13 +76,13 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { cancelRequested = true; } - public synchronized Optional calculate() { + public synchronized Optional calculate(long timeout) { if (isFinished) { throw new IllegalStateException("Path Finder is currently in use, and cannot be reused!"); } this.cancelRequested = false; try { - Optional path = calculate0(); + Optional path = calculate0(timeout); isFinished = true; return path; } catch (Exception e) { @@ -96,7 +96,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { } } - protected abstract Optional calculate0(); + protected abstract Optional calculate0(long timeout); /** * Determines the distance squared from the specified node to the start diff --git a/src/main/java/baritone/pathing/calc/IPathFinder.java b/src/main/java/baritone/pathing/calc/IPathFinder.java index bbcc7bda4..dceee65df 100644 --- a/src/main/java/baritone/pathing/calc/IPathFinder.java +++ b/src/main/java/baritone/pathing/calc/IPathFinder.java @@ -39,7 +39,7 @@ public interface IPathFinder { * * @return The final path */ - Optional calculate(); + Optional calculate(long timeout); /** * Intended to be called concurrently with calculatePath from a different thread to tell if it's finished yet