Implement tags !
This commit is contained in:
@@ -49,22 +49,22 @@ there will be holes in the world behind them.
|
||||
|
||||
### Behavior
|
||||
|
||||
| Field | Default | Meaning |
|
||||
| ---------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `collision` | `true` | Whether entities bump into it. Plants and water set `false`. |
|
||||
| `mining.toughness` | unbreakable | Seconds to break by hand. Without `mining`, a block can't be broken. |
|
||||
| `mining.tool` | none | The [tool type](../items/tools.md) that breaks it faster, like `pickaxe`, `axe` or `shovel`. |
|
||||
| `mining.requires_tool` | `false` | Only drops when broken with `mining.tool`. |
|
||||
| `mining.tier` | `0` | With `requires_tool`, the lowest tool tier it drops for. Iron ore is `1`, so a wood pickaxe gets nothing. |
|
||||
| `drops` | nothing | The item id it drops when broken. |
|
||||
| `item` | `true` | Also register an item that places it, with the same id. |
|
||||
| `interactive` | `false` | Right clicking it does something, like opening a screen, so clients don't guess that it places a block. |
|
||||
| `replaceable` | `false` | Placing a block into it replaces it, like water. |
|
||||
| `place_in` | see meaning | Block ids it can be placed into, replacing them, like `["bworld:water"]` for rice. Air and `replaceable` blocks when not set. |
|
||||
| `place_on` | anywhere | Block ids it can stand on, like `["bworld:hoed_dirt"]` for crops. See [below](#placement). |
|
||||
| `states` | none | Named [state](states.md) bits, like a crop's age. |
|
||||
| `components` | none | [Components](components.md) and their parameters. |
|
||||
| `item_display` | none | Shows an item on top of it, see [Tile Data](tiledata.md#showing-an-item). |
|
||||
| Field | Default | Meaning |
|
||||
| ---------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `collision` | `true` | Whether entities bump into it. Plants and water set `false`. |
|
||||
| `mining.toughness` | unbreakable | Seconds to break by hand. Without `mining`, a block can't be broken. |
|
||||
| `mining.tool` | none | The [tool type](../items/tools.md) that breaks it faster, like `pickaxe`, `axe` or `shovel`. |
|
||||
| `mining.requires_tool` | `false` | Only drops when broken with `mining.tool`. |
|
||||
| `mining.tier` | `0` | With `requires_tool`, the lowest tool tier it drops for. Iron ore is `1`, so a wood pickaxe gets nothing. |
|
||||
| `drops` | nothing | The item id it drops when broken. |
|
||||
| `item` | `true` | Also register an item that places it, with the same id. |
|
||||
| `interactive` | `false` | Right clicking it does something, like opening a screen, so clients don't guess that it places a block. |
|
||||
| `replaceable` | `false` | Placing a block into it replaces it, like water. |
|
||||
| `place_in` | see meaning | Block ids or [tags](../resources/tags.md) it can be placed into, replacing them, like `["bworld:water"]` for rice. Air and `replaceable` blocks when not set. |
|
||||
| `place_on` | anywhere | Block ids or [tags](../resources/tags.md) it can stand on, like `["bworld:hoed_dirt"]` for crops or `["#bworld:logs"]`. See [below](#placement). |
|
||||
| `states` | none | Named [state](states.md) bits, like a crop's age. |
|
||||
| `components` | none | [Components](components.md) and their parameters. |
|
||||
| `item_display` | none | Shows an item on top of it, see [Tile Data](tiledata.md#showing-an-item). |
|
||||
|
||||
A block's definition goes to every player, since clients need it to draw the block, time breaking and collide with it.
|
||||
It can't hold functions.
|
||||
|
||||
@@ -20,6 +20,9 @@ Two namespaces are reserved:
|
||||
|
||||
`bworld:air` is the one exception: it's the engine's empty block, but keeps that id because every save has it.
|
||||
|
||||
[Tags](../resources/tags.md) aren't registered like this: they're lists that every mod can add to, their ids can have
|
||||
folders (`c:ingots/iron`), and the `c` namespace is shared by every mod.
|
||||
|
||||
The same id can name different kinds of thing. A block registers an item with the same id unless it sets
|
||||
`"item": false`, and its texture is often named the same too.
|
||||
|
||||
@@ -29,8 +32,8 @@ The server and every client load mods the same way, in the same order:
|
||||
|
||||
1. **Order.** Dependencies come before the mods that need them, and otherwise mods load alphabetically. Mods that depend
|
||||
on each other in a circle are an error. The server sends its order to clients, and they follow it.
|
||||
2. **Data**, one mod at a time: its block models, blocks (and their items), items, entity models, entities, then recipes
|
||||
and ores.
|
||||
2. **Data**, one mod at a time: its block models, blocks (and their items), items, entity models and entities. Then
|
||||
every mod's [tags](../resources/tags.md), merged in load order, then each mod's recipes and ores, which can use tags.
|
||||
3. **Scripts.** Server scripts' `setup` runs on the server, and client scripts' on each client. Worldgen scripts'
|
||||
`setup` runs on the server before it makes chunks.
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ mods/
|
||||
models/*.geo.json # entity models
|
||||
entities/*.json
|
||||
recipes/*.json
|
||||
tags/<registry>/<namespace>/*.json # tags, see resources/tags.md
|
||||
worldgen/ores.json
|
||||
textures/*.png
|
||||
scripts/
|
||||
@@ -34,8 +35,8 @@ Data folders can have subfolders. Every data file holds one definition, wrapped
|
||||
}
|
||||
```
|
||||
|
||||
The key is `block`, `item`, `model`, `entity` or `recipe`, depending on the folder. File names don't matter, the `id`
|
||||
inside does.
|
||||
The key is `block`, `item`, `model`, `entity`, `recipe` or `tag`, depending on the folder. File names don't matter, the
|
||||
`id` inside does, except for [tags](../resources/tags.md), whose id is their path.
|
||||
|
||||
## `manifest.json`
|
||||
|
||||
|
||||
@@ -68,15 +68,23 @@ recipes with the same tool, material and addition are an error.
|
||||
|
||||
## Choices
|
||||
|
||||
Anywhere a recipe takes an item (`key` values, `input`, `item`), a list of ids means any of them fits:
|
||||
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:
|
||||
|
||||
```json
|
||||
"key": { "P": ["bworld:planks", "bworld:birch_planks", "bworld:spruce_planks"] }
|
||||
"key": { "P": "#bworld:planks" }
|
||||
```
|
||||
|
||||
```json
|
||||
"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
|
||||
@@ -101,8 +109,8 @@ 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
|
||||
return json;
|
||||
// ...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)) };
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
# Tags
|
||||
|
||||
A tag is a named list of blocks, items or entities, like every kind of planks. Recipes and blocks can use a tag anywhere
|
||||
they take an id, and any mod can add to any tag, so a mod's planks can make sticks just by adding them to
|
||||
`#bworld:planks`. Tags work like [NeoForge's](https://docs.neoforged.net/docs/resources/server/tags).
|
||||
|
||||
A tag's id starts with `#` where it's used, so `#bworld:planks` is the tag and `bworld:planks` is the oak planks item.
|
||||
|
||||
## Tag Files
|
||||
|
||||
Tags are data in a mod's `tags/` folder, at `tags/<registry>/<namespace>/<path>.json`:
|
||||
|
||||
```
|
||||
tags/
|
||||
items/
|
||||
bworld/planks.json # the item tag #bworld:planks
|
||||
c/ingots/copper.json # #c:ingots/copper
|
||||
blocks/
|
||||
my_mod/soft.json # the block tag #my_mod:soft
|
||||
```
|
||||
|
||||
`<registry>` is `blocks`, `items` or `entities`. A block tag and an item tag with the same id are two different tags, so
|
||||
a block that should be in both, like planks, needs a file for each.
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": 1,
|
||||
"tag": {
|
||||
"values": [
|
||||
"my_mod:maple_planks",
|
||||
"#my_mod:painted_planks",
|
||||
{ "id": "other_mod:birch_planks", "required": false }
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Default | Meaning |
|
||||
| --------- | ------- | -------------------------------------------------------------------------------------- |
|
||||
| `values` | | What's in the tag: ids, and `#tags` whose contents are all in it too. |
|
||||
| `replace` | `false` | Throws away what mods loaded before this one put in the tag. |
|
||||
| `remove` | none | Ids and `#tags` to take out of the tag again, if they're in it. Written like `values`. |
|
||||
|
||||
An entry in `values` must exist, or the tag doesn't load and the server doesn't start. Write it as
|
||||
`{ "id": ..., "required": false }` when it's fine for it to be missing, like another mod's item that may not be
|
||||
installed. What `remove` lists never has to exist.
|
||||
|
||||
A tag can't contain itself, directly or through other tags.
|
||||
|
||||
## Adding to Other Mods' Tags
|
||||
|
||||
A mod's tag files can be in any namespace. Every mod's file for the same tag is merged, in
|
||||
[load order](../concepts/registries.md#loading), so adding to someone else's tag only adds to it. This is
|
||||
`mods/maple/tags/items/bworld/planks.json`:
|
||||
|
||||
```json
|
||||
{ "format_version": 1, "tag": { "values": ["maple:maple_planks"] } }
|
||||
```
|
||||
|
||||
`replace` and `remove` apply in load order too: a mod can take out what an earlier mod added, and a later mod can add it
|
||||
back. Depend on the mod whose tag you change, so your file loads after its. check-mods warns when you don't.
|
||||
|
||||
## Choosing a Namespace
|
||||
|
||||
- A tag for your own mod's behavior, like the blocks your drill can't break, goes in your namespace.
|
||||
- A tag other mods would want to share, like a new metal's ingots, goes in the `c` namespace, like NeoForge's and
|
||||
Fabric's shared tags. No mod owns `c`, so using it needs no dependency.
|
||||
- Tag names are plural (`planks`, `ingots`). Group them with folders, with a tag for the whole folder holding each tag
|
||||
in it: `#c:ingots` holds `#c:ingots/iron`, `#c:ingots/copper` and so on.
|
||||
|
||||
## The Base Game's Tags
|
||||
|
||||
| Tag | Registry | What's in it |
|
||||
| ---------------- | ------------- | ------------------------------------------------------------------------ |
|
||||
| `#bworld:planks` | items, blocks | Every kind of planks. |
|
||||
| `#bworld:logs` | items, blocks | Every kind of log. |
|
||||
| `#bworld:leaves` | blocks | Every kind of leaves. |
|
||||
| `#c:ingots` | items | `#c:ingots/copper`, `#c:ingots/tin`, `#c:ingots/iron`, `#c:ingots/gold`. |
|
||||
|
||||
## Using Tags in Data
|
||||
|
||||
- **Recipes**: anywhere a recipe takes an item (shaped `key` values, furnace `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).
|
||||
|
||||
A tag nobody defines is a check-mods error there.
|
||||
|
||||
## Using Tags in Scripts
|
||||
|
||||
Server and client scripts both have `ctx.tags`. Tags can be written with or without their `#`:
|
||||
|
||||
```ts
|
||||
ctx.tags.has("items", "bworld:planks", item.id); // whether it's in the tag
|
||||
ctx.tags.get("blocks", "#bworld:logs"); // every id in it, including its tags' ids
|
||||
ctx.tags.of("items", "bworld:iron_ingot"); // every tag it's in: ["c:ingots", "c:ingots/iron"]
|
||||
ctx.tags.exists("items", "c:ingots/tin"); // whether any mod defines it
|
||||
ctx.tags.expand(["#bworld:planks", "bworld:stick"]); // every item a recipe's choice stands for
|
||||
```
|
||||
|
||||
`has` and `get` treat a tag nobody defines as empty.
|
||||
|
||||
Mods' own [recipe types](recipes.md#custom-recipe-types) should take tags like the base game's do. `expand` turns a
|
||||
choice into the items it stands for, so the mod's server script can check and match them:
|
||||
|
||||
```ts
|
||||
const ingredient = ctx.tags.expand(json.ingredient); // "#bworld:planks" -> ["bworld:planks", "bworld:spruce_planks", ...]
|
||||
```
|
||||
Reference in New Issue
Block a user