Skip to content

Fix BetterBlockPos leaking into block entity map, fixes #4307#4999

Closed
mankool0 wants to merge 1 commit into
cabaletta:1.21.11from
mankool0:betterblockpos-leak-fix
Closed

Fix BetterBlockPos leaking into block entity map, fixes #4307#4999
mankool0 wants to merge 1 commit into
cabaletta:1.21.11from
mankool0:betterblockpos-leak-fix

Conversation

@mankool0

@mankool0 mankool0 commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

In these cases minecraft's functions getShape and getCollisionShape get called with BetterBlockPos and minecrafts block entity map doesn't contain that position yet then you'll get a crash.

The reachable function has a leak in BuilderProcess::toBreakNearPlayer:

if (!(curr.getBlock() instanceof AirBlock) && !(curr.getBlock() == Blocks.WATER || curr.getBlock() == Blocks.LAVA) && !valid(curr, desired, false)) {
    BetterBlockPos pos = new BetterBlockPos(x, y, z);
    Optional<Rotation> rot = RotationUtils.reachable(ctx, pos, ctx.playerController().getBlockReachDistance());
    if (rot.isPresent()) {
        return Optional.of(new Tuple<>(pos, rot.get()));
    }
}

And calculateBlockCenter has a leak in MovementTraverse::updateState as dest is protected final BetterBlockPos dest;:

// combine the yaw to the center of the destination, and the pitch to the specific block we're trying to break
// it's safe to do this since the two blocks we break (in a traverse) are right on top of each other and so will have the same yaw
float yawToDest = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.calculateBlockCenter(ctx.world(), dest), ctx.playerRotations()).getYaw();

This fixes issue #4307

@ZacSharp ZacSharp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Feel like #4501 would be more correct, but it's been sitting long enough, so might as well try to get this one in.

@ZacSharp

Copy link
Copy Markdown
Collaborator

Me is stupid, and did not notice you were pring this against 1.21.11. The dev branch is still 1.19.4 and will be 1.21.4 (probably once Unimined 1.4.2 releases) so you should target this at either of those branches (preferably 1.19.4, if possible).

@mankool0

Copy link
Copy Markdown
Contributor Author

Sounds good, I'll make a new pr for 1.19.4. I just looked and saw that this was the most recently updated one, and thought it was the correct one.

@mankool0

Copy link
Copy Markdown
Contributor Author

Closing in favor of the 1.19.4 branch PR #5006

@mankool0 mankool0 closed this Apr 20, 2026
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.

2 participants