juancarloscp52 / BedrockIfy

A Minecraft mod that implements some Minecraft Bedrock features into Java edition.
GNU General Public License v3.0
165 stars 35 forks source link

Improve reach-around parity by using raycast calculations instead of pitch equality #320

Closed axialeaa closed 2 months ago

axialeaa commented 5 months ago

Hi! I'm making this pull request to highlight a proposition for a more parity-friendly approach to the reach-around placement feature, alongside a couple of other related changes.

My main idea here is that the old pitch check for calculating whether a block is eligible for reach-around placement should be dropped in favour of a small bit of math to check if a vector drawn from the player's eyes to the end of their reach distance intersects with the block position in front of them. This is functionally more accurate (identical?) to vanilla Bedrock's implementation:

private Optional<Vec3d> getRaycastIntersection(@NotNull Entity player) {
    if (client.interactionManager == null) {
        return Optional.empty();
    }

    Vec3d rayStartPos = player.getEyePos();
    Vec3d rayEndPos = player.getRotationVec(1.0F).multiply(client.interactionManager.getReachDistance()).add(rayStartPos);

    return new Box(getFacingSteppingBlockPos(player)).raycast(rayStartPos, rayEndPos);
}

The main canReachAround() method now just returns getRaycastIntersection(player).isPresent().

One drawback of this change which may be a controversial make-or-break, is the now-obsolescence of the config options used to specify the distance and pitch requirements. The distance is handled within the raycasting math itself, so it doesn't make sense to reference it elsewhere. That being said, while writing this, I did attempt to make the raycast length customisable. However, it turned out to be far too confusing to use in my opinion as it didn't modify the functionality proportionate to the player's location on the block. I'm open to other ideas. :)

Some additional changes in this pull request:

juancarloscp52 commented 2 months ago

Hello! Sorry for the late reply! Its a great implementation! thank you so much :)

axialeaa commented 2 months ago

No, thank you!