From a7a3da8802afca9ec7bc952d95d8b14a3551448e Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Thu, 23 Feb 2023 10:37:28 +0100 Subject: [PATCH] Avoid duplicate game event on initial fill (#8887) --- ...-CauldronLevelChange-on-initial-fill.patch | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/patches/server/Fire-CauldronLevelChange-on-initial-fill.patch b/patches/server/Fire-CauldronLevelChange-on-initial-fill.patch index d654e93456..e631e1e3ca 100644 --- a/patches/server/Fire-CauldronLevelChange-on-initial-fill.patch +++ b/patches/server/Fire-CauldronLevelChange-on-initial-fill.patch @@ -16,7 +16,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 if (precipitation == Biome.Precipitation.RAIN) { - world.setBlockAndUpdate(pos, Blocks.WATER_CAULDRON.defaultBlockState()); + // Paper start - call event for initial fill -+ if (!LayeredCauldronBlock.changeLevel(state, world, pos, Blocks.WATER_CAULDRON.defaultBlockState(), null, CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL)) { ++ if (!LayeredCauldronBlock.changeLevel(state, world, pos, Blocks.WATER_CAULDRON.defaultBlockState(), null, CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL, false)) { // avoid duplicate game event + return; + } + // Paper end @@ -24,7 +24,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } else if (precipitation == Biome.Precipitation.SNOW) { - world.setBlockAndUpdate(pos, Blocks.POWDER_SNOW_CAULDRON.defaultBlockState()); + // Paper start - call event for initial fill -+ if (!LayeredCauldronBlock.changeLevel(state, world, pos, Blocks.POWDER_SNOW_CAULDRON.defaultBlockState(), null, CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL)) { ++ if (!LayeredCauldronBlock.changeLevel(state, world, pos, Blocks.POWDER_SNOW_CAULDRON.defaultBlockState(), null, CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL, false)) { // avoid duplicate game event + return; + } + // Paper end @@ -62,7 +62,22 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 // CraftBukkit start - public static boolean changeLevel(BlockState iblockdata, Level world, BlockPos blockposition, BlockState newBlock, Entity entity, CauldronLevelChangeEvent.ChangeReason reason) { ++ // Paper start + public static boolean changeLevel(BlockState iblockdata, Level world, BlockPos blockposition, BlockState newBlock, @javax.annotation.Nullable Entity entity, CauldronLevelChangeEvent.ChangeReason reason) { // Paper - entity is nullable ++ return changeLevel(iblockdata, world, blockposition, newBlock, entity, reason, true); ++ } ++ ++ public static boolean changeLevel(BlockState iblockdata, Level world, BlockPos blockposition, BlockState newBlock, @javax.annotation.Nullable Entity entity, CauldronLevelChangeEvent.ChangeReason reason, boolean sendGameEvent) { // Paper - entity is nullable ++ // Paper end CraftBlockState newState = CraftBlockStates.getBlockState(world, blockposition); newState.setData(newBlock); +@@ -0,0 +0,0 @@ public class LayeredCauldronBlock extends AbstractCauldronBlock { + return false; + } + newState.update(true); +- world.gameEvent(GameEvent.BLOCK_CHANGE, blockposition, GameEvent.Context.of(newBlock)); ++ if (sendGameEvent) world.gameEvent(GameEvent.BLOCK_CHANGE, blockposition, GameEvent.Context.of(newBlock)); // Paper + return true; + } + // CraftBukkit end