form start

This commit is contained in:
ForestOfLight
2025-04-12 19:53:42 -07:00
Unverified
parent 0c90e13e2c
commit e43fb49d48
13 changed files with 372 additions and 48 deletions
+26
View File
@@ -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);
}
+5 -5
View File
@@ -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)}` });
}