配方管理器
Link to 配方管理器
配方管理器是使用原版数据包JSON系统的制作系统(如工作台、熔炉或营火)。
大多数配方管理器都有相同的移除方法,但添加配方的方法不同。
Recipe Managers are generally what you will be using to interact with recipes in the game, there are however some mods that don't use the DataPack JSON system, and for those mods you would need to add and remove recipes differently.
Referencing Recipe Managers
Link to referencing-recipe-managers
Recipe Managers are usually referenced via a Bracket Handler (the exception being Vanilla Recipe Managers which can be referenced via a global value).
The Recipe manager format is:
ZenScript Copy<recipetype:modid:name>
一些示例:
ZenScript Copy<recipetype:minecraft:smoking> // References the Smoking Recipe Manager
<recipetype:botania:mana_infusion> // References the Botania Mana Infusion Recipe Manager
<recipetype:thermal:pulverizer> // References the Thermal Expansion Pulverizer Recipe Manager
Vanilla Recipe Managers are special as they have dedicated Global Variables that allow you to reference them without using a BracketHandler.
The Vanilla Recipe Managers are:
Recipe Manager | Bracket Handler | 全局变量 |
---|---|---|
Recipe Manager 高炉 | Bracket Handler <recipetype:minecraft:blasting> | 全局变量 blastFurnace |
Recipe Manager 营火 | Bracket Handler <recipetype:minecraft:campfire_cooking> | 全局变量 campfire |
Recipe Manager 工作台合成 | Bracket Handler <recipetype:minecraft:crafting> | 全局变量 craftingTable |
Recipe Manager 熔炉 | Bracket Handler <recipetype:minecraft:smelting> | 全局变量 furnace |
Recipe Manager 锻造台 | Bracket Handler <recipetype:minecraft:smithing> | 全局变量 smithing |
Recipe Manager 烟熏炉 | Bracket Handler <recipetype:minecraft:smoking> | 全局变量 smoker |
Recipe Manager 切石机 | Bracket Handler <recipetype:minecraft:stonecutting> | 全局变量 stoneCutter |
The Vanilla Recipe Managers can be referenced by either their Bracket Handler or the Global Variable, for example:
ZenScript Copy<recipetype:minecraft:blasting>.removeAll() // Removes all Blast Furnace Recipes
Is the same as doing:
ZenScript CopyblastFurnace.removeAll() // Removes all Blast Furnace Recipes
The Global Variables just allow the Recipe Managers to be referenced easier.
The reason that not all Recipe Managers are given Global Variables is that there would be conflicting names if two different mods both added a machine with the same name, such as two mods adding Crushers.
使用方式
Link to 使用方式
Name: getRecipeByName
This method gets a recipe by it's name, and returns a Recipe.
ZenScript CopygetRecipeByName(String name);
You could use this method to get the ingredients
of a recipe and print the commandString
of each ingredient.
ZenScript Copyfor ingredient in craftingTable.getRecipeByName("minecraft:arrow").ingredients {
println(ingredient.commandString);
}
Name: getRecipesByOutput
This method gets a list of recipes based on their outputs, and returns a list of Recipe.
ZenScript CopygetRecipesByOutput(IIngredient name);
You could use this method to get the ingredients
of all the recipes that output a certain item and print the commandString
of each ingredient of each recipe.
ZenScript Copyfor recipe in craftingTable.getRecipesByOutput(<item:minecraft:stick>) {
println("> " + recipe.id);
for ingredient in recipe.ingredients {
println(ingredient.commandString);
}
}
Name: getAllRecipes
This method gets a list of all the recipes for the Recipe Manager and returns a list of Recipe.
ZenScript CopygetAllRecipes();
You could use this method to get the ingredients
of all the recipes and print the commandString
of each ingredient of each recipe.
ZenScript Copyfor recipe in furnace.getAllRecipes() {
println("> " + recipe.id);
for ingredient in recipe.ingredients {
println(ingredient.commandString);
}
}
Name: remove
This method allows you to remove recipes from this Recipe Manager by the recipe's output item.
ZenScript Copyremove(IItemStack output);
An example use case for this method is removing the recipe for Sticks from the Crafting Table:
ZenScript CopycraftingTable.remove(<item:minecraft:stick>);
Another example of this method would be removing the Diamond Ore to Diamond recipe from the furnace:
ZenScript Copyfurnace.remove(<item:minecraft:diamond>);
Name: removeByName
This method allows you to remove recipes from this Recipe Manager by the recipe's name.
ZenScript CopyremoveByName(String name);
#根据配方名称删除配方
An example use case for this method is removing the recipe for an Arrow from the Crafting Table:
ZenScript CopycraftingTable.removeByName("minecraft:arrow");
Name: removeByModid
This method allows you to remove recipes from this Recipe Manager based on the the recipe name's modid.
There is an optional parameter that is used to exclude recipes from being removed.
Note: The name given to the RecipeFilter is just the path of the recipe id.
For example, if the recipe id is minecraft:orange_wool
, the name given will be orange_wool
. Another example would be the recipe id modid:path/name
, the name given will be path/name
ZenScript CopyremoveByModid(String modid);
or
removeByModid(String modid, RecipeFilter exclude);
An example use case for this method is removing all the recipe from "minecraft" from the Crafting Table:
ZenScript CopycraftingTable.removeByModid("minecraft");
Another use case would be removing all the recipes from "minecraft" excluding the recipe for Orange Wool.
ZenScript CopycraftingTable.removeByModid("minecraft", (name as string) => {
return name == "orange_wool";
});
Name: removeByRegex
This method allows you to remove recipes from this Recipe Manager by testing the recipe's id against a regex pattern.
ZenScript CopyremoveByName(String name);
#根据配方名称删除配方(为啥会有重复的)
An example use case for this method is removing all recipes who's id matches .*wool.*
(anything that has the work wool
in it).
ZenScript CopycraftingTable.removeByRegex(".*wool.*");
Name: removeAll
This method allows you to remove all the recipes from the Recipe Manager.
ZenScript CopyremoveAll(String regex);
An example use case for this method is removing all the Blast Furnace recipes.
ZenScript CopyblastFurnace.removeAll();