-
-
Notifications
You must be signed in to change notification settings - Fork 29
Ingredient Collections
Ruben Taelman edited this page Jan 14, 2019
·
14 revisions
Using the Ingredient Components abstraction layer from CommonCapabilities, CyclopsCore introduces the Ingredient Collections API, which forms a set of interfaces and classes that make it possible to store and query ingredient component instances in a generic way.
Here's a short example of some things that are possible with this API:
IIngredientCollectionMutable<ItemStack, Integer> myCollection
= new IngredientCollectionPrototypeMap<>(IngredientComponent.ITEMSTACK);
// Add an item to the collection
myCollection.add(new ItemStack(Items.APPLE, 1));
// The following item will stack with the previous instance
myCollection.add(new ItemStack(Items.APPLE, 1));
// The following will NOT stack, because it has a different meta value
myCollection.add(new ItemStack(Items.APPLE, 1, 1));
// Even though this is a different object, it _will_ reduce the stacksize of the internal apple.
myCollection.remove(new ItemStack(Items.APPLE, 1));
// This will return an iterator that emits all items that have the `Items.APPLE` item.
myCollection.iterator(new ItemStack(Items.APPLE, 1), ItemMatch.ITEM);
// This will return an iterator that emits all items that have the `Items.APPLE` item AND meta value 0.
myCollection.iterator(new ItemStack(Items.APPLE, 1, 0), ItemMatch.ITEM | ItemMatch.DAMAGE);