PaperMC/nms-patches/BlockDropper.patch

51 lines
2.7 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- 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 {
2015-02-26 23:41:06 +01:00
private final IDispenseBehavior P = new DispenseBehaviorItem();
@@ -14,7 +19,7 @@
return new TileEntityDropper();
}
- protected void dispense(World world, BlockPosition blockposition) {
+ public void dispense(World world, BlockPosition blockposition) { // CraftBukkit - public
SourceBlock sourceblock = new SourceBlock(world, blockposition);
TileEntityDispenser tileentitydispenser = (TileEntityDispenser) sourceblock.getTileEntity();
@@ -38,8 +43,25 @@
itemstack1 = null;
}
} else {
- itemstack1 = TileEntityHopper.addItem(iinventory, itemstack.cloneItemStack().a(1), enumdirection.opposite());
- if (itemstack1 == null) {
+ // CraftBukkit start - Fire event when pushing items into other inventories
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(itemstack.cloneItemStack().a(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(iinventory, CraftItemStack.asNMSCopy(event.getItem()), enumdirection.opposite());
+ if (event.getItem().equals(oitemstack) && itemstack1 == null) {
+ // CraftBukkit end
itemstack1 = itemstack.cloneItemStack();
2015-05-05 22:43:47 +02:00
if (--itemstack1.count <= 0) {
itemstack1 = null;