feat(cli): add construct:place command

This commit is contained in:
ForestOfLight
2026-05-19 21:41:35 -07:00
Unverified
parent 4caa9c7473
commit 4fe45b5a7b
4 changed files with 59 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
import { CustomCommandParamType, CustomCommandStatus, system, world } 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 PlaceCommand extends Command {
constructor() {
super({
name: 'place',
description: 'construct.commands.place',
mandatoryParameters: [
{ name: 'instanceName', type: CustomCommandParamType.String },
{ 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 };
const dimensionId = this.resolveDimensionId(source);
system.run(() => {
instance.place(dimensionId, pos);
source.sendMessage({
rawtext: [{ translate: 'construct.commands.place.success',
with: [instanceName, String(pos.x), String(pos.y), String(pos.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 placeCommand = new PlaceCommand();
+1
View File
@@ -15,6 +15,7 @@ import './commands/NewCommand';
import './commands/DeleteCommand'; import './commands/DeleteCommand';
import './commands/RenameCommand'; import './commands/RenameCommand';
import './commands/ListCommand'; import './commands/ListCommand';
import './commands/PlaceCommand';
// Other // Other
import './classes/BlockInfo'; import './classes/BlockInfo';
+4
View File
@@ -131,3 +131,7 @@ construct.commands.list=List all registered instances.
construct.commands.list.empty=§7No instances registered. construct.commands.list.empty=§7No instances registered.
construct.commands.list.header=§eRegistered instances (%1):§r construct.commands.list.header=§eRegistered instances (%1):§r
construct.commands.list.row=§a%1§r §8[§r%2§8]§r §7%3§r 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.
+4
View File
@@ -131,3 +131,7 @@ construct.commands.list=List all registered instances.
construct.commands.list.empty=§7No instances registered. construct.commands.list.empty=§7No instances registered.
construct.commands.list.header=§eRegistered instances (%1):§r construct.commands.list.header=§eRegistered instances (%1):§r
construct.commands.list.row=§a%1§r §8[§r%2§8]§r §7%3§r 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.