Interface IDecomposedRecipe
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 Summary
Modifier and TypeMethodDescriptionstatic DecomposedRecipeBuilderbuilder()Constructs a builder which can be used to build a decomposed recipe.Set<IRecipeComponent<?>> Obtains allIRecipeComponents that are currently present in the recipe.<C> List<C> get(IRecipeComponent<C> component) Gets the values that are being pointed to by the givenIRecipeComponent, if any.default <C> List<C> getOrThrow(IRecipeComponent<C> component) Gets the values that are being pointed to by the givenIRecipeComponent.default <C> CgetOrThrowSingle(IRecipeComponent<C> component) Gets the single value that is being pointed to by the givenIRecipeComponent.default <C> voidset(IRecipeComponent<C> component, C object) Sets the value that is being pointed to by the givenIRecipeComponentto the given object.<C> voidset(IRecipeComponent<C> component, List<C> object) Sets the values that are being pointed to by the givenIRecipeComponentto the givenList.
-
Method Details
-
builder
Constructs a builder which can be used to build a decomposed recipe.- Returns:
- An instance of the builder.
- Since:
- 10.0.0
-
get
Gets the values that are being pointed to by the givenIRecipeComponent, if any.If the given component is not part of this decomposed recipe instance, then
nullwill 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
nullfor any component that is listed incomponents().- Type Parameters:
C- The type of elements that the component points to.- Parameters:
component- The component whose values need to be retrieved.- Returns:
- A
Listcontaining the values pointed to by the component, if any. - Since:
- 10.0.0
-
getOrThrow
Gets the values that are being pointed to by the givenIRecipeComponent.If the given component is not part of this decomposed recipe instance, then an
IllegalArgumentExceptionis 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
Listcontaining 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
Gets the single value that is being pointed to by the givenIRecipeComponent.If the given component is not part of this decomposed recipe instance, then an
IllegalArgumentExceptionis raised. Similarly, if the given component points to aListwith more than one element, aIllegalArgumentExceptionis 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
Sets the values that are being pointed to by the givenIRecipeComponentto the givenList.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
nulllist 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- AListcontaining the new values that the component should point to.- Since:
- 10.0.0
-
set
Sets the value that is being pointed to by the givenIRecipeComponentto 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
nullto 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 allIRecipeComponents 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 theSetreturned by this method.- Returns:
- A set containing all components of this recipe.
- Since:
- 10.0.0
-