Fix block update resets for optimized paths #330
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.
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.