Invalid leaf directive! `since`

Handles the replacement of IRecipeComponent<T>s for Recipe<C>s.

Due to the expensive nature of the replacing process, once the replacer is created, it is not immediately executed like with other calls, but rather the user needs to determine when the execution should occur with the this#execute() method. It is suggested to chain as many replacements as possible in a single invocation to avoid too big performance hits.

A replacer instance can be created through this#create() and various filters specified through this#filter(IFilteringRule). Note that all filters are positive, meaning that they specify the set of recipes the replacer should target. Replacements can then be specified with the various replace methods. Refer to their documentation for more information.

Importing the class

Link to importing-the-class

It might be required for you to import the package if you encounter any issues (like casting an Array), so better be safe than sorry and add the import at the very top of the file.

ZenScript
Copy
import crafttweaker.api.recipe.replacement.Replacer;

Name: create

Creates a new replacer instance.

Returns: A new replacer instance.
Return Type: Replacer

ZenScript
Copy
// Replacer.create() as Replacer

Replacer.create();

Name: execute

Executes the replacer, carrying out all replacements determined up until now.

After this method is called, the replacer will be exhausted, meaning that a new replacer will be needed to carry out additional replacements.

ZenScript
Copy
// Replacer.execute()

Replacer.create().execute();

Name: filter

Specifies an IFilteringRule that the replacer must follow.

Note that the rules are positive, meaning that they specify the recipes that the replacer should act upon.

You can specify as many filters as you want. Note that they will all be applied at the same time. For example, filtering for mod "crafttweaker" and with recipe type <recipetype:minecraft:crafting> will indicate that only recipes added by you to the crafting table will be targeted.

A replacer cannot be modified after execution.

Returns: This for chaining.
Return Type: Replacer

ZenScript
Copy
Replacer.filter(rule as IFilteringRule) as Replacer
ParameterTypeDescription
Parameter
rule
Type
IFilteringRule
Description
The rule that should be applied.

Name: replace

Specifies a replacement that should be carried out by this replacer.

In particular, the given IRecipeComponent<T> will be used to query the recipe and alter exactly what has been specified. The first element is then used to determine what needs to be replaced and the second element indicates what the element should be replaced by. In other words, any instance of toReplace will be replaced by with.

The replacement strategy used will be default one, so the components will be checked directly, without examining the various elements in detail. For example, a IIngredient like <item:minecraft:dirt> | <item:minecraft:diamond> will be considered like a single entity. Attempting to replace only dirt, for example, won't work.

A replacer cannot be modified after execution.

Returns: This replacer for chaining.
Return Type: Replacer

ZenScript
Copy
Replacer.replace<T : Object>(component as IRecipeComponent<T>, toReplace as T, with as T) as Replacer
ParameterTypeDescription
Parameter
component
Type
IRecipeComponent<T>
Description
The IRecipeComponent<T> indicating what should be targeted.
Parameter
toReplace
Type
T
Description
The oracle representing the element that needs to be replaced.
Parameter
with
Type
T
Description
The element which will replace the oracle as needed.
Parameter
T
Type
Object
Description
The type of elements targeted by the component.

Name: replace

Specifies a replacement that should be carried out by this replacer.

In particular, the given IRecipeComponent<T> will be used to query the recipe and alter exactly what has been specified. The predicate will be used to determine whether a specific target needs to be replaced, whereas the function will determine what the element should be replaced by. In other words, any instance that makes toReplace return true will be replaced by the result of the execution of with.

The strategy used can be determined by you, allowing for example to consider each element in detail instead of directly. For example, a IIngredient like <item:minecraft:dirt> | <item:minecraft:diamond> can also be considered as two separate ingredients and thus replacing only dirt can happen.

A replacer cannot be modified after execution.

Returns: This replacer for chaining.
Return Type: Replacer

ZenScript
Copy
Replacer.replace<T : Object>(component as IRecipeComponent<T>, strategy as ITargetingStrategy, toReplace as Predicate<T>, with as Function<T,T>) as Replacer
ParameterTypeDescription
Parameter
component
Type
IRecipeComponent<T>
Description
The IRecipeComponent<T> indicating what should be targeted.
Parameter
strategy
Type
ITargetingStrategy
Description
The ITargetingStrategy that will be used to target components.
Parameter
toReplace
Type
Predicate<T>
Description
A Predicate<T> determining whether a specific element should be replaced or not. The
argument given to it is the target that might have to be replaced.
Parameter
with
Type
Function<T,T>
Description
A Function<T,R> that determines the replacement for elements that toReplace deems
necessary of replacement. The argument given to the function is the target that needs to be
replaced. The function can then determine freely how the replacement should be carried out.
Parameter
T
Type
Object
Description
The type of elements targeted by the component.

Name: replace

Specifies a replacement that should be carried out by this replacer.

In particular, the given IRecipeComponent<T> will be used to query the recipe and alter exactly what has been specified. The first element is then used to determine what needs to be replaced and the second element will determine what the element should be replaced by. In other words, any instance of toReplace will be replaced by the result of the execution of with.

The strategy used can be determined by you, allowing for example to consider each element in detail instead of directly. For example, a IIngredient like <item:minecraft:dirt> | <item:minecraft:diamond> can also be considered as two separate ingredients and thus replacing only dirt can happen.

A replacer cannot be modified after execution.

Returns: This replacer for chaining.
Return Type: Replacer

ZenScript
Copy
Replacer.replace<T : Object>(component as IRecipeComponent<T>, strategy as ITargetingStrategy, toReplace as T, with as Function<T,T>) as Replacer
ParameterTypeDescription
Parameter
component
Type
IRecipeComponent<T>
Description
The IRecipeComponent<T> indicating what should be targeted.
Parameter
strategy
Type
ITargetingStrategy
Description
The ITargetingStrategy that will be used to target components.
Parameter
toReplace
Type
T
Description
The oracle representing the element that needs to be replaced.
Parameter
with
Type
Function<T,T>
Description
A Function<T,R> that determines the replacement for toReplace. The argument given to
the function is the target that needs to be replaced. The function can then determine freely how
the replacement should be carried out.
Parameter
T
Type
Object
Description
The type of elements targeted by the component.

Name: replace

Specifies a replacement that should be carried out by this replacer.

In particular, the given IRecipeComponent<T> will be used to query the recipe and alter exactly what has been specified. The first element is then used to determine what needs to be replaced and the second element indicates what the element should be replaced by. In other words, any instance of toReplace will be replaced by with.

The strategy used can be determined by you, allowing for example to consider each element in detail instead of directly. For example, a IIngredient like <item:minecraft:dirt> | <item:minecraft:diamond> can also be considered as two separate ingredients and thus replacing only dirt can happen.

A replacer cannot be modified after execution.

Returns: This replacer for chaining.
Return Type: Replacer

ZenScript
Copy
Replacer.replace<T : Object>(component as IRecipeComponent<T>, strategy as ITargetingStrategy, toReplace as T, with as T) as Replacer
ParameterTypeDescription
Parameter
component
Type
IRecipeComponent<T>
Description
The IRecipeComponent<T> indicating what should be targeted.
Parameter
strategy
Type
ITargetingStrategy
Description
The ITargetingStrategy that will be used to target components.
Parameter
toReplace
Type
T
Description
The oracle representing the element that needs to be replaced.
Parameter
with
Type
T
Description
The element which will replace the oracle as needed.
Parameter
T
Type
Object
Description
The type of elements targeted by the component.