diff --git a/src/server/commands/navigation/jumpto.ts b/src/server/commands/navigation/jumpto.ts index 3204905f2..14d2c3b2d 100644 --- a/src/server/commands/navigation/jumpto.ts +++ b/src/server/commands/navigation/jumpto.ts @@ -1,5 +1,5 @@ import { PlayerUtil } from "@modules/player_util.js"; -import { RawText } from "@notbeer-api"; +import { RawText, Vector } from "@notbeer-api"; import { getCommandFunc, registerCommand } from "../register_commands.js"; import config from "config.js"; @@ -11,8 +11,13 @@ const registerInformation = { }; registerCommand(registerInformation, function (session, builder) { - const hit = PlayerUtil.traceForBlock(builder, config.traceDistance - 1); - builder.teleport(hit.offset(0.5, 0, 0.5), { dimension: builder.dimension }); - getCommandFunc("unstuck")(session, builder, new Map()); + const hit = PlayerUtil.traceForBlock(builder); + if (hit) { + builder.teleport(hit.offset(0.5, 0, 0.5), { dimension: builder.dimension }); + getCommandFunc("unstuck")(session, builder, new Map()); + } else { + const teleportTo = Vector.add(builder.location, Vector.mul(builder.getViewDirection(), config.traceDistance)); + builder.runCommand(`tp ${teleportTo.x.toFixed(3)} ${teleportTo.y.toFixed(3)} ${teleportTo.z.toFixed(3)}`); + } return RawText.translate("commands.wedit:jumpto.explain"); });