Tp command

This commit is contained in:
2026-10-02 13:51:07 -03:00
parent 7b3cdd925e
commit d2dde8c14f
3 changed files with 23 additions and 0 deletions
+1
View File
@@ -113,6 +113,7 @@ Commands can only be registered during `setup`.
| `/time` | Shows the time |
| `/time set <day\|noon\|sunset\|night\|midnight\|ticks>` | Jumps to the next time of day. Time never goes back |
| `/time add <ticks>` | Moves time forward |
| `/tp <x> <y> <z>` | 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 |
+16
View File
@@ -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<ServerCommandSource>("tp").describe("Teleports you to x y z").then(
argument<number, ServerCommandSource>("x", number()).then(
argument<number, ServerCommandSource>("y", number()).then(
argument<number, ServerCommandSource>("z", number()).executes((context) => {
const [x, y, z] = ["x", "y", "z"].map((axis) => context.get<number>(axis));
this.teleport(context.source.server_player, x, y, z);
context.source.send_message(`Teleported to ${x} ${y} ${z}`);
}),
),
),
),
);
register(
literal<ServerCommandSource>("tps").describe("Shows how the game loop keeps up").executes((context) => {
if (!this.loop) {
+6
View File
@@ -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]);
});