Class Replacer
IRecipeManagers and Recipes.
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 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 useForRenaming(BiFunction), or just for a specific set of recipes via
explicitlyRename(ResourceLocation, String).
An example usage of a Replacer could be
Replacer.forTypes(craftingTable).replace(<item:minecraft:string>, <item:minecraft:diamond>).execute();
- DocParam:
- this Replacer.forEverything()
-
Method Summary
Modifier and TypeMethodDescriptionexcluding(IRecipeManager<?>... managers) Excludes a set of managers from undergoing replacement.excluding(net.minecraft.resources.ResourceLocation... recipes) Excludes a set of recipes, identified by their name, from undergoing replacement.excludingMods(String... modids) Excludes all recipes that are under the given modids from undergoing replacement.voidexecute()Executes all replacements that have been queued on this replacer, if any.explicitlyRename(net.minecraft.resources.ResourceLocation oldName, String newName) Indicates that the recipe with the givenoldNameshould be renamed to thenewName.static ReplacerDeprecated.static ReplacerforAllTypesExcluding(IRecipeManager<?>... managers) Deprecated.UseforEverything()to create a replacer then useexcluding(IRecipeManager...)to exclude the various unwanted managers.static ReplacerforCustomRecipeSet(BiPredicate<net.minecraft.world.item.crafting.Recipe<?>, IRecipeManager<?>> function) Creates aReplacerthat will perform replacements only on the recipes whitelisted by the given function.static ReplacerCreates aReplacerthat will perform replacements globally.static ReplacerCreates aReplacerthat targets only the given mods.static ReplacerforOutput(IIngredient output, IRecipeManager<?>... whitelist) Creates aReplacerthat will perform replacement only on recipes with the given output, optionally restricted to a set of whitelisted managers.static ReplacerforRecipes(net.minecraft.world.item.crafting.Recipe<?>... recipes) Creates aReplacerthat targets only the specifiedRecipes.static ReplacerforRegexRecipes(String regex) Creates aReplacerthat will perform replacement on all recipes whose names match the given regular expression.static ReplacerforRegexTypes(String regex) Creates aReplacerthat will perform replacement on allIRecipeManagers that match the given regular expression.static ReplacerforTypes(IRecipeManager<?>... managers) Creates aReplacerthat targets only the specifiedIRecipeManagers.replace(IIngredient from, IIngredient to) replace(IItemStack from, IIngredient to) replaceFully(IIngredient from, IIngredient to) Suppresses warnings that arise when trying to replace unsupported recipes.useForRenaming(BiFunction<net.minecraft.resources.ResourceLocation, String, String> function) Specifies theBiFunctionthat will be used for renaming all recipes.
-
Method Details
-
forRecipes
Creates aReplacerthat targets only the specifiedRecipes.In other words, the replacer will perform ingredient replacement only on the recipes that are given in this list.
- Parameters:
recipes- The recipes that should be targeted by the replacer. It must be at least one.- Returns:
- A new
Replacerthat targets only the specified recipes. - DocParam:
- recipes craftingTable.getRecipeByName("minecraft:emerald_block")
-
forMods
Creates aReplacerthat targets only the given mods.In other words, the replacer will perform ingredient replacement across all
IRecipeManagers, targeting only the recipes added by the specified mods.- Parameters:
mods- The mods whose recipes should be targeted by the replacer. It must be at least one.- Returns:
- A new
Replacerthat targets only the specified mods. - DocParam:
- mods "minecraft"
-
forTypes
Creates aReplacerthat targets only the specifiedIRecipeManagers.In other words, the replacer will perform ingredient replacement only on the managers that are given in this list.
- Parameters:
managers- The managers that will be targeted by the replacer. It must be at least one.- Returns:
- A new
Replacerthat targets only the specified managers. - DocParam:
- managers smithing
-
forAllTypes
Deprecated.UseforEverything()instead.Creates aReplacerthat 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.
-
forEverything
Creates aReplacerthat 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.
-
forAllTypesExcluding
Deprecated.UseforEverything()to create a replacer then useexcluding(IRecipeManager...)to exclude the various unwanted managers.Creates aReplacerthat will perform replacements on allIRecipeManagers except the ones specified.- Parameters:
managers- The managers to exclude from the replacer.- Returns:
- A new
Replacerthat targets all managers except the ones specified. - DocParam:
- managers stoneCutter
-
forOutput
Creates aReplacerthat 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.
- Parameters:
output- The output that should be matched.whitelist- An optional list of managers that should be whitelisted in the replacement.- Returns:
- A new
Replacerfor recipes with the given output and an optional whitelist. - DocParam:
- output <tag:items:forge:rods/wooden>, whitelist stoneCutter
-
forRegexTypes
Creates aReplacerthat will perform replacement on allIRecipeManagers 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 onminecraft:craftingonly.- Parameters:
regex- The regular expression that should be used for matching.- Returns:
- A new
Replacerfor managers that satisfy the given regular expression. - DocParam:
- regex "^minecraft:[a-z]*ing"
-
forRegexRecipes
Creates aReplacerthat will perform replacement on all recipes whose names match the given regular expression.- Parameters:
regex- The regular expression that should be used for matching.- Returns:
- A new
Replacerfor recipes that satisfy the given regular expression. - DocParam:
- regex "\\d_\\d"
-
forCustomRecipeSet
public static Replacer forCustomRecipeSet(BiPredicate<net.minecraft.world.item.crafting.Recipe<?>, IRecipeManager<?>> function) Creates aReplacerthat will perform replacements only on the recipes whitelisted by the given function.The first parameter of the predicate is a
Recipethat indicates the recipe that is currently being tested, whereas the second is theIRecipeManagerthat 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.
- Parameters:
function- The custom whitelisting function.- Returns:
- A new
Replacerthat uses the given function for whitelisting. - DocParam:
- function myPredicate
-
excluding
Excludes a set of recipes, identified by their name, from undergoing replacement.- Parameters:
recipes- The list of recipes that should be excluded.- Returns:
- A Replacer that excludes the given set of recipes.
- DocParam:
- recipes <resource:minecraft:comparator>
-
excluding
Excludes a set of managers from undergoing replacement.- Parameters:
managers- The list of managers that should be excluded.- Returns:
- A Replacer that excludes the given set of recipe managers.
- DocParam:
- managers stoneCutter
-
excludingMods
Excludes all recipes that are under the given modids from undergoing replacement.- Parameters:
modids- The list of modids that should be excluded.- Returns:
- A Replacer that excludes the given set of modids.
- DocParam:
- modids "mekanism"
-
replace
Replaces every match of thefromIIngredientwith the one given into.This replacement behavior is recursive, meaning that any
IIngredientthat 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 thatminecraft:stonesis a tag that containsminecraft:stoneamong other items).If this behavior is not desired, refer to
replaceFully(IIngredient, IIngredient)instead.This method is a specialized by
replace(IItemStack, IIngredient)forIItemStacks and should be preferred in these cases.- Parameters:
from- AnIIngredientthat will be used to match stacks that need to be replaced.to- The replacementIIngredient.- Returns:
- A Replacer that will carry out the specified operation.
- DocParam:
- from <tag:items:forge:storage_blocks/redstone>, to <item:minecraft:diamond_block>
-
replace
Replaces every match of thefromIItemStackwith the one given into.This replacement behavior is recursive, meaning that any
IIngredientthat 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 thatminecraft:stonesis a tag that containsminecraft:stoneamong other items).If this behavior is not desired, refer to
replaceFully(IIngredient, IIngredient)instead.This method is a specialization of
replace(IIngredient, IIngredient)forIItemStacks and should be preferred in these cases.- Parameters:
from- AnIItemStackthat will be used to match stacks that need to be replaced.to- The replacementIIngredient.- Returns:
- A Replacer that will carry out the specified operation.
- DocParam:
- from <item:minecraft:coal_block>, to <item:minecraft:diamond_block>
-
replaceFully
Replaces every instance of the targetfromIIngredientwith thetoone.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
replace(IIngredient, IIngredient)instead.- Parameters:
from- AnIIngredientthat will be used to match to specify the ingredient to replace.to- The replacementIIngredient.- Returns:
- A Replacer that will carry out the specified operation.
- DocParam:
- from <tag:items:minecraft:anvil>, to <tag:items:minecraft:flowers>
-
explicitlyRename
Indicates that the recipe with the givenoldNameshould be renamed to thenewName.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).- Parameters:
oldName- TheResourceLocationof the name of the recipe that should be renamed.newName- The new name of the recipe.- Returns:
- A Replacer that will rename the recipe according to the specified rule.
- DocParam:
- oldName <resource:minecraft:birch_sign>, newName "damn_hard_birch_sign"
-
useForRenaming
public Replacer useForRenaming(BiFunction<net.minecraft.resources.ResourceLocation, String, String> function) Specifies theBiFunctionthat will be used for renaming all recipes.The first argument to the function is the
ResourceLocationthat 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.- Parameters:
function- The renaming function.- Returns:
- A Replacer that will use the given function for renaming.
- DocParam:
- function myFunction
-
suppressWarnings
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
excluding(ResourceLocation...)would prove to be too cumbersome.- Returns:
- A Replacer with replacement warnings suppressed.
-
execute
public void execute()Executes all replacements that have been queued on this replacer, if any. -
addReplacementRule
-
forEverything()instead.