From 42bd7e9023a9836f73379315c0ee5b0595dce17a Mon Sep 17 00:00:00 2001 From: ForestOfLight Date: Sat, 7 Jun 2025 21:34:55 -0700 Subject: [PATCH 1/2] add vanilla custom command to mirror canopy's --- Construct[BP]/scripts/commands/construct.js | 30 +++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Construct[BP]/scripts/commands/construct.js b/Construct[BP]/scripts/commands/construct.js index 0755464..7338a3d 100644 --- a/Construct[BP]/scripts/commands/construct.js +++ b/Construct[BP]/scripts/commands/construct.js @@ -1,6 +1,6 @@ import { Command } from '../lib/canopy/CanopyExtension'; import { extension } from '../config'; -import { world, system, EntityComponentTypes, ItemStack } from '@minecraft/server'; +import { world, system, EntityComponentTypes, ItemStack, CommandPermissionLevel, CustomCommandStatus, Player } from '@minecraft/server'; import { MenuForm } from '../classes/MenuForm'; import { structureCollection } from '../classes/Structure/StructureCollection' @@ -10,10 +10,36 @@ const menuCmd = new Command({ name: 'construct', description: { text: 'Gives you the Construct item. Use it to open the Construct menu.' }, usage: 'construct', - callback: (sender) => sender.getComponent(EntityComponentTypes.Inventory)?.container?.addItem(new ItemStack(ACTION_ITEM)) + callback: (sender) => { + const origin = { sourceEntity: sender }; + givePlayerConstructItem(origin); + } }); extension.addCommand(menuCmd); +system.beforeEvents.startup.subscribe((event) => { + const command = { + name: 'construct:item', + description: 'Gives you the Construct item. Use it to open the Construct menu.', + permissionLevel: CommandPermissionLevel.Any + }; + event.customCommandRegistry.registerCommand(command, givePlayerConstructItem) +}); + +function givePlayerConstructItem(origin) { + const player = origin.sourceEntity; + if (player instanceof Player === false) + return { status: CustomCommandStatus.Failure, message: 'This command can only be used by players.' }; + system.run(() => { + const givenItemStack = player.getComponent(EntityComponentTypes.Inventory)?.container?.addItem(new ItemStack(ACTION_ITEM)); + if (givenItemStack) + player.sendMessage('§cFailed to give you the Construct item.'); + else + player.sendMessage('§aYou recieved the Construct item! Use it to open the Construct menu.'); + }); + return { status: CustomCommandStatus.Success }; +} + world.beforeEvents.itemUse.subscribe((event) => { if (!event.source || event.itemStack?.typeId !== ACTION_ITEM) return; event.cancel = true; From 1528ebdbbb7fd9b29350c1931b036312880d4261 Mon Sep 17 00:00:00 2001 From: ForestOfLight Date: Sat, 7 Jun 2025 21:53:38 -0700 Subject: [PATCH 2/2] revert canopy command to open menu --- Construct[BP]/scripts/commands/construct.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Construct[BP]/scripts/commands/construct.js b/Construct[BP]/scripts/commands/construct.js index 7338a3d..8f0b75f 100644 --- a/Construct[BP]/scripts/commands/construct.js +++ b/Construct[BP]/scripts/commands/construct.js @@ -10,10 +10,7 @@ const menuCmd = new Command({ name: 'construct', description: { text: 'Gives you the Construct item. Use it to open the Construct menu.' }, usage: 'construct', - callback: (sender) => { - const origin = { sourceEntity: sender }; - givePlayerConstructItem(origin); - } + callback: (sender) => openMenu(sender) }); extension.addCommand(menuCmd);