From 7b4afa8b825c606f08219b823a0b1a7df5ac9d09 Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Sun, 15 Dec 2024 17:27:16 +0100 Subject: [PATCH] readd EntityInsideBlockEvent for pitcher crop --- .../cauldron/CauldronInteraction.java.patch | 8 +++--- .../level/block/CauldronBlock.java.patch | 8 +++--- .../world/level/block/CommandBlock.java.patch | 2 +- .../level/block/DetectorRailBlock.java.patch | 2 +- .../level/block/DragonEggBlock.java.patch | 10 +++---- .../world/level/block/FireBlock.java.patch | 2 +- .../block/LayeredCauldronBlock.java.patch | 28 ++++++------------- .../level/block/PitcherCropBlock.java.patch | 8 ++++++ 8 files changed, 32 insertions(+), 36 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/core/cauldron/CauldronInteraction.java.patch b/paper-server/patches/sources/net/minecraft/core/cauldron/CauldronInteraction.java.patch index 46043286c6..a6f2415f52 100644 --- a/paper-server/patches/sources/net/minecraft/core/cauldron/CauldronInteraction.java.patch +++ b/paper-server/patches/sources/net/minecraft/core/cauldron/CauldronInteraction.java.patch @@ -23,7 +23,7 @@ if (potionContents != null && potionContents.is(Potions.WATER)) { if (!level.isClientSide) { + // CraftBukkit start -+ if (!LayeredCauldronBlock.changeLevel(state, level, pos, Blocks.WATER_CAULDRON.defaultBlockState(), player, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.BOTTLE_EMPTY, false)) { // Paper - Call CauldronLevelChangeEvent ++ if (!LayeredCauldronBlock.changeLevel(level, pos, Blocks.WATER_CAULDRON.defaultBlockState(), player, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.BOTTLE_EMPTY, false)) { // Paper - Call CauldronLevelChangeEvent + return InteractionResult.SUCCESS; + } + // CraftBukkit end @@ -82,7 +82,7 @@ if (potionContents != null && potionContents.is(Potions.WATER)) { if (!level.isClientSide) { + // CraftBukkit start -+ if (!LayeredCauldronBlock.changeLevel(state, level, pos, state.cycle(LayeredCauldronBlock.LEVEL), player, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.BOTTLE_EMPTY, false)) { // Paper - Call CauldronLevelChangeEvent ++ if (!LayeredCauldronBlock.changeLevel(level, pos, state.cycle(LayeredCauldronBlock.LEVEL), player, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.BOTTLE_EMPTY, false)) { // Paper - Call CauldronLevelChangeEvent + return InteractionResult.SUCCESS; + } + // CraftBukkit end @@ -145,7 +145,7 @@ + } + // Paper end - fire PlayerBucketFillEvent + // CraftBukkit start -+ if (!LayeredCauldronBlock.changeLevel(state, level, pos, Blocks.CAULDRON.defaultBlockState(), player, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.BUCKET_FILL, false)) { // Paper - Call CauldronLevelChangeEvent ++ if (!LayeredCauldronBlock.changeLevel(level, pos, Blocks.CAULDRON.defaultBlockState(), player, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.BUCKET_FILL, false)) { // Paper - Call CauldronLevelChangeEvent + return InteractionResult.SUCCESS; + } + // CraftBukkit end @@ -179,7 +179,7 @@ + } + // Paper end - fire PlayerBucketEmptyEvent + // CraftBukkit start -+ if (!LayeredCauldronBlock.changeLevel(state, level, pos, state, player, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.BUCKET_EMPTY, false)) { // Paper - Call CauldronLevelChangeEvent ++ if (!LayeredCauldronBlock.changeLevel(level, pos, state, player, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.BUCKET_EMPTY, false)) { // Paper - Call CauldronLevelChangeEvent + return InteractionResult.SUCCESS; + } + // CraftBukkit end diff --git a/paper-server/patches/sources/net/minecraft/world/level/block/CauldronBlock.java.patch b/paper-server/patches/sources/net/minecraft/world/level/block/CauldronBlock.java.patch index e420669453..84db4f9fcc 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/block/CauldronBlock.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/block/CauldronBlock.java.patch @@ -5,7 +5,7 @@ if (shouldHandlePrecipitation(level, precipitation)) { if (precipitation == Biome.Precipitation.RAIN) { + // Paper start - Call CauldronLevelChangeEvent -+ if (!LayeredCauldronBlock.changeLevel(state, level, pos, Blocks.WATER_CAULDRON.defaultBlockState(), null, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL, false)) { // avoid duplicate game event ++ if (!LayeredCauldronBlock.changeLevel(level, pos, Blocks.WATER_CAULDRON.defaultBlockState(), null, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL, false)) { // avoid duplicate game event + return; + } + // Paper end - Call CauldronLevelChangeEvent @@ -13,7 +13,7 @@ level.gameEvent(null, GameEvent.BLOCK_CHANGE, pos); } else if (precipitation == Biome.Precipitation.SNOW) { + // Paper start - Call CauldronLevelChangeEvent -+ if (!LayeredCauldronBlock.changeLevel(state, level, pos, Blocks.POWDER_SNOW_CAULDRON.defaultBlockState(), null, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL, false)) { // avoid duplicate game event ++ if (!LayeredCauldronBlock.changeLevel(level, pos, Blocks.POWDER_SNOW_CAULDRON.defaultBlockState(), null, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL, false)) { // avoid duplicate game event + return; + } + // Paper end - Call CauldronLevelChangeEvent @@ -27,7 +27,7 @@ - level.setBlockAndUpdate(pos, blockState); - level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(blockState)); + // Paper start - Call CauldronLevelChangeEvent; don't send level event or game event if cancelled -+ if (!LayeredCauldronBlock.changeLevel(state, level, pos, blockState, null, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL)) { // CraftBukkit ++ if (!LayeredCauldronBlock.changeLevel(level, pos, blockState, null, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL)) { // CraftBukkit + return; + } + // Paper end - Call CauldronLevelChangeEvent @@ -37,7 +37,7 @@ - level.setBlockAndUpdate(pos, blockState); - level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(blockState)); + // Paper start - Call CauldronLevelChangeEvent; don't send level event or game event if cancelled -+ if (!LayeredCauldronBlock.changeLevel(state, level, pos, blockState, null, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL)) { // CraftBukkit ++ if (!LayeredCauldronBlock.changeLevel(level, pos, blockState, null, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL)) { // CraftBukkit + return; + } + // Paper end - Call CauldronLevelChangeEvent diff --git a/paper-server/patches/sources/net/minecraft/world/level/block/CommandBlock.java.patch b/paper-server/patches/sources/net/minecraft/world/level/block/CommandBlock.java.patch index f285e643af..a1cc0188d9 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/block/CommandBlock.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/block/CommandBlock.java.patch @@ -21,7 +21,7 @@ protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) { BlockEntity blockEntity = level.getBlockEntity(pos); - if (blockEntity instanceof CommandBlockEntity && player.canUseGameMasterBlocks()) { -+ if (blockEntity instanceof CommandBlockEntity && (player.canUseGameMasterBlocks() || (player.isCreative() && player.getBukkitEntity().hasPermission("minecraft.commandblock")))) { // Paper - command block permission ++ if (blockEntity instanceof CommandBlockEntity && (player.canUseGameMasterBlocks() || (player.isCreative() && player.getBukkitEntity().hasPermission("minecraft.commandblock")))) { // Paper - command block permission player.openCommandBlock((CommandBlockEntity)blockEntity); return InteractionResult.SUCCESS; } else { diff --git a/paper-server/patches/sources/net/minecraft/world/level/block/DetectorRailBlock.java.patch b/paper-server/patches/sources/net/minecraft/world/level/block/DetectorRailBlock.java.patch index 3dcaa1506e..d65731b15f 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/block/DetectorRailBlock.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/block/DetectorRailBlock.java.patch @@ -12,7 +12,7 @@ private void checkPressed(Level level, BlockPos pos, BlockState state) { if (this.canSurvive(state, level, pos)) { -+ if (state.getBlock() != this) { return; } // Paper - Fix some rails connecting improperly ++ if (!state.is(this)) { return; } // Paper - Fix some rails connecting improperly boolean poweredValue = state.getValue(POWERED); boolean flag = false; List interactingMinecartOfType = this.getInteractingMinecartOfType(level, pos, AbstractMinecart.class, entity -> true); diff --git a/paper-server/patches/sources/net/minecraft/world/level/block/DragonEggBlock.java.patch b/paper-server/patches/sources/net/minecraft/world/level/block/DragonEggBlock.java.patch index 4d35f93eec..235b049f77 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/block/DragonEggBlock.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/block/DragonEggBlock.java.patch @@ -1,16 +1,14 @@ --- a/net/minecraft/world/level/block/DragonEggBlock.java +++ b/net/minecraft/world/level/block/DragonEggBlock.java -@@ -55,6 +_,18 @@ +@@ -55,6 +_,16 @@ level.random.nextInt(16) - level.random.nextInt(16) ); if (level.getBlockState(blockPos).isAir() && worldBorder.isWithinBounds(blockPos)) { + // CraftBukkit start -+ org.bukkit.block.Block from = level.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()); -+ org.bukkit.block.Block to = level.getWorld().getBlockAt(blockPos.getX(), blockPos.getY(), blockPos.getZ()); ++ org.bukkit.block.Block from = org.bukkit.craftbukkit.block.CraftBlock.at(level, pos); ++ org.bukkit.block.Block to = org.bukkit.craftbukkit.block.CraftBlock.at(level, blockPos); + org.bukkit.event.block.BlockFromToEvent event = new org.bukkit.event.block.BlockFromToEvent(from, to); -+ org.bukkit.Bukkit.getPluginManager().callEvent(event); -+ -+ if (event.isCancelled()) { ++ if (!event.callEvent()) { + return; + } + diff --git a/paper-server/patches/sources/net/minecraft/world/level/block/FireBlock.java.patch b/paper-server/patches/sources/net/minecraft/world/level/block/FireBlock.java.patch index ac0a574cbf..ebd1c8425d 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/block/FireBlock.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/block/FireBlock.java.patch @@ -132,7 +132,7 @@ level.setBlock(pos, this.getStateWithAge(level, pos, min), 3); } else { - level.removeBlock(pos, false); -+ if(blockState.getBlock() != Blocks.TNT) level.removeBlock(pos, false); // Paper - TNTPrimeEvent; We might be cancelling it below, move the setAir down ++ if (!blockState.is(Blocks.TNT)) level.removeBlock(pos, false); // Paper - TNTPrimeEvent; We might be cancelling it below, move the setAir down } Block block = blockState.getBlock(); diff --git a/paper-server/patches/sources/net/minecraft/world/level/block/LayeredCauldronBlock.java.patch b/paper-server/patches/sources/net/minecraft/world/level/block/LayeredCauldronBlock.java.patch index 3bd7696353..b676bda200 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/block/LayeredCauldronBlock.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/block/LayeredCauldronBlock.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/LayeredCauldronBlock.java +++ b/net/minecraft/world/level/block/LayeredCauldronBlock.java -@@ -61,35 +_,79 @@ +@@ -61,35 +_,69 @@ @Override protected void entityInside(BlockState state, Level level, BlockPos pos, Entity entity) { @@ -12,7 +12,7 @@ + // CraftBukkit start - moved down + // entity.clearFire(); + if ((entity instanceof net.minecraft.world.entity.player.Player || serverLevel.getGameRules().getBoolean(net.minecraft.world.level.GameRules.RULE_MOBGRIEFING)) && entity.mayInteract(serverLevel, pos)) { // Paper - Fixes MC-248588 -+ if (this.handleEntityOnFireInsideWithEvent(state, level, pos, entity)) { // Paper - fix powdered snow cauldron extinguishing entities ++ if (this.handleEntityOnFireInside(state, level, pos, entity)) { // Paper - fix powdered snow cauldron extinguishing entities + entity.clearFire(); + } + // CraftBukkit end @@ -22,7 +22,6 @@ - private void handleEntityOnFireInside(BlockState state, Level level, BlockPos pos) { + // CraftBukkit start -+ @io.papermc.paper.annotation.DoNotUse @Deprecated // Paper - fix powdered snow cauldron extinguishing entities; use #handleEntityOnFireInsideWithEvent + private boolean handleEntityOnFireInside(BlockState state, Level level, BlockPos pos, Entity entity) { if (this.precipitationType == Biome.Precipitation.SNOW) { - lowerFillLevel(Blocks.WATER_CAULDRON.defaultBlockState().setValue(LEVEL, state.getValue(LEVEL)), level, pos); @@ -46,26 +45,17 @@ + int i = (Integer) state.getValue(LayeredCauldronBlock.LEVEL) - 1; + BlockState iblockdata1 = i == 0 ? Blocks.CAULDRON.defaultBlockState() : (BlockState) state.setValue(LayeredCauldronBlock.LEVEL, i); + -+ return LayeredCauldronBlock.changeLevel(state, level, BlockPos, iblockdata1, entity, reason); ++ return LayeredCauldronBlock.changeLevel(level, BlockPos, iblockdata1, entity, reason); + } -+ // Paper start - fix powdered snow cauldron extinguishing entities -+ protected boolean handleEntityOnFireInsideWithEvent(BlockState state, Level world, BlockPos pos, Entity entity) { -+ if (this.precipitationType == Biome.Precipitation.SNOW) { -+ return LayeredCauldronBlock.lowerFillLevel((BlockState) Blocks.WATER_CAULDRON.defaultBlockState().setValue(LayeredCauldronBlock.LEVEL, (Integer) state.getValue(LayeredCauldronBlock.LEVEL)), world, pos, entity, CauldronLevelChangeEvent.ChangeReason.EXTINGUISH); -+ } else { -+ return LayeredCauldronBlock.lowerFillLevel(state, world, pos, entity, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.EXTINGUISH); -+ } -+ } -+ // Paper end - fix powdered snow cauldron extinguishing entities + + // CraftBukkit start + // Paper start - Call CauldronLevelChangeEvent -+ public static boolean changeLevel(BlockState iblockdata, Level world, BlockPos blockposition, BlockState newBlock, @javax.annotation.Nullable Entity entity, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason reason) { // Paper - entity is nullable -+ return changeLevel(iblockdata, world, blockposition, newBlock, entity, reason, true); ++ public static boolean changeLevel(Level world, BlockPos blockposition, BlockState newBlock, @javax.annotation.Nullable Entity entity, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason reason) { // Paper - entity is nullable ++ return changeLevel(world, blockposition, newBlock, entity, reason, true); + } + -+ public static boolean changeLevel(BlockState iblockdata, Level world, BlockPos blockposition, BlockState newBlock, @javax.annotation.Nullable Entity entity, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason reason, boolean sendGameEvent) { // Paper - entity is nullable -+ // Paper end - Call CauldronLevelChangeEvent ++ public static boolean changeLevel(Level world, BlockPos blockposition, BlockState newBlock, @javax.annotation.Nullable Entity entity, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason reason, boolean sendGameEvent) { // Paper - entity is nullable ++ // Paper end - Call CauldronLevelChangeEvent + org.bukkit.craftbukkit.block.CraftBlockState newState = org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(world, blockposition); + newState.setData(newBlock); + @@ -89,7 +79,7 @@ BlockState blockState = state.cycle(LEVEL); - level.setBlockAndUpdate(pos, blockState); - level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(blockState)); -+ LayeredCauldronBlock.changeLevel(state, level, pos, blockState, null, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL); // CraftBukkit ++ LayeredCauldronBlock.changeLevel(level, pos, blockState, null, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL); // CraftBukkit } } @@ -100,7 +90,7 @@ - level.setBlockAndUpdate(pos, blockState); - level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(blockState)); + // CraftBukkit start -+ if (!LayeredCauldronBlock.changeLevel(state, level, pos, blockState, null, CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL)) { ++ if (!LayeredCauldronBlock.changeLevel(level, pos, blockState, null, org.bukkit.event.block.CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL)) { + return; + } + // CraftBukkit end diff --git a/paper-server/patches/sources/net/minecraft/world/level/block/PitcherCropBlock.java.patch b/paper-server/patches/sources/net/minecraft/world/level/block/PitcherCropBlock.java.patch index 174bccf67d..7015f932e1 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/block/PitcherCropBlock.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/block/PitcherCropBlock.java.patch @@ -1,5 +1,13 @@ --- a/net/minecraft/world/level/block/PitcherCropBlock.java +++ b/net/minecraft/world/level/block/PitcherCropBlock.java +@@ -107,6 +_,7 @@ + + @Override + public void entityInside(BlockState state, Level level, BlockPos pos, Entity entity) { ++ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(level, pos)).callEvent()) { return; } // Paper - Add EntityInsideBlockEvent + if (level instanceof ServerLevel serverLevel && entity instanceof Ravager && serverLevel.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { + serverLevel.destroyBlock(pos, true, entity); + } @@ -131,7 +_,7 @@ @Override public void randomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {