Class IngredientCollections

java.lang.Object
org.cyclops.cyclopscore.ingredient.collection.IngredientCollections

public final class IngredientCollections extends Object
Helper functions for ingredient collections.
  • 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

      public static boolean equalsOrdered(IIngredientCollection<?,?> c1, IIngredientCollection<?,?> c2)
      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

      public static boolean equalsMap(IIngredientMap<?,?,?> c1, IIngredientMap<?,?,?> c2)
      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, V> boolean equalsMapChecked(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

      public static <T, M> int hash(IIngredientCollection<T,M> collection)
      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

      public static <T, M, V> int hash(IIngredientMap<T,M,V> map)
      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

      public static <T, M> String toString(IIngredientCollection<T,M> collection)
      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

      public static <T, M, V> String toString(IIngredientMap<T,M,V> map)
      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

      public static <T, M> net.minecraft.nbt.CompoundTag serialize(IIngredientCollection<T,M> collection)
      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 a IIngredientCollectionMutable from an IngredientComponent.
      Returns:
      An ingredient collection.
      Throws:
      IllegalArgumentException - If the tag was invalid.
    • deserialize

      public static IngredientArrayList<?,?> deserialize(net.minecraft.nbt.CompoundTag tag)
      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.