Home Commands Examples Getting Started With Scripts Global Keywords
BracketDumpers BracketHandlers BracketValidators ResourceLocationBracketHandler

Replacer

Importing the class

If you need to reference this type directly, like when casting an Array, or as a parameter, you will need to import it. Simply add the import at the top of the file.

script.zs
import crafttweaker.api.recipe.replacement.Replacer;

Description

Handles the replacement of IRecipeComponents for net.minecraft.world.item.crafting.Recipes.

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 #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 #create() and various filters specified through #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.

Members

static create() as Replacer
Creates a new replacer instance.

Returns: A new replacer instance.

script.zs
// Replacer.create() as Replacer;
Replacer.create();

Return Type: Replacer

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.

script.zs
// Replacer.execute();
myReplacer.execute();
filter(rule as IFilteringRule) as Replacer
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.

script.zs
// Replacer.filter(rule as IFilteringRule) as Replacer;
myReplacer.filter(myIFilteringRule);

Parameters:

rule Type: IFilteringRule - The rule that should be applied.

Return Type: Replacer

replace(component as IRecipeComponent<T>, toReplace as T, with as T) as Replacer
Specifies a replacement that should be carried out by this replacer.

In particular, the given IRecipeComponent 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 com.blamejared.crafttweaker.api.ingredient.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.

script.zs
// Replacer.replace<T>(component as IRecipeComponent<T>, toReplace as T, with as T) as Replacer;
myReplacer.replace<T>(myIRecipeComponent, myT, myT);

Parameters:

component Type: IRecipeComponent<T> - The IRecipeComponent indicating what should be targeted.
toReplace Type: T - The oracle representing the element that needs to be replaced.
with Type: T - The element which will replace the oracle as needed.

Return Type: Replacer

replace(component as IRecipeComponent<T>, strategy as ITargetingStrategy, toReplace as T, with as T) as Replacer
Specifies a replacement that should be carried out by this replacer.

In particular, the given IRecipeComponent 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 com.blamejared.crafttweaker.api.ingredient.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.

script.zs
// Replacer.replace<T>(component as IRecipeComponent<T>, strategy as ITargetingStrategy, toReplace as T, with as T) as Replacer;
myReplacer.replace<T>(myIRecipeComponent, myITargetingStrategy, myT, myT);

Parameters:

component Type: IRecipeComponent<T> - The IRecipeComponent indicating what should be targeted.
strategy Type: ITargetingStrategy - The ITargetingStrategy that will be used to target components.
toReplace Type: T - The oracle representing the element that needs to be replaced.
with Type: T - The element which will replace the oracle as needed.

Return Type: Replacer

replace(component as IRecipeComponent<T>, strategy as ITargetingStrategy, toReplace as T, with as function(r as T) as T) as Replacer
Specifies a replacement that should be carried out by this replacer.

In particular, the given IRecipeComponent 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 com.blamejared.crafttweaker.api.ingredient.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.

script.zs
// Replacer.replace<T>(component as IRecipeComponent<T>, strategy as ITargetingStrategy, toReplace as T, with as function(r as T) as T) as Replacer;
myReplacer.replace<T>(myIRecipeComponent, myITargetingStrategy, myT, myFunction);

Parameters:

component Type: IRecipeComponent<T> - The IRecipeComponent indicating what should be targeted.
strategy Type: ITargetingStrategy - The ITargetingStrategy that will be used to target components.
toReplace Type: T - The oracle representing the element that needs to be replaced.
with Type: function(r as T) as T - A Function 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.

Return Type: Replacer

replace(component as IRecipeComponent<T>, strategy as ITargetingStrategy, toReplace as function(t as T) as bool, with as function(r as T) as T) as Replacer
Specifies a replacement that should be carried out by this replacer.

In particular, the given IRecipeComponent 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 com.blamejared.crafttweaker.api.ingredient.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.

script.zs
// Replacer.replace<T>(component as IRecipeComponent<T>, strategy as ITargetingStrategy, toReplace as function(t as T) as bool, with as function(r as T) as T) as Replacer;
myReplacer.replace<T>(myIRecipeComponent, myITargetingStrategy, myPredicate, myFunction);

Parameters:

component Type: IRecipeComponent<T> - The IRecipeComponent indicating what should be targeted.
strategy Type: ITargetingStrategy - The ITargetingStrategy that will be used to target components.
toReplace Type: function(t as T) as bool - A Predicate determining whether a specific element should be replaced or not. The
argument given to it is the target that might have to be replaced.
with Type: function(r as T) as T - A Function 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.

Return Type: Replacer