fix pathfinding repathNode issue (#2330)

This commit is contained in:
iam 2024-08-14 00:28:25 -04:00 committed by GitHub
parent d47db68950
commit 0651c4e401
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View File

@ -35,7 +35,7 @@ public final class Navigator {
private double minimumDistance;
NodeGenerator nodeGenerator = new GroundNodeGenerator();
NodeGenerator nodeGenerator = new GroundNodeGenerator();
private NodeFollower nodeFollower;
public Navigator(@NotNull Entity entity) {

View File

@ -16,7 +16,6 @@ import java.util.concurrent.Executors;
public class PathGenerator {
private static final ExecutorService pool = Executors.newWorkStealingPool();
private static final PNode repathNode = new PNode(0, 0, 0, 0, 0, PNode.NodeType.REPATH, null);
private static final Comparator<PNode> pNodeComparator = (s1, s2) -> (int) (((s1.g() + s1.h()) - (s2.g() + s2.h())) * 1000);
public static @NotNull PPath generate(@NotNull Instance instance, @NotNull Pos orgStart, @NotNull Point orgTarget, double closeDistance, double maxDistance, double pathVariance, @NotNull BoundingBox boundingBox, boolean isOnGround, @NotNull NodeGenerator generator, @Nullable Runnable onComplete) {
@ -34,6 +33,10 @@ public class PathGenerator {
return path;
}
private static PNode buildRepathNode(PNode parent) {
return new PNode(0, 0, 0, 0, 0, PNode.NodeType.REPATH, parent);
}
private static void computePath(Instance instance, Point start, Point target, double closeDistance, double maxDistance, double pathVariance, BoundingBox boundingBox, PPath path, NodeGenerator generator) {
double closestDistance = Double.MAX_VALUE;
double straightDistance = generator.heuristic(start, target);
@ -93,8 +96,7 @@ public class PathGenerator {
current = closestFoundNodes.get(0);
if (!open.isEmpty()) {
repathNode.setParent(current);
current = repathNode;
current = buildRepathNode(current);
}
}