Replacer
Handles the replacing of ingredients in recipes for various IRecipeManager<T>s and Recipe<C>s.
Differently from various other mechanisms in CraftTweaker, each replacement that gets specified from within a
Replacer doesn’t get run immediately, rather it gets stored and all replacements are then applied together
when the this#execute() method is called. This change is done so that multiple replacements can be performed at
the same time, with a net gain on performance.
Note that replacement must be explicitly supported by modded recipe types and managers, meaning
that a Replacer may not be able to perform replacement on a certain set of recipes. If this is the case, a
warning will be printed in the logs, so that you may review it.
Creating a Replacer gets done via the various forXxx methods, where Xxx identifies any
suffix. Refer to the specific documentation to get more information on their behavior.
The various replace methods, listed both in this page and in other mod’s possible expansions, then allow
you to specify what should be the replacements that need to be carried out by the Replacer itself.
All recipes that get replaced by a Replacer get renamed according to a set naming scheme. You can modify
completely by providing a lambda via this#useForRenaming(BiFunction), or just for a specific set of recipes via
this#explicitlyRename(ResourceLocation, String).
An example usage of a Replacer could be
Replacer.forTypes(craftingTable).replace(<item:minecraft:string>, <item:minecraft:diamond>).execute();
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.
import crafttweaker.api.recipe.Replacer;Static Methods
Creates a Replacer that will perform replacements globally. 
  
  In other words, the replacer will perform ingredient replacement on every recipe manager in 
  the game, as long as it supports replacement.
Returns: A new global Replacer.
Return Type: Replacer
// Replacer.forAllTypes() as Replacer
Replacer.forAllTypes();Creates a Replacer that will perform replacements on all IRecipeManager<T>s except the ones 
  specified.
Returns: A new Replacer that targets all managers except the ones specified.
Return Type: Replacer
// Replacer.forAllTypesExcluding(managers as IRecipeManager[]) as Replacer
Replacer.forAllTypesExcluding(stoneCutter);| Parameter | Type | Description | 
|---|---|---|
| Parametermanagers | TypeIRecipeManager[] | DescriptionThe managers to exclude from the replacer. | 
Creates a Replacer that will perform replacements only on the recipes whitelisted by the given function. 
  
  The first parameter of the predicate is a Recipe<C> that indicates the recipe that is currently 
  being tested, whereas the second is the IRecipeManager<T> that is responsible for handling that particular 
  type of recipes. The function should then return a boolean that either whitelists the recipe for replacement 
  (true) or blacklists it (false). 
  
  The given function must be a pure function, which means that the output must be the same 
  given the same set of inputs. In other words, you should not rely on external state for this function, since it 
  may be called multiple times on the same set of inputs in the same replacer run.
Returns: A new Replacer that uses the given function for whitelisting.
Return Type: Replacer
// Replacer.forCustomRecipeSet(function as BiPredicate<Recipe,IRecipeManager>) as Replacer
Replacer.forCustomRecipeSet(myPredicate);| Parameter | Type | Description | 
|---|---|---|
| Parameterfunction | TypeBiPredicate<Recipe,IRecipeManager> | DescriptionThe custom whitelisting function. | 
Creates a Replacer that will perform replacements globally. 
  
  In other words, the replacer will perform ingredient replacement on every recipe manager in 
  the game, as long as it supports replacement.
Returns: A new global Replacer.
Return Type: Replacer
// Replacer.forEverything() as Replacer
Replacer.forEverything();Creates a Replacer that targets only the given mods. 
  
  In other words, the replacer will perform ingredient replacement across all 
  IRecipeManager<T>s, targeting only the recipes added by the specified mods.
Returns: A new Replacer that targets only the specified mods.
Return Type: Replacer
// Replacer.forMods(mods as string[]) as Replacer
Replacer.forMods("minecraft");| Parameter | Type | Description | 
|---|---|---|
| Parametermods | Typestring[] | DescriptionThe mods whose recipes should be targeted by the replacer. It must be at least one. | 
Creates a Replacer that will perform replacement only on recipes with the given output, optionally 
  restricted to a set of whitelisted managers. 
  
  The passed in whitelist may also be empty, in which case it’ll be treated as meaning every possible recipe 
  manager. If the whitelist is not empty, on the other hand, only the selected recipe managers will be considered 
  when replacing ingredients.
Returns: A new Replacer for recipes with the given output and an optional whitelist.
Return Type: Replacer
// Replacer.forOutput(output as IIngredient, whitelist as IRecipeManager[]) as Replacer
Replacer.forOutput(<tag:items:forge:rods/wooden>, stoneCutter);| Parameter | Type | Description | 
|---|---|---|
| Parameteroutput | TypeIIngredient | DescriptionThe output that should be matched. | 
| Parameterwhitelist | TypeIRecipeManager[] | DescriptionAn optional list of managers that should be whitelisted in the replacement. | 
Creates a Replacer that targets only the specified Recipe<C>s. 
  
  In other words, the replacer will perform ingredient replacement only on the recipes that 
  are given in this list.
Returns: A new Replacer that targets only the specified recipes.
Return Type: Replacer
// Replacer.forRecipes(recipes as Recipe[]) as Replacer
Replacer.forRecipes(craftingTable.getRecipeByName("minecraft:emerald_block"));| Parameter | Type | Description | 
|---|---|---|
| Parameterrecipes | TypeRecipe[] | DescriptionThe recipes that should be targeted by the replacer. It must be at least one. | 
Creates a Replacer that will perform replacement on all recipes whose names match the given regular 
  expression.
Returns: A new Replacer for recipes that satisfy the given regular expression.
Return Type: Replacer
// Replacer.forRegexRecipes(regex as string) as Replacer
Replacer.forRegexRecipes("\\d_\\d");| Parameter | Type | Description | 
|---|---|---|
| Parameterregex | Typestring | DescriptionThe regular expression that should be used for matching. | 
Creates a Replacer that will perform replacement on all IRecipeManager<T>s that match the given 
  regular expression. 
  
  The managers will be matched on their bracket identifier, which corresponds to their bracket expression 
  stripped of <recipetype: and >. E.g., a manager obtained in a script via 
  <recipetype:minecraft:crafting> will be matched on minecraft:crafting only.
Returns: A new Replacer for managers that satisfy the given regular expression.
Return Type: Replacer
// Replacer.forRegexTypes(regex as string) as Replacer
Replacer.forRegexTypes("^minecraft:[a-z]*ing");| Parameter | Type | Description | 
|---|---|---|
| Parameterregex | Typestring | DescriptionThe regular expression that should be used for matching. | 
Creates a Replacer that targets only the specified IRecipeManager<T>s. 
  
  In other words, the replacer will perform ingredient replacement only on the managers that 
  are given in this list.
Returns: A new Replacer that targets only the specified managers.
Return Type: Replacer
// Replacer.forTypes(managers as IRecipeManager[]) as Replacer
Replacer.forTypes(smithing);| Parameter | Type | Description | 
|---|---|---|
| Parametermanagers | TypeIRecipeManager[] | DescriptionThe managers that will be targeted by the replacer. It must be at least one. | 
Methods
Excludes a set of managers from undergoing replacement.
Returns: A Replacer that excludes the given set of recipe managers.
Return Type: Replacer
// Replacer.excluding(managers as IRecipeManager[]) as Replacer
Replacer.forEverything().excluding(stoneCutter);| Parameter | Type | Description | 
|---|---|---|
| Parametermanagers | TypeIRecipeManager[] | DescriptionThe list of managers that should be excluded. | 
Excludes a set of recipes, identified by their name, from undergoing replacement.
Returns: A Replacer that excludes the given set of recipes.
Return Type: Replacer
// Replacer.excluding(recipes as ResourceLocation[]) as Replacer
Replacer.forEverything().excluding(<resource:minecraft:comparator>);| Parameter | Type | Description | 
|---|---|---|
| Parameterrecipes | TypeResourceLocation[] | DescriptionThe list of recipes that should be excluded. | 
Excludes all recipes that are under the given modids from undergoing replacement.
Returns: A Replacer that excludes the given set of modids.
Return Type: Replacer
// Replacer.excludingMods(modids as string[]) as Replacer
Replacer.forEverything().excludingMods("mekanism");| Parameter | Type | Description | 
|---|---|---|
| Parametermodids | Typestring[] | DescriptionThe list of modids that should be excluded. | 
Executes all replacements that have been queued on this replacer, if any.
Return Type: void
// Replacer.execute() as void
Replacer.forEverything().execute();Indicates that the recipe with the given oldName should be renamed to the newName.
This rename will only be applied if a replacement is carried out. Moreover, the given new name will also be fixed according to NameUtil#fixing(String).
Returns: A Replacer that will rename the recipe according to the specified rule.
Return Type: Replacer
// Replacer.explicitlyRename(oldName as ResourceLocation, newName as string) as Replacer
Replacer.forEverything().explicitlyRename(<resource:minecraft:birch_sign>, "damn_hard_birch_sign");| Parameter | Type | Description | 
|---|---|---|
| ParameteroldName | TypeResourceLocation | DescriptionThe ResourceLocation of the name of the recipe that should be renamed. | 
| ParameternewName | Typestring | DescriptionThe new name of the recipe. | 
Replaces every match of the from IIngredient with the one given in to.
This replacement behavior is recursive, meaning that any IIngredient that gets found is looped
recursively trying to identify matches. As an example, attempting to replace <item:minecraft:stone> with
<item:minecraft:diamond> will perform this replacement even in compound ingredients, such as <item:minecraft:stone> | <item:minecraft:gold_ingot> or <tag:items:minecraft:stones> (supposing that
minecraft:stones is a tag that contains minecraft:stone among other items).
If this behavior is not desired, refer to this#replaceFully(IIngredient, IIngredient) instead.
This method is a specialized by this#replace(IItemStack, IIngredient) for IItemStacks and should be preferred in these cases.
Returns: A Replacer that will carry out the specified operation.
Return Type: Replacer
// Replacer.replace(from as IIngredient, to as IIngredient) as Replacer
Replacer.forEverything().replace(<tag:items:forge:storage_blocks/redstone>, <item:minecraft:diamond_block>);| Parameter | Type | Description | 
|---|---|---|
| Parameterfrom | TypeIIngredient | DescriptionAn IIngredient that will be used to match stacks that need to be replaced. | 
| Parameterto | TypeIIngredient | DescriptionThe replacement IIngredient. | 
Replaces every match of the from IItemStack with the one given in to.
This replacement behavior is recursive, meaning that any IIngredient that gets found is looped
recursively trying to identify matches. As an example, attempting to replace <item:minecraft:stone> with
<item:minecraft:diamond> will perform this replacement even in compound ingredients, such as <item:minecraft:stone> | <item:minecraft:gold_ingot> or <tag:items:minecraft:stones> (supposing that
minecraft:stones is a tag that contains minecraft:stone among other items).
If this behavior is not desired, refer to this#replaceFully(IIngredient, IIngredient) instead.
This method is a specialization of this#replace(IIngredient, IIngredient) for IItemStacks and should be preferred in these cases.
Returns: A Replacer that will carry out the specified operation.
Return Type: Replacer
// Replacer.replace(from as IItemStack, to as IIngredient) as Replacer
Replacer.forEverything().replace(<item:minecraft:coal_block>, <item:minecraft:diamond_block>);| Parameter | Type | Description | 
|---|---|---|
| Parameterfrom | TypeIItemStack | DescriptionAn IItemStack that will be used to match stacks that need to be replaced. | 
| Parameterto | TypeIIngredient | DescriptionThe replacement IIngredient. | 
Replaces every instance of the target from IIngredient with the to one.
This replacement behavior is not recursive, meaning that the IIngredients will be matched closely
instead of recursively. As an example, attempting to replace fully <item:minecraft:stone> will only
replace ingredients that explicitly specify <item:minecraft:stone> as an input, while compound
ingredients such as <item:minecraft:stone> | <item:minecraft:gold_ingot> won’t be replaced.
If this behavior is not desired, refer to this#replace(IIngredient, IIngredient) instead.
Returns: A Replacer that will carry out the specified operation.
Return Type: Replacer
// Replacer.replaceFully(from as IIngredient, to as IIngredient) as Replacer
Replacer.forEverything().replaceFully(<tag:items:minecraft:anvil>, <tag:items:minecraft:flowers>);| Parameter | Type | Description | 
|---|---|---|
| Parameterfrom | TypeIIngredient | DescriptionAn IIngredient that will be used to match to specify the ingredient to replace. | 
| Parameterto | TypeIIngredient | DescriptionThe replacement IIngredient. | 
Suppresses warnings that arise when trying to replace unsupported recipes.
Additional warnings will not be suppressed. Note that it is suggested to keep this disabled while testing and enable it only if excluding the problematic recipes via this#excluding(ResourceLocation…) would prove to be too cumbersome.
Returns: A Replacer with replacement warnings suppressed.
Return Type: Replacer
// Replacer.suppressWarnings() as Replacer
Replacer.forEverything().suppressWarnings();Specifies the BiFunction<T,U,R> that will be used for renaming all recipes.
The first argument to the function is the ResourceLocation that uniquely identifies its name, whereas the second represents the default name for the recipe according to the default replacement rules. The return value of the function will then represent the new name of the recipe.
Returns: A Replacer that will use the given function for renaming.
Return Type: Replacer
// Replacer.useForRenaming(function as BiFunction<ResourceLocation,string,string>) as Replacer
Replacer.forEverything().useForRenaming(myFunction);| Parameter | Type | Description | 
|---|---|---|
| Parameterfunction | TypeBiFunction<ResourceLocation,string,string> | DescriptionThe renaming function. |