diff --git a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/AbstractPathJob.java b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/AbstractPathJob.java index b7fbdb9493d..f4d6239d780 100644 --- a/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/AbstractPathJob.java +++ b/src/main/java/com/minecolonies/core/entity/pathfinding/pathjobs/AbstractPathJob.java @@ -124,6 +124,11 @@ public abstract class AbstractPathJob implements Callable, IPathJob */ private PathingOptions pathingOptions = new PathingOptions(); + /** + * Whether the path reached its destination + */ + private boolean reachesDestination = false; + /** * AbstractPathJob constructor. * @@ -262,8 +267,6 @@ protected Path search() // breakpoint at which we start scoring potential ending points final double heuristicCutoff = bestNode.getHeuristic() > 0 ? bestNode.getHeuristic() / 3 : 200; - boolean isAtDestination = false; - while (!nodesToVisit.isEmpty()) { if (Thread.currentThread().isInterrupted()) @@ -281,7 +284,7 @@ protected Path search() break; } - if (isAtDestination && extraNodes > 0) + if (reachesDestination && extraNodes > 0) { extraNodes--; if (extraNodes == 0) @@ -293,9 +296,9 @@ protected Path search() handleDebugOptions(node); node.setVisited(); - if (!isAtDestination && isAtDestination(node)) + if (!reachesDestination && isAtDestination(node)) { - isAtDestination = true; + reachesDestination = true; bestNode = node; bestNodeEndScore = getEndNodeScore(node); result.setPathReachesDestination(true); @@ -318,7 +321,7 @@ protected Path search() final double nodeEndSCore = getEndNodeScore(node); if (nodeEndSCore < bestNodeEndScore) { - if (!isAtDestination || isAtDestination(node)) + if (!reachesDestination || isAtDestination(node)) { bestNode = node; bestNodeEndScore = nodeEndSCore; @@ -804,7 +807,7 @@ else if (p.isOnRails() && points.length > pathLength + 1) doDebugPrinting(points); - return new Path(Arrays.asList(points), new BlockPos(targetNode.x, targetNode.y, targetNode.z), result.isPathReachingDestination()); + return new Path(Arrays.asList(points), new BlockPos(targetNode.x, targetNode.y, targetNode.z), reachesDestination); } /**