public float checkTemps(IInventory inv) { float temp = 0; float[] temp1 = new float[inv.getSizeInventory()]; for (int i = 0; i < inv.getSizeInventory(); i++) { ItemStack is = inv.getStackInSlot(i); if (is != null && is.hasTagCompound() && !is.getItem().getUnlocalizedName(is).contains("Clay")) { if (is.getTagCompound().hasKey("temperature")) { temp1[i] = is.getTagCompound().getFloat("temperature"); if (temp1[i] < TFC_ItemHeat.getMeltingPoint(is)) { return (float) -1; } } else { return (float) -1; } } else if (is == null) { temp1[i] = -1; } } int temp2 = 0; for (int i = 0; i < inv.getSizeInventory(); i++) { if (temp1[i] >= 0) { temp += temp1[i]; temp2++; } } if (temp2 > 0) { temp /= temp2; } return temp; }
@Override public ItemStack transferStackInSlot(EntityPlayer player, int slotNum) { ItemStack itemCopy = null; Slot slot = (Slot) this.inventorySlots.get(slotNum); if (slot != null && slot.getHasStack()) { ItemStack item = slot.getStack(); itemCopy = item.copy(); if (!(item.getItem() instanceof ItemPotion)) return null; if (slotNum < inventory.getSizeInventory()) { if (!this.mergeItemStack( item, inventory.getSizeInventory(), this.inventorySlots.size(), true)) { return null; } } else if (!this.mergeItemStack(item, 0, inventory.getSizeInventory(), false)) { return null; } if (item.stackSize == 0) { slot.putStack((ItemStack) null); } else { slot.onSlotChanged(); } } return itemCopy; }
@Override public ItemStack transferStackInSlot(EntityPlayer player, int slotID) { ItemStack stack = null; Slot slot = (Slot) inventorySlots.get(slotID); // null checks and checks if the item can be stacked (maxStackSize > 1) if (slot != null && slot.getHasStack()) { ItemStack stackInSlot = slot.getStack(); stack = stackInSlot.copy(); // merges the item into player inventory since its in the tileEntity if (slotID < tileEntity.getSizeInventory()) { if (!this.mergeItemStack( stackInSlot, tileEntity.getSizeInventory(), this.inventorySlots.size(), true)) { return null; } } // merge into tileEntity inventory, since it is in player's inventory else if (!this.mergeItemStack(stackInSlot, 0, tileEntity.getSizeInventory(), false)) { return null; } if (stackInSlot.stackSize == 0) { slot.putStack(null); } else { slot.onSlotChanged(); } } return stack; }
@Override public void onCrafting(EntityPlayer player, ItemStack item, IInventory inv) { if (item.itemID == ModItems.Marshmallow.itemID) { if (item.getItemDamage() == 0) { ItemStack bowl = new ItemStack(Item.bowlEmpty); player.inventory.addItemStackToInventory(bowl); } } for (int i = 0; i < inv.getSizeInventory(); i++) { if (inv.getStackInSlot(i) != null) { ItemStack j = inv.getStackInSlot(i); if (j.getItem() != null && ToolHelper.isTool(j) && !ToolHelper.isTool(item)) { ItemStack k = ToolHelper.addDamage(j, player); if (k != null) k.stackSize++; inv.setInventorySlotContents(i, k); } } } if (item.itemID == ModItems.CampingBag.itemID) { for (int i = 0; i < inv.getSizeInventory(); i++) { if (inv.getStackInSlot(i) != null) { ItemStack j = inv.getStackInSlot(i); if (j.getItem() != null && j.itemID == ModItems.CampingBag.itemID) { if (j.hasTagCompound()) { item.setTagCompound((NBTTagCompound) j.getTagCompound().copy()); } } } } } if (item.itemID == ModBlocks.campfire.blockID) { if (item.getItemDamage() == campfire[0].getItemDamage()) player.addStat(ModAchievements.Campfire, 1); if (item.getItemDamage() == campfire[1].getItemDamage()) player.addStat(ModAchievements.CampfireMultiCook, 1); if (item.getItemDamage() == campfire[2].getItemDamage()) player.addStat(ModAchievements.CampfireFastCook, 1); if (item.getItemDamage() == campfire[3].getItemDamage()) player.addStat(ModAchievements.CampfireCheapCook, 1); if (item.getItemDamage() == campfire[4].getItemDamage()) player.addStat(ModAchievements.CampfireInstaCook, 1); } if (item.itemID == ModItems.CampingBag.itemID) { if (item.getItemDamage() == bag[0].getItemDamage()) player.addStat(ModAchievements.CampingBagSmall, 1); if (item.getItemDamage() == bag[1].getItemDamage()) player.addStat(ModAchievements.CampingBagNormal, 1); if (item.getItemDamage() == bag[2].getItemDamage()) player.addStat(ModAchievements.CampingBagLarge, 1); } if (item.itemID == ModItems.CampTool.itemID) player.addStat(ModAchievements.CampersTool, 1); if (item.itemID == ModItems.TentParts.itemID) player.addStat(ModAchievements.TentParts, 1); if (item.itemID == tent.itemID) player.addStat(ModAchievements.Tent, 1); }
public int[] getSizeInventorySide(int side) { IInventory inventory = getOrCreateTradeInventory(); if (slotIndices == null) { slotIndices = new int[inventory.getSizeInventory()]; for (int i = 0; i < inventory.getSizeInventory(); i++) slotIndices[i] = i; } return slotIndices; }
private void checkInventoryStatus(int cx, int cy, int cz) { TileEntity tileEntity = worldObj.getTileEntity(cx, cy, cz); if (tileEntity instanceof IInventory) { IInventory inventory = (IInventory) tileEntity; if (inventory.getSizeInventory() > 0) { inventories.add(new InvBlockInfo(new Coordinate(cx, cy, cz), inventory.getSizeInventory())); notifyBlockUpdate(); } } }
@LuaMethod( returnType = LuaType.TABLE, description = "Get a table with all the items of the chest") public ItemStack[] getAllStacks(IComputerAccess computer, IInventory target) { IInventory inventory = InventoryUtils.getInventory(target); ItemStack[] allStacks = new ItemStack[inventory.getSizeInventory()]; for (int i = 0; i < inventory.getSizeInventory(); i++) { allStacks[i] = inventory.getStackInSlot(i); } return allStacks; }
@Override public void performEffect(IMasterRitualStone ritualStone) { String owner = ritualStone.getOwner(); World world = ritualStone.getWorld(); int x = ritualStone.getXCoord(); int y = ritualStone.getYCoord(); int z = ritualStone.getZCoord(); TileEntity tile = world.getTileEntity(x, y + 1, z); IInventory tileEntity; if (tile instanceof IInventory) { tileEntity = (IInventory) tile; } else { return; } if (tileEntity.getSizeInventory() <= 0) { return; } int currentEssence = SoulNetworkHandler.getCurrentEssence(owner); if (currentEssence < this.getCostPerRefresh()) { EntityPlayer entityOwner = SpellHelper.getPlayerForUsername(owner); if (entityOwner == null) { return; } SoulNetworkHandler.causeNauseaToPlayer(owner); } else { for (int i = x - 2; i <= x + 2; i++) { for (int k = z - 2; k <= z + 2; k++) { for (int inv = 0; inv < tileEntity.getSizeInventory(); inv++) { if (world.getBlock(i, y, k).isReplaceable(world, i, y + 1, k) && tileEntity.getStackInSlot(inv) != null && tileEntity.getStackInSlot(inv).stackSize != 0) { if (tileEntity.getStackInSlot(inv).getItem() instanceof ItemBlock && world.getBlock(i, y - 1, k) != null) { world.setBlock( i, y, k, Block.getBlockFromItem(tileEntity.getStackInSlot(inv).getItem()), tileEntity.getStackInSlot(inv).getItemDamage(), 3); tileEntity.decrStackSize(inv, 1); tileEntity.markDirty(); SoulNetworkHandler.syphonFromNetwork(owner, getCostPerRefresh()); } } } } } } }
public ContainerInventoryDodo( IInventory invPlayer, final IInventory invDodo, final EntityDodo dodo) { LogHelper.info("ContainerInventoryDodo: constructor called."); this.invDodo = invDodo; this.dodo = dodo; ((InventoryDino) invDodo).openInventory(player); /* Hotbar inventory */ final int HOTBAR_YPOS = 142; for (int col = 0; col < 9; col++) { addSlotToContainer(new Slot(invPlayer, col, 8 + col * 18, HOTBAR_YPOS)); } /* Player inventory */ final int PLAYER_INVENTORY_YPOS = 84; for (int row = 0; row < 3; row++) { for (int col = 0; col < 9; col++) { int slotIndex = col + row * 9 + 9; addSlotToContainer( new Slot(invPlayer, slotIndex, 8 + col * 18, PLAYER_INVENTORY_YPOS + row * 18)); } } /* Chest inventory */ if (DODO_SLOT_COUNT != invDodo.getSizeInventory()) { LogHelper.error( "Mismatched slot count in container(" + DODO_SLOT_COUNT + ") and DodoInventory (" + invDodo.getSizeInventory() + ")"); } final int DODO_INVENTORY_XPOS = 98; final int DODO_INVENTORY_YPOS = 18; if (dodo.isChested()) { for (int row = 0; row < 3; row++) { for (int col = 0; col < 3; col++) { int slotIndex = col + row * 3; addSlotToContainer( new Slot( invDodo, slotIndex, DODO_INVENTORY_XPOS + col * 18, DODO_INVENTORY_YPOS + row * 18)); } } } }
public static InvStack takeTopStack(IInventory inventory, int side) { if (!(inventory instanceof ISidedInventory)) { inventory = checkChestInv(inventory); for (int i = inventory.getSizeInventory() - 1; i >= 0; i--) { if (inventory.getStackInSlot(i) != null) { ItemStack toSend = inventory.getStackInSlot(i).copy(); return new InvStack(inventory, i, toSend); } } } else { ISidedInventory sidedInventory = (ISidedInventory) inventory; int[] slots = sidedInventory.getAccessibleSlotsFromSide( ForgeDirection.getOrientation(side).getOpposite().ordinal()); if (slots != null && slots.length != 0) { for (int get = slots.length - 1; get >= 0; get--) { int slotID = slots[get]; if (sidedInventory.getStackInSlot(slotID) != null) { ItemStack toSend = sidedInventory.getStackInSlot(slotID); if (sidedInventory.canExtractItem( slotID, toSend, ForgeDirection.getOrientation(side).getOpposite().ordinal())) { return new InvStack(inventory, slotID, toSend); } } } } } return null; }
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) { ItemStack itemstack = null; Slot slot = (Slot) this.inventorySlots.get(par2); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); int s = gear.getSizeInventory(); if (par2 < s) { if (!this.mergeItemStack(itemstack1, s, this.inventorySlots.size(), true)) { return null; } } else if (!this.mergeItemStack(itemstack1, 0, s, false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack(null); } else { slot.onSlotChanged(); } } return itemstack; }
public static void DropItems(TileEntity tileEntity) { if (!(tileEntity instanceof IInventory)) return; IInventory inventory = (IInventory) tileEntity; if (inventory != null) DropItems(tileEntity, 0, inventory.getSizeInventory() - 1); }
@Override public ItemStack getCraftingResult(IInventory inventory) { ItemStack skinStack = null; ItemStack blackStack = null; for (int slotId = 0; slotId < inventory.getSizeInventory(); slotId++) { ItemStack stack = inventory.getStackInSlot(slotId); if (stack != null) { Item item = stack.getItem(); if (item == ModItems.equipmentSkin && EquipmentNBTHelper.stackHasSkinData(stack)) { if (skinStack != null) { return null; } skinStack = stack; } else if (item == ModItems.equipmentSkinTemplate & !EquipmentNBTHelper.stackHasSkinData(stack)) { if (blackStack != null) { return null; } blackStack = stack; } else { return null; } } } if (skinStack != null && blackStack != null) { ItemStack returnStack = new ItemStack(ModItems.equipmentSkin, 1); SkinPointer skinData = EquipmentNBTHelper.getSkinPointerFromStack(skinStack); EquipmentNBTHelper.addSkinDataToStack(returnStack, skinData.skinType, skinData.skinId, false); return returnStack; } return null; }
public ContainerSaltFridge(IInventory par1IInventory, IInventory par2IInventory) { this.fridgeInventory = par2IInventory; this.numRows = par2IInventory.getSizeInventory() / 9; par2IInventory.openChest(); int i = (this.numRows - 4) * 18; int j; int k; for (j = 0; j < this.numRows; ++j) { for (k = 0; k < 9; ++k) { this.addSlotToContainer(new Slot(par2IInventory, k + j * 9, 8 + k * 18, 18 + j * 18)); } } for (j = 0; j < 3; ++j) { for (k = 0; k < 9; ++k) { this.addSlotToContainer( new Slot(par1IInventory, k + j * 9 + 9, 8 + k * 18, 103 + j * 18 + i)); } } for (j = 0; j < 9; ++j) { this.addSlotToContainer(new Slot(par1IInventory, j, 8 + j * 18, 161 + i)); } }
public static ItemStack insertStackIntoInventory( IInventory inventory, ItemStack stack, int side) { if (stack == null || inventory == null) return null; int stackSize = stack.stackSize; if (inventory instanceof ISidedInventory) { ISidedInventory sidedInv = (ISidedInventory) inventory; int slots[] = sidedInv.getAccessibleSlotsFromSide(side); if (slots == null) return stack; for (int i = 0; i < slots.length && stack != null; i++) { if (sidedInv.canInsertItem(slots[i], stack, side)) { ItemStack existingStack = inventory.getStackInSlot(slots[i]); if (OreDictionary.itemMatches(existingStack, stack, true) && ItemStack.areItemStackTagsEqual(stack, existingStack)) stack = addToOccupiedSlot(sidedInv, slots[i], stack, existingStack); } } for (int i = 0; i < slots.length && stack != null; i++) if (inventory.getStackInSlot(slots[i]) == null && sidedInv.canInsertItem(slots[i], stack, side)) stack = addToEmptyInventorySlot(sidedInv, slots[i], stack); } else { int invSize = inventory.getSizeInventory(); for (int i = 0; i < invSize && stack != null; i++) { ItemStack existingStack = inventory.getStackInSlot(i); if (OreDictionary.itemMatches(existingStack, stack, true) && ItemStack.areItemStackTagsEqual(stack, existingStack)) stack = addToOccupiedSlot(inventory, i, stack, existingStack); } for (int i = 0; i < invSize && stack != null; i++) if (inventory.getStackInSlot(i) == null) stack = addToEmptyInventorySlot(inventory, i, stack); } if (stack == null || stack.stackSize != stackSize) inventory.markDirty(); return stack; }
/** * Adds an ItemStack to the first available slot in the provided IInventory, continuing to * distribute the stack as necessary until the stacksize reaches 0, if possible * * @return the number of items remaining in the stack, zero if all were added */ public static int addItemToInventory(ItemStack stack, IInventory inv) { int remaining = stack.stackSize; for (int i = 0; i < inv.getSizeInventory() && remaining > 0; ++i) { ItemStack slotstack = inv.getStackInSlot(i); if (slotstack == null && inv.isItemValidForSlot(i, stack)) { remaining -= inv.getInventoryStackLimit(); stack.stackSize = (remaining > 0 ? inv.getInventoryStackLimit() : stack.stackSize); inv.setInventorySlotContents(i, stack); inv.markDirty(); } else if (slotstack != null && stack.isStackable() && inv.isItemValidForSlot(i, stack)) { if (slotstack.getItem() == stack.getItem() && (!stack.getHasSubtypes() || stack.getItemDamage() == slotstack.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack, slotstack)) { int l = slotstack.stackSize + remaining; if (l <= stack.getMaxStackSize() && l <= inv.getInventoryStackLimit()) { remaining = 0; slotstack.stackSize = l; inv.markDirty(); } else if (slotstack.stackSize < stack.getMaxStackSize() && stack.getMaxStackSize() <= inv.getInventoryStackLimit()) { remaining -= stack.getMaxStackSize() - slotstack.stackSize; slotstack.stackSize = stack.getMaxStackSize(); inv.markDirty(); } } } } return remaining; }
public static boolean canInsertStackIntoInventory( IInventory inventory, ItemStack stack, int side) { if (stack == null || inventory == null) return false; if (inventory instanceof ISidedInventory) { ISidedInventory sidedInv = (ISidedInventory) inventory; int slots[] = sidedInv.getAccessibleSlotsFromSide(side); if (slots == null) return false; for (int i = 0; i < slots.length && stack != null; i++) { if (sidedInv.canInsertItem(slots[i], stack, side) && sidedInv.isItemValidForSlot(slots[i], stack)) { ItemStack existingStack = inventory.getStackInSlot(slots[i]); if (existingStack == null) return true; else if (OreDictionary.itemMatches(existingStack, stack, true) && ItemStack.areItemStackTagsEqual(stack, existingStack)) if (existingStack.stackSize + stack.stackSize < inventory.getInventoryStackLimit() && existingStack.stackSize + stack.stackSize < existingStack.getMaxStackSize()) return true; } } } else { int invSize = inventory.getSizeInventory(); for (int i = 0; i < invSize && stack != null; i++) if (inventory.isItemValidForSlot(i, stack)) { ItemStack existingStack = inventory.getStackInSlot(i); if (existingStack == null) return true; else if (OreDictionary.itemMatches(existingStack, stack, true) && ItemStack.areItemStackTagsEqual(stack, existingStack)) if (existingStack.stackSize + stack.stackSize < inventory.getInventoryStackLimit() && existingStack.stackSize + stack.stackSize < existingStack.getMaxStackSize()) return true; } } return false; }
public static boolean requestElements( EntityPlayer player, ElementList list, int purityRequired, boolean doit) { if (player.capabilities.isCreativeMode) return true; IInventory mainInv = player.inventory; int invSize = mainInv.getSizeInventory(); for (int i = 0; i < invSize; i++) { ItemStack stackInSlot = mainInv.getStackInSlot(i); if (stackInSlot != null && stackInSlot.getItem() instanceof IElementProvider) { IElementProvider elementItem = (IElementProvider) stackInSlot.getItem(); if (elementItem.getPurity(player, stackInSlot) < purityRequired) continue; ElementList els = elementItem.getElements(player, stackInSlot); if (els.size() != 0) { ItemStack newStack = elementItem.consumeElements(player, stackInSlot, list, doit); if (newStack.stackSize <= 0) mainInv.setInventorySlotContents(i, null); else mainInv.setInventorySlotContents(i, newStack); if (list.size() == 0) return true; } } } return false; }
public static StorageChunk cutWorldBB(World worldObj, AxisAlignedBB bb) { StorageChunk chunk = StorageChunk.copyWorldBB(worldObj, bb); for (int x = (int) bb.minX; x <= bb.maxX; x++) { for (int z = (int) bb.minZ; z <= bb.maxZ; z++) { for (int y = (int) bb.minY; y <= bb.maxY; y++) { // Workaround for dupe TileEntity tile = worldObj.getTileEntity(x, y, z); if (tile instanceof IInventory) { IInventory inv = (IInventory) tile; for (int i = 0; i < inv.getSizeInventory(); i++) { inv.setInventorySlotContents(i, null); } } worldObj.setBlock(x, y, z, Blocks.air, 0, 2); } } } // Carpenter's block's dupe for (Object entity : worldObj.getEntitiesWithinAABB(EntityItem.class, bb.expand(5, 5, 5))) { ((Entity) entity).setDead(); } return chunk; }
private void dropItems(World world, int x, int y, int z) { Random rand = new Random(); TileEntity tileEntity = world.getBlockTileEntity(x, y, z); if (!(tileEntity instanceof IInventory)) { return; } IInventory inventory = (IInventory) tileEntity; for (int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack item = inventory.getStackInSlot(i); if (item != null && item.stackSize > 0) { float rx = rand.nextFloat() * 0.8F + 0.1F; float ry = rand.nextFloat() * 0.8F + 0.1F; float rz = rand.nextFloat() * 0.8F + 0.1F; EntityItem entityItem = new EntityItem( world, x + rx, y + ry, z + rz, new ItemStack(item.itemID, item.stackSize, item.getItemDamage())); if (item.hasTagCompound()) { entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy()); } float factor = 0.05F; entityItem.motionX = rand.nextGaussian() * factor; entityItem.motionY = rand.nextGaussian() * factor + 0.2F; entityItem.motionZ = rand.nextGaussian() * factor; world.spawnEntityInWorld(entityItem); item.stackSize = 0; } } }
protected void dropInventory(World world, int x, int y, int z) { TileEntity tileEntity = world.getTileEntity(x, y, z); if (!(tileEntity instanceof IInventory)) { return; } IInventory inventory = (IInventory) tileEntity; for (int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack itemStack = inventory.getStackInSlot(i); if (itemStack != null && itemStack.stackSize > 0) { Random rand = new Random(); float dX = rand.nextFloat() * 0.8F + 0.1F; float dY = rand.nextFloat() * 0.8F + 0.1F; float dZ = rand.nextFloat() * 0.8F + 0.1F; EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, itemStack.copy()); if (itemStack.hasTagCompound()) { entityItem .getEntityItem() .setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy()); } float factor = 0.05F; entityItem.motionX = rand.nextGaussian() * factor; entityItem.motionY = rand.nextGaussian() * factor + 0.2F; entityItem.motionZ = rand.nextGaussian() * factor; world.spawnEntityInWorld(entityItem); itemStack.stackSize = 0; } } }
/** Inserts a stack into an inventory. Args: Inventory, stack, side. Returns leftover items. */ public static ItemStack insertStack( IInventory par0IInventory, ItemStack par1ItemStack, int par2) { if (par0IInventory instanceof ISidedInventory && par2 > -1) { ISidedInventory isidedinventory = (ISidedInventory) par0IInventory; int[] aint = isidedinventory.getAccessibleSlotsFromSide(par2); for (int j = 0; j < aint.length && par1ItemStack != null && par1ItemStack.stackSize > 0; ++j) { par1ItemStack = func_102014_c(par0IInventory, par1ItemStack, aint[j], par2); } } else { int k = par0IInventory.getSizeInventory(); for (int l = 0; l < k && par1ItemStack != null && par1ItemStack.stackSize > 0; ++l) { par1ItemStack = func_102014_c(par0IInventory, par1ItemStack, l, par2); } } if (par1ItemStack != null && par1ItemStack.stackSize == 0) { par1ItemStack = null; } return par1ItemStack; }
public static ItemStack insertItem( IInventory inventory, ItemStack itemStack, boolean test, boolean force) { if (test) { itemStack = itemStack.copy(); } int size = inventory.getSizeInventory(); for (int i = 0; i < size; i++) { if (inventory.isItemValidForSlot(i, itemStack) || force) { ItemStack storedItem = inventory.getStackInSlot(i); if (storedItem != null) { if (equalItemAndNBT(storedItem, itemStack)) { int maxStackSize = Math.min(itemStack.getMaxStackSize(), inventory.getInventoryStackLimit()); int add = Math.min(itemStack.stackSize, maxStackSize - storedItem.stackSize); if (!test) { storedItem.stackSize += add; } itemStack.stackSize -= add; inventory.setInventorySlotContents(i, storedItem); } } else { storedItem = itemStack.copy(); storedItem.stackSize = Math.min(itemStack.stackSize, itemStack.getMaxStackSize()); if (!test) { inventory.setInventorySlotContents(i, storedItem); } itemStack.stackSize -= storedItem.stackSize; } if (itemStack.stackSize <= 0) { return null; } } } return itemStack; }
/** * @param t - the TileEntity * @param loadTag - the tag */ public static void loadInventory(TileEntity t, NBTTagCompound loadTag) { if (t instanceof IInventory) { IInventory tile = (IInventory) t; for (int i = 0; i < tile.getSizeInventory(); ++i) { tile.setInventorySlotContents(i, null); } NBTTagList nbttaglist = loadTag.getTagList("Items", 10); for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); byte b0 = nbttagcompound1.getByte("Slot"); if (b0 >= 0 && b0 < tile.getSizeInventory()) { tile.setInventorySlotContents(b0, ItemStack.loadItemStackFromNBT(nbttagcompound1)); } } } }
@Override public ItemStack pullItem(ForgeDirection side, boolean doPull) { int xo = xCoord + side.offsetX; int yo = yCoord + side.offsetY; int zo = zCoord + side.offsetZ; TileEntity t = worldObj.getBlockTileEntity(xo, yo, zo); if (t instanceof IInventory) { if (t instanceof ISpecialInventory) { ISpecialInventory isi = (ISpecialInventory) t; ItemStack[] items = isi.extractItem(doPull, side.getOpposite(), 1); if (items != null && items.length > 0) return items[0]; } else if (t instanceof ISidedInventory) { ISidedInventory isi = (ISidedInventory) t; int[] slots = isi.getAccessibleSlotsFromSide(side.getOpposite().ordinal()); for (int i = 0; i < slots.length; i++) { ItemStack pulled = isi.getStackInSlot(slots[i]); if (pulled != null && isi.canExtractItem(slots[i], pulled, side.getOpposite().ordinal())) { ItemStack result = null; // pulled.copy().splitStack(1); // pulled.stackSize--; // isi.setInventorySlotContents(slots[i], pulled); // if(pulled.stackSize <= 0) isi.setInventorySlotContents(slots[i], null); if (doPull) { result = isi.decrStackSize(slots[i], 1); isi.onInventoryChanged(); } else { result = pulled.copy().splitStack(1); } return result; } } } else { IInventory ii = (IInventory) t; for (int i = 0; i < ii.getSizeInventory(); i++) { ItemStack pulled = ii.getStackInSlot(i); if (pulled != null) { ItemStack result = null; // pulled.stackSize--; // ii.setInventorySlotContents(i, pulled); // if(pulled.stackSize <= 0)ii.setInventorySlotContents(i, null); if (doPull) { result = ii.decrStackSize(i, 1); ii.onInventoryChanged(); } else { result = pulled.copy().splitStack(1); } return result; } } } } return null; }
@Override public int[] getSlots() { int[] slots = new int[_inv.getSizeInventory()]; for (int i = 0; i < slots.length; i++) { slots[i] = i; } return slots; }
public ContainerConveyorSmallInventory(InventoryPlayer inventoryPlayer, IInventory te) { tileEntity = te; for (int i = 0; i < te.getSizeInventory(); i++) { addSlotToContainer(new Slot(tileEntity, i, 44 + i * 18, 20)); } bindPlayerInventory(inventoryPlayer); }
/** Call when a container block is broken to drop the entire inv into the world */ public static void dropContainerBlockInventory(World world, int x, int y, int z) { TileEntity tileEntity = world.getTileEntity(x, y, z); if (!(tileEntity instanceof IInventory)) { return; } IInventory inv = (IInventory) tileEntity; for (int i = 0; i < inv.getSizeInventory(); ++i) { spawnItemWithRandom(world, inv.getStackInSlotOnClosing(i), x, y, z); } }
@Override public void onCraft(IInventory inventory) { for (int slotId = 0; slotId < inventory.getSizeInventory(); slotId++) { ItemStack stack = inventory.getStackInSlot(slotId); Item item = stack.getItem(); if (item == ModItems.equipmentSkinTemplate & !EquipmentNBTHelper.stackHasSkinData(stack)) { inventory.decrStackSize(slotId, 1); } } }
@Override public void buildBlock(BptSlotInfo slot, IBptContext context) { super.buildBlock(slot, context); IInventory inv = (IInventory) context.world().getTileEntity(slot.x, slot.y, slot.z); for (int i = 0; i < inv.getSizeInventory(); ++i) { inv.setInventorySlotContents(i, null); } }