feat(cli): add construct:layer command

This commit is contained in:
ForestOfLight
2026-05-19 21:58:56 -07:00
Unverified
parent 544b5c5d95
commit 8850b3c63b
4 changed files with 56 additions and 0 deletions
+45
View File
@@ -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();
+1
View File
@@ -18,6 +18,7 @@ import './commands/ListCommand';
import './commands/PlaceCommand'; import './commands/PlaceCommand';
import './commands/MoveCommand'; import './commands/MoveCommand';
import './commands/ActiveCommand'; import './commands/ActiveCommand';
import './commands/LayerCommand';
// Other // Other
import './classes/BlockInfo'; import './classes/BlockInfo';
+5
View File
@@ -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=Enable or disable an instance.
construct.commands.active.success=§aSet instance "%1" active=%2. construct.commands.active.success=§aSet instance "%1" active=%2.
construct.commands.error.noLocation=§cInstance "%1" has no saved location. 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).
+5
View File
@@ -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=Enable or disable an instance.
construct.commands.active.success=§aSet instance "%1" active=%2. construct.commands.active.success=§aSet instance "%1" active=%2.
construct.commands.error.noLocation=§cInstance "%1" has no saved location. 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).