2021-01-19 23:55:25 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Matthew Miller <mnmiller1@me.com>
Date: Sun, 17 Jan 2021 13:16:09 +1000
Subject: [PATCH] Implement BlockPreDispenseEvent
2021-03-16 08:19:45 +01:00
diff --git a/src/main/java/net/minecraft/world/level/block/BlockDispenser.java b/src/main/java/net/minecraft/world/level/block/BlockDispenser.java
index 966051ab3e720e5b3f0fb9ab852c8908c5f23f3b..9b92824f1c2797e321ced953d33d2c2fd339374a 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockDispenser.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockDispenser.java
@@ -88,6 +88,7 @@ public class BlockDispenser extends BlockTileEntity {
2021-01-19 23:55:25 +01:00
IDispenseBehavior idispensebehavior = this.a(itemstack);
if (idispensebehavior != IDispenseBehavior.NONE) {
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockPreDispenseEvent(worldserver, blockposition, itemstack, i)) return; // Paper - BlockPreDispenseEvent is called here
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
2021-04-12 03:03:08 +02:00
index 22da2cc26fc526d7222f64c296eaf26cabd23626..47906539c3e6cd7f34c0880a0bab2a185d79b71c 100644
2021-01-19 23:55:25 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2021-03-16 14:04:28 +01:00
@@ -69,6 +69,7 @@ import net.minecraft.world.phys.MovingObjectPosition;
2021-03-16 08:19:45 +01:00
import net.minecraft.world.phys.MovingObjectPositionBlock;
import net.minecraft.world.phys.MovingObjectPositionEntity;
2021-03-16 14:04:28 +01:00
import net.minecraft.world.phys.Vec3D;
2021-03-16 08:19:45 +01:00
+import io.papermc.paper.event.block.BlockPreDispenseEvent; // Paper
import org.bukkit.Bukkit;
import org.bukkit.Location; // Paper
import org.bukkit.Material;
2021-03-16 14:04:28 +01:00
@@ -1780,5 +1781,11 @@ public class CraftEventFactory {
2021-01-19 23:55:25 +01:00
BlockFailedDispenseEvent event = new BlockFailedDispenseEvent(block);
return event.callEvent();
}
+
+ public static boolean handleBlockPreDispenseEvent(WorldServer worldserver, BlockPosition blockposition, ItemStack itemStack, int slot) {
+ org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ BlockPreDispenseEvent event = new BlockPreDispenseEvent(block, org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), slot);
+ return event.callEvent();
+ }
// Paper end
}