From d644c5b75401f6b7326caa99034e3363c24c8ae0 Mon Sep 17 00:00:00 2001 From: Babbaj Date: Tue, 15 Oct 2024 18:56:46 -0400 Subject: [PATCH] a bit more elegant --- src/main/java/baritone/pathing/calc/Path.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/Path.java b/src/main/java/baritone/pathing/calc/Path.java index b749dff64..0c5dda00f 100644 --- a/src/main/java/baritone/pathing/calc/Path.java +++ b/src/main/java/baritone/pathing/calc/Path.java @@ -71,12 +71,21 @@ class Path extends PathBase { Path(BetterBlockPos realStart, PathNode start, PathNode end, int numNodes, Goal goal, CalculationContext context) { this.start = realStart; - var startNodePos = new BetterBlockPos(start.x, start.y, start.z); this.end = new BetterBlockPos(end.x, end.y, end.z); this.numNodes = numNodes; this.movements = new ArrayList<>(); this.goal = goal; this.context = context; + + // If the position the player is at is different from the position we told A* to start from + // see PathingBehavior#createPathfinder and https://github.com/cabaletta/baritone/pull/4519 + var startNodePos = new BetterBlockPos(start.x, start.y, start.z); + if (!realStart.equals(startNodePos)) { + PathNode fakeNode = new PathNode(realStart.x, realStart.y, realStart.z, goal); + fakeNode.cost = 0; + start.previous = fakeNode; + } + PathNode current = end; List tempPath = new ArrayList<>(); List tempNodes = new ArrayList<>(); @@ -85,13 +94,6 @@ class Path extends PathBase { tempPath.add(new BetterBlockPos(current.x, current.y, current.z)); current = current.previous; } - // If the position the player is at is different from the position we told A* to start from - if (!realStart.equals(startNodePos)) { - PathNode fakeNode = new PathNode(realStart.x, realStart.y, realStart.z, goal); - fakeNode.cost = 0; - tempNodes.add(fakeNode); - tempPath.add(realStart); - } // Nodes are traversed last to first so we need to reverse the list this.path = Lists.reverse(tempPath); this.nodes = Lists.reverse(tempNodes);