diff --git a/docs/modding/misc/commands.md b/docs/modding/misc/commands.md index 8eb8077..f17aa5c 100644 --- a/docs/modding/misc/commands.md +++ b/docs/modding/misc/commands.md @@ -113,6 +113,7 @@ Commands can only be registered during `setup`. | `/time` | Shows the time | | `/time set ` | Jumps to the next time of day. Time never goes back | | `/time add ` | Moves time forward | +| `/tp ` | Teleports you there | | `/tps` | Shows how the game loop keeps up | | `/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 | diff --git a/server/game/game_server.ts b/server/game/game_server.ts index 54a6295..1480e56 100644 --- a/server/game/game_server.ts +++ b/server/game/game_server.ts @@ -42,6 +42,7 @@ import { integer, item, literal, + number, word, } from "$/common/commands.ts"; import type { GameLoop } from "./game_loop.ts"; @@ -1218,6 +1219,21 @@ export class GameServer { ), ); + // TODO: only let operators do this + register( + literal("tp").describe("Teleports you to x y z").then( + argument("x", number()).then( + argument("y", number()).then( + argument("z", number()).executes((context) => { + const [x, y, z] = ["x", "y", "z"].map((axis) => context.get(axis)); + this.teleport(context.source.server_player, x, y, z); + context.source.send_message(`Teleported to ${x} ${y} ${z}`); + }), + ), + ), + ), + ); + register( literal("tps").describe("Shows how the game loop keeps up").executes((context) => { if (!this.loop) { diff --git a/tests/vitals_test.ts b/tests/vitals_test.ts index 553e958..5f9cf16 100644 --- a/tests/vitals_test.ts +++ b/tests/vitals_test.ts @@ -217,3 +217,9 @@ Deno.test("/effect gives you an effect, for 30 seconds or as many as you say", a t.send(1, { type: "chat", text: "/effect bworld:regeneration 5" }); assertEquals(t.player.get_effect("bworld:regeneration")?.duration, 100); }); + +Deno.test("/tp x y z teleports you there", async () => { + const t = await setup(); + t.send(1, { type: "chat", text: "/tp 10 120.5 -3" }); + assertEquals([t.player.x, t.player.y, t.player.z], [10, 120.5, -3]); +});