List of usage examples for net.minecraftforge.items IItemHandler getStackInSlot
@Nonnull
ItemStack getStackInSlot(int slot);
From source file:blusunrize.immersiveengineering.common.blocks.BlockIETileProvider.java
@Override public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) // public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { TileEntity tile = world.getTileEntity(pos); DimensionBlockPos dpos = new DimensionBlockPos(pos, world instanceof World ? ((World) world).provider.getDimension() : 0); if (tile == null && tempTile.containsKey(dpos)) tile = tempTile.get(dpos);//from w w w .j a va 2 s.c o m if (tile != null && (!(tile instanceof ITileDrop) || !((ITileDrop) tile).preventInventoryDrop())) { if (tile instanceof IIEInventory && ((IIEInventory) tile).getDroppedItems() != null) { for (ItemStack s : ((IIEInventory) tile).getDroppedItems()) if (!s.isEmpty()) drops.add(s); } else if (tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) { IItemHandler h = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); if (h instanceof IEInventoryHandler) for (int i = 0; i < h.getSlots(); i++) if (!h.getStackInSlot(i).isEmpty()) { drops.add(h.getStackInSlot(i)); ((IEInventoryHandler) h).setStackInSlot(i, ItemStack.EMPTY); } } } if (tile instanceof ITileDrop) { NonNullList<ItemStack> s = ((ITileDrop) tile).getTileDrops(harvesters.get(), state); drops.addAll(s); } else super.getDrops(drops, world, pos, state, fortune); tempTile.remove(dpos); }
From source file:blusunrize.immersiveengineering.common.blocks.metal.TileEntityToolbox.java
@Override public void readOnPlacement(EntityLivingBase placer, ItemStack stack) { if (stack.getItem() instanceof ItemInternalStorage) { IItemHandler inv = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); if (inv != null) { inventory = NonNullList.withSize(inv.getSlots(), ItemStack.EMPTY); for (int i = 0; i < inv.getSlots(); i++) inventory.set(i, inv.getStackInSlot(i)); }/*from ww w .ja v a2 s . co m*/ if (stack.hasDisplayName()) this.name = stack.getDisplayName(); enchantments = stack.getEnchantmentTagList(); } }
From source file:blusunrize.immersiveengineering.common.items.ItemDrill.java
@Override public void removeFromWorkbench(EntityPlayer player, ItemStack stack) { IItemHandler inv = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); if (inv != null && !inv.getStackInSlot(0).isEmpty() && !inv.getStackInSlot(1).isEmpty() && !inv.getStackInSlot(2).isEmpty() && !inv.getStackInSlot(3).isEmpty()) Utils.unlockIEAdvancement(player, "main/upgrade_drill"); }
From source file:blusunrize.immersiveengineering.common.items.ItemDrill.java
public ItemStack getHead(ItemStack drill) { ItemStack head;//from w w w. ja v a2 s.c o m boolean remote = FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT; IItemHandler cap = drill.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); if (!remote && cap.getStackInSlot(0).isEmpty()) remote = true; else if (remote && !ItemNBTHelper.hasKey(drill, "head")) remote = false; if (remote) head = new ItemStack(ItemNBTHelper.getTagCompound(drill, "head")); else head = cap.getStackInSlot(0); return !head.isEmpty() && head.getItem() instanceof IDrillHead ? head : ItemStack.EMPTY; }
From source file:blusunrize.immersiveengineering.common.items.ItemInternalStorage.java
public NonNullList<ItemStack> getContainedItems(ItemStack stack) { IItemHandler handler = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); if (handler instanceof IEItemStackHandler) return ((IEItemStackHandler) handler).getContainedItems(); else if (handler != null) { IELogger.warn(// ww w .j a v a2s . c o m "Inefficiently getting contained items. Why does " + stack + " have a non-IE IItemHandler?"); NonNullList<ItemStack> inv = NonNullList.withSize(handler.getSlots(), ItemStack.EMPTY); for (int i = 0; i < handler.getSlots(); i++) inv.set(i, handler.getStackInSlot(i)); return inv; } else IELogger.info("No valid inventory handler found for " + stack); return NonNullList.create(); }
From source file:blusunrize.immersiveengineering.common.items.ItemRevolver.java
public boolean isEmpty(ItemStack stack, boolean allowCasing) { IItemHandler inv = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); if (inv != null) for (int i = 0; i < inv.getSlots(); i++) { ItemStack b = inv.getStackInSlot(i); if (!b.isEmpty() && b.getItem() instanceof ItemBullet && (allowCasing || ItemNBTHelper.hasKey(b, "bullet"))) return false; }/*from ww w.j a v a 2s . c o m*/ return true; }
From source file:blusunrize.immersiveengineering.common.items.ItemRevolver.java
@Override public void removeFromWorkbench(EntityPlayer player, ItemStack stack) { IItemHandler inv = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); if (inv != null && !inv.getStackInSlot(18).isEmpty() && !inv.getStackInSlot(19).isEmpty()) Utils.unlockIEAdvancement(player, "main/upgrade_revolver"); }
From source file:blusunrize.immersiveengineering.common.items.ItemRevolver.java
@Nullable @Override/*ww w .ja va 2 s .c o m*/ public NBTTagCompound getNBTShareTag(ItemStack stack) { NBTTagCompound ret = super.getNBTShareTag(stack); if (ret == null) ret = new NBTTagCompound(); else ret = ret.copy(); IItemHandler handler = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); if (handler != null) { NonNullList<ItemStack> bullets = NonNullList.withSize(getBulletCount(stack), ItemStack.EMPTY); for (int i = 0; i < getBulletCount(stack); i++) bullets.set(i, handler.getStackInSlot(i)); ret.setTag("bullets", Utils.writeInventory(bullets)); } return ret; }
From source file:blusunrize.immersiveengineering.common.items.ItemSpeedloader.java
public boolean isEmpty(ItemStack stack) { IItemHandler inv = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); if (inv != null) for (int i = 0; i < inv.getSlots(); i++) { ItemStack b = inv.getStackInSlot(i); if (!b.isEmpty() && b.getItem() instanceof ItemBullet && ItemNBTHelper.hasKey(b, "bullet")) return false; }//from w w w .j ava2 s .c o m return true; }
From source file:blusunrize.immersiveengineering.common.items.ItemSpeedloader.java
@Nullable @Override/*from www .j a v a 2 s.c o m*/ public NBTTagCompound getNBTShareTag(ItemStack stack) { NBTTagCompound ret = super.getNBTShareTag(stack); if (ret == null) ret = new NBTTagCompound(); else ret = ret.copy(); IItemHandler handler = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); if (handler != null) { NonNullList<ItemStack> bullets = NonNullList.withSize(getSlotCount(stack), ItemStack.EMPTY); for (int i = 0; i < getSlotCount(stack); i++) bullets.set(i, handler.getStackInSlot(i)); ret.setTag("bullets", Utils.writeInventory(bullets)); } return ret; }