diff --git a/scripts/classes/InstanceEditForm.js b/scripts/classes/InstanceEditForm.js index d50d972..6adc11d 100644 --- a/scripts/classes/InstanceEditForm.js +++ b/scripts/classes/InstanceEditForm.js @@ -2,6 +2,7 @@ import { structureCollection } from './StructureCollection'; import { MenuForm } from '../classes/MenuForm'; import { ActionFormData } from '@minecraft/server-ui'; import { InstanceEditOptions } from './InstanceEditOptions'; +import { InstanceEditFormBuilder } from './InstanceEditFormBuilder'; export class InstanceEditForm { instanceName; @@ -34,8 +35,8 @@ export class InstanceEditForm { } show() { - const form = this.buildInstanceForm(); - form.show(this.player).then((response) => { + const currentOptions = this.instance.isPlaced() ? this.options.isPlaced : this.options.notPlaced; + InstanceEditFormBuilder.buildInstance(this.instanceName, currentOptions, this.options.common).show(this.player).then((response) => { if (response.canceled) return; let selectedOption; if (this.instance.isPlaced()) @@ -46,20 +47,6 @@ export class InstanceEditForm { }); } - buildInstanceForm() { - const instanceOptions = this.instance.isPlaced() ? this.options.isPlaced : this.options.notPlaced; - const form = new ActionFormData() - .title('§l§2StrucTool §8Menu') - .body(`Instance: §2${this.instanceName}`) - instanceOptions.forEach(option => { - form.button(`${option}`); - }); - this.options.common.forEach(option => { - form.button(`${option}`); - }); - return form; - } - handleOption(option) { switch (option) { case InstanceEditOptions.PlaceInstance: @@ -111,6 +98,10 @@ export class InstanceEditForm { } setLayerForm() { - // should have a toggle for if it should layer the structure or notw + InstanceEditFormBuilder.buildSetLayer(this.instance.getBounds().max.y, this.instance.getLayer()).show(this.player).then((response) => { + if (response.canceled) return; + const selectedLayer = response.formValues[0]; + this.instance.setLayer(parseInt(selectedLayer)); + }); } } \ No newline at end of file diff --git a/scripts/classes/InstanceEditFormBuilder.js b/scripts/classes/InstanceEditFormBuilder.js index 5b39a61..4700e76 100644 --- a/scripts/classes/InstanceEditFormBuilder.js +++ b/scripts/classes/InstanceEditFormBuilder.js @@ -1,7 +1,32 @@ import { ActionFormData, ModalFormData } from '@minecraft/server-ui'; +import { MenuFormBuilder } from './MenuFormBuilder'; export class InstanceEditFormBuilder { + static buildInstance(instanceName, currentOptions, commonOptions) { + const form = new ActionFormData() + .title(MenuFormBuilder.menuTitle) + .body(`Instance: §2${instanceName}`) + currentOptions.forEach(option => { + form.button(`${option}`); + }); + commonOptions.forEach(option => { + form.button(`${option}`); + }); + return form; + } + static buildRenameInstance() { - + return new ModalFormData() + .title(MenuFormBuilder.menuTitle) + .textField('Enter a new name for the instance:', 'example_instance') + .submitButton('Rename'); + } + + static buildSetLayer(maxLayer, currentLayer) { + return new ModalFormData() + .title(MenuFormBuilder.menuTitle) + .label('Use the slider to select the layer. Use 0 for all layers.') + .slider("Layer", 0, maxLayer, 1, currentLayer) + .submitButton('Set Layer'); } } \ No newline at end of file diff --git a/scripts/classes/MenuForm.js b/scripts/classes/MenuForm.js index 0e60e93..89d03a3 100644 --- a/scripts/classes/MenuForm.js +++ b/scripts/classes/MenuForm.js @@ -28,7 +28,7 @@ export class MenuForm { async getInstanceNameFromForm() { try { - return forceShow(this.player, MenuFormBuilder.buildAllInstanceNameForm()).then((response) => { + return forceShow(this.player, MenuFormBuilder.buildAllInstanceName()).then((response) => { if (response.canceled) return; const selectedInstanceName = structureCollection.getInstanceNames()[response.selection]; return selectedInstanceName || this.createNewInstance(); @@ -43,7 +43,7 @@ export class MenuForm { } async createNewInstance() { - return MenuFormBuilder.buildNewInstanceForm().show(this.player).then(async (response) => { + return MenuFormBuilder.buildNewInstance().show(this.player).then(async (response) => { if (response.canceled) return; const instanceName = response.formValues[0]; @@ -58,7 +58,7 @@ export class MenuForm { } async getStructureId() { - return MenuFormBuilder.buildAllStructuresForm().show(this.player).then((response) => { + return MenuFormBuilder.buildAllStructures().show(this.player).then((response) => { if (response.canceled) return; const selectedStructureId = structureCollection.getWorldStructureIds()[response.selection]; @@ -67,7 +67,7 @@ export class MenuForm { } getOtherStructureId() { - return MenuFormBuilder.buildOtherStructureForm().show(this.player).then((response) => { + return MenuFormBuilder.buildOtherStructure().show(this.player).then((response) => { if (response.canceled) return; const structureId = response.formValues[0]; diff --git a/scripts/classes/MenuFormBuilder.js b/scripts/classes/MenuFormBuilder.js index 01422e3..e07cf7e 100644 --- a/scripts/classes/MenuFormBuilder.js +++ b/scripts/classes/MenuFormBuilder.js @@ -4,7 +4,7 @@ import { structureCollection } from './StructureCollection'; export class MenuFormBuilder { static menuTitle = '§l§2StrucTool §8Menu'; - static buildAllInstanceNameForm() { + static buildAllInstanceName() { const allInstanceNameForm = new ActionFormData() .title(this.menuTitle) .body('Select an instance:'); @@ -15,14 +15,14 @@ export class MenuFormBuilder { return allInstanceNameForm; } - static buildNewInstanceForm() { + static buildNewInstance() { return new ModalFormData() .title(this.menuTitle) .textField('Enter a name for the new instance:', 'example_instance') .submitButton('Submit'); } - static buildAllStructuresForm() { + static buildAllStructures() { const allStructuresForm = new ActionFormData() .title(this.menuTitle) .body('Select a structure:'); @@ -34,7 +34,7 @@ export class MenuFormBuilder { return allStructuresForm; } - static buildOtherStructureForm() { + static buildOtherStructure() { return new ModalFormData() .title(this.menuTitle) .textField('Enter the Structure ID:', 'example_structure') diff --git a/scripts/classes/StructureInstance.js b/scripts/classes/StructureInstance.js index 6ee2252..f5e5feb 100644 --- a/scripts/classes/StructureInstance.js +++ b/scripts/classes/StructureInstance.js @@ -115,7 +115,7 @@ export class StructureInstance { } setLayer(layer) { - if (layer < 1 || layer > this.#structure.size.y) + if (layer < 0 || layer > this.#structure.size.y) throw new Error(`[StrucTool] Instance '${this.name}' of '${this.structureId}' does not have layer ${layer}.`); this.#options.currentLayer = layer; this.updateOptions(); @@ -129,7 +129,7 @@ export class StructureInstance { const { min, max } = this.getLayeredBounds(); this.outliner = new Outliner(this.#options.dimensionId, this.toGlobalCoords(min), this.toGlobalCoords(max)); } else { - this.outliner = new Outliner(dimensionId, this.toGlobalCoords(this.getBounds().min), this.toGlobalCoords(this.getBounds().max)); + this.outliner = new Outliner(this.#options.dimensionId, this.toGlobalCoords(this.getBounds().min), this.toGlobalCoords(this.getBounds().max)); } } diff --git a/scripts/commands/menu.js b/scripts/commands/menu.js index fe20ea4..02c06fb 100644 --- a/scripts/commands/menu.js +++ b/scripts/commands/menu.js @@ -1,7 +1,5 @@ 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'; diff --git a/scripts/rules/easyPlace.js b/scripts/rules/easyPlace.js index 28b744f..d05e116 100644 --- a/scripts/rules/easyPlace.js +++ b/scripts/rules/easyPlace.js @@ -9,7 +9,7 @@ const ACTION_SLOT = 35; const easyPlace = new Rule({ identifier: 'easyPlace', - description: { text: 'Simplifies placing blocks in a structure (paper in bottom right inventory slot).' }, + description: { text: "Simplifies placing blocks in a structure (paper named 'easyPlace' in bottom right inventory slot)." }, onEnableCallback: () => { world.beforeEvents.playerPlaceBlock.subscribe(onPlayerPlaceBlock); }, onDisableCallback: () => { world.beforeEvents.playerPlaceBlock.unsubscribe(onPlayerPlaceBlock); } }) @@ -29,7 +29,7 @@ function hasActionItemInCorrectSlot(player) { if (!inventory) return false; const actionSlot = inventory.getSlot(ACTION_SLOT); - return actionSlot.hasItem() && actionSlot.typeId === 'minecraft:paper'; + return actionSlot.hasItem() && actionSlot.typeId === 'minecraft:paper' && actionSlot.nameTag === 'easyPlace'; } function fetchStructureBlock(location) { diff --git a/scripts/rules/fastEasyPlace.js b/scripts/rules/fastEasyPlace.js index f941bda..28a04bb 100644 --- a/scripts/rules/fastEasyPlace.js +++ b/scripts/rules/fastEasyPlace.js @@ -8,7 +8,7 @@ import { Raycaster } from '../classes/Raycaster'; let runner = void 0; const easyPlace = new Rule({ identifier: 'fastEasyPlace', - description: { text: 'Looking at structure blocks with paper in your hand will place them.' }, + description: { text: "Looking at structure blocks with paper named 'easyPlace' in your hand will place them." }, onEnableCallback: () => { runner = system.runInterval(onTick, 2); }, onDisableCallback: () => { system.clearRun(runner); } }) @@ -35,7 +35,7 @@ function isHoldingActionItem(player) { const mainhandItemStack = player.getComponent(EntityComponentTypes.Equippable).getEquipment(EquipmentSlot.Mainhand); if (!mainhandItemStack) return false; - return mainhandItemStack.typeId === 'minecraft:paper'; + return mainhandItemStack.typeId === 'minecraft:paper' && mainhandItemStack.nameTag === 'easyPlace'; } function tryPlaceBlock(player, worldBlock, structureBlock) {