Interface IItemSource


public interface IItemSource
Represent an item source. Take only, cannot be placed back.
  • Method Details

    • take

      @Nonnull Map<ItemStack, Integer> take(Predicate<ItemStack> predicate, boolean simulate, int count)
      Retrieve some amount of items from this item source matching given filter.

      We probably don't need to get a lot of items from this method, so I don't care about the overhead of storing all fetched items even if downstream code doesn't need it

      Parameters:
      predicate - filtering predicate. should return true for ItemStacks that should be added to result collection
      simulate - whether to actually commit the modification. true for dry run, false otherwise.
      count - how many items to extract.
      Returns:
      A nonnull map reflecting the result of extraction. Note this map is NBT and metadata aware.
    • takeOne

      default ItemStack takeOne(Predicate<ItemStack> predicate, boolean simulate)
      Take exactly one item that matches the predicate.
      Parameters:
      predicate - filtering predicate. should return true for ItemStacks that should be added to result collection
      simulate - whether to actually commit the modification. true for dry run, false otherwise.
      Returns:
      item stack, or null if none matches
      Throws:
      IllegalArgumentException - if given predicate is null.
    • takeAll

      default boolean takeAll(Predicate<ItemStack> predicate, boolean simulate, int count)
      Take exactly count amount of items matching predicate.
      Parameters:
      predicate - filtering predicate. should return true for ItemStacks that should be added to result collection
      simulate - whether to actually commit the modification. true for dry run, false otherwise.
      count - how many items to extract.
      Returns:
      true if at least count amount of items can be/is taken.
      Throws:
      IllegalArgumentException - if given predicate is null
    • takeOne

      default boolean takeOne(ItemStack stack, boolean simulate)
      Take exactly one item. ItemStack given must have a stack size of 1.

      This is meant to be an optimized version of takeOne(Predicate, boolean). Implementations that support item storage indexed by ItemStack can use this to speed up calculation.

      Parameters:
      stack - what item to extract. The NBT tag of this ItemStack is siginifcant and will be considered during matching. must have a stack size of 1.
      simulate - whether to actually commit the modification. true for dry run, false otherwise.
      Returns:
      true if found. false otherwise
      Throws:
      IllegalArgumentException - if given stack is invalid, or has a stack size other than 1.
    • takeAll

      default boolean takeAll(ItemStack stack, boolean simulate)
      Take some item. Will not take item if it cannot find enough items to take.

      This is meant to be an optimized version of takeOne(Predicate, boolean). Implementations that support indexing off ItemStack can use this to speed up calculation.

      Parameters:
      stack - what item and how many to extract. The NBT tag of this ItemStack is siginifcant and will be considered during matching
      simulate - whether to actually commit the modification. true for dry run, false otherwise.
      Returns:
      true if enough item can be/has been extracted. false otherwise
      Throws:
      IllegalArgumentException - if given stack is invalid
    • fromPlayer

      static IItemSource fromPlayer(EntityPlayerMP player)
      Construct an IItemSource from inventories associated with given player.

      This will be backed by InventoryUtility

    • fromInventory

      static IItemSource fromInventory(IInventory inv)
      Construct an IItemSource from given inventory

      This will be backed by InventoryUtility