3.3 KiB
Structures
Schematics
Schematics are pre-defined block patterns to be placed somewhere in the world
Schematic format
Schematics are json data, encoded and decoded with MessagePack (@std/msgpack), they are saved in .cbsm files
On the schematic the objects have i, s and p keys, these correspond to index, state and position, they are
shorten to save on bytes on msgpack
The data on palette.palette[number].data is from BlockComponent.export_data
Example:
{
"format_version": 1,
"schematic": {
"id": "bworld:my_schematic",
"size": [2, 2, 1],
"palette": [
{ "id": "bworld:stone" },
{ "id": "bworld:dirt" },
{
"id": "bworld:furnace",
"s": { "facing": 1 }
}
],
"blocks": [
{
"i": 0,
"p": [0, 0, 0]
},
{
"i": 1,
"p": [1, 0, 0]
},
{
"i": 2,
"p": [1, 1, 0],
"data": { "items": [] }
}
],
"entities": [
{
"p": [0.5, 1.0, 0.5],
"id": "bworld:chicken",
"data": {}
}
]
}
}
Schematics will come from the schematics directory inside mods or through ctx.schematics.register() function
Block data serialization
BlockComponent will have new methods:
// the block's data as it's kept outside the world, with its containers' items written in
export_data?(block: BlockRef, params: P): unknown;
// the other way, for a block placed from a structure: creates its containers from those items
import_data?(block: BlockRef, params: P, data: unknown): void;
Blocks without the hooks just copy data unchanged, which is fine for plain fields.
Placing schematics
ctx.schematics.place(id, { position, dimension, position_pivot, rotation, mirror });
Rotation and mirroring
rotationis0,90,180or270degrees clockwise seen from above, the same as the"y"of a block variantmirroris"x"or"z", the axis that gets flipped, or left out for none- the mirror is applied first, then the rotation, both around
position_pivot
Positions, relative to the pivot:
- mirror
"x":xbecomes-x - mirror
"z":zbecomes-z - each 90 degrees:
[x, z]becomes[-z, x]
The only state that changes is one named facing, the standard one. Its values are always 0 north, 1 east, 2
south, 3 west, then 4 up and 5 down for a 3 bit one (see FACINGS in common/block_rules.ts and the importer's
ORDERS):
- mirror
"x"swaps east and west (1and3) - mirror
"z"swaps north and south (0and2) - each 90 degrees adds 1 to a value under 4, wrapping around (
(facing + 1) % 4) - up and down never change
Every other state (axis, door hinges, stair shapes) is copied as it is, so those blocks can come out wrong in a turned
or mirrored schematic. A hook for them can come later if it's needed.
Entities get their position turned the same way as blocks, and their yaw with it (yaw 0 looks north, east is -π/2):
- mirror
"x":yawbecomes-yaw - mirror
"z":yawbecomesπ - yaw - each 90 degrees:
yawbecomesyaw - π/2
Saving schematics
ctx.schematics.export(dimension, from, to); // saves the schematic file to a temporary directory and prints the location on the chat for the player
And a /exportschematic [x1] [y1] [z1] [x2] [y2] [z2] command that calls ctx.schematics.export on the player's
dimension