aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0577-Implement-BlockPreDispenseEvent.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/server/0577-Implement-BlockPreDispenseEvent.patch')
-rw-r--r--patches/server/0577-Implement-BlockPreDispenseEvent.patch34
1 files changed, 34 insertions, 0 deletions
diff --git a/patches/server/0577-Implement-BlockPreDispenseEvent.patch b/patches/server/0577-Implement-BlockPreDispenseEvent.patch
new file mode 100644
index 0000000000..34982b77cc
--- /dev/null
+++ b/patches/server/0577-Implement-BlockPreDispenseEvent.patch
@@ -0,0 +1,34 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Madeline Miller <[email protected]>
+Date: Sun, 17 Jan 2021 13:16:09 +1000
+Subject: [PATCH] Implement BlockPreDispenseEvent
+
+
+diff --git a/src/main/java/net/minecraft/world/level/block/DispenserBlock.java b/src/main/java/net/minecraft/world/level/block/DispenserBlock.java
+index 85c5319837295bd2f85baebfe8d6660b267f1d5f..8f55d0753fa26924235c943595f0d1a06a933a6f 100644
+--- a/src/main/java/net/minecraft/world/level/block/DispenserBlock.java
++++ b/src/main/java/net/minecraft/world/level/block/DispenserBlock.java
+@@ -93,6 +93,7 @@ public class DispenserBlock extends BaseEntityBlock {
+ DispenseItemBehavior idispensebehavior = this.getDispenseMethod(itemstack);
+
+ if (idispensebehavior != DispenseItemBehavior.NOOP) {
++ if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockPreDispenseEvent(world, pos, itemstack, i)) return; // Paper - BlockPreDispenseEvent is called here
+ DispenserBlock.eventFired = false; // CraftBukkit - reset event status
+ tileentitydispenser.setItem(i, idispensebehavior.dispense(sourceblock, itemstack));
+ }
+diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+index 7bafab016aeb3b1177b23f44696e7178f25d414a..2c45c71274e026936c0e1c91e1b0555f21a7a611 100644
+--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
++++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+@@ -1886,5 +1886,11 @@ public class CraftEventFactory {
+ io.papermc.paper.event.block.BlockFailedDispenseEvent event = new io.papermc.paper.event.block.BlockFailedDispenseEvent(block);
+ return event.callEvent();
+ }
++
++ public static boolean handleBlockPreDispenseEvent(ServerLevel serverLevel, BlockPos pos, ItemStack itemStack, int slot) {
++ org.bukkit.block.Block block = serverLevel.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++ io.papermc.paper.event.block.BlockPreDispenseEvent event = new io.papermc.paper.event.block.BlockPreDispenseEvent(block, org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), slot);
++ return event.callEvent();
++ }
+ // Paper end
+ }