public void a(TileEntityHopper tileentityhopper) { this.ct(); this.a.b( new Packet100OpenWindow( this.cu, 9, tileentityhopper.b(), tileentityhopper.j_(), tileentityhopper.c())); this.bM = new ContainerHopper(this.bK, tileentityhopper); this.bM.d = this.cu; this.bM.a((ICrafting) this); }
private static ItemStack tryMoveInItem(IInventory iinventory, ItemStack itemstack, int i, int j) { ItemStack itemstack1 = iinventory.getItem(i); if (canPlaceItemInInventory(iinventory, itemstack, i, j)) { boolean flag = false; if (itemstack1 == null) { iinventory.setItem(i, itemstack); itemstack = null; flag = true; } else if (canMergeItems(itemstack1, itemstack)) { int k = itemstack.getMaxStackSize() - itemstack1.count; int l = Math.min(itemstack.count, k); itemstack.count -= l; itemstack1.count += l; flag = l > 0; } if (flag) { if (iinventory instanceof TileEntityHopper) { ((TileEntityHopper) iinventory) .c(((TileEntityHopper) iinventory).world.spigotConfig.hopperTransfer); // Spigot iinventory.update(); } iinventory.update(); } } return itemstack; }
private static boolean tryTakeInItemFromSlot( IHopper ihopper, IInventory iinventory, int i, int j) { ItemStack itemstack = iinventory.getItem(i); if (itemstack != null && canTakeItemFromInventory(iinventory, itemstack, i, j)) { ItemStack itemstack1 = itemstack.cloneItemStack(); // CraftBukkit start - Call event on collection of items from inventories into the hopper CraftItemStack oitemstack = CraftItemStack.asCraftMirror(iinventory.splitStack(i, 1)); Inventory sourceInventory; // Have to special case large chests as they work oddly if (iinventory instanceof InventoryLargeChest) { sourceInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest( (InventoryLargeChest) iinventory); } else if (isIronChest) { sourceInventory = null; } else { sourceInventory = iinventory.getOwner().getInventory(); } InventoryMoveItemEvent event = new InventoryMoveItemEvent( sourceInventory, oitemstack.clone(), ihopper.getOwner().getInventory(), false); ihopper.getWorld().getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { iinventory.setItem(i, itemstack1); if (ihopper instanceof TileEntityHopper) { ((TileEntityHopper) ihopper).c(ihopper.getWorld().spigotConfig.hopperTransfer); // Spigot } else if (ihopper instanceof EntityMinecartHopper) { ((EntityMinecartHopper) ihopper) .l(ihopper.getWorld().spigotConfig.hopperTransfer / 2); // Spigot } return false; } ItemStack itemstack2 = addItem(ihopper, CraftItemStack.asNMSCopy(event.getItem()), -1); if (itemstack2 == null || itemstack2.count == 0) { if (event.getItem().equals(oitemstack)) { iinventory.update(); } else { iinventory.setItem(i, itemstack1); } // CraftBukkit end return true; } iinventory.setItem(i, itemstack1); } return false; }
// Spigot start // Helper method for scheduleTicks. If the hopper at x0, y0, z0 is pointed // at this tile entity, then make it active. private void scheduleTick(int x0, int y0, int z0) { TileEntity tileEntity = world.getTileEntity(x0, y0, z0); if (tileEntity instanceof TileEntityHopper && tileEntity.world != null) { // i is the metadeta assoiated with the direction the hopper faces. int i = BlockHopper.b(tileEntity.p()); // Facing class provides arrays for direction offset. if (tileEntity.x + Facing.b[i] == x && tileEntity.y + Facing.c[i] == y && tileEntity.z + Facing.d[i] == z) { ((TileEntityHopper) tileEntity).makeTick(); } } }
// Called from update when the contents have changed, so hoppers need updates. // Check all 6 faces. public void scheduleTicks() { if (world != null && world.spigotConfig.altHopperTicking) { // Check the top scheduleTick(x, y + 1, z); // Check the sides for (int i = 2; i < 6; i++) { scheduleTick(x + Facing.b[i], y, z + Facing.d[i]); } // Check the bottom. TileEntity tileEntity = world.getTileEntity(x, y - 1, z); if (tileEntity instanceof TileEntityHopper && tileEntity.world != null) { ((TileEntityHopper) tileEntity).makeTick(); } } }