Remove structures planning

This commit is contained in:
2026-11-21 15:24:31 -03:00
parent 94463b3cea
commit 717d2cb766
6 changed files with 9 additions and 138 deletions
+2 -4
View File
@@ -393,8 +393,7 @@ Stonecutting is built, as `bworld:stonecutting` with the stonecutter, and the sa
are mostly those. They're components with placement rules in `mods/bworld`, like the fence and trapdoor.
**S11. Layered ore features** (P2). Create's striated ores are bands of stone types, not blobs. A worldgen feature in
`mods/create/scripts/worldgen.ts`, or a data feature if STRUCTURES.md's data features exist by then. Zinc is a plain ore
in `ores.json`.
`mods/create/scripts/worldgen.ts`, or a data feature if those exist by then. Zinc is a plain ore in `ores.json`.
**S12. Mod config** (P1, built). A mod's settings and their defaults in its `config.json`, which the server script reads
as `ctx.config` from `setup` on, like NeoForge's server configs. A server changes them in `config/<mod id>.json` next to
@@ -403,8 +402,7 @@ starting. Players' copies of a mod leave the config out, so what clients need is
change settings with `test_game`'s fourth argument. Create's stress values, speed limits and processing times go there
as the machines that use them are built.
**S13. NBT** (P11). Reading and writing structure NBT, shared with STRUCTURES.md's `common/nbt.ts`, for schematics and
ponder scenes.
**S13. NBT** (P11). Reading and writing structure NBT, for schematics and ponder scenes.
**S14. Uploading files** (P11). A client sending a file to the server in pieces over a mod channel, for schematics.
-129
View File
@@ -1,129 +0,0 @@
# 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 blocks[number].data is from BlockComponent.export_data. A block's client data, like the item a cutting board
holds, goes in blocks[number].client_data. `id` is left out of exported schematics, it's set when one is registered
Example:
```json
{
"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": { "progress": 0, "container": [{ "id": "bworld:coal", "count": 5 }, null, null] }
}
],
"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:
```typescript
// 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
Built without `import_data`, see `docs/modding/misc/schematics.md`:
```typescript
ctx.schematics.register(id, schematic);
ctx.schematics.place(id, { position, position_pivot, rotation, mirror });
```
Mods' `schematics/<name>.cbsm` files are registered as `<mod id>:<name>` before scripts run. They're decoded when the
mod is checked and packed into its `data.json` like its other server only data, so players don't get them. There's no
`dimension` yet, like export. Blocks with data in the schematic get it as it is and skip `on_create`, the rest get their
`on_create`, then every placed block tells its neighbors.
### Rotation and mirroring
- `rotation` is `0`, `90`, `180` or `270` degrees clockwise seen from above, the same as the `"y"` of a block variant
- `mirror` is `"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"`: `x` becomes `-x`
- mirror `"z"`: `z` becomes `-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 (`1` and `3`)
- mirror `"z"` swaps north and south (`0` and `2`)
- 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"`: `yaw` becomes `-yaw`
- mirror `"z"`: `yaw` becomes `π - yaw`
- each 90 degrees: `yaw` becomes `yaw - π/2`
### Saving schematics
Built, see `docs/modding/misc/schematics.md`:
```typescript
// writes a .cbsm file to the system's temporary directory and resolves to its path
ctx.schematics.export(from, to);
```
It has no dimension argument yet, since a server only has one world. `/exportschematic x1 y1 z1 x2 y2 z2` calls it and
tells the player the path in chat. The game worker can't write files, so the host writes it (`write_schematic` in
`server/game/host_protocol.ts`).
+2 -1
View File
@@ -705,7 +705,8 @@ export interface SchematicPlacement {
position: Position;
// the block it turns and mirrors around, from its lowest corner. 0 0 0 by default
position_pivot?: Position;
// clockwise seen from above. turns positions, a state named facing and entities' yaw, see STRUCTURES.md
// clockwise seen from above. turns positions, a state named facing and entities' yaw, see
// docs/modding/misc/schematics.md
rotation?: 0 | 90 | 180 | 270;
// the axis that gets flipped, before it's turned
mirror?: "x" | "z";
+2 -1
View File
@@ -2,7 +2,8 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// schematics: blocks and entities from a box of the world, kept to be placed again somewhere else. a .cbsm file is
// one encoded with msgpack. the short keys (i, s, p) are there to keep files small, see STRUCTURES.md
// one encoded with msgpack. the short keys (i, s, p) are there to keep files small, see
// docs/modding/misc/schematics.md
import { decode, encode } from "@std/msgpack";
import * as z from "zod";
import { find_problems, id, json_object, type Problems, vec3 } from "./schema.ts";
+1 -1
View File
@@ -5,7 +5,7 @@ placed again somewhere else. Schematic files end in `.cbsm` and are [MessagePack
`common/schematic.ts` for their format.
Exporting, registering, reading and placing are built. Blocks making what their data points to when they're placed
(`import_data`) is planned in `STRUCTURES.md`.
(`import_data`) is planned.
## Exporting
+2 -2
View File
@@ -165,8 +165,8 @@ interface Turn {
mirror?: "x" | "z";
}
// where a schematic's blocks and its entities go for a placement, see SchematicPlacement and STRUCTURES.md. the
// entities as saved entities, ready to load. throws for a placement that isn't one
// where a schematic's blocks and its entities go for a placement, see SchematicPlacement and
// docs/modding/misc/schematics.md. the entities as saved entities, ready to load. throws for a placement that isn't one
export function placed_schematic(
{ schematic, palette }: RegisteredSchematic,
placement: SchematicPlacement,