form start
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { Command } from '../lib/canopy/CanopyExtension';
|
||||
import { extension } from '../config';
|
||||
import { structureCollection } from '../classes/StructureCollection';
|
||||
import { MaterialCounter } from '../classes/MaterialCounter';
|
||||
import { world, system } from '@minecraft/server';
|
||||
import { MenuForm } from '../classes/MenuForm';
|
||||
|
||||
const ACTION_ITEM = 'minecraft:paper';
|
||||
|
||||
const structCmd = new Command({
|
||||
name: 'menu',
|
||||
description: { text: 'Manages current StrucTool structures.' },
|
||||
usage: 'menu',
|
||||
callback: structCommand
|
||||
});
|
||||
extension.addCommand(structCmd);
|
||||
|
||||
world.beforeEvents.itemUse.subscribe((event) => {
|
||||
if (!event.source || event.itemStack?.typeId !== ACTION_ITEM) return;
|
||||
event.cancel = true;
|
||||
system.run(() => structCommand(event.source));
|
||||
});
|
||||
|
||||
function structCommand(sender) {
|
||||
new MenuForm(sender);
|
||||
}
|
||||
@@ -17,7 +17,7 @@ const structCmd = new Command({
|
||||
extension.addCommand(structCmd);
|
||||
|
||||
function structCommand(sender, args) {
|
||||
const { option, name, arg3 } = args;
|
||||
const { name, option, arg3 } = args;
|
||||
switch (option) {
|
||||
case 'add':
|
||||
addStructure(sender, name);
|
||||
@@ -41,7 +41,7 @@ function structCommand(sender, args) {
|
||||
|
||||
function addStructure(sender, name) {
|
||||
try {
|
||||
structureCollection.add(name);
|
||||
structureCollection.add(name, name);
|
||||
} catch (e) {
|
||||
if (e.message.includes('already exists')) {
|
||||
sender.sendMessage({ text: `§cStructure '${name}' already exists.` });
|
||||
@@ -70,7 +70,7 @@ function placeStructure(sender, name) {
|
||||
structure = structureCollection.get(name);
|
||||
} catch (e) {
|
||||
try {
|
||||
structure = structureCollection.add(name);
|
||||
structure = structureCollection.add(name, name);
|
||||
} catch (e) {
|
||||
if (e.message.includes('already exists')) {
|
||||
sender.sendMessage({ text: `§cStructure '${name}' already exists.` });
|
||||
@@ -108,8 +108,8 @@ function printInfo(sender, name) {
|
||||
sender.sendMessage({ text: `§cStructure '${name}' not found.` });
|
||||
return;
|
||||
}
|
||||
const location = structure.getLocation();
|
||||
sender.sendMessage({ text: `§7Structure '${name}' at [${location.x} ${location.y} ${location.z}]` });
|
||||
const { dimensionId, location } = structure.getLocation();
|
||||
sender.sendMessage({ text: `§7Structure '${name}' at [${location.x} ${location.y} ${location.z}] in '${dimensionId}'` });
|
||||
sender.sendMessage({ text: `§7Current Layer: ${structure.getLayer()}` });
|
||||
sender.sendMessage({ text: `§7Materials: ${MaterialCounter.getPrintable(name)}` });
|
||||
}
|
||||
Reference in New Issue
Block a user