From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: TheViperShow <29604693+TheViperShow@users.noreply.github.com> Date: Wed, 22 Apr 2020 09:40:38 +0200 Subject: [PATCH] Add BlockFailedDispenseEvent 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 3d05e71fef8fa70df05311a6a9ddad99994892a6..352f5412fc469a1fde6f14ffcaf00e88613b2704 100644 --- a/src/main/java/net/minecraft/world/level/block/DispenserBlock.java +++ b/src/main/java/net/minecraft/world/level/block/DispenserBlock.java @@ -98,8 +98,10 @@ public class DispenserBlock extends BaseEntityBlock { int i = tileentitydispenser.getRandomSlot(world.random); if (i < 0) { + if (org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFailedDispenseEvent(world, pos)) { // Paper - Add BlockFailedDispenseEvent world.levelEvent(1001, pos, 0); world.gameEvent((Holder) GameEvent.BLOCK_ACTIVATE, pos, GameEvent.Context.of(tileentitydispenser.getBlockState())); + } // Paper - Add BlockFailedDispenseEvent } else { ItemStack itemstack = tileentitydispenser.getItem(i); DispenseItemBehavior idispensebehavior = this.getDispenseMethod(world, 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 09e5ff5a0270cb88f3505a28c07ef816f18ac23b..3e09d4b11c881b9c7d3447df379286238076cfee 100644 --- a/src/main/java/net/minecraft/world/level/block/DropperBlock.java +++ b/src/main/java/net/minecraft/world/level/block/DropperBlock.java @@ -60,6 +60,7 @@ public class DropperBlock extends DispenserBlock { int i = tileentitydispenser.getRandomSlot(world.random); if (i < 0) { + if (org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFailedDispenseEvent(world, pos)) // Paper - Add BlockFailedDispenseEvent world.levelEvent(1001, pos, 0); } else { ItemStack itemstack = tileentitydispenser.getItem(i); diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 9f97216a4be562acb69281f4a638dad139c6bc7d..1e918ef9296e5127b78a7eb0460225448982772e 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -2125,4 +2125,12 @@ public class CraftEventFactory { return org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getPotion()); } // Paper end - WitchReadyPotionEvent + + // Paper start + public static boolean handleBlockFailedDispenseEvent(ServerLevel serverLevel, BlockPos pos) { + org.bukkit.block.Block block = CraftBlock.at(serverLevel, pos); + io.papermc.paper.event.block.BlockFailedDispenseEvent event = new io.papermc.paper.event.block.BlockFailedDispenseEvent(block); + return event.callEvent(); + } + // Paper end }