aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/unapplied/server/0471-Add-BlockPreDispenseEvent.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/unapplied/server/0471-Add-BlockPreDispenseEvent.patch')
-rw-r--r--patches/unapplied/server/0471-Add-BlockPreDispenseEvent.patch46
1 files changed, 46 insertions, 0 deletions
diff --git a/patches/unapplied/server/0471-Add-BlockPreDispenseEvent.patch b/patches/unapplied/server/0471-Add-BlockPreDispenseEvent.patch
new file mode 100644
index 0000000000..58c12a1348
--- /dev/null
+++ b/patches/unapplied/server/0471-Add-BlockPreDispenseEvent.patch
@@ -0,0 +1,46 @@
+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] Add 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 f4853a5ff8a45efcda2d7781c1fa897c47d8ea46..a02f24448b002824b068278fa427003008c0d0f1 100644
+--- a/src/main/java/net/minecraft/world/level/block/DispenserBlock.java
++++ b/src/main/java/net/minecraft/world/level/block/DispenserBlock.java
+@@ -107,6 +107,7 @@ public class DispenserBlock extends BaseEntityBlock {
+ DispenseItemBehavior idispensebehavior = this.getDispenseMethod(world, itemstack);
+
+ if (idispensebehavior != DispenseItemBehavior.NOOP) {
++ if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockPreDispenseEvent(world, pos, itemstack, i)) return; // Paper - Add BlockPreDispenseEvent
+ DispenserBlock.eventFired = false; // CraftBukkit - reset event status
+ tileentitydispenser.setItem(i, idispensebehavior.dispense(sourceblock, itemstack));
+ }
+diff --git a/src/main/java/net/minecraft/world/level/block/DropperBlock.java b/src/main/java/net/minecraft/world/level/block/DropperBlock.java
+index 91b514967405115f22edf4255775361a672e5c2f..ddecf443df3679e3098eb54edd19585a0512e342 100644
+--- a/src/main/java/net/minecraft/world/level/block/DropperBlock.java
++++ b/src/main/java/net/minecraft/world/level/block/DropperBlock.java
+@@ -71,6 +71,7 @@ public class DropperBlock extends DispenserBlock {
+ ItemStack itemstack1;
+
+ if (iinventory == null) {
++ if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockPreDispenseEvent(world, pos, itemstack, i)) return; // Paper - Add BlockPreDispenseEvent
+ itemstack1 = DropperBlock.DISPENSE_BEHAVIOUR.dispense(sourceblock, itemstack);
+ } else {
+ // CraftBukkit start - Fire event when pushing items into other inventories
+diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+index 696867479e74c3c94e4131f2bbb97c857ed5e9dd..6d1d3451054af05e2381d70d71b99869f37c0901 100644
+--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
++++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+@@ -2132,5 +2132,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 = CraftBlock.at(serverLevel, pos);
++ 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
+ }