placeschematic command
This commit is contained in:
@@ -118,6 +118,7 @@ Commands can only be registered while the server phase runs.
|
|||||||
| `/locatebiome <biome>` | Says where the nearest biome of that kind is, up to 6400 blocks away |
|
| `/locatebiome <biome>` | Says where the nearest biome of that kind is, up to 6400 blocks away |
|
||||||
| `/tp <x> <y> <z>` | Teleports you there |
|
| `/tp <x> <y> <z>` | Teleports you there |
|
||||||
| `/fill <x1> <y1> <z1> <x2> <y2> <z2> <block>` | Fills the box between two corners with a block, `air` to clear it |
|
| `/fill <x1> <y1> <z1> <x2> <y2> <z2> <block>` | Fills the box between two corners with a block, `air` to clear it |
|
||||||
|
| `/placeschematic <id> <x> <y> <z>` | Places a registered schematic with its lowest corner there |
|
||||||
| `/fly` | Toggles flying: jump goes up, sneak goes down, sprint goes faster |
|
| `/fly` | Toggles flying: jump goes up, sneak goes down, sprint goes faster |
|
||||||
| `/creative` | Toggles placing blocks without using them up and instant breaking |
|
| `/creative` | Toggles placing blocks without using them up and instant breaking |
|
||||||
| `/tps` | Shows how the game loop keeps up |
|
| `/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 |
|
| `/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 |
|
| `/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
|
`/give`'s data is the stack's `data`, and with `fluid` it's the fluid's (see
|
||||||
[Fluids](../resources/fluids.md#containers)):
|
[Fluids](../resources/fluids.md#containers)):
|
||||||
|
|||||||
@@ -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.
|
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
|
## Reading
|
||||||
|
|
||||||
`get` gives a copy of a registered schematic, a file's or one a script registered, with its `id`, or `undefined` for an
|
`get` gives a copy of a registered schematic, a file's or one a script registered, with its `id`, or `undefined` for an
|
||||||
|
|||||||
@@ -1882,6 +1882,29 @@ export class GameServer {
|
|||||||
.then(coordinates(["x1", "y1", "z1", "x2", "y2", "z2"], (context) => this.#export_schematic(context))),
|
.then(coordinates(["x1", "y1", "z1", "x2", "y2", "z2"], (context) => this.#export_schematic(context))),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO: only let operators do this
|
||||||
|
register(
|
||||||
|
literal<ServerCommandSource>("placeschematic")
|
||||||
|
.describe("Places a schematic with its lowest corner at x y z")
|
||||||
|
.then(
|
||||||
|
argument<string, ServerCommandSource>("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<string>("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<number>(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
|
// TODO: only let operators do this
|
||||||
register(
|
register(
|
||||||
literal<ServerCommandSource>("fill")
|
literal<ServerCommandSource>("fill")
|
||||||
|
|||||||
@@ -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");
|
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 () => {
|
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 t = await place_setup();
|
||||||
const hut = t.schematics.get("testmod:hut")!;
|
const hut = t.schematics.get("testmod:hut")!;
|
||||||
|
|||||||
Reference in New Issue
Block a user