63 lines
3.4 KiB
Markdown
63 lines
3.4 KiB
Markdown
# Registries
|
|
|
|
Every block, item, block model, entity, entity model, status effect, fluid and texture has an id, and is registered
|
|
under it once, while mods load. After that the game refers to things only by their id.
|
|
|
|
## Identifiers
|
|
|
|
An id looks like `namespace:name`, like `bworld:cabbage`:
|
|
|
|
- `namespace` is the id of the mod that registers it, 1-32 characters of `a-z`, `0-9` and `_`.
|
|
- `name` is `a-z`, `0-9` and `_`.
|
|
- A mod only registers ids in its own namespace. It can _refer to_ any id, like using `bworld:oak_planks` in a recipe.
|
|
- Registering an id that's already registered, by the same mod or another, is an error.
|
|
|
|
Two namespaces are reserved:
|
|
|
|
- `bworld` belongs to the base game, `mods/bworld`.
|
|
- `cubi` belongs to the engine: the empty block `cubi:air`, the entity types `cubi:player` and `cubi:item`, the
|
|
[attributes](../entities/players.md) like `cubi:max_health`, the missing texture `cubi:missing`, the breaking cracks
|
|
`cubi:break_0` to `cubi:break_8`, and the built-in block models `cubi:cube`, `cubi:cross` and `cubi:crop`.
|
|
|
|
[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.
|
|
|
|
## Loading
|
|
|
|
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), including the ones its
|
|
[content script](sides.md#content-scripts) registers, after its `blocks/` files, items, entity models, entities,
|
|
effects and fluids. 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.
|
|
|
|
Scripts read the registries but can't add to them. Content comes from data files, and from content scripts, which the
|
|
server runs when it loads mods, before anything else, and whose blocks go to players as data.
|
|
|
|
> [!IMPORTANT]
|
|
> The server and the client must end up with exactly the same blocks, items and recipes. They do as long as content is
|
|
> only data, since both load the same files in the same order. Content scripts only run on the server, and players get
|
|
> what they made as data.
|
|
|
|
## Numeric Ids
|
|
|
|
Blocks get a number when they register, and chunks store those numbers. Numbers are **local to one running program**:
|
|
the server and each client can number blocks differently, so saves and the network always use string ids. When a player
|
|
joins, the server sends its list of block ids, and the client translates chunks into its own numbers as they arrive.
|
|
|
|
The practical rule: never save or send a block's number. Use its id.
|
|
|
|
## Changing What Exists
|
|
|
|
Ids never change and blocks and items can't be removed, because saves refer to them. A world saved with your mod
|
|
installed keeps your ids in its chunks, inventories and chests, so renaming a block breaks those worlds.
|
|
|
|
To retire something, stop it from being obtainable: take away its recipes and drops.
|