/** * We can assume that if null is passed for the container that the container was consumed by the * process and we should just remove the input container. * * @param inv * @param inputSlot * @param outputSlot * @param container */ private static void storeContainer( IInventory inv, int inputSlot, int outputSlot, ItemStack container) { if (container == null) { inv.decrStackSize(inputSlot, 1); return; } ItemStack output = inv.getStackInSlot(outputSlot); if (output == null) inv.setInventorySlotContents(outputSlot, container); else output.stackSize++; inv.decrStackSize(inputSlot, 1); }
@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 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 onCrafting(EntityPlayer player, ItemStack output, IInventory craftMatrix) { ItemStack itemstack1 = craftMatrix.getStackInSlot(0); // Assumption: Only 1 input, will always be decreased by only 1 if (itemstack1 != null) { craftMatrix.decrStackSize(0, 1); } updateResult(); }
@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 ItemStack checkExtractGeneric( IInventory inventory, boolean doRemove, ForgeDirection from, int[] slots) { for (int i : slots) { ItemStack slot = inventory.getStackInSlot(i); if (slot != null && slot.stackSize > 0 && canExtract(slot)) { if (doRemove) { return inventory.decrStackSize(i, (int) powerProvider.useEnergy(1, slot.stackSize, true)); } else { return slot; } } } return null; }
@Override public List<RanchedItem> ranch(World world, EntityLivingBase entity, IInventory rancher) { List<RanchedItem> drops = new LinkedList<RanchedItem>(); IInventoryManager manager = InventoryManager.create(rancher, ForgeDirection.UP); int bucketIndex = manager.findItem(new ItemStack(Item.bucketEmpty)); if (bucketIndex >= 0) { drops.add(new RanchedItem(Item.bucketMilk)); rancher.decrStackSize(bucketIndex, 1); } else { FluidStack milk = FluidRegistry.getFluidStack("milk", FluidContainerRegistry.BUCKET_VOLUME); drops.add(new RanchedItem(milk)); } return drops; }
private static boolean insertStackFromInventory( Hopper par0Hopper, IInventory par1IInventory, int par2, int par3) { ItemStack itemstack = par1IInventory.getStackInSlot(par2); if (itemstack != null && canExtractItemFromInventory(par1IInventory, itemstack, par2, par3)) { ItemStack itemstack1 = itemstack.copy(); ItemStack itemstack2 = insertStack(par0Hopper, par1IInventory.decrStackSize(par2, 1), -1); if (itemstack2 == null || itemstack2.stackSize == 0) { par1IInventory.onInventoryChanged(); return true; } par1IInventory.setInventorySlotContents(par2, itemstack1); } return false; }
@Override public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { if (!this.isLinked()) return new ItemStack[0]; ItemStack product = null; IInventory inventory = getOrCreateTradeInventory(); for (int i = TradeStation.SLOT_OUTPUTBUF_1; i < TradeStation.SLOT_OUTPUTBUF_1 + TradeStation.SLOT_BUFFER_COUNT; i++) { ItemStack stackSlot = inventory.getStackInSlot(i); if (stackSlot == null) continue; if (stackSlot.stackSize <= 0) continue; product = inventory.decrStackSize(i, 1); break; } if (product != null) return new ItemStack[] {product}; else return new ItemStack[0]; }
@Override public List<ItemStack> ranch(World world, EntityLiving entity, IInventory rancher) { List<ItemStack> drops = new LinkedList<ItemStack>(); IInventoryManager manager = InventoryManager.create(rancher, ForgeDirection.UP); int bowlIndex = manager.findItem(new ItemStack(Item.bowlEmpty)); if (bowlIndex >= 0) { drops.add(new ItemStack(Item.bowlSoup)); rancher.decrStackSize(bowlIndex, 1); } int bucketIndex = manager.findItem(new ItemStack(Item.bucketEmpty)); if (bucketIndex >= 0) { drops.add(new ItemStack(Item.bucketMilk)); rancher.setInventorySlotContents(bucketIndex, null); } else { LiquidStack soup = LiquidDictionary.getLiquid("mushroomsoup", 1000); drops.add(new ItemStack(soup.itemID, 1, soup.itemMeta)); } return drops; }
@Override public void onPickupFromSlot(EntityPlayer player, ItemStack itemstack) { itemstack.onCrafting(thePlayer.worldObj, thePlayer, slotNumber); TerraFirmaCraft.proxy.takenFromCrafting(thePlayer, itemstack, craftMatrix); for (int i = 0; i < craftMatrix.getSizeInventory(); i++) { ItemStack itemstack1 = craftMatrix.getStackInSlot(i); if (itemstack1 != null) { craftMatrix.decrStackSize(i, 1); if (player.worldObj.isRemote && player.openContainer instanceof ContainerSpecialCrafting) ((GuiKnapping) Minecraft.getMinecraft().currentScreen).resetButton(i); if (itemstack1.getItem().getContainerItem() != null) { ItemStack itemstack2 = new ItemStack(itemstack1.getItem().getContainerItem()); if (!itemstack1.getItem().doesContainerItemLeaveCraftingGrid(itemstack1) || !thePlayer.inventory.addItemStackToInventory(itemstack2)) { if (craftMatrix.getStackInSlot(i) == null) craftMatrix.setInventorySlotContents(i, itemstack2); else thePlayer.entityDropItem(itemstack2, 0); } } } } }
public static ItemStack takeTopItemFromInventory(IInventory inventory, int side) { if (!(inventory instanceof ISidedInventory)) { for (int i = inventory.getSizeInventory() - 1; i >= 0; i--) { if (inventory.getStackInSlot(i) != null) { ItemStack toSend = inventory.getStackInSlot(i).copy(); toSend.stackSize = 1; inventory.decrStackSize(i, 1); return toSend; } } } else { ISidedInventory sidedInventory = (ISidedInventory) inventory; int[] slots = sidedInventory.getAccessibleSlotsFromSide(side); if (slots != null) { for (int get = slots.length - 1; get >= 0; get--) { int slotID = slots[get]; if (sidedInventory.getStackInSlot(slotID) != null) { ItemStack toSend = sidedInventory.getStackInSlot(slotID); toSend.stackSize = 1; if (sidedInventory.canExtractItem(slotID, toSend, side)) { sidedInventory.decrStackSize(slotID, 1); return toSend; } } } } } return null; }
@Override public ItemStack decrStackSize(int slot, int amount) { return inv.decrStackSize(start + slot, amount); }
@Override public void performEffect(IMasterRitualStone ritualStone) { String owner = ritualStone.getOwner(); int currentEssence = SoulNetworkHandler.getCurrentEssence(owner); World world = ritualStone.getWorld(); int x = ritualStone.getXCoord(); int y = ritualStone.getYCoord(); int z = ritualStone.getZCoord(); if (world.getWorldTime() % 20 != 0) { return; } double horizRange = 16; double vertRange = 16; List<EntityPlayer> playerList = SpellHelper.getPlayersInRange(world, x + 0.5, y + 0.5, z + 0.5, horizRange, vertRange); if (playerList == null) { return; } if (currentEssence < this.getCostPerRefresh() * playerList.size()) { SoulNetworkHandler.causeNauseaToPlayer(owner); } else { TileEntity tile = world.getTileEntity(x, y + 1, z); IInventory inventory = null; if (tile instanceof IInventory) { inventory = (IInventory) tile; } else { tile = world.getTileEntity(x, y - 1, z); if (tile instanceof IInventory) { inventory = (IInventory) tile; } } int count = 0; if (inventory != null) { for (EntityPlayer player : playerList) { FoodStats foodStats = player.getFoodStats(); float satLevel = foodStats.getSaturationLevel(); for (int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack stack = inventory.getStackInSlot(i); if (stack != null && stack.getItem() instanceof ItemFood) { ItemFood foodItem = (ItemFood) stack.getItem(); int regularHeal = foodItem.func_150905_g(stack); float saturatedHeal = foodItem.func_150906_h(stack) * regularHeal * 2.0f; if (saturatedHeal + satLevel <= 20) { NBTTagCompound nbt = new NBTTagCompound(); foodStats.writeNBT(nbt); nbt.setFloat("foodSaturationLevel", saturatedHeal + satLevel); foodStats.readNBT(nbt); inventory.decrStackSize(i, 1); count++; break; } } } } } SoulNetworkHandler.syphonFromNetwork(owner, this.getCostPerRefresh() * count); } }