Interface IRecipeComponent<T>

Type Parameters:
T - The type of objects pointed to by the component.
All Superinterfaces:
CommandStringDisplayable

@ZenRegister public sealed interface IRecipeComponent<T> extends CommandStringDisplayable
Represents a part of a recipe after it has been decomposed.

Recipe components in a recipe are associated with a list of data, whose type varies depending on the component. The data indicates what the component is made up of, allowing for introspection and selective editing of any recipe that can be decomposed and then recomposed, without requiring explicit support for every type of change.

Obtaining an instance of a recipe component in a script can be done through the usage of the <recipecomponent> bracket handler. Integration writers can instead refer to the find method.

Every recipe component must be registered to the registry through a plugin to be able to be used effectively and discovered by script writers. New recipe components can be created with either simple or composite. A set of common components is already provided by CraftTweaker.

Since:
10.0.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> IRecipeComponent<T>
    composite(net.minecraft.resources.ResourceLocation id, com.google.gson.reflect.TypeToken<T> objectType, BiPredicate<T,T> matcher, Function<T,Collection<T>> unwrappingFunction, Function<Collection<T>,T> wrapper)
    Builds a new IRecipeComponent whose data is a composite of multiple smaller units.
    static <T> IRecipeComponent<T>
    find(net.minecraft.resources.ResourceLocation id)
    Identifies the recipe component with the given id, if registered.
    default String
    Returns the BEP to get this thingy
    net.minecraft.resources.ResourceLocation
    id()
    Gets the ID that uniquely identifies this component.
    boolean
    match(T oracle, T object)
    Verifies if the two given objects are the same according to this component.
    com.google.gson.reflect.TypeToken<T>
    Gets a TypeToken representing the type of objects pointed to by this component.
    static <T> IRecipeComponent<T>
    simple(net.minecraft.resources.ResourceLocation id, com.google.gson.reflect.TypeToken<T> objectType, BiPredicate<T,T> matcher)
    Builds a new IRecipeComponent that cannot be further decomposed into a list of lists.
    unwrap(T object)
    Unwraps the given element into a collection of smaller "atoms" if possible.
    wrap(Collection<T> objects)
    Wraps the given Collection of elements into a single composite element if possible.
  • Method Details

    • find

      static <T> IRecipeComponent<T> find(net.minecraft.resources.ResourceLocation id)
      Identifies the recipe component with the given id, if registered.

      This method must be invoked only after all registries have been built. If such an action is performed, the result is undefined behavior.

      Type Parameters:
      T - The type of data pointed to by the recipe component. Note that no checks are performed on the validity of this value. It is the caller responsibility to ensure that objectType() and T represent the same or compatible types.
      Parameters:
      id - The id of the recipe component that should be found.
      Returns:
      The recipe component with the given id, if it exists.
      Throws:
      IllegalArgumentException - If no recipe component with the given ID has been registered.
      Since:
      10.0.0
    • simple

      static <T> IRecipeComponent<T> simple(net.minecraft.resources.ResourceLocation id, com.google.gson.reflect.TypeToken<T> objectType, BiPredicate<T,T> matcher)
      Builds a new IRecipeComponent that cannot be further decomposed into a list of lists.

      In other words, this identifies a component whose data cannot be further decomposed into "atoms", as it represents a base type directly. An example is IItemStack, which cannot be further decomposed into a list of smaller stacks.

      Take note that the returned component must still be manually registered through a plugin to be able to be used.

      Type Parameters:
      T - The type of objects being pointed to by the component.
      Parameters:
      id - The ID of the component that needs to be created.
      objectType - A TypeToken representing the type of objects being pointed to by the component.
      matcher - A BiPredicate used to determine whether two of the objects pointed to by the component are the same. The first argument of the predicate is the oracle, meaning the fixed element that is used to perform the comparison. The second argument is the element that needs to be compared. Take note that the distinction is not necessarily meaningful as the general contract of equality must be preserved, with reflectivity, symmetry, and transitivity.
      Returns:
      A new recipe component constructed according to the given data.
      Since:
      10.0.0
    • composite

      static <T> IRecipeComponent<T> composite(net.minecraft.resources.ResourceLocation id, com.google.gson.reflect.TypeToken<T> objectType, BiPredicate<T,T> matcher, Function<T,Collection<T>> unwrappingFunction, Function<Collection<T>,T> wrapper)
      Builds a new IRecipeComponent whose data is a composite of multiple smaller units.

      In other words, this identifies a component whose data can be further decomposed into "atoms" and then brought back together into the same container. An example is IIngredient, which can be further decomposed into a list of basic ingredients (items, tags, predicates...). The various parts can then be added back together again through the | operator to build the initial ingredient back. Note how the type of the various atoms is the same as the initial container: this is mandatory for composite recipe components.

      Take note that the returned component must still be manually registered through a plugin to be able to be used.

      Type Parameters:
      T - The type of objects being pointed to by the component.
      Parameters:
      id - The ID of the component that needs to be created.
      objectType - A TypeToken representing the type of objects being pointed to by the component.
      matcher - A BiPredicate used to determine whether two of the objects pointed to by the component are the same. The first argument of the predicate is the oracle, meaning the fixed element that is used to perform the comparison. The second argument is the element that needs to be compared. Take note that this distinction is not necessarily meaningful as the general contract of equality must be preserved, with reflectivity, symmetry, and transitivity.
      unwrappingFunction - A Function that can decompose an instance of an object pointed to by the component into a Collection of smaller atoms. Note how the type must be preserved. The collection can have any size as deemed necessary by the client.
      wrapper - A Function that can compose together a Collection of objects pointed to by the component into a single composite unit. Note how the type must be preserved. The function is allowed to throw IllegalArgumentException in case the amount of items present in the collection is incorrect for proper composition.
      Returns:
      A new recipe component constructed according to the given data.
      Since:
      10.0.0
    • id

      net.minecraft.resources.ResourceLocation id()
      Gets the ID that uniquely identifies this component.
      Returns:
      This component's ID.
      Since:
      10.0.0
    • objectType

      com.google.gson.reflect.TypeToken<T> objectType()
      Gets a TypeToken representing the type of objects pointed to by this component.
      Returns:
      The type.
      Since:
      10.0.0
    • match

      boolean match(T oracle, T object)
      Verifies if the two given objects are the same according to this component.

      Note that the distinction between the first and second argument is not necessarily meaningful, as the general contract of equality must still be followed, with reflectivity, symmetry, and transitivity.

      Parameters:
      oracle - The element that is used to perform the comparison.
      object - The element that must be compared to the oracle.
      Returns:
      Whether the two objects match.
      Since:
      10.0.0
    • unwrap

      Collection<T> unwrap(T object)
      Unwraps the given element into a collection of smaller "atoms" if possible.

      It is disallowed for this method to throw an exception if no decomposition is possible. In such a case, the given object is already the most decomposed instance, and a Collection containing it as the sole element must be returned.

      The type of the component is preserved.

      Parameters:
      object - The object that should be unwrapped.
      Returns:
      A collection containing atoms.
      Since:
      10.0.0
    • wrap

      T wrap(Collection<T> objects)
      Wraps the given Collection of elements into a single composite element if possible.

      If the object is already a base type, then the sole instance of it acts as also the composite element, so that instance should be returned.

      It is allowed for this method to throw an exception if the size of the collection is invalid, as specified further.

      The type of the component is preserved.

      Parameters:
      objects - The collection of objects that should be wrapped.
      Returns:
      The composite type containing the given atoms.
      Throws:
      IllegalArgumentException - If the size of the collection does not allow proper recomposition. For example, a non-decomposable element should throw an exception if the given collection's size is not 1, as no merging can be performed.
      Since:
      10.0.0
    • getCommandString

      default String getCommandString()
      Description copied from interface: CommandStringDisplayable
      Returns the BEP to get this thingy
      Specified by:
      getCommandString in interface CommandStringDisplayable