From a45d2c6068dd5d2c71c59605a46e4c6acc5b50fb Mon Sep 17 00:00:00 2001
From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
Date: Sun, 7 Aug 2022 22:16:36 +0200
Subject: [PATCH] Add source block to BlockPhysicsEvent

---
 .../redstone/CollectingNeighborUpdater.java.patch     | 11 +++++++++++
 .../world/level/redstone/NeighborUpdater.java.patch   | 11 +++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)
 create mode 100644 paper-server/patches/sources/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java.patch

diff --git a/paper-server/patches/sources/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java.patch b/paper-server/patches/sources/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java.patch
new file mode 100644
index 0000000000..d055cf38c0
--- /dev/null
+++ b/paper-server/patches/sources/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java.patch
@@ -0,0 +1,11 @@
+--- a/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java
++++ b/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java
+@@ -135,7 +135,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
+             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/NeighborUpdater.java.patch b/paper-server/patches/sources/net/minecraft/world/level/redstone/NeighborUpdater.java.patch
index d54de0c799..a8973333ac 100644
--- 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
@@ -18,14 +18,21 @@
  
  public interface NeighborUpdater {
  
-@@ -50,7 +56,22 @@
+@@ -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));
++                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()) {