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:
@@ -23,7 +23,7 @@
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -373,10 +_,167 @@
|
||||
@@ -373,10 +_,166 @@
|
||||
return InteractionResult.PASS;
|
||||
} else {
|
||||
Item item = this.getItem();
|
||||
@@ -175,10 +175,9 @@
|
||||
+ }
|
||||
+
|
||||
+ // SPIGOT-1288 - play sound stripped from BlockItem
|
||||
+ if (this.item instanceof BlockItem) {
|
||||
+ if (this.item instanceof BlockItem && success.paperSuccessContext().placedBlockPosition() != null) {
|
||||
+ // Paper start - Fix spigot sound playing for BlockItem ItemStacks
|
||||
+ BlockPos pos = new net.minecraft.world.item.context.BlockPlaceContext(context).getClickedPos();
|
||||
+ net.minecraft.world.level.block.state.BlockState state = serverLevel.getBlockState(pos);
|
||||
+ net.minecraft.world.level.block.state.BlockState state = serverLevel.getBlockState(success.paperSuccessContext().placedBlockPosition());
|
||||
+ net.minecraft.world.level.block.SoundType soundType = state.getSoundType();
|
||||
+ // Paper end - Fix spigot sound playing for BlockItem ItemStacks
|
||||
+ serverLevel.playSound(player, clickedPos, soundType.getPlaceSound(), net.minecraft.sounds.SoundSource.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F);
|
||||
|
||||
Reference in New Issue
Block a user