Class IngredientCollections
java.lang.Object
org.cyclops.cyclopscore.ingredient.collection.IngredientCollections
Helper functions for ingredient collections.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Helper interface for constructing anIIngredientCollection
based on anIngredientComponent
. -
Method Summary
Modifier and TypeMethodDescriptionstatic IngredientArrayList<?,
?> deserialize
(net.minecraft.nbt.CompoundTag tag) Deserialize the given NBT tag to an ingredient array list.static <C extends IIngredientCollectionMutable<?,
?>>
Cdeserialize
(net.minecraft.nbt.CompoundTag tag, IngredientCollections.IIngredientCollectionConstructor<C> ingredientCollectionFactory) Deserialize the given NBT tag to an ingredient array list.static <T,
M> IIngredientCollection<T, M> emptyCollection
(IngredientComponent<T, M> ingredientComponent) Create a new immutable empty collection.static <T,
M> boolean equalsCheckedOrdered
(IIngredientCollection<T, M> c1, IIngredientCollection<T, M> c2) Check if the two collection are equal by order using safe types.static boolean
equalsMap
(IIngredientMap<?, ?, ?> c1, IIngredientMap<?, ?, ?> c2) Check if the two maps are equal.static <T,
M, V> boolean equalsMapChecked
(IIngredientMap<T, M, V> c1, IIngredientMap<T, M, V> c2) Check if the two maps are equal using safe types.static boolean
equalsOrdered
(IIngredientCollection<?, ?> c1, IIngredientCollection<?, ?> c2) Check if the two collection are equal by order.static <T,
M> int hash
(IIngredientCollection<T, M> collection) Hash the given collection.static <T,
M, V> int hash
(IIngredientMap<T, M, V> map) Hash the given map.static <T,
M> net.minecraft.nbt.CompoundTag serialize
(IIngredientCollection<T, M> collection) Serialize the given collection to an NBT tag.static <T,
M> IngredientArrayList<T, M> sort
(IIngredientCollection<T, M> collection, Comparator<? super T> comparator) Created a sorted collection using the given comparator and all instances from the given collection.static <T,
M> String toString
(IIngredientCollection<T, M> collection) Stringifies the given collection.static <T,
M, V> String toString
(IIngredientMap<T, M, V> map) Stringifies the given map.
-
Method Details
-
emptyCollection
public static <T,M> IIngredientCollection<T,M> emptyCollection(IngredientComponent<T, M> ingredientComponent) Create a new immutable empty collection.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
ingredientComponent
- The ingredient component the collection should be made for.- Returns:
- An immutable empty ingredient collection.
-
equalsOrdered
Check if the two collection are equal by order.- Parameters:
c1
- A first collection.c2
- A second collection.- Returns:
- If the two collection are equal by order.
-
equalsCheckedOrdered
public static <T,M> boolean equalsCheckedOrdered(IIngredientCollection<T, M> c1, IIngredientCollection<T, M> c2) Check if the two collection are equal by order using safe types.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
c1
- A first collection.c2
- A second collection.- Returns:
- If the two collection are equal by order.
-
equalsMap
Check if the two maps are equal.- Parameters:
c1
- A first map.c2
- A second map.- Returns:
- If the two maps are equal.
-
equalsMapChecked
public static <T,M, boolean equalsMapCheckedV> (IIngredientMap<T, M, V> c1, IIngredientMap<T, M, V> c2) Check if the two maps are equal using safe types.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.V
- The value type.- Parameters:
c1
- A first map.c2
- A second map.- Returns:
- If the two maps are equal.
-
hash
Hash the given collection. This will hash each instance in the collection using the component type.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
collection
- A collection.- Returns:
- A hashcode.
-
hash
Hash the given map. This will hash each instance in the map using the component type.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.V
- The type of mapped values.- Parameters:
map
- A map.- Returns:
- A hashcode.
-
toString
Stringifies the given collection. This will create a string by calling the toString() method on each instance in the collection.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
collection
- A collection.- Returns:
- A string representation of the collection.
-
toString
Stringifies the given map. This will create a string by calling the toString() method on each entry in the map.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.V
- The type of mapped values.- Parameters:
map
- A map.- Returns:
- A string representation of the map.
-
sort
public static <T,M> IngredientArrayList<T,M> sort(IIngredientCollection<T, M> collection, Comparator<? super T> comparator) Created a sorted collection using the given comparator and all instances from the given collection.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
collection
- A collection to create a sorted copy of.comparator
- A compatator.- Returns:
- A sorted collection based on the given collection and comparator.
-
serialize
Serialize the given collection to an NBT tag. The type of collection will be lost, only the component type and the ingredients will be saved.- Type Parameters:
T
- The instance type.M
- The matching condition parameter.- Parameters:
collection
- An ingredient collection.- Returns:
- An NBT tag.
-
deserialize
public static <C extends IIngredientCollectionMutable<?,?>> C deserialize(net.minecraft.nbt.CompoundTag tag, IngredientCollections.IIngredientCollectionConstructor<C> ingredientCollectionFactory) Deserialize the given NBT tag to an ingredient array list.- Type Parameters:
C
- The collection type.- Parameters:
tag
- An NBT tag.ingredientCollectionFactory
- A function that creates aIIngredientCollectionMutable
from anIngredientComponent
.- Returns:
- An ingredient collection.
- Throws:
IllegalArgumentException
- If the tag was invalid.
-
deserialize
Deserialize the given NBT tag to an ingredient array list.- Parameters:
tag
- An NBT tag.- Returns:
- An ingredient array list.
- Throws:
IllegalArgumentException
- If the tag was invalid.
-