Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix loops in path #4532

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions src/main/java/baritone/pathing/calc/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,12 @@ class Path extends PathBase {
private volatile boolean verified;

Path(BetterBlockPos realStart, PathNode start, PathNode end, int numNodes, Goal goal, CalculationContext context) {
this.start = realStart;
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<BetterBlockPos> tempPath = new ArrayList<>();
List<PathNode> tempNodes = new ArrayList<>();
Expand All @@ -94,6 +84,22 @@ 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,
// and A* gave us no movements, then add a fake node that will allow a movement to be created
// that gets us to the single position in the path.
// 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) && start.equals(end)) {
this.start = realStart;
PathNode fakeNode = new PathNode(realStart.x, realStart.y, realStart.z, goal);
fakeNode.cost = 0;
tempNodes.add(fakeNode);
tempPath.add(realStart);
} else {
this.start = startNodePos;
}

// Nodes are traversed last to first so we need to reverse the list
this.path = Lists.reverse(tempPath);
this.nodes = Lists.reverse(tempNodes);
Expand Down