1
0
Fork 0
mirror of https://github.com/PaperMC/Paper.git synced 2024-12-13 02:11:05 +01:00
PaperMC/nms-patches/BlockDropper.patch
2018-07-15 10:00:00 +10:00

41 lines
2.3 KiB
Diff

--- a/net/minecraft/server/BlockDropper.java
+++ b/net/minecraft/server/BlockDropper.java
@@ -1,5 +1,10 @@
package net.minecraft.server;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.inventory.InventoryMoveItemEvent;
+// CraftBukkit end
+
public class BlockDropper extends BlockDispenser {
private static final IDispenseBehavior c = new DispenseBehaviorItem();
@@ -34,8 +39,25 @@
if (iinventory == null) {
itemstack1 = BlockDropper.c.dispense(sourceblock, itemstack);
} else {
- itemstack1 = TileEntityHopper.addItem(tileentitydispenser, iinventory, itemstack.cloneItemStack().cloneAndSubtract(1), enumdirection.opposite());
- if (itemstack1.isEmpty()) {
+ // CraftBukkit start - Fire event when pushing items into other inventories
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(itemstack.cloneItemStack().cloneAndSubtract(1));
+
+ org.bukkit.inventory.Inventory destinationInventory;
+ // Have to special case large chests as they work oddly
+ if (iinventory instanceof InventoryLargeChest) {
+ destinationInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((InventoryLargeChest) iinventory);
+ } else {
+ destinationInventory = iinventory.getOwner().getInventory();
+ }
+
+ InventoryMoveItemEvent event = new InventoryMoveItemEvent(tileentitydispenser.getOwner().getInventory(), oitemstack.clone(), destinationInventory, true);
+ world.getServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
+ itemstack1 = TileEntityHopper.addItem(tileentitydispenser, iinventory, CraftItemStack.asNMSCopy(event.getItem()), enumdirection.opposite());
+ if (event.getItem().equals(oitemstack) && itemstack1.isEmpty()) {
+ // CraftBukkit end
itemstack1 = itemstack.cloneItemStack();
itemstack1.subtract(1);
} else {