From 8850b3c63bc02dca576c8d888478df6502160453 Mon Sep 17 00:00:00 2001 From: ForestOfLight Date: Tue, 19 May 2026 21:58:56 -0700 Subject: [PATCH] feat(cli): add construct:layer command --- packs/BP/scripts/commands/LayerCommand.js | 45 +++++++++++++++++++++++ packs/BP/scripts/main.js | 1 + packs/RP/texts/en_US.lang | 5 +++ packs/RP/texts/zh_CN.lang | 5 +++ 4 files changed, 56 insertions(+) create mode 100644 packs/BP/scripts/commands/LayerCommand.js diff --git a/packs/BP/scripts/commands/LayerCommand.js b/packs/BP/scripts/commands/LayerCommand.js new file mode 100644 index 0000000..5f0ff01 --- /dev/null +++ b/packs/BP/scripts/commands/LayerCommand.js @@ -0,0 +1,45 @@ +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'; + +export class LayerCommand extends Command { + constructor() { + super({ + name: 'layer', + description: 'construct.commands.layer', + mandatoryParameters: [ + { name: 'instanceName', type: CustomCommandParamType.String }, + { name: 'layer', type: CustomCommandParamType.Integer } + ], + callback: (source, instanceName, layer) => this.run(source, instanceName, layer) + }); + } + + run(source, instanceName, layer) { + try { + const instance = findInstance(source, instanceName); + if (!instance) return { status: CustomCommandStatus.Failure }; + const max = instance.getMaxLayer(); + if (layer < 0 || layer > max) { + system.run(() => source.sendMessage({ + rawtext: [{ translate: 'construct.commands.layer.outOfBounds', + with: [String(layer), instanceName, String(max)] }] + })); + return { status: CustomCommandStatus.Failure }; + } + system.run(() => { + instance.setLayer(layer); + source.sendMessage({ + rawtext: [{ translate: 'construct.commands.layer.success', + with: [instanceName, String(layer)] }] + }); + }); + return { status: CustomCommandStatus.Success }; + } catch (err) { + return commandError(source, err); + } + } +} + +export const layerCommand = new LayerCommand(); diff --git a/packs/BP/scripts/main.js b/packs/BP/scripts/main.js index 1b1ee76..3066101 100644 --- a/packs/BP/scripts/main.js +++ b/packs/BP/scripts/main.js @@ -18,6 +18,7 @@ import './commands/ListCommand'; import './commands/PlaceCommand'; import './commands/MoveCommand'; import './commands/ActiveCommand'; +import './commands/LayerCommand'; // Other import './classes/BlockInfo'; diff --git a/packs/RP/texts/en_US.lang b/packs/RP/texts/en_US.lang index baa4427..7804ce2 100644 --- a/packs/RP/texts/en_US.lang +++ b/packs/RP/texts/en_US.lang @@ -145,3 +145,8 @@ construct.commands.move.posRequired=§cMust provide coordinates when not running construct.commands.active=Enable or disable an instance. construct.commands.active.success=§aSet instance "%1" active=%2. construct.commands.error.noLocation=§cInstance "%1" has no saved location. + +## construct:layer +construct.commands.layer=Set the active layer of an instance (0 = whole structure). +construct.commands.layer.success=§aSet instance "%1" layer to %2. +construct.commands.layer.outOfBounds=§cLayer %1 is out of bounds for instance "%2" (max %3). diff --git a/packs/RP/texts/zh_CN.lang b/packs/RP/texts/zh_CN.lang index 1513d74..19dd07e 100644 --- a/packs/RP/texts/zh_CN.lang +++ b/packs/RP/texts/zh_CN.lang @@ -145,3 +145,8 @@ construct.commands.move.posRequired=§cMust provide coordinates when not running construct.commands.active=Enable or disable an instance. construct.commands.active.success=§aSet instance "%1" active=%2. construct.commands.error.noLocation=§cInstance "%1" has no saved location. + +## construct:layer +construct.commands.layer=Set the active layer of an instance (0 = whole structure). +construct.commands.layer.success=§aSet instance "%1" layer to %2. +construct.commands.layer.outOfBounds=§cLayer %1 is out of bounds for instance "%2" (max %3).