From abaf275c5d8a53bbcb0863215687b51ddafdc214 Mon Sep 17 00:00:00 2001 From: ForestOfLight Date: Wed, 20 May 2026 03:15:14 -0700 Subject: [PATCH] feat(cli): add construct:tag command --- packs/BP/scripts/commands/TagCommand.js | 47 +++++++++++++++++++++++++ packs/BP/scripts/main.js | 1 + packs/RP/texts/en_US.lang | 5 +++ packs/RP/texts/zh_CN.lang | 5 +++ 4 files changed, 58 insertions(+) create mode 100644 packs/BP/scripts/commands/TagCommand.js diff --git a/packs/BP/scripts/commands/TagCommand.js b/packs/BP/scripts/commands/TagCommand.js new file mode 100644 index 0000000..18b076a --- /dev/null +++ b/packs/BP/scripts/commands/TagCommand.js @@ -0,0 +1,47 @@ +import { CustomCommandParamType, CustomCommandStatus, EntityComponentTypes, EquipmentSlot, system } from '@minecraft/server'; +import { Command } from '../classes/Commands/Command'; +import { PlayerCommandOrigin } from '../classes/Commands/PlayerCommandOrigin'; +import { findInstance } from '../classes/Commands/lib/findInstance'; +import { requirePlayer } from '../classes/Commands/lib/requirePlayer'; +import { commandError } from '../classes/Commands/lib/commandError'; +import { MENU_ITEM } from '../consts'; + +export class TagCommand extends Command { + constructor() { + super({ + name: 'tag', + description: 'construct.commands.tag', + allowedSources: [PlayerCommandOrigin], + mandatoryParameters: [ + { name: 'instanceName', type: CustomCommandParamType.String } + ], + callback: (source, instanceName) => this.run(source, instanceName) + }); + } + + run(source, instanceName) { + try { + const player = requirePlayer(source); + const instance = findInstance(source, instanceName); + if (!instance) return { status: CustomCommandStatus.Failure }; + const equipment = player.getComponent(EntityComponentTypes.Equippable); + const itemStack = equipment?.getEquipment(EquipmentSlot.Mainhand); + if (itemStack?.typeId !== MENU_ITEM) { + system.run(() => source.sendMessage({ translate: 'construct.commands.tag.notHoldingItem' })); + return { status: CustomCommandStatus.Failure }; + } + system.run(() => { + itemStack.nameTag = instanceName; + equipment.setEquipment(EquipmentSlot.Mainhand, itemStack); + source.sendMessage({ + rawtext: [{ translate: 'construct.commands.tag.success', with: [instanceName] }] + }); + }); + return { status: CustomCommandStatus.Success }; + } catch (err) { + return commandError(source, err); + } + } +} + +export const tagCommand = new TagCommand(); diff --git a/packs/BP/scripts/main.js b/packs/BP/scripts/main.js index b8a94bb..b17ac0b 100644 --- a/packs/BP/scripts/main.js +++ b/packs/BP/scripts/main.js @@ -26,6 +26,7 @@ import './commands/OptionCommand'; import './commands/InfoCommand'; import './commands/StatsCommand'; import './commands/MaterialsCommand'; +import './commands/TagCommand'; // Other import './classes/BlockInfo'; diff --git a/packs/RP/texts/en_US.lang b/packs/RP/texts/en_US.lang index 389655a..ba04508 100644 --- a/packs/RP/texts/en_US.lang +++ b/packs/RP/texts/en_US.lang @@ -188,3 +188,8 @@ construct.commands.materials=Print the material list for an instance. construct.commands.materials.headerAll=§eMaterials for "%1":§r construct.commands.materials.headerMissing=§eMissing materials for "%1":§r construct.commands.materials.empty=§7(no materials) + +## construct:tag +construct.commands.tag=Rename the held Construct item to an instance name for quick-open. +construct.commands.tag.success=§aTagged held Construct item with instance "%1". +construct.commands.tag.notHoldingItem=§cYou must be holding a Construct item. diff --git a/packs/RP/texts/zh_CN.lang b/packs/RP/texts/zh_CN.lang index 1c009c7..0447bef 100644 --- a/packs/RP/texts/zh_CN.lang +++ b/packs/RP/texts/zh_CN.lang @@ -188,3 +188,8 @@ construct.commands.materials=Print the material list for an instance. construct.commands.materials.headerAll=§eMaterials for "%1":§r construct.commands.materials.headerMissing=§eMissing materials for "%1":§r construct.commands.materials.empty=§7(no materials) + +## construct:tag +construct.commands.tag=Rename the held Construct item to an instance name for quick-open. +construct.commands.tag.success=§aTagged held Construct item with instance "%1". +construct.commands.tag.notHoldingItem=§cYou must be holding a Construct item.