3.4 KiB
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:
namespaceis the id of the mod that registers it, 1-32 characters ofa-z,0-9and_.nameisa-z,0-9and_.- A mod only registers ids in its own namespace. It can refer to any id, like using
bworld:oak_planksin a recipe. - Registering an id that's already registered, by the same mod or another, is an error.
Two namespaces are reserved:
bworldbelongs to the base game,mods/bworld.cubibelongs to the engine: the empty blockcubi:air, the entity typescubi:playerandcubi:item, the attributes likecubi:max_health, the missing texturecubi:missing, the breaking crackscubi:break_0tocubi:break_8, and the built-in block modelscubi:cube,cubi:crossandcubi:crop.
Tags 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:
- 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.
- Data, one mod at a time: its block models, blocks (and their items), including the ones its
content phase registers, after its
blocks/files, items, entity models, entities, effects and fluids. Then every mod's tags, merged in load order, then each mod's recipes and ores, which can use tags. - Scripts. Every mod's shared phase runs, then its server phase on the server and its client phase on each client. The worldgen phase runs wherever the server makes chunks.
Scripts read the registries but can't add to them. Content comes from data files, and from content phases, 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 phases 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.