4.1 KiB
Recipes
Recipes are data in a mod's recipes/ folder, one per file. The base game has four types, for its crafting grid,
furnace and smithing table. Mods can make up types of their own for their machines.
Crafting: shaped
For the crafting grid in the player's inventory screen:
{
"format_version": 1,
"recipe": {
"type": "shaped",
"pattern": ["PPP", "P P", "PPP"],
"key": { "P": "bworld:oak_planks" },
"result": { "id": "bworld:chest", "count": 1 }
}
}
pattern is 1 to 3 rows of 1 to 3 characters, where a space is an empty slot. key maps each letter to an item. The
pattern fits anywhere in the grid.
Smelting: furnace and fuel
{
"format_version": 1,
"recipe": {
"type": "furnace",
"input": "bworld:iron_ore",
"output": { "id": "bworld:iron_ingot", "count": 1 },
"cook_time": 200
}
}
{
"format_version": 1,
"recipe": { "type": "fuel", "item": "bworld:coal", "burn_time": 1000 }
}
cook_time and burn_time are in ticks, 20 to a second. Two furnace recipes for the same input are an error. For fuel,
a later recipe for the same item replaces an earlier one.
Smithing: smithing
For the smithing table, which upgrades a tool:
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:wood_pickaxe",
"material": { "id": "bworld:stone", "count": 5 },
"result": "bworld:stone_pickaxe"
}
}
An optional addition is a third item it also takes. Upgrading uses up the tool, count of the material and the
addition, and the result keeps the tool's data, like its durability. Two smithing
recipes with the same tool, material and addition are an error.
Choices
Anywhere a recipe takes an item (key values, input, item), an item tag means anything in it fits, and
so does a list of ids and tags:
"key": { "P": "#bworld:planks" }
"item": ["bworld:coal", "#bworld:logs"]
In the crafting grid, each slot can hold a different one of them, so a stick can be made from oak and birch planks together. The recipe viewer takes turns showing them.
Use a tag rather than listing ids when other mods might have more of the same thing: a mod that adds planks to
#bworld:planks makes them work in every recipe that takes it.
Custom Recipe Types
Any type with a namespace is a mod's own, like farmersdelight:cooking for the cooking pot. The engine only stores
these recipes. Everything else about them is up to the mod:
{
"format_version": 1,
"recipe": {
"type": "farmersdelight:cooking",
"ingredients": ["farmersdelight:cabbage", ["bworld:carrot", "bworld:potato", "farmersdelight:onion"]],
"result": { "id": "farmersdelight:cabbage_rolls", "count": 1 },
"cook_time": 100
}
}
The mod's server script reads them in setup and checks their fields itself:
const recipes = ctx.recipes.list("farmersdelight:cooking").map((json, i) => {
if (!Array.isArray(json.ingredients) || json.ingredients.length > 6) {
throw new Error(`cooking recipe ${i + 1}: ingredients must be 1 to 6 items`);
}
// ...check the rest, and turn it into whatever the machine needs. expand turns #tags into their items
return { ingredients: json.ingredients.map((choice) => ctx.tags.expand(choice)) };
});
Throwing in setup stops the server from starting with the error, so a broken recipe is caught when the server starts
rather than when someone uses the machine. Other mods can add recipes of your type too, as long as they depend on your
mod.
list returns copies, in load order. Client scripts can read every recipe with ctx.recipes.list(type?), which is how
the recipe viewer shows mods' own types.
Looking Up Recipes
Server scripts can ask about the base game's types:
ctx.recipes.furnace_result("bworld:iron_ore"); // { output, cook_time }, or undefined
ctx.recipes.is_smeltable("bworld:iron_ore");
ctx.recipes.is_fuel("bworld:coal");
ctx.recipes.fuel_value("bworld:coal"); // burn time in ticks, 0 when it isn't fuel
ctx.recipes.smithing("bworld:wood_pickaxe", "bworld:stone"); // { result, material_count }, or undefined