Java Code Examples for net.minecraft.inventory.IInventory#markDirty()
The following examples show how to use
net.minecraft.inventory.IInventory#markDirty() .
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: InventoryUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
/** * Static default implementation for IInventory method */ @Nonnull public static ItemStack decrStackSize(IInventory inv, int slot, int size) { ItemStack item = inv.getStackInSlot(slot); if (!item.isEmpty()) { if (item.getCount() <= size) { inv.setInventorySlotContents(slot, ItemStack.EMPTY); inv.markDirty(); return item; } ItemStack itemstack1 = item.split(size); if (item.getCount() == 0) { inv.setInventorySlotContents(slot, ItemStack.EMPTY); } else { inv.setInventorySlotContents(slot, item); } inv.markDirty(); return itemstack1; } return ItemStack.EMPTY; }
Example 2
Source File: AdapterWritingDesk.java From OpenPeripheral-Integration with MIT License | 6 votes |
@ScriptCallable( returnTypes = ReturnType.NUMBER, description = "Push a page from the notebook into a specific slot in external inventory. Returns the amount of items moved") public int pushNotebookPage( TileEntity desk, @Arg(name = "deskSlot") Index deskSlot, @Arg(name = "direction", description = "The direction of the other inventory. (north, south, east, west, up or down)") ForgeDirection direction, @Arg(name = "fromSlot", description = "The page slot in inventory that you're pushing from") Index fromSlot, @Optionals @Arg(name = "intoSlot", description = "The slot in the other inventory that you want to push into") Index intoSlot) { IInventory source = createInventoryWrapper(desk, deskSlot); IInventory target = getTargetTile(desk, direction); if (intoSlot == null) intoSlot = Index.fromJava(-1, 0); final int amount = ItemDistribution.moveItemInto(source, fromSlot.value, target, intoSlot.value, 64, direction.getOpposite(), true); if (amount > 0) target.markDirty(); return amount; }
Example 3
Source File: AdapterWritingDesk.java From OpenPeripheral-Integration with MIT License | 6 votes |
@ScriptCallable(returnTypes = ReturnType.BOOLEAN, description = "Pull an item from the target inventory into any slot in the current one. Returns true if item was consumed") public boolean pullNotebookPage(TileEntity desk, @Arg(name = "deskSlot") Index deskSlot, @Arg(name = "direction", description = "The direction of the other inventory)") ForgeDirection direction, @Arg(name = "fromSlot", description = "The slot in the other inventory that you're pulling from") Index fromSlot) { IInventory inv = getTargetTile(desk, direction); fromSlot.checkElementIndex("input slot", inv.getSizeInventory()); ItemStack stack = inv.getStackInSlot(fromSlot.value); Preconditions.checkNotNull(stack, "Other inventory empty"); final NotebookWrapper wrapper = createInventoryWrapper(desk, deskSlot); ItemStack added = wrapper.addPage(stack); inv.setInventorySlotContents(fromSlot.value, added); inv.markDirty(); return added == null; }
Example 4
Source File: AdapterInventory.java From OpenPeripheral-Integration with MIT License | 6 votes |
@Asynchronous(false) @ScriptCallable(description = "Condense and tidy the stacks in an inventory") public void condenseItems(IInventory target) { IInventory inventory = InventoryUtils.getInventory(target); List<ItemStack> stacks = Lists.newArrayList(); for (int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack sta = inventory.getStackInSlot(i); if (sta != null) stacks.add(sta.copy()); inventory.setInventorySlotContents(i, null); } for (ItemStack stack : stacks) ItemDistribution.insertItemIntoInventory(inventory, stack, ForgeDirection.UNKNOWN, ANY_SLOT); target.markDirty(); }
Example 5
Source File: AdapterInventory.java From OpenPeripheral-Integration with MIT License | 6 votes |
@Asynchronous(false) @ScriptCallable(description = "Swap two slots in the inventory") public void swapStacks(IInventory target, @Arg(name = "from", description = "The first slot") Index fromSlot, @Arg(name = "to", description = "The other slot") Index intoSlot, @Optionals @Arg(name = "fromDirection") ForgeDirection fromDirection, @Arg(name = "fromDirection") ForgeDirection toDirection) { IInventory inventory = InventoryUtils.getInventory(target); Preconditions.checkNotNull(inventory, "Invalid target!"); final int size = inventory.getSizeInventory(); fromSlot.checkElementIndex("first slot id", size); intoSlot.checkElementIndex("second slot id", size); if (inventory instanceof ISidedInventory) { InventoryUtils.swapStacks((ISidedInventory)inventory, fromSlot.value, Objects.firstNonNull(fromDirection, ForgeDirection.UNKNOWN), intoSlot.value, Objects.firstNonNull(toDirection, ForgeDirection.UNKNOWN)); } else InventoryUtils.swapStacks(inventory, fromSlot.value, intoSlot.value); inventory.markDirty(); }
Example 6
Source File: InventoryUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
/** * Static default implementation for IInventory method */ public static ItemStack decrStackSize(IInventory inv, int slot, int size) { ItemStack item = inv.getStackInSlot(slot); if (item != null) { if (item.stackSize <= size) { inv.setInventorySlotContents(slot, null); inv.markDirty(); return item; } ItemStack itemstack1 = item.splitStack(size); if (item.stackSize == 0) inv.setInventorySlotContents(slot, null); else inv.setInventorySlotContents(slot, item); inv.markDirty(); return itemstack1; } return null; }
Example 7
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 8
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 9
Source File: AdapterWritingDesk.java From OpenPeripheral-Integration with MIT License | 5 votes |
@ScriptCallable(returnTypes = ReturnType.NUMBER, description = "Pull an item from the target inventory into any slot in the current one. Returns the amount of items moved") public int pullNotebookPage(TileEntity desk, @Arg(name = "deskSlot") Index deskSlot, @Arg(name = "direction", description = "The direction of the other inventory)") ForgeDirection direction, @Arg(name = "fromSlot", description = "The slot in the other inventory that you're pulling from") int notebookSlot) { IInventory source = getTargetTile(desk, direction); IInventory target = createInventoryWrapper(desk, deskSlot); final int amount = ItemDistribution.moveItemInto(source, notebookSlot - 1, target, -1, 1, direction.getOpposite(), true, false); if (amount > 0) source.markDirty(); return amount; }
Example 10
Source File: AdapterWorldInventory.java From OpenPeripheral-Integration with MIT License | 5 votes |
@Alias("pullItemIntoSlot") @ScriptCallable(returnTypes = ReturnType.NUMBER, description = "Pull an item from a slot in another inventory into a slot in this one. Returns the amount of items moved") public int pullItem(IInventory target, @Arg(name = "direction", description = "The direction of the other inventory") ForgeDirection direction, @Arg(name = "slot", description = "The slot in the OTHER inventory that you're pulling from") Index fromSlot, @Optionals @Arg(name = "maxAmount", description = "The maximum amount of items you want to pull") Integer maxAmount, @Arg(name = "intoSlot", description = "The slot in the current inventory that you want to pull into") Index intoSlot) { final TileEntity otherTarget = getNeighborTarget(target, direction); if (otherTarget == null) throw new IllegalArgumentException("Other block not found"); if (!(otherTarget instanceof IInventory)) throw new IllegalArgumentException("Other block is not inventory"); final IInventory otherInventory = InventoryUtils.getInventory((IInventory)otherTarget); final IInventory thisInventory = InventoryUtils.getInventory(target); if (otherTarget == target) return 0; if (maxAmount == null) maxAmount = 64; if (intoSlot == null) intoSlot = ANY_SLOT_INDEX; checkSlotId(otherInventory, fromSlot, "input"); checkSlotId(thisInventory, intoSlot, "output"); final int amount = ItemDistribution.moveItemInto(otherInventory, fromSlot.value, thisInventory, intoSlot.value, maxAmount, direction.getOpposite(), true); if (amount > 0) { thisInventory.markDirty(); otherInventory.markDirty(); } return amount; }
Example 11
Source File: AdapterWorldInventory.java From OpenPeripheral-Integration with MIT License | 5 votes |
@Alias("pushItemIntoSlot") @ScriptCallable(returnTypes = ReturnType.NUMBER, description = "Push an item from the current inventory into pipe or slot on the other inventory. Returns the amount of items moved") public int pushItem(IInventory target, @Arg(name = "direction", description = "The direction of the other inventory") ForgeDirection direction, @Arg(name = "slot", description = "The slot in the current inventory that you're pushing from") Index fromSlot, @Optionals @Arg(name = "maxAmount", description = "The maximum amount of items you want to push") Integer maxAmount, @Arg(name = "intoSlot", description = "The slot in the other inventory that you want to push into (ignored when target is pipe") Index intoSlot) { final TileEntity otherTarget = getNeighborTarget(target, direction); Preconditions.checkNotNull(otherTarget, "Other target not found"); final IInventory thisInventory = InventoryUtils.getInventory(target); if (maxAmount == null) maxAmount = 64; if (intoSlot == null) intoSlot = ANY_SLOT_INDEX; checkSlotId(thisInventory, fromSlot, "input"); final int amount; if (otherTarget instanceof IInventory) { final IInventory otherInventory = InventoryUtils.getInventory((IInventory)otherTarget); checkSlotId(otherInventory, intoSlot, "output"); amount = ItemDistribution.moveItemInto(thisInventory, fromSlot.value, otherInventory, intoSlot.value, maxAmount, direction, true); if (amount > 0) otherInventory.markDirty(); } else { final CustomSinks.ICustomSink adapter = CustomSinks.createSink(otherTarget); if (adapter == null) throw new IllegalArgumentException("Invalid target"); amount = ItemDistribution.moveItemInto(thisInventory, fromSlot.value, adapter, maxAmount, direction, true); } if (amount > 0) thisInventory.markDirty(); return amount; }
Example 12
Source File: AdapterInventory.java From OpenPeripheral-Integration with MIT License | 5 votes |
@Asynchronous(false) @ScriptCallable(description = "Destroy a stack") public void destroyStack(IInventory target, @Arg(name = "slotNumber", description = "The slot number") Index slot) { IInventory inventory = InventoryUtils.getInventory(target); slot.checkElementIndex("slot id", inventory.getSizeInventory()); inventory.setInventorySlotContents(slot.value, null); inventory.markDirty(); }
Example 13
Source File: AdapterInterface.java From OpenPeripheral-Integration with MIT License | 4 votes |
@ScriptCallable(description = "Exports the specified item into the target inventory.", returnTypes = ReturnType.TABLE) public IAEItemStack exportItem(Object tileEntityInterface, @Arg(name = "fingerprint", description = "Details of the item you want to export (can be result of .getStackInSlot() or .getAvailableItems())") ItemFingerprint needle, @Arg(name = "direction", description = "Location of target inventory") ForgeDirection direction, @Optionals @Arg(name = "maxAmount", description = "The maximum amount of items you want to export") Integer maxAmount, @Arg(name = "intoSlot", description = "The slot in the other inventory that you want to export into") Index intoSlot) { final IActionHost host = (IActionHost)tileEntityInterface; final IInventory neighbor = getNeighborInventory(tileEntityInterface, direction); Preconditions.checkArgument(neighbor != null, "No neighbour attached"); if (intoSlot == null) intoSlot = Index.fromJava(-1, 0); IStorageGrid storageGrid = getStorageGrid(host); IMEMonitor<IAEItemStack> monitor = storageGrid.getItemInventory(); IAEItemStack stack = findStack(monitor.getStorageList(), needle); Preconditions.checkArgument(stack != null, "Can't find item fingerprint %s", needle); IAEItemStack toExtract = stack.copy(); if (maxAmount == null || maxAmount < 1 || maxAmount > toExtract.getItemStack().getMaxStackSize()) { toExtract.setStackSize(toExtract.getItemStack().getMaxStackSize()); } else { toExtract.setStackSize(maxAmount); } // Actually export the items from the ME system. MachineSource machineSource = new MachineSource(host); IAEItemStack extracted = monitor.extractItems(toExtract, Actionable.MODULATE, machineSource); if (extracted == null) return null; ItemStack toInsert = extracted.getItemStack().copy(); // Put the item in the neighbor inventory if (ItemDistribution.insertItemIntoInventory(neighbor, toInsert, direction.getOpposite(), intoSlot.value)) { neighbor.markDirty(); } // If we've moved some items, but others are still remaining. // Insert them back into the ME system. if (toInsert.stackSize > 0) { final IAEItemStack toReturn = AEApi.instance().storage().createItemStack(toInsert); monitor.injectItems(toReturn, Actionable.MODULATE, machineSource); extracted.decStackSize(toInsert.stackSize); } // Return what we've actually extracted return extracted; }