Use correct placed block position for sound (#12410)

Previously the server attempted to compute the block placed by using the
BlockPlaceContext. This approach however fails on replacable blocks, as
the BlockPlaceContext computes this during its construction, which
happened after the actual world modification.

The commit reworks this approach and now stores metadata in the
InteractionResult which can later be read.
The diff is structured to allow for easy future expansion of the tracked
metadata.
This commit is contained in:
Bjarne Koll
2025-04-27 14:19:42 +02:00
committed by GitHub
parent f8fa4f6f5e
commit b9d3147d3b
4 changed files with 55 additions and 7 deletions

View File

@@ -56,6 +56,15 @@
level.playSound(
player,
clickedPos,
@@ -88,7 +_,7 @@
);
level.gameEvent(GameEvent.BLOCK_PLACE, clickedPos, GameEvent.Context.of(player, blockState));
itemInHand.consume(1, player);
- return InteractionResult.SUCCESS;
+ return InteractionResult.SUCCESS.configurePaper(e -> e.placedBlockAt(clickedPos.immutable())); // Paper - track placed block position from block item
}
}
}
@@ -137,8 +_,19 @@
protected boolean canPlace(BlockPlaceContext context, BlockState state) {