From 38a1c3ccbc4f0e38c98a77b1d92b76727fa90482 Mon Sep 17 00:00:00 2001 From: ForestOfLight Date: Tue, 19 May 2026 21:47:39 -0700 Subject: [PATCH] feat(cli): add construct:move command --- packs/BP/scripts/commands/MoveCommand.js | 62 ++++++++++++++++++++++++ packs/BP/scripts/main.js | 1 + packs/RP/texts/en_US.lang | 5 ++ packs/RP/texts/zh_CN.lang | 5 ++ 4 files changed, 73 insertions(+) create mode 100644 packs/BP/scripts/commands/MoveCommand.js diff --git a/packs/BP/scripts/commands/MoveCommand.js b/packs/BP/scripts/commands/MoveCommand.js new file mode 100644 index 0000000..455dcc9 --- /dev/null +++ b/packs/BP/scripts/commands/MoveCommand.js @@ -0,0 +1,62 @@ +import { CustomCommandParamType, CustomCommandStatus, system } from '@minecraft/server'; +import { Command } from '../classes/Commands/Command'; +import { findInstance } from '../classes/Commands/lib/findInstance'; +import { commandError } from '../classes/Commands/lib/commandError'; +import { PlayerCommandOrigin } from '../classes/Commands/PlayerCommandOrigin'; +import { BlockCommandOrigin } from '../classes/Commands/BlockCommandOrigin'; +import { EntityCommandOrigin } from '../classes/Commands/EntityCommandOrigin'; + +export class MoveCommand extends Command { + constructor() { + super({ + name: 'move', + description: 'construct.commands.move', + mandatoryParameters: [ + { name: 'instanceName', type: CustomCommandParamType.String } + ], + optionalParameters: [ + { name: 'pos', type: CustomCommandParamType.Location } + ], + callback: (source, instanceName, pos) => this.run(source, instanceName, pos) + }); + } + + run(source, instanceName, pos) { + try { + const instance = findInstance(source, instanceName); + if (!instance) return { status: CustomCommandStatus.Failure }; + let dimensionId; + let location = pos; + if (location === undefined) { + if (!(source instanceof PlayerCommandOrigin)) + return { status: CustomCommandStatus.Failure, message: 'construct.commands.move.posRequired' }; + const player = source.getSource(); + location = player.location; + dimensionId = player.dimension.id; + } else { + dimensionId = this.resolveDimensionId(source); + } + system.run(() => { + instance.move(dimensionId, location); + source.sendMessage({ + rawtext: [{ translate: 'construct.commands.move.success', + with: [instanceName, String(Math.floor(location.x)), String(Math.floor(location.y)), + String(Math.floor(location.z)), dimensionId.replace('minecraft:', '')] }] + }); + }); + return { status: CustomCommandStatus.Success }; + } catch (err) { + return commandError(source, err); + } + } + + resolveDimensionId(source) { + if (source instanceof PlayerCommandOrigin || source instanceof EntityCommandOrigin) + return source.getSource().dimension.id; + if (source instanceof BlockCommandOrigin) + return source.getSource().dimension.id; + return 'minecraft:overworld'; + } +} + +export const moveCommand = new MoveCommand(); diff --git a/packs/BP/scripts/main.js b/packs/BP/scripts/main.js index 7e744ca..59c4141 100644 --- a/packs/BP/scripts/main.js +++ b/packs/BP/scripts/main.js @@ -16,6 +16,7 @@ import './commands/DeleteCommand'; import './commands/RenameCommand'; import './commands/ListCommand'; import './commands/PlaceCommand'; +import './commands/MoveCommand'; // Other import './classes/BlockInfo'; diff --git a/packs/RP/texts/en_US.lang b/packs/RP/texts/en_US.lang index 88b27fc..a9b344c 100644 --- a/packs/RP/texts/en_US.lang +++ b/packs/RP/texts/en_US.lang @@ -135,3 +135,8 @@ construct.commands.list.row=§a%1§r §8[§r%2§8]§r §7%3§r ## construct:place construct.commands.place=Place an instance at world coordinates (enables it). construct.commands.place.success=§aPlaced instance "%1" at %2 %3 %4 in %5. + +## construct:move +construct.commands.move=Reposition an instance without toggling its enabled state. +construct.commands.move.success=§aMoved instance "%1" to %2 %3 %4 in %5. +construct.commands.move.posRequired=§cMust provide coordinates when not running as a player. diff --git a/packs/RP/texts/zh_CN.lang b/packs/RP/texts/zh_CN.lang index c135825..a49666d 100644 --- a/packs/RP/texts/zh_CN.lang +++ b/packs/RP/texts/zh_CN.lang @@ -135,3 +135,8 @@ construct.commands.list.row=§a%1§r §8[§r%2§8]§r §7%3§r ## construct:place construct.commands.place=Place an instance at world coordinates (enables it). construct.commands.place.success=§aPlaced instance "%1" at %2 %3 %4 in %5. + +## construct:move +construct.commands.move=Reposition an instance without toggling its enabled state. +construct.commands.move.success=§aMoved instance "%1" to %2 %3 %4 in %5. +construct.commands.move.posRequired=§cMust provide coordinates when not running as a player.