2021-06-14 21:58:32 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2021-09-20 11:30:04 +02:00
From: Madeline Miller <mnmiller1@me.com>
2021-06-14 21:58:32 +02:00
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
2021-11-24 19:27:25 +01:00
index 07d357b5fcb30ed9ff074a196a19de1481fe3738..83ac86b3c1e7b9233f2db8e5488f97c5b44f8843 100644
2021-06-14 21:58:32 +02:00
--- a/src/main/java/net/minecraft/world/level/block/DispenserBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/DispenserBlock.java
2021-11-24 19:27:25 +01:00
@@ -92,6 +92,7 @@ public class DispenserBlock extends BaseEntityBlock {
2021-06-14 21:58:32 +02:00
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
2022-02-12 14:20:33 +01:00
index 6d5d42a40a42b0d1e8e80d802cd629dd2854ae9b..97fd237a4fc31875fa66683c9ea8fed1fa794abf 100644
2021-06-14 21:58:32 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2022-02-12 14:20:33 +01:00
@@ -1885,5 +1885,11 @@ public class CraftEventFactory {
2021-06-14 21:58:32 +02:00
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
}