Recipe types from shared scripts and stuff
This commit is contained in:
@@ -320,7 +320,7 @@ catch up. If it's further behind than that, it skips the rest and logs a warning
|
||||
| ----------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `bworld:storage` | `rows` | A chest: `rows` × 9 slots, dropped when it's broken. |
|
||||
| `bworld:shipping_bin` | `rows` | Like `bworld:storage`, and every morning at 06:00 sells what's in it that has a sell value for coins. |
|
||||
| `bworld:furnace` | none | Smelts with `furnace` and `fuel` [recipes](../resources/recipes.md). Needs `lit` and `facing` states, see `blocks/furnace.json`. |
|
||||
| `bworld:furnace` | none | Smelts with `bworld:smelting` and `bworld:fuel` [recipes](../resources/recipes.md). Needs `lit` and `facing` states, see `blocks/furnace.json`. |
|
||||
| `bworld:smithing_table` | none | Upgrades tools with `bworld:smithing` recipes. |
|
||||
| `bworld:stonecutter` | none | Cuts one item into another with `bworld:stonecutting` recipes, picked from a list. |
|
||||
| `bworld:hoeable` | `tool`, `into` | Right clicking with a tool of type `tool` turns it into `into`, like a hoe on grass. |
|
||||
|
||||
@@ -22,8 +22,8 @@ export function setup(ctx: ServerContext) {
|
||||
const smelter = ctx.menus.register<BlockRef>("copper_tools:smelter", (menu, block, player) => {
|
||||
const container = ctx.containers.get(block.data.container)!;
|
||||
menu.title = "Smelter";
|
||||
menu.add_slot(container, 0, { x: 55, y: 16, filter: "smeltable" });
|
||||
menu.add_slot(container, 1, { x: 55, y: 52, filter: "fuel" });
|
||||
menu.add_slot(container, 0, { x: 55, y: 16, filter: (item) => !!ctx.recipes.find("bworld:smelting", item.id) });
|
||||
menu.add_slot(container, 1, { x: 55, y: 52, filter: (item) => !!ctx.recipes.find("bworld:fuel", item.id) });
|
||||
menu.add_slot(container, 2, { x: 115, y: 34, output_only: true });
|
||||
menu.add_player_inventory(7, 84);
|
||||
menu.add_data("progress", () => block.data.progress);
|
||||
@@ -57,7 +57,7 @@ returns the slot's **menu slot index**: slots are numbered in the order they're
|
||||
| Option | Meaning |
|
||||
| ------------- | ----------------------------------------------------------------------------------------------------------------- |
|
||||
| `x`, `y` | Where its 18 pixel frame goes, in GUI pixels from the screen's top left. |
|
||||
| `filter` | What can be put in: `"smeltable"` (has a furnace recipe), `"fuel"`, or a function `(item) => boolean`. |
|
||||
| `filter` | What can be put in: a function `(item) => boolean`, like one that looks for a [recipe](../resources/recipes.md). |
|
||||
| `output_only` | Can only be taken from, all at once, like the furnace result. |
|
||||
| `on_take` | For `output_only` slots: runs when a player takes from it, before they get the item. Return `false` to stop them. |
|
||||
| `icon` | A texture drawn in the slot while it's empty, like Minecraft's armor slots. |
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -120,8 +120,8 @@ interface RecipeRegistry {
|
||||
- Common scripts only run during loading and can't reach the world or players. They get the same `ctx` on both sides, so
|
||||
they can't accidentally register different things.
|
||||
- `register_type` would let `check-mods` and the loader validate mods' own recipe types, instead of each mod checking
|
||||
its recipes in `setup`. `shaped`, `furnace` and `fuel` become short for `bworld:shaped` and so on. Shared scripts can
|
||||
now register types with `ctx.recipes.register_type`, and `bworld:smithing` is one.
|
||||
its recipes in `setup`. `shaped` becomes short for `bworld:shaped`. Shared scripts can now register types with
|
||||
`ctx.recipes.register_type`, and `bworld:smithing`, `bworld:smelting` and `bworld:fuel` are.
|
||||
|
||||
### The Freeze and the Registry Hash
|
||||
|
||||
@@ -277,7 +277,7 @@ engine assets in `assets/`.
|
||||
| ---------------------------------------------------------------------- | ------------------------------------------------------------------------ | ------- |
|
||||
| Blocks, items, models, entities, recipes, textures, credits | `mods/bworld` | Done |
|
||||
| Hoeing, chest, furnace, smithing table, farming, watering can, fishing | `mods/bworld/scripts/server.ts` | Done |
|
||||
| Recipe types `shaped`, `furnace`, `fuel` | engine (`common/mod_loader.ts`, `server/game/crafting.ts`) | Phase 5 |
|
||||
| Recipe type `shaped` | engine (`common/mod_loader.ts`, `server/game/crafting.ts`) | Phase 5 |
|
||||
| The player's inventory screen and crafting grid | engine (`client/gui/gui_player_inventory.ts`, `server/game/crafting.ts`) | Phase 5 |
|
||||
| The hotbar and crosshair | engine (`client/gui/hud.ts`) | Phase 5 |
|
||||
| `/give`, `/time` and `/summon` | engine (`server/game/game_server.ts`) | Phase 5 |
|
||||
|
||||
Reference in New Issue
Block a user