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 block update resets for optimized paths #330

Conversation

m000z0rz
Copy link
Contributor

On a block update, the current path gets reset if the block updated is near one of the path nodes.

On optimized paths, the distance between path nodes may be significant. Checking only the path nodes themselves may mean that a block update along the line between two path nodes gets ignored when it could impact the path.

Consider a bot that farms pumpkins - after breaking many blocks and picking them up, it could try to navigate to the next part of the farm to harvest - across flat open land, this could easily be a straight line that optimizes nicely. But, a pumpkin could suddenly grow and block the bot. Currently, if the pumpkin didn't grow right at the beginning or end of that path segment, it would be ignored, and the bot may get stuck on the newly grown pumpkin.

Improve isPositionNearPath to consider the space between path nodes by comparing the given position to the closest point along the path segment instead of just the current node.

Two optimizations keep this fast:

  1. If the segment is short enough (x / y / z deltas are 2 or under) then we fall back to the previous logic where we just compare the block update position to the current node - this looks like an unoptimized path, so the old fast logic suffices.

  2. If the segment looks optimized, we first check pos against the AABB enclosing the path segment. If it isn't near the AABB, then it isn't near the segment.

On a block update, the current path gets reset if the block updated
is near one of the path nodes.

On optimized paths, the distance between path nodes may be
significant. Checking only the path nodes themselves may mean that a
block update along the line between two path nodes gets ignored when
it could impact the path.

Consider a bot that farms pumpkins - after breaking many blocks and
picking them up, it could try to navigate to the next part of the farm
to harvest - across flat open land, this could easily be a straight
line that optimizes nicely. But, a pumpkin could suddenly grow and
block the bot. Currently, if the pumpkin didn't grow right at the
beginning or end of that path segment, it would be ignored, and the
bot may get stuck on the newly grown pumpkin.

Improve isPositionNearPath to consider the space between path nodes by
comparing the given position to the closest point along the path
segment instead of just the current node.

Two optimizations keep this fast:

1) If the segment is short enough (x / y / z deltas are 2 or under)
then we fall back to the previous logic where we just compare the
block update position to the current node - this looks like an
unoptimized path, so the old fast logic suffices.

2) If the segment looks optimized, we first check pos against the AABB
enclosing the path segment. If it isn't near the AABB, then it isn't
near the segment.
@m000z0rz m000z0rz force-pushed the m000z0rz/fix-block-update-path-reset-for-optimized-paths branch from 3735646 to 93e56cf Compare August 20, 2023 23:29
@IceTank
Copy link
Collaborator

IceTank commented Aug 21, 2023

Ok looks good. I presume this also fixes a potential issue when the bot plans on making a sprint jump over a larger hole. Have you actually tried this in combination with optimized paths? I though optimizing paths was somewhat broken.

@m000z0rz
Copy link
Contributor Author

I'm not familiar with the sprint jump over a larger hole issue. I have been using this in combination with optimized paths. I've been using them mostly because they were the default, but I do really like the movement and plan to keep using it. I've seenother issues a couple other issues, but in a mostly-open open area with underground storage it's actually working quite well for me!

@IceTank IceTank merged commit 844a09e into PrismarineJS:master Aug 28, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

2 participants