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 not moving from edge of block #4519

Merged
merged 3 commits into from
Oct 15, 2024
Merged

Fix not moving from edge of block #4519

merged 3 commits into from
Oct 15, 2024

Conversation

babbaj
Copy link
Collaborator

@babbaj babbaj commented Oct 14, 2024

To try to keep you safe, if you are standing on the edge of a block baritone will choose to start the path on that block rather than the feet because you are standing on air. If the goal happens to also be on that block, the start will already be in the goal and A* will return no movements so baritone will not move. If that is the case then it should be safe to just path from the feet anyways.

tl;dr this fixes baritone not moving when you are on the edge of a block and the goal is in your face

more information in #209

@ZacSharp
Copy link
Collaborator

If that is the case then it should be safe to just path from the feet anyways.

No, it's not. Walking onto the supporting block should be safe, but there is no guarantee that a* will decide to do so.
E.g. if all four directions lead directly to a goal, evaluation order decides which is picked. In this video that's consistently -z even if the only safe option is +z.

2024-10-14.15-25-13.mp4

@leijurv
Copy link
Member

leijurv commented Oct 14, 2024

Thanks for checking that zac, this is the exact case that I was avoiding back in 2018. Particularly, when pathing around 2b2t spawn, it would sometimes get stuck and recalculate, meaning this could happen in the middle of a path not just at the beginning. Sometimes it would be just off the edge of a block, and so if there was no foot support underneath the first movement, it would sometimes decide to do a walk (or a parkour) that would instantly fall like that.

@babbaj
Copy link
Collaborator Author

babbaj commented Oct 14, 2024

Just pushed a completely different way to fix this buy prepending the feet position the the path if the start position is different from the feet and only 1 block away

@babbaj babbaj changed the title pathStart() = feet if we're at the goal Fix not moving from edge of block Oct 14, 2024
@leijurv
Copy link
Member

leijurv commented Oct 15, 2024

This is a much better approach I think.

If I'm understanding right, if I'm sneaking off the edge of a block, this will insert an initial movement from playerFeet to pathStart?

This solves your issue because if I'm sneaking off the edge of the goal, this will create a 1 movement long path that basically just centers the player on the block? Does that actually work though? Like will AStarPathFinder actually return an empty path, which you prepend that one movement to?

In the actual technique here, I think there might be a more elegant way:

startNode = getNodeAtPosition(startX, startY, startZ, BetterBlockPos.longHash(startX, startY, startZ));
startNode.cost = 0;
startNode.combinedCost = startNode.estimatedCostToGoal;
BinaryHeapOpenSet openSet = new BinaryHeapOpenSet();
openSet.insert(startNode);

Could there just be like a "if we are doing the fake extra movement, make a node called realStart, and do startNode.prev=realStart? That way AStar won't freak out on a path of length 0?

@babbaj
Copy link
Collaborator Author

babbaj commented Oct 15, 2024

If I'm understanding right, if I'm sneaking off the edge of a block, this will insert an initial movement from playerFeet to pathStart?

yes

I did some debugging to understand what happens and A* does return a path of 0 length. This only changes what happens after A* returns. That change would be a bit more elegant but wouldn't make any difference because the PathNodes aren't treated like a linked list after that (assembleMovements uses list indexing).

@leijurv
Copy link
Member

leijurv commented Oct 15, 2024

Okay! So, for example, in zacsharp's example gif, this version would not fall into lava, it would instead path from the supporting block around the lava to the goal, then insert a movement from the above lava position to the supporting block? So it would make like a ? shape?

If you want to do it this way, IMO that's fine. Prepending a blockpos is fine. I just think "realStart" is a bit of a vague name, but fine. Can you add a block comment somewhere explaining the idea and linking to this PR?

@babbaj
Copy link
Collaborator Author

babbaj commented Oct 15, 2024

then insert a movement from the above lava position to the supporting block? So it would make like a ? shape?

yes

I just think "realStart" is a bit of a vague name

It could be called playerAt or something but that's not the case when baritone is pathfinding ahead

@leijurv leijurv merged commit f22f4ae into cabaletta:1.19.4 Oct 15, 2024
4 checks passed
@ZacSharp
Copy link
Collaborator

Found an edge case: #4528

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants