From 527f2fb5a7de3f5ca6e789c6c6cf792df965263b Mon Sep 17 00:00:00 2001 From: Paula Date: Sun, 22 Nov 2026 16:09:11 -0300 Subject: [PATCH] ctx.schematics.ids --- common/mod_api/server.ts | 2 ++ docs/modding/misc/schematics.md | 7 +++++++ server/game/mod_runtime.ts | 1 + tests/schematic_test.ts | 6 ++++++ 4 files changed, 16 insertions(+) diff --git a/common/mod_api/server.ts b/common/mod_api/server.ts index b415b4c..d4473f5 100644 --- a/common/mod_api/server.ts +++ b/common/mod_api/server.ts @@ -737,6 +737,8 @@ export interface SchematicApi { // StructureTemplateManager.get. undefined for an id nothing registered. for reading what's in it before placing it, // like where a room's doorways are get(id: Id): Schematic | undefined; + // every registered schematic's id, the files' and the ones scripts registered, in the order they were registered + ids(): Id[]; // puts a registered schematic in the world, all of it at once, replacing what was there, air too. replaced blocks // get their on_break. blocks it has data for get that data as it is, the rest their on_create, then everything // placed tells the blocks beside it. its entities come with new uuids. throws for an id nothing registered, or a diff --git a/docs/modding/misc/schematics.md b/docs/modding/misc/schematics.md index bbc3cdc..c41ccc9 100644 --- a/docs/modding/misc/schematics.md +++ b/docs/modding/misc/schematics.md @@ -88,6 +88,13 @@ const doorways = room.blocks.filter((block) => room.palette[block.i].id === "cop Positions in it are from its lowest corner, before it's turned. Changing the copy doesn't change what `place` puts. +`ids` gives every registered schematic's id, the files' and the ones scripts registered, in the order they were +registered, like for a tool that lets players pick one: + +```ts +const rooms = ctx.schematics.ids().filter((id) => id.startsWith("copper_tools:room_")); +``` + 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. diff --git a/server/game/mod_runtime.ts b/server/game/mod_runtime.ts index 169eebd..00f1d48 100644 --- a/server/game/mod_runtime.ts +++ b/server/game/mod_runtime.ts @@ -1210,6 +1210,7 @@ export class ModRuntime { const registered = game().schematics.get(id); return registered && { ...structuredClone(registered.schematic), id }; }, + ids: () => [...game().schematics.keys()], place: (id, placement) => game().place_schematic(id, placement), }, menus: { diff --git a/tests/schematic_test.ts b/tests/schematic_test.ts index f690ac2..ba01cb1 100644 --- a/tests/schematic_test.ts +++ b/tests/schematic_test.ts @@ -288,6 +288,12 @@ Deno.test("get gives a copy of a registered schematic with its id, a file's or a assertEquals(t.game.world.get_block_id(10, 100, 20), "bworld:oak_planks"); }); +Deno.test("ids gives every registered schematic's id, the files' first, without the ones that failed", async () => { + const t = await place_setup(); + const ids = t.schematics.ids().filter((id) => id.startsWith("testmod:")); + assertEquals(ids, ["testmod:post", "testmod:hut", "testmod:partial"]); +}); + Deno.test("a mod's schematics/.cbsm files are registered as : before its scripts run", async () => { const t = await place_setup(); assertStringIncludes(String(t.game.mods.storage.testmod?.post), "registered twice");