Interface IItemSource
public interface IItemSource
Represent an item source. Take only, cannot be placed back.
-
Method Summary
Modifier and TypeMethodDescriptionstatic IItemSourcefromInventory(IInventory inv) Construct an IItemSource from given inventorystatic IItemSourcefromPlayer(EntityPlayerMP player) Construct an IItemSource from inventories associated with given player.Retrieve some amount of items from this item source matching given filter.default booleanTake exactly count amount of items matching predicate.default booleanTake some item.default ItemStackTake exactly one item that matches the predicate.default booleanTake exactly one item.
-
Method Details
-
take
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 collectionsimulate- 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
Take exactly one item that matches the predicate.- Parameters:
predicate- filtering predicate. should return true for ItemStacks that should be added to result collectionsimulate- 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
Take exactly count amount of items matching predicate.- Parameters:
predicate- filtering predicate. should return true for ItemStacks that should be added to result collectionsimulate- 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
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
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 matchingsimulate- 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
Construct an IItemSource from inventories associated with given player.This will be backed by
InventoryUtility -
fromInventory
Construct an IItemSource from given inventoryThis will be backed by
InventoryUtility
-