Class InvUtils

java.lang.Object
io.github.bakedlibs.dough.inventory.InvUtils

public final class InvUtils extends Object
  • Method Details

    • hasEmptySlot

      public static boolean hasEmptySlot(@Nonnull Inventory inv)
      Returns whether the Inventory has at least one empty slot
      Parameters:
      inv - The Inventory to check
      Returns:
      Whether an empty slot exists
    • isEmpty

      public static boolean isEmpty(@Nonnull Inventory inv)
      This checks if the given Inventory is empty.
      Parameters:
      inv - The Inventory to check
      Returns:
      Whether that Inventory is 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 inventory
      item - The ItemStack that shall be tested for
      inv - 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 given InventoryType accepts items of the given Material
      Parameters:
      itemType - The Material of the ItemStack
      inventoryType - The InventoryType
      Returns:
      Whether the given InventoryType allows this Material to be stored within
    • fits

      public static boolean fits(@Nonnull Inventory inv, @Nonnull ItemStack item, int... slots)
      This method checks if an Item can fit into the specified slots. Note that this also checks ItemStack.getAmount() If you do not specify any Slots, all Slots of the Inventory will be checked.
      Parameters:
      inv - The inventory to check
      item - The Item that shall be tested for
      slots - The Slots that shall be iterated over
      Returns:
      Whether the slots have space for the ItemStack
    • fitAll

      public static boolean fitAll(@Nonnull Inventory inv, @Nonnull ItemStack[] items, int... slots)
      This method works similar to fits(Inventory, ItemStack, int...) but allows this check to be done for multiple ItemStacks. If you do not specify any Slots, all Slots of the Inventory will be checked.
      Parameters:
      inv - The inventory to check
      items - The Items that shall be tested for
      slots - 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)
      This method removes a given amount of items from a given Inventory if they pass the given Predicate
      Parameters:
      inv - The Inventory from which to remove the item
      amount - The amount of items that should be removed
      replaceConsumables - 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