-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix block visibility calculation using canSeeBlock(block) function #3730
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
base: master
Are you sure you want to change the base?
Fix block visibility calculation using canSeeBlock(block) function #3730
Conversation
…y check logic in `canSeeBlock` function.
Changes: New
Enhanced
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation seems quite inefficient if you're doing multiple raycast within the loop. Also this should likely be implemented in prismarine-world
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes block visibility calculation in the canSeeBlock
function by ensuring distance calculations use the block's center point rather than its corner. The change aligns the distance measurement with the direction vector used in raycasting, resolving visibility detection issues where blocks should be visible but the check fails.
Key changes:
- Updated distance calculation to use block center coordinates (offset by 0.5, 0.5, 0.5)
- Added comprehensive face-based visibility checking as fallback
- Introduced helper function for determining visible block faces
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
…culation to block faces for code clarity.
Performance considerations: Example:
Yes, this algorithm uses 2 additional raycasts. This is 2x slower, but in the context of bot operation where it can take 5 seconds to find a path to a block, this is negligible compared to the benefits this method provides. Also, I couldn't find any mention of something similar in prismarine-world or any other module. I can add an optional |
Changes:
Changed distance calculation from block.position to block.position.offset(0.5, 0.5, 0.5)
The blue line represents the distance calculation to the block's corner (block.position), while the red line shows the direction vector to the block's center (block.position.offset(0.5, 0.5, 0.5)).
The Issue:
When the raycast checks if the bot can see the block along the red path, it uses the distance from the blue line. However, this distance is calculated to the wrong point (corner instead of center), causing the raycast to fail even when the block should be visible.
The Fix:
By changing the distance calculation to block.position.offset(0.5, 0.5, 0.5), we now measure the distance to the block's center, which aligns with the direction vector used in the raycast. This ensures that the distance and direction calculations are consistent, allowing the visibility check to work correctly.