Placing schematics
This commit is contained in:
@@ -61,7 +61,7 @@ the block and the component.
|
||||
|
||||
| Handler | Called when | Returns |
|
||||
| --------------------------------------------- | --------------------------------------------------------------------------------------------------------- | -------------------------------- |
|
||||
| `on_create(block, params)` | The block is placed or set, by a player or a script. | |
|
||||
| `on_create(block, params)` | The block is placed or set, by a player, a script, or a schematic without data for it. | |
|
||||
| `on_break(block, params, player?)` | The block is broken or replaced. `player` when a player broke it. | |
|
||||
| `on_click(block, params, player)` | A player starts hitting it. | |
|
||||
| `on_interact(block, params, player)` | A player right clicks it. | `true` if it did something |
|
||||
|
||||
@@ -4,7 +4,8 @@ A schematic is a box of the world saved to a file: its blocks with their states
|
||||
placed again somewhere else. Schematic files end in `.cbsm` and are [MessagePack](https://msgpack.org), see
|
||||
`common/schematic.ts` for their format.
|
||||
|
||||
Only exporting is built so far. Placing schematics, and mods shipping their own, are planned in `STRUCTURES.md`.
|
||||
Exporting, registering and placing are built. Mods shipping their own as files, and blocks making what their data points
|
||||
to when they're placed (`import_data`), are planned in `STRUCTURES.md`.
|
||||
|
||||
## Exporting
|
||||
|
||||
@@ -32,6 +33,44 @@ What goes in:
|
||||
|
||||
Positions are from the box's lowest corner.
|
||||
|
||||
## Placing
|
||||
|
||||
A schematic is registered by id in the server phase, then placed by that id:
|
||||
|
||||
```ts
|
||||
ctx.schematics.register("copper_tools:hut", schematic);
|
||||
|
||||
ctx.schematics.place("copper_tools:hut", {
|
||||
position: { x: 100, y: 64, z: 40 },
|
||||
rotation: 90,
|
||||
});
|
||||
```
|
||||
|
||||
`register` checks it right away, so a schematic with a block, state or entity that isn't registered stops the mod from
|
||||
loading, instead of failing when it's placed. It takes a `Schematic` (exported from `cubi/server`), the same shape as a
|
||||
file's.
|
||||
|
||||
`place` puts the whole schematic in at once, replacing what was there, air too:
|
||||
|
||||
- `position` is where its lowest corner goes.
|
||||
- `rotation` is `0`, `90`, `180` or `270` degrees clockwise seen from above. `mirror` is `"x"` or `"z"`, the axis that
|
||||
gets flipped. The mirror is applied first, then the rotation, both around `position_pivot`, a block from the
|
||||
schematic's lowest corner, `0 0 0` by default. Each placement can come out different, so a mod can turn the same room
|
||||
to face each way.
|
||||
- Only a state named `facing` turns with it (`0` north, `1` east, `2` south, `3` west, `4` up and `5` down stay). Other
|
||||
states, like a stair's shape, stay as they are. Entities' positions and yaw turn too.
|
||||
- Replaced blocks get their `on_break`, like with `ctx.world.set_block`, so a chest it replaces drops what it holds.
|
||||
- Blocks the schematic has data or client data for get it as it is. Other blocks get their `on_create`. Then every block
|
||||
placed tells the blocks beside it, so a fence at its edge joins what's outside. Blocks hear of it once all of them are
|
||||
in, so a door's two halves are both there by then.
|
||||
- Entities come with new uuids each time.
|
||||
- Parts above or below the world are left out. Ungenerated chunks it reaches are generated first.
|
||||
|
||||
It throws for an id nothing registered, or a placement that isn't one, before anything changes.
|
||||
|
||||
Until `import_data` is built, a block's exported data goes back in as it is, so a chest placed from a schematic has its
|
||||
items' list in its data and no container.
|
||||
|
||||
## Block Data
|
||||
|
||||
Tile data goes into a schematic as it is, which is right for plain fields like a furnace's progress. Data that only
|
||||
|
||||
Reference in New Issue
Block a user