From 717d2cb766cbf6f4e161dba468afc27f48275f52 Mon Sep 17 00:00:00 2001 From: Paula Date: Sat, 21 Nov 2026 15:24:31 -0300 Subject: [PATCH] Remove structures planning --- CREATE.md | 6 +- STRUCTURES.md | 129 -------------------------------- common/mod_api/server.ts | 3 +- common/schematic.ts | 3 +- docs/modding/misc/schematics.md | 2 +- server/game/schematics.ts | 4 +- 6 files changed, 9 insertions(+), 138 deletions(-) delete mode 100644 STRUCTURES.md diff --git a/CREATE.md b/CREATE.md index abd2505..f8351db 100644 --- a/CREATE.md +++ b/CREATE.md @@ -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/.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. diff --git a/STRUCTURES.md b/STRUCTURES.md deleted file mode 100644 index b609891..0000000 --- a/STRUCTURES.md +++ /dev/null @@ -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/.cbsm` files are registered as `:` 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`). diff --git a/common/mod_api/server.ts b/common/mod_api/server.ts index a18059d..9ed3afc 100644 --- a/common/mod_api/server.ts +++ b/common/mod_api/server.ts @@ -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"; diff --git a/common/schematic.ts b/common/schematic.ts index ac68900..06ccef0 100644 --- a/common/schematic.ts +++ b/common/schematic.ts @@ -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"; diff --git a/docs/modding/misc/schematics.md b/docs/modding/misc/schematics.md index 9005cc6..bbc3cdc 100644 --- a/docs/modding/misc/schematics.md +++ b/docs/modding/misc/schematics.md @@ -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 diff --git a/server/game/schematics.ts b/server/game/schematics.ts index 886ff33..d5d3771 100644 --- a/server/game/schematics.ts +++ b/server/game/schematics.ts @@ -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,