Paper/patches/server/0539-Implement-BlockPreDispenseEvent.patch

35 Zeilen
2.3 KiB
Diff

2021-06-14 21:58:32 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
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
2023-09-22 19:25:18 +02:00
index 5cf5b451fecb1ff04d0c4aca1fb0b702c7f99bdf..9b1e51c1d95da885c80c6d05000d83436b7bcfb4 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
2023-09-22 07:41:27 +02:00
@@ -98,6 +98,7 @@ public class DispenserBlock extends BaseEntityBlock {
DispenseItemBehavior idispensebehavior = this.getDispenseMethod(itemstack);
2021-06-14 21:58:32 +02:00
2023-09-22 07:41:27 +02:00
if (idispensebehavior != DispenseItemBehavior.NOOP) {
2021-06-14 21:58:32 +02:00
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockPreDispenseEvent(world, pos, itemstack, i)) return; // Paper - BlockPreDispenseEvent is called here
2023-09-22 07:41:27 +02:00
DispenserBlock.eventFired = false; // CraftBukkit - reset event status
tileentitydispenser.setItem(i, idispensebehavior.dispense(sourceblock, itemstack));
}
2021-06-14 21:58:32 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index ecbdddf42495e69bc899a017e1313a9f0c32f0c4..46ab61bf75bf15bb6156dc9204e4071779e812e6 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
@@ -2044,5 +2044,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
}