Java Code Examples for net.minecraft.inventory.IInventory#decrStackSize()
The following examples show how to use
net.minecraft.inventory.IInventory#decrStackSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SemiBlockHeatFrame.java From PneumaticCraft with GNU General Public License v3.0 | 6 votes |
private boolean tryCookSlot(IInventory inv, int slot){ ItemStack stack = inv.getStackInSlot(slot); if(stack != null) { ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(stack); if(result != null) { ItemStack remainder = IOHelper.insert(getTileEntity(), result, true); if(remainder == null) { IOHelper.insert(getTileEntity(), result, false); inv.decrStackSize(slot, 1); lastValidSlot = slot; return true; } } } return false; }
Example 2
Source File: InventoryUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
/** * Consumes one item from slot in inv with support for containers. */ public static void consumeItem(IInventory inv, int slot) { ItemStack stack = inv.getStackInSlot(slot); Item item = stack.getItem(); if (item.hasContainerItem(stack)) { ItemStack container = item.getContainerItem(stack); inv.setInventorySlotContents(slot, container); } else { inv.decrStackSize(slot, 1); } }
Example 3
Source File: TileWarpCore.java From AdvancedRocketry with MIT License | 5 votes |
@Override public void onInventoryUpdated() { //Needs completion if(itemInPorts.isEmpty() /*&& !worldObj.isRemote*/) { attemptCompleteStructure(world.getBlockState(pos)); } if(getSpaceObject() == null || getSpaceObject().getFuelAmount() == getSpaceObject().getMaxFuelAmount()) return; for(IInventory inv : itemInPorts) { for(int i = 0; i < inv.getSizeInventory(); i++) { ItemStack stack = inv.getStackInSlot(i); int amt = 0; if(stack != null && OreDictionary.itemMatches(MaterialRegistry.getItemStackFromMaterialAndType("Dilithium", AllowedProducts.getProductByName("CRYSTAL")), stack, false)) { int stackSize = stack.getCount(); if(!world.isRemote) amt = getSpaceObject().addFuel(Configuration.fuelPointsPerDilithium*stack.getCount()); else amt = Math.min(getSpaceObject().getFuelAmount() + 10*stack.getCount(), getSpaceObject().getMaxFuelAmount()) - getSpaceObject().getFuelAmount();// inv.decrStackSize(i, amt/10); inv.markDirty(); //If full if(stackSize/10 != amt) return; } } } }
Example 4
Source File: TileChemicalReactor.java From AdvancedRocketry with MIT License | 5 votes |
public void consumeItemsSpecial(IRecipe recipe) { List<List<ItemStack>> ingredients = recipe.getIngredients(); for(int ingredientNum = 0;ingredientNum < ingredients.size(); ingredientNum++) { List<ItemStack> ingredient = ingredients.get(ingredientNum); ingredientCheck: for(IInventory hatch : itemInPorts) { for(int i = 0; i < hatch.getSizeInventory(); i++) { ItemStack stackInSlot = hatch.getStackInSlot(i); for (ItemStack stack : ingredient) { if(stackInSlot != null && stackInSlot.getCount() >= stack.getCount() && stackInSlot.isItemEqual(stack)) { ItemStack stack2 = hatch.decrStackSize(i, stack.getCount()); if(stack2.getItem() instanceof ItemArmor) { stack2.addEnchantment(AdvancedRocketryAPI.enchantmentSpaceProtection, 1); List<ItemStack> list = new LinkedList<ItemStack>(); list.add(stack2); setOutputs(list); } hatch.markDirty(); world.notifyBlockUpdate(pos, world.getBlockState(((TileEntity)hatch).getPos()), world.getBlockState(((TileEntity)hatch).getPos()), 6); break ingredientCheck; } } } } } }
Example 5
Source File: InventoryUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
/** * Consumes one item from slot in inv with support for containers. */ public static void consumeItem(IInventory inv, int slot) { ItemStack stack = inv.getStackInSlot(slot); Item item = stack.getItem(); if (item.hasContainerItem(stack)) { ItemStack container = item.getContainerItem(stack); inv.setInventorySlotContents(slot, container); } else { inv.decrStackSize(slot, 1); } }
Example 6
Source File: SemiBlockHeatFrame.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
private boolean tryCoolSlot(IInventory inv, int slot){ ItemStack stack = inv.getStackInSlot(slot); if(stack != null) { for(Pair<Object, ItemStack> recipe : PneumaticRecipeRegistry.getInstance().heatFrameCoolingRecipes) { if(PneumaticRecipeRegistry.isItemEqual(recipe.getKey(), stack)) { int amount = PneumaticRecipeRegistry.getItemAmount(recipe.getKey()); if(stack.stackSize >= amount) { ItemStack containerItem = stack.getItem().getContainerItem(stack); boolean canStoreContainerItem = false; boolean canStoreOutput = false; for(int i = 0; i < inv.getSizeInventory(); i++) { ItemStack s = inv.getStackInSlot(i); if(s == null) { if(canStoreOutput) { canStoreContainerItem = true; } else { canStoreOutput = true; } } else { if(s.isItemEqual(recipe.getRight()) && ItemStack.areItemStackTagsEqual(s, recipe.getRight()) && s.getMaxStackSize() >= s.stackSize + recipe.getRight().stackSize) { canStoreOutput = true; } if(containerItem != null && s.isItemEqual(containerItem) && ItemStack.areItemStackTagsEqual(s, containerItem) && s.getMaxStackSize() >= s.stackSize + containerItem.stackSize) { canStoreContainerItem = true; } } } if(canStoreOutput && (containerItem == null || canStoreContainerItem)) { inv.decrStackSize(slot, amount); IOHelper.insert(getTileEntity(), recipe.getValue().copy(), false); if(containerItem != null) IOHelper.insert(getTileEntity(), containerItem.copy(), false); return true; } } } } } return false; }
Example 7
Source File: TileEntitySolderingStation.java From ExtraCells1 with MIT License | 5 votes |
public Boolean decreaseItemStack(ItemStack toRemove, IInventory inventory) { for (int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack current = inventory.getStackInSlot(i); if (current != null && current.isItemEqual(toRemove)) { inventory.decrStackSize(i, 1); return true; } } return false; }
Example 8
Source File: TileRocketUnloader.java From AdvancedRocketry with MIT License | 4 votes |
@Override public void update() { //Move a stack of items if(!world.isRemote && rocket != null ) { boolean isAllowedToOperate = (inputstate == RedstoneState.OFF || isStateActive(inputstate, getStrongPowerForSides(world, getPos()))); List<TileEntity> tiles = rocket.storage.getInventoryTiles(); boolean foundStack = false; boolean rocketContainsNoItems = true; out: //Function returns if something can be moved for(TileEntity tile : tiles) { if(tile instanceof IInventory && !(tile instanceof TileGuidanceComputer)) { IInventory inv = ((IInventory)tile); for(int i = 0; i < inv.getSizeInventory(); i++) { if(!inv.getStackInSlot(i).isEmpty()) { rocketContainsNoItems = false; //Loop though this inventory's slots and find a suitible one for(int j = 0; j < getSizeInventory(); j++) { if(getStackInSlot(j).isEmpty()) { if(isAllowedToOperate) { inventory.setInventorySlotContents(j, inv.getStackInSlot(i)); inv.setInventorySlotContents(i,ItemStack.EMPTY); } break out; } else if(!inv.getStackInSlot(i).isEmpty() && isItemValidForSlot(j, inv.getStackInSlot(i))) { if(isAllowedToOperate) { ItemStack stack2 = inv.decrStackSize(i, getStackInSlot(j).getMaxStackSize() - getStackInSlot(j).getCount()); getStackInSlot(j).setCount(getStackInSlot(j).getCount() + stack2.getCount()); } if(inv.getStackInSlot(i).isEmpty()) break out; foundStack = true; } } } if(foundStack) break out; } } } //Update redstone state setRedstoneState(rocketContainsNoItems); } }
Example 9
Source File: TileEntityAssemblyIOUnit.java From PneumaticCraft with GNU General Public License v3.0 | 4 votes |
private boolean getItemFromCurrentDirection(){ TileEntity tile = getTileEntityForCurrentDirection(); boolean extracted = false; /* * we must not .reset here because we might inadvertently change this.state right before this.state++ * if((tile == null) || !(tile instanceof IInventory)) // TE / inventory is gone reset(); */ if(isImportUnit()) { if(searchedItemStack == null) { // we don't know what we're supposed to pick up reset(); } else if(tile instanceof IInventory) { IInventory inv = (IInventory)tile; int oldStackSize = inventory[0] == null ? 0 : inventory[0].stackSize; for(int i = 0; i < inv.getSizeInventory(); i++) { if(inv.getStackInSlot(i) != null) { if(inventory[0] == null) { if(inv.getStackInSlot(i).isItemEqual(searchedItemStack)) { inventory[0] = inv.decrStackSize(i, 1); } } else if(inv.getStackInSlot(i).isItemEqual(inventory[0])) { inv.decrStackSize(i, 1); inventory[0].stackSize++; } extracted = (inventory[0] == null ? 0 : inventory[0].stackSize) == searchedItemStack.stackSize; // we might need to pickup more than 1 item if(extracted) break; } } if(oldStackSize == (inventory[0] == null ? 0 : inventory[0].stackSize)) // nothing picked up, search for different inventory state = STATE_SEARCH_SRC; } else state = STATE_SEARCH_SRC; // inventory gone } else { if(tile instanceof TileEntityAssemblyPlatform) { TileEntityAssemblyPlatform plat = (TileEntityAssemblyPlatform)tile; if(plat.openClaw()) { inventory[0] = plat.getHeldStack(); plat.setHeldStack(null); extracted = inventory[0] != null; if(!extracted) // something went wrong - either the platform is gone altogether, or the item is not there anymore state = STATE_SEARCH_SRC; } } } return extracted; }