Class InvUtils
java.lang.Object
io.github.bakedlibs.dough.inventory.InvUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanThis method works similar tofits(Inventory, ItemStack, int...)but allows this check to be done for multipleItemStacks.static booleanThis method checks if an Item can fit into the specified slots.static booleanhasEmptySlot(Inventory inv) Returns whether the Inventory has at least one empty slotstatic booleanThis checks if the givenInventoryis empty.static booleanisItemAllowed(Material itemType, InventoryType inventoryType) This checks if a givenInventoryTypeaccepts items of the givenMaterialstatic booleanisValidStackSize(ItemStack stack, ItemStack item, Inventory inv) This method checks both an ItemStack's and an Inventory's maxStackSize to determine if a given ItemStack can stack with another ItemStack in the given Inventorystatic booleanremoveItem(Inventory inv, int amount, boolean replaceConsumables, Predicate<ItemStack> predicate)
-
Method Details
-
hasEmptySlot
Returns whether the Inventory has at least one empty slot- Parameters:
inv- The Inventory to check- Returns:
- Whether an empty slot exists
-
isEmpty
This checks if the givenInventoryis empty. -
isValidStackSize
public static boolean isValidStackSize(@Nonnull ItemStack stack, @Nonnull ItemStack item, @Nonnull Inventory inv) This method checks both an ItemStack's and an Inventory's maxStackSize to determine if a given ItemStack can stack with another ItemStack in the given Inventory- Parameters:
stack- The ItemStack already in the inventoryitem- The ItemStack that shall be tested forinv- The Inventory these items are existing in- Returns:
- Whether the maxStackSizes allow for these items to stack
-
isItemAllowed
public static boolean isItemAllowed(@Nonnull Material itemType, @Nonnull InventoryType inventoryType) This checks if a givenInventoryTypeaccepts items of the givenMaterial- Parameters:
itemType- TheMaterialof theItemStackinventoryType- TheInventoryType- Returns:
- Whether the given
InventoryTypeallows thisMaterialto be stored within
-
fits
This method checks if an Item can fit into the specified slots. Note that this also checksItemStack.getAmount()If you do not specify any Slots, all Slots of the Inventory will be checked.- Parameters:
inv- The inventory to checkitem- The Item that shall be tested forslots- The Slots that shall be iterated over- Returns:
- Whether the slots have space for the
ItemStack
-
fitAll
This method works similar tofits(Inventory, ItemStack, int...)but allows this check to be done for multipleItemStacks. If you do not specify any Slots, all Slots of the Inventory will be checked.- Parameters:
inv- The inventory to checkitems- The Items that shall be tested forslots- The Slots that shall be iterated over- Returns:
- Whether the slots have space for the given
ItemStacks
-
removeItem
public static boolean removeItem(@Nonnull Inventory inv, int amount, boolean replaceConsumables, @Nonnull Predicate<ItemStack> predicate) - Parameters:
inv- TheInventoryfrom which to remove the itemamount- The amount of items that should be removedreplaceConsumables- Whether to replace consumables, e.g. turn potions into glass bottles etc...predicate- The Predicate that tests the item- Returns:
- Whether the operation was successful
-