Class Replacer
IRecipeComponents for 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.
- Since:
- 10.0.0
- DocParam:
- this Replacer.create()
-
Method Summary
Modifier and TypeMethodDescriptionstatic Replacercreate()Creates a new replacer instance.voidexecute()Executes the replacer, carrying out all replacements determined up until now.filter(IFilteringRule rule) Specifies anIFilteringRulethat the replacer must follow.<T> Replacerreplace(IRecipeComponent<T> component, ITargetingStrategy strategy, Predicate<T> toReplace, Function<T, T> with) Specifies a replacement that should be carried out by this replacer.<T> Replacerreplace(IRecipeComponent<T> component, ITargetingStrategy strategy, T toReplace, Function<T, T> with) Specifies a replacement that should be carried out by this replacer.<T> Replacerreplace(IRecipeComponent<T> component, ITargetingStrategy strategy, T toReplace, T with) Specifies a replacement that should be carried out by this replacer.<T> Replacerreplace(IRecipeComponent<T> component, Function<T, T> with) Specifies a replacement that should be carried out by this replacer.<T> Replacerreplace(IRecipeComponent<T> component, Predicate<T> toReplace, Function<T, T> with) Specifies a replacement that should be carried out by this replacer.<T> Replacerreplace(IRecipeComponent<T> component, T toReplace, T with) Specifies a replacement that should be carried out by this replacer.
-
Method Details
-
create
Creates a new replacer instance.- Returns:
- A new replacer instance.
- Since:
- 10.0.0
-
filter
Specifies anIFilteringRulethat 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.
- Parameters:
rule- The rule that should be applied.- Returns:
- This for chaining.
- Since:
- 10.0.0
-
replace
Specifies a replacement that should be carried out by this replacer.In particular, the given
IRecipeComponentwill 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 oftoReplacewill be replaced bywith.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
IIngredientlike<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.
- Type Parameters:
T- The type of elements targeted by the component.- Parameters:
component- TheIRecipeComponentindicating what should be targeted.toReplace- The oracle representing the element that needs to be replaced.with- The element which will replace the oracle as needed.- Returns:
- This replacer for chaining.
- Since:
- 10.0.0
-
replace
public <T> Replacer replace(IRecipeComponent<T> component, ITargetingStrategy strategy, T toReplace, T with) Specifies a replacement that should be carried out by this replacer.In particular, the given
IRecipeComponentwill 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 oftoReplacewill be replaced bywith.The strategy used can be determined by you, allowing for example to consider each element in detail instead of directly. For example, a
IIngredientlike<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.
- Type Parameters:
T- The type of elements targeted by the component.- Parameters:
component- TheIRecipeComponentindicating what should be targeted.strategy- TheITargetingStrategythat will be used to target components.toReplace- The oracle representing the element that needs to be replaced.with- The element which will replace the oracle as needed.- Returns:
- This replacer for chaining.
- Since:
- 10.0.0
-
replace
public <T> Replacer replace(IRecipeComponent<T> component, ITargetingStrategy strategy, T toReplace, Function<T, T> with) Specifies a replacement that should be carried out by this replacer.In particular, the given
IRecipeComponentwill 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 oftoReplacewill be replaced by the result of the execution ofwith.The strategy used can be determined by you, allowing for example to consider each element in detail instead of directly. For example, a
IIngredientlike<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.
- Type Parameters:
T- The type of elements targeted by the component.- Parameters:
component- TheIRecipeComponentindicating what should be targeted.strategy- TheITargetingStrategythat will be used to target components.toReplace- The oracle representing the element that needs to be replaced.with- AFunctionthat determines the replacement fortoReplace. 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.- Returns:
- This replacer for chaining.
- Since:
- 10.0.0
-
replace
public <T> Replacer replace(IRecipeComponent<T> component, ITargetingStrategy strategy, Predicate<T> toReplace, Function<T, T> with) Specifies a replacement that should be carried out by this replacer.In particular, the given
IRecipeComponentwill 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 makestoReplacereturntruewill be replaced by the result of the execution ofwith.The strategy used can be determined by you, allowing for example to consider each element in detail instead of directly. For example, a
IIngredientlike<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.
- Type Parameters:
T- The type of elements targeted by the component.- Parameters:
component- TheIRecipeComponentindicating what should be targeted.strategy- TheITargetingStrategythat will be used to target components.toReplace- APredicatedetermining whether a specific element should be replaced or not. The argument given to it is the target that might have to be replaced.with- AFunctionthat determines the replacement for elements thattoReplacedeems 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.- Returns:
- This replacer for chaining.
- Since:
- 10.0.0
-
replace
public <T> Replacer replace(IRecipeComponent<T> component, Predicate<T> toReplace, Function<T, T> with) Specifies a replacement that should be carried out by this replacer.In particular, the given
IRecipeComponentwill 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 makestoReplacereturntruewill be replaced by the result of the execution ofwith.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
IIngredientlike<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.
- Type Parameters:
T- The type of elements targeted by the component.- Parameters:
component- TheIRecipeComponentindicating what should be targeted.toReplace- APredicatedetermining whether a specific element should be replaced or not. The argument given to it is the target that might have to be replaced.with- AFunctionthat determines the replacement for elements thattoReplacedeems 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.- Returns:
- This replacer for chaining.
- Since:
- 14.0.0
-
replace
Specifies a replacement that should be carried out by this replacer.In particular, the given
IRecipeComponentwill be used to query the recipe and alter exactly what has been specified. The function can be used to modify all elements.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
IIngredientlike<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.
- Type Parameters:
T- The type of elements targeted by the component.- Parameters:
component- TheIRecipeComponentindicating what should be targeted.with- AFunctionthat determines the replacement for elements thattoReplacedeems 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.- Returns:
- This replacer for chaining.
- Since:
- 14.0.0
-
execute
public void 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.
- Since:
- 10.0.0
-