diff --git a/packs/BP/scripts/commands/PlaceCommand.js b/packs/BP/scripts/commands/PlaceCommand.js new file mode 100644 index 0000000..a64a61f --- /dev/null +++ b/packs/BP/scripts/commands/PlaceCommand.js @@ -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(); diff --git a/packs/BP/scripts/main.js b/packs/BP/scripts/main.js index 6b9ff4b..7e744ca 100644 --- a/packs/BP/scripts/main.js +++ b/packs/BP/scripts/main.js @@ -15,6 +15,7 @@ import './commands/NewCommand'; import './commands/DeleteCommand'; import './commands/RenameCommand'; import './commands/ListCommand'; +import './commands/PlaceCommand'; // Other import './classes/BlockInfo'; diff --git a/packs/RP/texts/en_US.lang b/packs/RP/texts/en_US.lang index 7d36c7b..88b27fc 100644 --- a/packs/RP/texts/en_US.lang +++ b/packs/RP/texts/en_US.lang @@ -131,3 +131,7 @@ construct.commands.list=List all registered instances. construct.commands.list.empty=§7No instances registered. construct.commands.list.header=§eRegistered instances (%1):§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. diff --git a/packs/RP/texts/zh_CN.lang b/packs/RP/texts/zh_CN.lang index 9299cfc..c135825 100644 --- a/packs/RP/texts/zh_CN.lang +++ b/packs/RP/texts/zh_CN.lang @@ -131,3 +131,7 @@ construct.commands.list=List all registered instances. construct.commands.list.empty=§7No instances registered. construct.commands.list.header=§eRegistered instances (%1):§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.