3
0
KCauldronX/patches/net/minecraft/block/BlockDropper.java.patch

73 lines
3.4 KiB
Diff
Raw Permalink Normal View History

2015-03-22 17:38:04 +00:00
--- ../src-base/minecraft/net/minecraft/block/BlockDropper.java
+++ ../src-work/minecraft/net/minecraft/block/BlockDropper.java
@@ -13,6 +13,11 @@
import net.minecraft.tileentity.TileEntityHopper;
import net.minecraft.util.Facing;
import net.minecraft.world.World;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.inventory.InventoryMoveItemEvent;
+import net.minecraft.inventory.InventoryLargeChest;
+// CraftBukkit end
public class BlockDropper extends BlockDispenser
{
@@ -38,7 +43,7 @@
return new TileEntityDropper();
}
- protected void func_149941_e(World p_149941_1_, int p_149941_2_, int p_149941_3_, int p_149941_4_)
+ public void func_149941_e(World p_149941_1_, int p_149941_2_, int p_149941_3_, int p_149941_4_) // CraftBukkit - protected -> public
{
BlockSourceImpl blocksourceimpl = new BlockSourceImpl(p_149941_1_, p_149941_2_, p_149941_3_, p_149941_4_);
TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity();
@@ -60,13 +65,36 @@
2015-03-22 17:38:04 +00:00
if (iinventory != null)
{
- itemstack1 = TileEntityHopper.func_145889_a(iinventory, itemstack.copy().splitStack(1), Facing.oppositeSide[i1]);
+ // CraftBukkit start - Fire event when pushing items into other inventories
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(itemstack.copy().splitStack(1));
+ org.bukkit.inventory.Inventory destinationInventory;
- if (itemstack1 == null)
+ // 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);
+ p_149941_1_.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled())
+ {
+ return;
+ }
+
+ itemstack1 = TileEntityHopper.func_145889_a(iinventory, CraftItemStack.asNMSCopy(event.getItem()), Facing.oppositeSide[i1]);
+
+ if (event.getItem().equals(oitemstack) && itemstack1 == null)
+ {
+ // CraftBukkit end
itemstack1 = itemstack.copy();
- if (--itemstack1.stackSize == 0)
+ if (--itemstack1.stackSize <= 0)
{
itemstack1 = null;
}
@@ -80,7 +108,7 @@
{
itemstack1 = this.field_149947_P.dispense(blocksourceimpl, itemstack);
- if (itemstack1 != null && itemstack1.stackSize == 0)
+ if (itemstack1 != null && itemstack1.stackSize <= 0)
{
itemstack1 = null;
}