Interface IDecomposedRecipe


public interface IDecomposedRecipe
Represents a recipe that has been decomposed into IRecipeComponents.

A decomposed recipe essentially tracks all information necessary to rebuild a recipe from scratch bar its name, allowing for easier manipulation of various recipes without having to know their internal structure or requiring explicit compatibility.

A decomposed recipe is characterized by a series of recipe components, each of them pointing to a List of elements pertaining to its type. For example, a recipe components specifying IItemStack outputs will point to a list of IItemStacks. Additional components can be added to the recipe or existing components can have their values altered.

Instances of this class can be constructed through the builder() or obtained through a recipe's specific IRecipeHandler.

Since:
10.0.0
  • Method Details

    • builder

      static DecomposedRecipeBuilder builder()
      Constructs a builder which can be used to build a decomposed recipe.
      Returns:
      An instance of the builder.
      Since:
      10.0.0
    • get

      <C> List<C> get(IRecipeComponent<C> component)
      Gets the values that are being pointed to by the given IRecipeComponent, if any.

      If the given component is not part of this decomposed recipe instance, then null will be returned. The returned list need not be modifiable. Clients wanting to perform modifications are encouraged to copy the list, edit it, then set it back into the instance.

      It is not allowed for a recipe to return null for any component that is listed in components().

      Type Parameters:
      C - The type of elements that the component points to.
      Parameters:
      component - The component whose values need to be retrieved.
      Returns:
      A List containing the values pointed to by the component, if any.
      Since:
      10.0.0
    • getOrThrow

      default <C> List<C> getOrThrow(IRecipeComponent<C> component)
      Gets the values that are being pointed to by the given IRecipeComponent.

      If the given component is not part of this decomposed recipe instance, then an IllegalArgumentException is raised. The returned list need not be modifiable. Clients wanting to perform modifications are encouraged to copy the list, edit it, then set it back into the instance.

      It is not allowed for a recipe to throw an exception for any component that is listed in components().

      Type Parameters:
      C - The type of elements that the component points to.
      Parameters:
      component - The component whose values need to be retrieved.
      Returns:
      A List containing the values pointed to by the component, if any.
      Throws:
      IllegalArgumentException - If the component is missing in the current recipe.
      Since:
      10.0.0
    • getOrThrowSingle

      default <C> C getOrThrowSingle(IRecipeComponent<C> component)
      Gets the single value that is being pointed to by the given IRecipeComponent.

      If the given component is not part of this decomposed recipe instance, then an IllegalArgumentException is raised. Similarly, if the given component points to a List with more than one element, a IllegalArgumentException is raised. The returned element might or might not be a copy. Clients are thus encouraged not to modify the instance directly, but rather create a new copy and set it back.

      It is not allowed for a recipe to throw an exception for any component that is listed in components().

      Type Parameters:
      C - The type of elements that the component points to.
      Parameters:
      component - The component whose values need to be retrieved.
      Returns:
      The value pointed to by the component, if any
      Throws:
      IllegalArgumentException - If the component is missing or has more than one instance in the current recipe.
      Since:
      10.0.0
    • set

      <C> void set(IRecipeComponent<C> component, List<C> object)
      Sets the values that are being pointed to by the given IRecipeComponent to the given List.

      If the given component is not part of the decomposed recipe instance, then it is added. Otherwise the existing data is modified to refer to the new list. The given list need not be used as is and the implementation is free to copy its contents to prevent tampering. Clients wanting to perform modifications are thus encouraged to invoke this method solely when all changes have been completed.

      It is disallowed to use a null list to remove a component from this decomposed recipe.

      Type Parameters:
      C - The type of elements that the component points to.
      Parameters:
      component - The component whose values need to be set.
      object - A List containing the new values that the component should point to.
      Since:
      10.0.0
    • set

      default <C> void set(IRecipeComponent<C> component, C object)
      Sets the value that is being pointed to by the given IRecipeComponent to the given object.

      If the given component is not part of the decomposed recipe instance, then it is added. Otherwise the existing data is modified to refer to the new object. Take note that no checks are performed on the actual size of the list, meaning that the component will point to a single element after this call. It is the caller's responsibility to ensure this respects the contract.

      The given element might be copied by the implementation to prevent tampering. Clients are thus encouraged not to set the instance directly assuming modifiability, but rather set the element only when all modifications have been completed.

      It is disallowed to use null to remove a component from the decomposed recipe.

      Type Parameters:
      C - The type of elements the component points to.
      Parameters:
      component - The component whose value needs to be set.
      object - The value that the component should point to.
      Since:
      10.0.0
    • components

      Set<IRecipeComponent<?>> components()
      Obtains all IRecipeComponents that are currently present in the recipe.

      Any components that do not exist originally in the recipe but are added through the set(IRecipeComponent, List) method need to be present in the Set returned by this method.

      Returns:
      A set containing all components of this recipe.
      Since:
      10.0.0