From 9793846a7e93d64e74ef2eb03acda187d1f5c906 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Fri, 13 Dec 2024 19:42:44 -0800 Subject: [PATCH] net.minecraft.world.level.redstone --- .../CollectingNeighborUpdater.java.patch | 6 +-- .../DefaultRedstoneWireEvaluator.java.patch | 20 ++++++++ ...perimentalRedstoneWireEvaluator.java.patch | 20 ++++++++ .../level/redstone/NeighborUpdater.java.patch | 32 ++++++++++++ .../DefaultRedstoneWireEvaluator.java.patch | 31 ------------ ...perimentalRedstoneWireEvaluator.java.patch | 31 ------------ .../level/redstone/NeighborUpdater.java.patch | 50 ------------------- 7 files changed, 75 insertions(+), 115 deletions(-) rename paper-server/patches/{unapplied => sources}/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java.patch (79%) create mode 100644 paper-server/patches/sources/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java.patch create mode 100644 paper-server/patches/sources/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java.patch create mode 100644 paper-server/patches/sources/net/minecraft/world/level/redstone/NeighborUpdater.java.patch delete mode 100644 paper-server/patches/unapplied/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java.patch delete mode 100644 paper-server/patches/unapplied/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java.patch delete mode 100644 paper-server/patches/unapplied/net/minecraft/world/level/redstone/NeighborUpdater.java.patch diff --git a/paper-server/patches/unapplied/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java.patch b/paper-server/patches/sources/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java.patch similarity index 79% rename from paper-server/patches/unapplied/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java.patch rename to paper-server/patches/sources/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java.patch index d055cf38c0..3fd8f69544 100644 --- a/paper-server/patches/unapplied/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java.patch @@ -1,11 +1,11 @@ --- a/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java +++ b/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java -@@ -135,7 +135,7 @@ +@@ -133,7 +_,7 @@ orientation = this.orientation.withFront(direction); } -- NeighborUpdater.executeUpdate(world, blockState, blockPos, this.sourceBlock, orientation, false); -+ NeighborUpdater.executeUpdate(world, blockState, blockPos, this.sourceBlock, orientation, false, this.sourcePos); // Paper - Add source block to BlockPhysicsEvent +- NeighborUpdater.executeUpdate(level, blockState, blockPos, this.sourceBlock, orientation, false); ++ NeighborUpdater.executeUpdate(level, blockState, blockPos, this.sourceBlock, orientation, false, this.sourcePos); // Paper - Add source block to BlockPhysicsEvent if (this.idx < NeighborUpdater.UPDATE_ORDER.length && NeighborUpdater.UPDATE_ORDER[this.idx] == this.skipDirection) { this.idx++; } diff --git a/paper-server/patches/sources/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java.patch b/paper-server/patches/sources/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java.patch new file mode 100644 index 0000000000..f5b42d763b --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java.patch @@ -0,0 +1,20 @@ +--- a/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java ++++ b/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java +@@ -17,7 +_,16 @@ + @Override + public void updatePowerStrength(Level level, BlockPos pos, BlockState state, @Nullable Orientation orientation, boolean updateShape) { + int i = this.calculateTargetStrength(level, pos); +- if (state.getValue(RedStoneWireBlock.POWER) != i) { ++ // CraftBukkit start ++ int oldPower = state.getValue(RedStoneWireBlock.POWER); ++ if (oldPower != i) { ++ org.bukkit.event.block.BlockRedstoneEvent event = new org.bukkit.event.block.BlockRedstoneEvent(org.bukkit.craftbukkit.block.CraftBlock.at(level, pos), oldPower, i); ++ level.getCraftServer().getPluginManager().callEvent(event); ++ ++ i = event.getNewCurrent(); ++ } ++ if (oldPower != i) { ++ // CraftBukkit end + if (level.getBlockState(pos) == state) { + level.setBlock(pos, state.setValue(RedStoneWireBlock.POWER, Integer.valueOf(i)), 2); + } diff --git a/paper-server/patches/sources/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java.patch b/paper-server/patches/sources/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java.patch new file mode 100644 index 0000000000..a5eebb497d --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java.patch @@ -0,0 +1,20 @@ +--- a/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java ++++ b/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java +@@ -36,7 +_,16 @@ + int intValue = entry.getIntValue(); + int i = unpackPower(intValue); + BlockState blockState = level.getBlockState(blockPos); +- if (blockState.is(this.wireBlock) && !blockState.getValue(RedStoneWireBlock.POWER).equals(i)) { ++ // CraftBukkit start ++ int oldPower = blockState.getValue(RedStoneWireBlock.POWER); // Paper - Call BlockRedstoneEvent properly; get the previous power from the right state ++ if (oldPower != i) { ++ org.bukkit.event.block.BlockRedstoneEvent event = new org.bukkit.event.block.BlockRedstoneEvent(org.bukkit.craftbukkit.block.CraftBlock.at(level, blockPos), oldPower, i); ++ level.getCraftServer().getPluginManager().callEvent(event); ++ ++ i = event.getNewCurrent(); ++ } ++ if (blockState.is((net.minecraft.world.level.block.Block) this.wireBlock) && oldPower != i) { ++ // CraftBukkit end + int i1 = 2; + if (!updateShape || !flag) { + i1 |= 128; diff --git a/paper-server/patches/sources/net/minecraft/world/level/redstone/NeighborUpdater.java.patch b/paper-server/patches/sources/net/minecraft/world/level/redstone/NeighborUpdater.java.patch new file mode 100644 index 0000000000..e4a2c7c33c --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/world/level/redstone/NeighborUpdater.java.patch @@ -0,0 +1,32 @@ +--- a/net/minecraft/world/level/redstone/NeighborUpdater.java ++++ b/net/minecraft/world/level/redstone/NeighborUpdater.java +@@ -42,8 +_,29 @@ + } + + static void executeUpdate(Level level, BlockState state, BlockPos pos, Block neighborBlock, @Nullable Orientation orientation, boolean movedByPiston) { ++ // Paper start - Add source block to BlockPhysicsEvent ++ executeUpdate(level, state, pos, neighborBlock, orientation, movedByPiston, pos); ++ } ++ ++ static void executeUpdate(Level level, BlockState state, BlockPos pos, Block neighborBlock, @Nullable Orientation orientation, boolean movedByPiston, BlockPos sourcePos) { ++ // Paper end - Add source block to BlockPhysicsEvent + try { ++ // CraftBukkit start ++ org.bukkit.craftbukkit.CraftWorld cworld = level.getWorld(); ++ if (cworld != null) { ++ org.bukkit.event.block.BlockPhysicsEvent event = new org.bukkit.event.block.BlockPhysicsEvent(org.bukkit.craftbukkit.block.CraftBlock.at(level, pos), org.bukkit.craftbukkit.block.data.CraftBlockData.fromData(state), org.bukkit.craftbukkit.block.CraftBlock.at(level, sourcePos)); // Paper - Add source block to BlockPhysicsEvent ++ level.getCraftServer().getPluginManager().callEvent(event); ++ ++ if (event.isCancelled()) { ++ return; ++ } ++ } ++ // CraftBukkit end + state.handleNeighborChanged(level, pos, neighborBlock, orientation, movedByPiston); ++ // Spigot Start ++ } catch (StackOverflowError ex) { ++ level.lastPhysicsProblem = new BlockPos(pos); ++ // Spigot End + } catch (Throwable var9) { + CrashReport crashReport = CrashReport.forThrowable(var9, "Exception while updating neighbours"); + CrashReportCategory crashReportCategory = crashReport.addCategory("Block being updated"); diff --git a/paper-server/patches/unapplied/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java.patch b/paper-server/patches/unapplied/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java.patch deleted file mode 100644 index 8862572ac8..0000000000 --- a/paper-server/patches/unapplied/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java.patch +++ /dev/null @@ -1,31 +0,0 @@ ---- a/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java -+++ b/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java -@@ -9,6 +9,10 @@ - import net.minecraft.world.level.Level; - import net.minecraft.world.level.block.RedStoneWireBlock; - import net.minecraft.world.level.block.state.BlockState; -+// CraftBukkit start -+import org.bukkit.craftbukkit.block.CraftBlock; -+import org.bukkit.event.block.BlockRedstoneEvent; -+// CraftBukkit end - - public class DefaultRedstoneWireEvaluator extends RedstoneWireEvaluator { - -@@ -20,7 +24,16 @@ - public void updatePowerStrength(Level world, BlockPos pos, BlockState state, @Nullable Orientation orientation, boolean blockAdded) { - int i = this.calculateTargetStrength(world, pos); - -- if ((Integer) state.getValue(RedStoneWireBlock.POWER) != i) { -+ // CraftBukkit start -+ int oldPower = state.getValue(RedStoneWireBlock.POWER); -+ if (oldPower != i) { -+ BlockRedstoneEvent event = new BlockRedstoneEvent(CraftBlock.at(world, pos), oldPower, i); -+ world.getCraftServer().getPluginManager().callEvent(event); -+ -+ i = event.getNewCurrent(); -+ } -+ if (oldPower != i) { -+ // CraftBukkit end - if (world.getBlockState(pos) == state) { - world.setBlock(pos, (BlockState) state.setValue(RedStoneWireBlock.POWER, i), 2); - } diff --git a/paper-server/patches/unapplied/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java.patch b/paper-server/patches/unapplied/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java.patch deleted file mode 100644 index 73e662622f..0000000000 --- a/paper-server/patches/unapplied/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java.patch +++ /dev/null @@ -1,31 +0,0 @@ ---- a/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java -+++ b/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java -@@ -16,6 +16,10 @@ - import net.minecraft.world.level.block.state.BlockState; - import net.minecraft.world.level.block.state.properties.EnumProperty; - import net.minecraft.world.level.block.state.properties.RedstoneSide; -+// CraftBukkit start -+import org.bukkit.craftbukkit.block.CraftBlock; -+import org.bukkit.event.block.BlockRedstoneEvent; -+// CraftBukkit end - - public class ExperimentalRedstoneWireEvaluator extends RedstoneWireEvaluator { - -@@ -41,7 +45,16 @@ - int j = ExperimentalRedstoneWireEvaluator.unpackPower(i); - BlockState iblockdata1 = world.getBlockState(blockposition1); - -- if (iblockdata1.is((Block) this.wireBlock) && !((Integer) iblockdata1.getValue(RedStoneWireBlock.POWER)).equals(j)) { -+ // CraftBukkit start -+ int oldPower = iblockdata1.getValue(RedStoneWireBlock.POWER); // Paper - Call BlockRedstoneEvent properly; get the previous power from the right state -+ if (oldPower != j) { -+ BlockRedstoneEvent event = new BlockRedstoneEvent(CraftBlock.at(world, blockposition1), oldPower, j); -+ world.getCraftServer().getPluginManager().callEvent(event); -+ -+ j = event.getNewCurrent(); -+ } -+ if (iblockdata1.is((Block) this.wireBlock) && oldPower != j) { -+ // CraftBukkit end - int k = 2; - - if (!blockAdded || !flag1) { diff --git a/paper-server/patches/unapplied/net/minecraft/world/level/redstone/NeighborUpdater.java.patch b/paper-server/patches/unapplied/net/minecraft/world/level/redstone/NeighborUpdater.java.patch deleted file mode 100644 index a8973333ac..0000000000 --- a/paper-server/patches/unapplied/net/minecraft/world/level/redstone/NeighborUpdater.java.patch +++ /dev/null @@ -1,50 +0,0 @@ ---- a/net/minecraft/world/level/redstone/NeighborUpdater.java -+++ b/net/minecraft/world/level/redstone/NeighborUpdater.java -@@ -8,11 +8,17 @@ - import net.minecraft.core.BlockPos; - import net.minecraft.core.Direction; - import net.minecraft.core.registries.BuiltInRegistries; -+import net.minecraft.server.level.ServerLevel; - import net.minecraft.world.level.Level; - import net.minecraft.world.level.LevelAccessor; - import net.minecraft.world.level.block.Block; - import net.minecraft.world.level.block.Blocks; - import net.minecraft.world.level.block.state.BlockState; -+import org.bukkit.craftbukkit.CraftWorld; -+import org.bukkit.craftbukkit.block.CraftBlock; -+import org.bukkit.craftbukkit.block.data.CraftBlockData; -+import org.bukkit.event.block.BlockPhysicsEvent; -+// CraftBukkit end - - public interface NeighborUpdater { - -@@ -49,8 +55,29 @@ - } - - static void executeUpdate(Level world, BlockState state, BlockPos pos, Block sourceBlock, @Nullable Orientation orientation, boolean notify) { -+ // Paper start - Add source block to BlockPhysicsEvent -+ executeUpdate(world, state, pos, sourceBlock, orientation, notify, pos); -+ } -+ -+ static void executeUpdate(Level world, BlockState state, BlockPos pos, Block sourceBlock, @Nullable Orientation orientation, boolean notify, BlockPos sourcePos) { -+ // Paper end - Add source block to BlockPhysicsEvent - try { -+ // CraftBukkit start -+ CraftWorld cworld = ((ServerLevel) world).getWorld(); -+ if (cworld != null) { -+ BlockPhysicsEvent event = new BlockPhysicsEvent(CraftBlock.at(world, pos), CraftBlockData.fromData(state), CraftBlock.at(world, sourcePos)); // Paper - Add source block to BlockPhysicsEvent -+ ((ServerLevel) world).getCraftServer().getPluginManager().callEvent(event); -+ -+ if (event.isCancelled()) { -+ return; -+ } -+ } -+ // CraftBukkit end - state.handleNeighborChanged(world, pos, sourceBlock, orientation, notify); -+ // Spigot Start -+ } catch (StackOverflowError ex) { -+ world.lastPhysicsProblem = new BlockPos(pos); -+ // Spigot End - } catch (Throwable throwable) { - CrashReport crashreport = CrashReport.forThrowable(throwable, "Exception while updating neighbours"); - CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Block being updated");