codechicken.lib.util.ItemUtils Java Examples
The following examples show how to use
codechicken.lib.util.ItemUtils.
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: ContainerPotionCreator.java From NotEnoughItems with MIT License | 6 votes |
@Override public ItemStack slotClick(ContainerExtended container, EntityPlayer player, int button, ClickType clickType) { ItemStack held = player.inventory.getItemStack(); if (button == 0 && clickType == ClickType.QUICK_MOVE) { NEIClientUtils.cheatItem(getStack(), button, -1); } else if (button == 1) { putStack(ItemStack.EMPTY); } else if (!held.isEmpty()) { if (isItemValid(held)) { putStack(ItemUtils.copyStack(held, 1)); player.inventory.setItemStack(ItemStack.EMPTY); } } else if (getHasStack()) { player.inventory.setItemStack(getStack()); } return ItemStack.EMPTY; }
Example #2
Source File: SlotDummy.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void putStack(@Nonnull ItemStack stack) { if (!stack.isEmpty() && stack.getCount() > stackLimit) { stack = ItemUtils.copyStack(stack, stackLimit); } super.putStack(stack); }
Example #3
Source File: InventoryUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
/** * Gets the maximum quantity of an item that can be inserted into inv */ public static int getInsertibleQuantity(InventoryRange inv, @Nonnull ItemStack stack) { int quantity = 0; stack = ItemUtils.copyStack(stack, Integer.MAX_VALUE); for (int slot : inv.slots) { quantity += fitStackInSlot(inv, slot, stack); } return quantity; }
Example #4
Source File: InventoryUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
/** * @param simulate If set to true, no items will actually be inserted * @return The number of items unable to be inserted */ public static int insertItem(InventoryRange inv, @Nonnull ItemStack stack, boolean simulate) { stack = stack.copy(); for (int pass = 0; pass < 2; pass++) { for (int slot : inv.slots) { ItemStack base = inv.inv.getStackInSlot(slot); if ((pass == 0) == (base.isEmpty())) { continue; } int fit = fitStackInSlot(inv, slot, stack); if (fit == 0) { continue; } if (!base.isEmpty()) { stack.shrink(fit); if (!simulate) { base.grow(fit); inv.inv.setInventorySlotContents(slot, base); } } else { if (!simulate) { inv.inv.setInventorySlotContents(slot, ItemUtils.copyStack(stack, fit)); } stack.shrink(fit); } if (stack.getCount() == 0) { return 0; } } } return stack.getCount(); }
Example #5
Source File: InventoryUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
/** * Counts the matching stacks. * Checks for insertion or extraction. * * @param handler The inventory. * @param filter What we are checking for. * @param insert If we are checking for insertion or extraction. * @return The total number of items of the specified filter type. */ public static int countMatchingStacks(IItemHandler handler, ItemStack filter, boolean insert) { int c = 0; for (int slot = 0; slot < handler.getSlots(); slot++) { ItemStack stack = handler.getStackInSlot(slot); if (!stack.isEmpty() && ItemUtils.areStacksSameType(filter, stack) && (insert ? canInsertStack(handler, slot, stack) : canExtractStack(handler, slot))) { c += stack.getCount(); } } return c; }
Example #6
Source File: InventoryUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
public static int getInsertableQuantity(IItemHandler handler, ItemStack stack) { ItemStack copy = ItemUtils.copyStack(stack, Integer.MAX_VALUE); int quantity = 0; for (int slot = 0; slot < handler.getSlots(); slot++) { if (canInsertStack(handler, slot, copy)) { ItemStack left = handler.insertItem(slot, copy, true); if (left.isEmpty()) { quantity += copy.getCount(); } else { quantity += copy.getCount() - left.getCount(); } } } return quantity; }
Example #7
Source File: InfiniteStackSizeHandler.java From NotEnoughItems with MIT License | 4 votes |
@Override public ItemStack getInfiniteItem(ItemStack typeStack) { return ItemUtils.copyStack(typeStack, -1); }
Example #8
Source File: DefaultOverlayHandler.java From NotEnoughItems with MIT License | 4 votes |
public DistributedIngred(ItemStack item) { stack = ItemUtils.copyStack(item, 1); }