Recipe types from shared scripts and stuff
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
# Recipes
|
||||
|
||||
Recipes are data in a mod's `recipes/` folder, one per file. The engine has three types, for the crafting grid and the
|
||||
furnace. Everything else, the base game's smithing table included, has a type of its own that a mod defines.
|
||||
Recipes are data in a mod's `recipes/` folder, one per file. The engine has one type, `shaped`, for the crafting grid in
|
||||
the player's inventory. Everything else, the base game's furnace and smithing table included, has a type of its own that
|
||||
a mod defines.
|
||||
|
||||
## Crafting: `shaped`
|
||||
|
||||
@@ -22,13 +23,16 @@ For the crafting grid in the player's inventory screen:
|
||||
`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`
|
||||
## Smelting: `bworld:smelting` and `bworld:fuel`
|
||||
|
||||
For the furnace. They're the base game's own types, registered by its shared script like
|
||||
[any mod's](#custom-recipe-types):
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "furnace",
|
||||
"type": "bworld:smelting",
|
||||
"input": "bworld:iron_ore",
|
||||
"output": { "id": "bworld:iron_ingot", "count": 1 },
|
||||
"cook_time": 200
|
||||
@@ -39,12 +43,13 @@ pattern fits anywhere in the grid.
|
||||
```json
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": { "type": "fuel", "item": "bworld:coal", "burn_time": 1000 }
|
||||
"recipe": { "type": "bworld: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.
|
||||
`cook_time` and `burn_time` are in ticks, 20 to a second. Two smelting recipes for the same input are an error. For
|
||||
fuel, a later recipe for the same item replaces an earlier one, so a mod that depends on the base game can change how
|
||||
long something burns.
|
||||
|
||||
## Smithing: `bworld:smithing`
|
||||
|
||||
@@ -137,8 +142,9 @@ furnace smelts.
|
||||
|
||||
## Choices
|
||||
|
||||
Anywhere a recipe takes an item (`key` values, `input`, `item`), an item [tag](tags.md) means anything in it fits, and
|
||||
so does a list of ids and tags:
|
||||
Anywhere a recipe takes a choice of items (`shaped` keys, and the fields a type reads with
|
||||
[`read.ingredient`](#custom-recipe-types), like smelting's `input` and fuel's `item`), an item [tag](tags.md) means
|
||||
anything in it fits, and so does a list of ids and tags:
|
||||
|
||||
```json
|
||||
"key": { "P": "#bworld:planks" }
|
||||
@@ -189,7 +195,8 @@ export function setup(ctx: SharedContext) {
|
||||
the server and every client. Throwing stops the mod loading with an error naming the recipe, so a broken one is caught
|
||||
when the server starts rather than when someone uses the machine. `read.item(json, field)` and `read.stack(json, field)`
|
||||
check a field the way the engine's own types are checked, an item id or `{ id, count }` of an item that exists, and
|
||||
throw naming the field.
|
||||
throw naming the field. `read.ingredient(json, field)` reads a [choice](#choices) of items, an item, a `#tag` or a list
|
||||
of them, as every item that fits. Its tags have to exist, but can be empty.
|
||||
|
||||
Then server, client and shared scripts look recipes up by what's in the machine, like NeoForge's
|
||||
`RecipeManager.getRecipeFor`:
|
||||
@@ -255,7 +262,7 @@ export function setup(ctx: SharedContext) {
|
||||
Shared scripts run on the server and on every player's client, from the same data, so every side makes the same recipes
|
||||
and nothing is sent: the crafting grid, `ctx.recipes.list` in server and client scripts, and recipe viewers see them
|
||||
like any other. That's also why it's only in shared scripts. Recipes can only be registered during `setup`, before any
|
||||
server or client script sets up, and one is checked like a file would be: a broken one, or a second furnace recipe for
|
||||
server or client script sets up, and one is checked like a file would be: a broken one, or a second smelting recipe for
|
||||
the same input, throws, which stops the mod loading.
|
||||
|
||||
`ctx.recipes.list(type?)` reads the recipes there are so far, copies in load order, like the client's: every mod's
|
||||
@@ -274,12 +281,10 @@ Make them from what's the same on every side, like items and their components, n
|
||||
|
||||
## Looking Up Recipes
|
||||
|
||||
Mods' registered types are looked up with [`find` and `all`](#custom-recipe-types). Server scripts can also ask about
|
||||
the furnace's:
|
||||
Every registered type, the base game's included, is looked up with [`find` and `all`](#custom-recipe-types). The base
|
||||
game's smelting and fuel recipes are found by an item id:
|
||||
|
||||
```ts
|
||||
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.find("bworld:smelting", "bworld:iron_ore"); // { input, output, cook_time }, or undefined
|
||||
ctx.recipes.find("bworld:fuel", "bworld:coal"); // { items, burn_time }, or undefined
|
||||
```
|
||||
|
||||
@@ -80,7 +80,7 @@ back. Depend on the mod whose tag you change, so your file loads after its. chec
|
||||
|
||||
## Using Tags in Data
|
||||
|
||||
- **Recipes**: anywhere a recipe takes an item (shaped `key` values, furnace `input`, fuel `item`) it can take an item
|
||||
- **Recipes**: anywhere a recipe takes an item (shaped `key` values, smelting `input`, fuel `item`) it can take an item
|
||||
tag, on its own or in a list: `"key": { "P": "#bworld:planks" }`. See [Choices](recipes.md#choices).
|
||||
- **Blocks**: `place_on` and `place_in` take block tags, like `"place_on": ["#bworld:logs"]` for a fungus that grows on
|
||||
any log. See [Placement](../blocks/index.md#placement).
|
||||
|
||||
Reference in New Issue
Block a user