Class InventoryHelper

java.lang.Object
de.ellpeck.rockbottom.api.helper.InventoryHelper

public class InventoryHelper extends Object
  • Constructor Details

    • InventoryHelper

      public InventoryHelper()
  • Method Details

    • collectItems

      public static List<ItemInstance> collectItems(IInventory inventory)
      Collects all the items in the inventory into single item instances even if the inventory has items separated.

      For example if you collect the players inventory and it has 1 stick slot with amount set to 5 and 3 stone slots each with amount set to 20, this method will return a list of 2 items, 1 stick with amount set to 5 and 1 stone with amount set to 60.

      Parameters:
      inventory - the inventory to collect items from.
      Returns:
      The list of items collected into single type instances.
    • removeFrom

      public static int removeFrom(IInventory inv, IUseInfo item)
      Attempts to remove the item from the inventory, deducting the amounts from multiple item instances if needed. For example if you try to remove 14 stone from the players inventory which has 2 instances of 10 stones each, it will first deduct 10 from the first instance and then 6 from the second instance leaving a single item with 4 stone.
      Parameters:
      inv - The inventory to remove the item from
      item - The item to remove from the inventory
      Returns:
      the remaining amount that was not removed from the inventory