From 04c9511b6ce697bc9749d257ae877216a702ca76 Mon Sep 17 00:00:00 2001 From: Paula Date: Sat, 21 Nov 2026 09:16:51 -0300 Subject: [PATCH] placeschematic command --- docs/modding/misc/commands.md | 3 ++- docs/modding/misc/schematics.md | 2 ++ server/game/game_server.ts | 23 +++++++++++++++++++++++ tests/schematic_test.ts | 14 ++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/docs/modding/misc/commands.md b/docs/modding/misc/commands.md index 504d0e7..eee31d2 100644 --- a/docs/modding/misc/commands.md +++ b/docs/modding/misc/commands.md @@ -118,6 +118,7 @@ Commands can only be registered while the server phase runs. | `/locatebiome ` | Says where the nearest biome of that kind is, up to 6400 blocks away | | `/tp ` | Teleports you there | | `/fill ` | Fills the box between two corners with a block, `air` to clear it | +| `/placeschematic ` | Places a registered schematic with its lowest corner there | | `/fly` | Toggles flying: jump goes up, sneak goes down, sprint goes faster | | `/creative` | Toggles placing blocks without using them up and instant breaking | | `/tps` | Shows how the game loop keeps up | @@ -125,7 +126,7 @@ Commands can only be registered while the server phase runs. | `/skin [url] [slim\|normal]` | Changes your skin to a 64×64 PNG, or back to the default | | `/help [command]` | Every command's usage, or one's | -`/fill` and `/exportschematic` suggest the block you're looking at for each corner. +`/fill`, `/exportschematic` and `/placeschematic` suggest the block you're looking at for each corner. `/give`'s data is the stack's `data`, and with `fluid` it's the fluid's (see [Fluids](../resources/fluids.md#containers)): diff --git a/docs/modding/misc/schematics.md b/docs/modding/misc/schematics.md index 30846b5..9005cc6 100644 --- a/docs/modding/misc/schematics.md +++ b/docs/modding/misc/schematics.md @@ -73,6 +73,8 @@ instead of failing when it's placed. Blocks that aren't registered are left out, It throws for an id nothing registered, or a placement that isn't one, before anything changes. +`/placeschematic id x y z` places one unturned, with its lowest corner at `x y z`. + ## Reading `get` gives a copy of a registered schematic, a file's or one a script registered, with its `id`, or `undefined` for an diff --git a/server/game/game_server.ts b/server/game/game_server.ts index dfffa48..f6382a7 100644 --- a/server/game/game_server.ts +++ b/server/game/game_server.ts @@ -1882,6 +1882,29 @@ export class GameServer { .then(coordinates(["x1", "y1", "z1", "x2", "y2", "z2"], (context) => this.#export_schematic(context))), ); + // TODO: only let operators do this + register( + literal("placeschematic") + .describe("Places a schematic with its lowest corner at x y z") + .then( + argument("schematic", word()) + .suggests((partial) => + [...this.schematics.keys()].filter((id) => id.startsWith(partial)).map((text) => ({ text })) + ) + .then(coordinates(["x", "y", "z"], (context) => { + const id = context.get("schematic"); + if (!this.schematics.has(id)) throw new CommandError(`There's no schematic ${id}`); + const [x, y, z] = ["x", "y", "z"].map((axis) => context.get(axis)); + try { + this.place_schematic(id, { position: { x, y, z } }); + } catch (e) { + throw new CommandError(`Couldn't place it: ${(e as Error).message}`); + } + context.source.send_message(`Placed ${id} at ${x} ${y} ${z}`); + })), + ), + ); + // TODO: only let operators do this register( literal("fill") diff --git a/tests/schematic_test.ts b/tests/schematic_test.ts index e66ccd8..f690ac2 100644 --- a/tests/schematic_test.ts +++ b/tests/schematic_test.ts @@ -259,6 +259,20 @@ Deno.test("blocks that aren't registered are left out of a schematic, and the re assertEquals(t.game.world.get_block_id(5, 101, 5), "bworld:oak_planks"); }); +Deno.test("/placeschematic places a registered schematic with its lowest corner at x y z", async () => { + const t = await place_setup(); + t.join(1, "alice"); + t.take(1); + t.send(1, { type: "chat", text: "/placeschematic testmod:post 3 100 4" }); + assertEquals(t.game.world.get_block_id(3, 100, 4), "bworld:oak_log"); + assertEquals(t.game.world.get_block_id(3, 101, 4), "bworld:oak_log"); + + t.take(1); + t.send(1, { type: "chat", text: "/placeschematic testmod:nothing 3 100 4" }); + const chat = t.take(1).filter((m: Msg) => m.type === "chat").map((m: Msg) => m.text as string); + assert(chat.some((text) => text.includes("no schematic testmod:nothing")), chat.join("\n")); +}); + Deno.test("get gives a copy of a registered schematic with its id, a file's or a script's", async () => { const t = await place_setup(); const hut = t.schematics.get("testmod:hut")!;