add vanilla custom command to mirror canopy's
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { Command } from '../lib/canopy/CanopyExtension';
|
import { Command } from '../lib/canopy/CanopyExtension';
|
||||||
import { extension } from '../config';
|
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 { MenuForm } from '../classes/MenuForm';
|
||||||
import { structureCollection } from '../classes/Structure/StructureCollection'
|
import { structureCollection } from '../classes/Structure/StructureCollection'
|
||||||
|
|
||||||
@@ -10,10 +10,36 @@ const menuCmd = new Command({
|
|||||||
name: 'construct',
|
name: 'construct',
|
||||||
description: { text: 'Gives you the Construct item. Use it to open the Construct menu.' },
|
description: { text: 'Gives you the Construct item. Use it to open the Construct menu.' },
|
||||||
usage: 'construct',
|
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);
|
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) => {
|
world.beforeEvents.itemUse.subscribe((event) => {
|
||||||
if (!event.source || event.itemStack?.typeId !== ACTION_ITEM) return;
|
if (!event.source || event.itemStack?.typeId !== ACTION_ITEM) return;
|
||||||
event.cancel = true;
|
event.cancel = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user