Paper/src/main/java/net/minecraft/server/BlockDropper.java

76 Zeilen
3.2 KiB
Java

2013-03-21 13:40:48 +01:00
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
// CraftBukkit end
2013-03-21 13:40:48 +01:00
public class BlockDropper extends BlockDispenser {
2013-11-04 14:07:38 +01:00
private final IDispenseBehavior P = new DispenseBehaviorItem();
2013-03-21 13:40:48 +01:00
2013-11-04 14:07:38 +01:00
public BlockDropper() {}
2013-03-21 13:40:48 +01:00
protected IDispenseBehavior a(ItemStack itemstack) {
2013-11-04 14:07:38 +01:00
return this.P;
2013-03-21 13:40:48 +01:00
}
2013-11-04 14:07:38 +01:00
public TileEntity a(World world, int i) {
2013-03-21 13:40:48 +01:00
return new TileEntityDropper();
}
public void dispense(World world, int i, int j, int k) { // CraftBukkit - protected -> public
2013-03-21 13:40:48 +01:00
SourceBlock sourceblock = new SourceBlock(world, i, j, k);
TileEntityDispenser tileentitydispenser = (TileEntityDispenser) sourceblock.getTileEntity();
if (tileentitydispenser != null) {
2013-11-04 14:07:38 +01:00
int l = tileentitydispenser.i();
2013-03-21 13:40:48 +01:00
if (l < 0) {
world.triggerEffect(1001, i, j, k, 0);
} else {
ItemStack itemstack = tileentitydispenser.getItem(l);
int i1 = world.getData(i, j, k) & 7;
IInventory iinventory = TileEntityHopper.getInventoryAt(world, (double) (i + Facing.b[i1]), (double) (j + Facing.c[i1]), (double) (k + Facing.d[i1]));
ItemStack itemstack1;
if (iinventory != null) {
2013-03-25 05:22:32 +01:00
// 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()), Facing.OPPOSITE_FACING[i1]);
if (event.getItem().equals(oitemstack) && itemstack1 == null) {
// CraftBukkit end
2013-03-21 13:40:48 +01:00
itemstack1 = itemstack.cloneItemStack();
if (--itemstack1.count == 0) {
itemstack1 = null;
}
} else {
itemstack1 = itemstack.cloneItemStack();
}
} else {
2013-11-04 14:07:38 +01:00
itemstack1 = this.P.a(sourceblock, itemstack);
2013-03-21 13:40:48 +01:00
if (itemstack1 != null && itemstack1.count == 0) {
itemstack1 = null;
}
}
tileentitydispenser.setItem(l, itemstack1);
}
}
}
}