diff --git a/StrucTool [BP]/manifest.json b/Construct [BP]/manifest.json similarity index 100% rename from StrucTool [BP]/manifest.json rename to Construct [BP]/manifest.json diff --git a/StrucTool [BP]/pack_icon.png b/Construct [BP]/pack_icon.png similarity index 100% rename from StrucTool [BP]/pack_icon.png rename to Construct [BP]/pack_icon.png diff --git a/StrucTool [BP]/scripts/classes/BlockInfo.js b/Construct [BP]/scripts/classes/BlockInfo.js similarity index 100% rename from StrucTool [BP]/scripts/classes/BlockInfo.js rename to Construct [BP]/scripts/classes/BlockInfo.js diff --git a/StrucTool [BP]/scripts/classes/BlockVerificationLevelRender.js b/Construct [BP]/scripts/classes/BlockVerificationLevelRender.js similarity index 100% rename from StrucTool [BP]/scripts/classes/BlockVerificationLevelRender.js rename to Construct [BP]/scripts/classes/BlockVerificationLevelRender.js diff --git a/StrucTool [BP]/scripts/classes/BlockVerifier.js b/Construct [BP]/scripts/classes/BlockVerifier.js similarity index 100% rename from StrucTool [BP]/scripts/classes/BlockVerifier.js rename to Construct [BP]/scripts/classes/BlockVerifier.js diff --git a/StrucTool [BP]/scripts/classes/InstanceEditForm.js b/Construct [BP]/scripts/classes/InstanceEditForm.js similarity index 99% rename from StrucTool [BP]/scripts/classes/InstanceEditForm.js rename to Construct [BP]/scripts/classes/InstanceEditForm.js index 9dfaa52..208ef1c 100644 --- a/StrucTool [BP]/scripts/classes/InstanceEditForm.js +++ b/Construct [BP]/scripts/classes/InstanceEditForm.js @@ -1,5 +1,5 @@ import { structureCollection } from './StructureCollection'; -import { MenuForm } from '../classes/MenuForm'; +import { MenuForm } from './MenuForm'; import { forceShow } from '../utils'; import { InstanceEditButtons } from './enums/InstanceEditButtons'; import { InstanceEditFormBuilder } from './InstanceEditFormBuilder'; diff --git a/StrucTool [BP]/scripts/classes/InstanceEditFormBuilder.js b/Construct [BP]/scripts/classes/InstanceEditFormBuilder.js similarity index 100% rename from StrucTool [BP]/scripts/classes/InstanceEditFormBuilder.js rename to Construct [BP]/scripts/classes/InstanceEditFormBuilder.js diff --git a/StrucTool [BP]/scripts/classes/InstanceOptions.js b/Construct [BP]/scripts/classes/InstanceOptions.js similarity index 100% rename from StrucTool [BP]/scripts/classes/InstanceOptions.js rename to Construct [BP]/scripts/classes/InstanceOptions.js diff --git a/StrucTool [BP]/scripts/classes/MaterialCounter.js b/Construct [BP]/scripts/classes/MaterialCounter.js similarity index 54% rename from StrucTool [BP]/scripts/classes/MaterialCounter.js rename to Construct [BP]/scripts/classes/MaterialCounter.js index a880a13..1cb2aec 100644 --- a/StrucTool [BP]/scripts/classes/MaterialCounter.js +++ b/Construct [BP]/scripts/classes/MaterialCounter.js @@ -1,38 +1,43 @@ -import { structureCollection } from '../classes/StructureCollection'; - class MaterialCounter { - static getAll(name) { - const structure = structureCollection.get(name); - const materials = {}; - for (const block of structure.getAllBlocks()) { - const typeId = block?.getItemStack()?.typeId.replace('minecraft:', ''); - if (!typeId) continue; - if (!materials[typeId]) { - materials[typeId] = 0; - } - materials[typeId]++; - } - return materials; + instance + materials; + + constructor(instance) { + this.instance = instance; + this.materials = {}; } - static getLayer(name, layer) { - const structure = structureCollection.get(name); - const materials = {}; - for (const block of structure.getLayerBlocks(layer)) { - const typeId = block?.getItemStack()?.typeId.replace('minecraft:', ''); - if (!typeId) continue; - if (!materials[typeId]) { - materials[typeId] = 0; - } - materials[typeId]++; - } - return materials; + populateAll() { + for (const layer = 0; layer < this.instance.getMaxLayer(); layer++) + this.getLayer(layer) } - static getPrintable(name) { - const structure = structureCollection.get(name); + populateLayer(layer) { + for (const block of this.instance.getLayerBlocks(layer)) + this.countBlock(block) + } + + populateActive() { + for (const block of this.instance.getActiveBlocks()) + this.countBlock(block) + } + + countBlock(block) { + const itemStack = block?.getItemStack(); + const typeId = itemStack?.typeId; + if (!typeId) return; + if (!this.materials[typeId]) + this.materials[typeId] = { count: 0, stackSize: itemStack.maxAmount }; + this.materials[typeId].count++; + } + + clear() { + this.materials = {}; // does this leak memory?? + } + + toString() { const materials = {}; - for (const block of structure.getAllBlocks()) { + for (const block of this.instance.getAllBlocks()) { const itemStack = block?.getItemStack(); const typeId = itemStack?.typeId.replace('minecraft:', ''); if (!typeId) continue; diff --git a/StrucTool [BP]/scripts/classes/MenuForm.js b/Construct [BP]/scripts/classes/MenuForm.js similarity index 86% rename from StrucTool [BP]/scripts/classes/MenuForm.js rename to Construct [BP]/scripts/classes/MenuForm.js index 22c6681..03b8c50 100644 --- a/StrucTool [BP]/scripts/classes/MenuForm.js +++ b/Construct [BP]/scripts/classes/MenuForm.js @@ -4,16 +4,16 @@ import { MenuFormBuilder } from './MenuFormBuilder'; import { InstanceEditForm } from './InstanceEditForm'; export class MenuForm { - constructor(player, { jumpToInstance = true } = {}) { + constructor(player, { jumpToInstance = false, instanceName = void 0 } = {}) { this.player = player; - this.show(jumpToInstance); + this.show(jumpToInstance, instanceName); } - async show(jumpToInstance = true) { - let instanceName; + async show(jumpToInstance = false, instanceName = void 0) { if (jumpToInstance) { - instanceName = structureCollection.getStructure(this.player.dimension.id, this.player.location, { useActiveLayer: false })?.getName(); - if (instanceName) { + if (!instanceName) + instanceName = structureCollection.getStructure(this.player.dimension.id, this.player.location, { useActiveLayer: false })?.getName(); + if (structureCollection.get(instanceName)) { new InstanceEditForm(this.player, instanceName); return; } diff --git a/StrucTool [BP]/scripts/classes/MenuFormBuilder.js b/Construct [BP]/scripts/classes/MenuFormBuilder.js similarity index 100% rename from StrucTool [BP]/scripts/classes/MenuFormBuilder.js rename to Construct [BP]/scripts/classes/MenuFormBuilder.js diff --git a/StrucTool [BP]/scripts/classes/Outliner.js b/Construct [BP]/scripts/classes/Outliner.js similarity index 100% rename from StrucTool [BP]/scripts/classes/Outliner.js rename to Construct [BP]/scripts/classes/Outliner.js diff --git a/StrucTool [BP]/scripts/classes/Raycaster.js b/Construct [BP]/scripts/classes/Raycaster.js similarity index 100% rename from StrucTool [BP]/scripts/classes/Raycaster.js rename to Construct [BP]/scripts/classes/Raycaster.js diff --git a/StrucTool [BP]/scripts/classes/Structure.js b/Construct [BP]/scripts/classes/Structure.js similarity index 100% rename from StrucTool [BP]/scripts/classes/Structure.js rename to Construct [BP]/scripts/classes/Structure.js diff --git a/StrucTool [BP]/scripts/classes/StructureCollection.js b/Construct [BP]/scripts/classes/StructureCollection.js similarity index 100% rename from StrucTool [BP]/scripts/classes/StructureCollection.js rename to Construct [BP]/scripts/classes/StructureCollection.js diff --git a/StrucTool [BP]/scripts/classes/StructureInstance.js b/Construct [BP]/scripts/classes/StructureInstance.js similarity index 92% rename from StrucTool [BP]/scripts/classes/StructureInstance.js rename to Construct [BP]/scripts/classes/StructureInstance.js index 8cd540b..8104ff6 100644 --- a/StrucTool [BP]/scripts/classes/StructureInstance.js +++ b/Construct [BP]/scripts/classes/StructureInstance.js @@ -52,15 +52,15 @@ export class StructureInstance { getDimension() { return this.options.getDimension(); } + + getLayer() { + return this.options.currentLayer; + } getMaxLayer() { return this.structure.getHeight(); } - getLayer() { - return this.options.currentLayer; - } - getBounds() { return { min: this.structure.getMin(), @@ -72,18 +72,18 @@ export class StructureInstance { if (!this.options.isEnabled) throw new Error(`[StrucTool] Instance '${this.options.instanceName}' is not placed.`); if (this.hasLayerSelected()) - return this.getLayeredBounds(); + return this.getLayerBounds(this.getLayer()); return this.getBounds(); } - getLayeredBounds() { + getLayerBounds(layer) { if (!this.options.isEnabled) throw new Error(`[StrucTool] Instance '${this.options.instanceName}' is not placed.`); const min = this.structure.getMin(); const max = this.structure.getMax(); return { - min: new Vector(min.x, this.options.currentLayer - 1, min.z), - max: new Vector(max.x, this.options.currentLayer, max.z) + min: new Vector(min.x, layer - 1, min.z), + max: new Vector(max.x, layer, max.z) }; } @@ -103,6 +103,14 @@ export class StructureInstance { return this.structure.getAllBlocks(); } + getActiveBlocks() { + if (!this.options.isEnabled) + throw new Error(`[StrucTool] Instance '${this.options.instanceName}' is not placed.`); + if (this.hasLayerSelected()) + return this.getLayerBlocks(this.getLayer()); + return this.getAllBlocks(); + } + isLocationActive(dimensionId, structureLocation, { useActiveLayer = true } = {}) { if (!this.options.isEnabled || this.options.dimensionId !== dimensionId) return false; diff --git a/StrucTool [BP]/scripts/classes/StructureOutliner.js b/Construct [BP]/scripts/classes/StructureOutliner.js similarity index 97% rename from StrucTool [BP]/scripts/classes/StructureOutliner.js rename to Construct [BP]/scripts/classes/StructureOutliner.js index 65648fa..023fde5 100644 --- a/StrucTool [BP]/scripts/classes/StructureOutliner.js +++ b/Construct [BP]/scripts/classes/StructureOutliner.js @@ -1,4 +1,4 @@ -import { Outliner } from '../classes/Outliner'; +import { Outliner } from './Outliner'; export class StructureOutliner { constructor(instance) { diff --git a/StrucTool [BP]/scripts/classes/StructureStatistics.js b/Construct [BP]/scripts/classes/StructureStatistics.js similarity index 100% rename from StrucTool [BP]/scripts/classes/StructureStatistics.js rename to Construct [BP]/scripts/classes/StructureStatistics.js diff --git a/StrucTool [BP]/scripts/classes/StructureVerifier.js b/Construct [BP]/scripts/classes/StructureVerifier.js similarity index 100% rename from StrucTool [BP]/scripts/classes/StructureVerifier.js rename to Construct [BP]/scripts/classes/StructureVerifier.js diff --git a/StrucTool [BP]/scripts/classes/enums/BlockVerificationLevel.js b/Construct [BP]/scripts/classes/enums/BlockVerificationLevel.js similarity index 100% rename from StrucTool [BP]/scripts/classes/enums/BlockVerificationLevel.js rename to Construct [BP]/scripts/classes/enums/BlockVerificationLevel.js diff --git a/StrucTool [BP]/scripts/classes/enums/InstanceEditButtons.js b/Construct [BP]/scripts/classes/enums/InstanceEditButtons.js similarity index 100% rename from StrucTool [BP]/scripts/classes/enums/InstanceEditButtons.js rename to Construct [BP]/scripts/classes/enums/InstanceEditButtons.js diff --git a/StrucTool [BP]/scripts/commands/structool.js b/Construct [BP]/scripts/commands/construct.js similarity index 59% rename from StrucTool [BP]/scripts/commands/structool.js rename to Construct [BP]/scripts/commands/construct.js index 39baffd..f6454c5 100644 --- a/StrucTool [BP]/scripts/commands/structool.js +++ b/Construct [BP]/scripts/commands/construct.js @@ -5,16 +5,23 @@ import { MenuForm } from '../classes/MenuForm'; const ACTION_ITEM = 'minecraft:paper'; -const structoolCmd = new Command({ +const menuCmd = new Command({ name: 'structool', description: { text: 'Opens the StrucTool Menu. Using a paper will also open the menu.' }, usage: 'structool', - callback: (sender) => new MenuForm(sender) + callback: (sender) => openMenu(sender) }); -extension.addCommand(structoolCmd); +extension.addCommand(menuCmd); world.beforeEvents.itemUse.subscribe((event) => { if (!event.source || event.itemStack?.typeId !== ACTION_ITEM) return; event.cancel = true; - system.run(() => structoolCmd.getCallback()(event.source)); -}); \ No newline at end of file + system.run(() => openMenu(event.source, event)); +}); + +function openMenu(sender, event = void 0) { + const options = { jumpToInstance: true } + if (event) + options.instanceName = event.itemStack?.typeId; + new MenuForm(sender, options); +} \ No newline at end of file diff --git a/StrucTool [BP]/scripts/config.js b/Construct [BP]/scripts/config.js similarity index 100% rename from StrucTool [BP]/scripts/config.js rename to Construct [BP]/scripts/config.js diff --git a/StrucTool [BP]/scripts/data.js b/Construct [BP]/scripts/data.js similarity index 100% rename from StrucTool [BP]/scripts/data.js rename to Construct [BP]/scripts/data.js diff --git a/StrucTool [BP]/scripts/lib/Vector.js b/Construct [BP]/scripts/lib/Vector.js similarity index 100% rename from StrucTool [BP]/scripts/lib/Vector.js rename to Construct [BP]/scripts/lib/Vector.js diff --git a/StrucTool [BP]/scripts/lib/canopy/CanopyExtension.js b/Construct [BP]/scripts/lib/canopy/CanopyExtension.js similarity index 99% rename from StrucTool [BP]/scripts/lib/canopy/CanopyExtension.js rename to Construct [BP]/scripts/lib/canopy/CanopyExtension.js index 4e39608..8cf1acc 100644 --- a/StrucTool [BP]/scripts/lib/canopy/CanopyExtension.js +++ b/Construct [BP]/scripts/lib/canopy/CanopyExtension.js @@ -23,7 +23,7 @@ * SOFTWARE. */ import { world } from '@minecraft/server'; -import IPC from '../../lib/ipc/ipc'; +import IPC from '../ipc/ipc'; import Command from './Command'; import Rule from './Rule'; import { CommandCallbackRequest, CommandPrefixRequest, Ready, RegisterCommand, RegisterExtension, RegisterRule, RuleValueRequest, RuleValueSet, CommandPrefixResponse, RuleValueResponse } from './extension.ipc'; diff --git a/StrucTool [BP]/scripts/lib/canopy/Command.js b/Construct [BP]/scripts/lib/canopy/Command.js similarity index 100% rename from StrucTool [BP]/scripts/lib/canopy/Command.js rename to Construct [BP]/scripts/lib/canopy/Command.js diff --git a/StrucTool [BP]/scripts/lib/canopy/Rule.js b/Construct [BP]/scripts/lib/canopy/Rule.js similarity index 100% rename from StrucTool [BP]/scripts/lib/canopy/Rule.js rename to Construct [BP]/scripts/lib/canopy/Rule.js diff --git a/StrucTool [BP]/scripts/lib/canopy/extension.ipc.js b/Construct [BP]/scripts/lib/canopy/extension.ipc.js similarity index 100% rename from StrucTool [BP]/scripts/lib/canopy/extension.ipc.js rename to Construct [BP]/scripts/lib/canopy/extension.ipc.js diff --git a/StrucTool [BP]/scripts/lib/ipc/ipc.d.ts b/Construct [BP]/scripts/lib/ipc/ipc.d.ts similarity index 100% rename from StrucTool [BP]/scripts/lib/ipc/ipc.d.ts rename to Construct [BP]/scripts/lib/ipc/ipc.d.ts diff --git a/StrucTool [BP]/scripts/lib/ipc/ipc.js b/Construct [BP]/scripts/lib/ipc/ipc.js similarity index 100% rename from StrucTool [BP]/scripts/lib/ipc/ipc.js rename to Construct [BP]/scripts/lib/ipc/ipc.js diff --git a/StrucTool [BP]/scripts/main.js b/Construct [BP]/scripts/main.js similarity index 65% rename from StrucTool [BP]/scripts/main.js rename to Construct [BP]/scripts/main.js index 55d31a8..4bc4dda 100644 --- a/StrucTool [BP]/scripts/main.js +++ b/Construct [BP]/scripts/main.js @@ -1,9 +1,10 @@ // Rules import './rules/easyPlace'; import './rules/fastEasyPlace'; +import './rules/materialGrabber'; // Commands -import './commands/structool'; +import './commands/construct'; // Other import './classes/BlockInfo'; diff --git a/StrucTool [BP]/scripts/rules/easyPlace.js b/Construct [BP]/scripts/rules/easyPlace.js similarity index 100% rename from StrucTool [BP]/scripts/rules/easyPlace.js rename to Construct [BP]/scripts/rules/easyPlace.js diff --git a/StrucTool [BP]/scripts/rules/fastEasyPlace.js b/Construct [BP]/scripts/rules/fastEasyPlace.js similarity index 100% rename from StrucTool [BP]/scripts/rules/fastEasyPlace.js rename to Construct [BP]/scripts/rules/fastEasyPlace.js diff --git a/Construct [BP]/scripts/rules/materialGrabber.js b/Construct [BP]/scripts/rules/materialGrabber.js new file mode 100644 index 0000000..411a9f3 --- /dev/null +++ b/Construct [BP]/scripts/rules/materialGrabber.js @@ -0,0 +1,24 @@ +import { Rule } from '../lib/canopy/CanopyExtension'; +import { extension } from '../config'; +import { world } from '@minecraft/server'; + +const easyPlace = new Rule({ + identifier: 'materialGrabber', + description: { text: "Automatically grabs structure materials out of inventories. Use a paper named 'materialGrabber' to get started." }, + onEnableCallback: () => { + world.beforeEvents.playerInteractWithBlock.subscribe(onPlayerInteract); + world.beforeEvents.playerInteractWithEntity.subscribe(onPlayerInteract); + }, + onDisableCallback: () => { + world.beforeEvents.playerInteractWithBlock.unsubscribe(onPlayerInteract); + world.beforeEvents.playerInteractWithEntity.unsubscribe(onPlayerInteract); + } +}) +extension.addRule(easyPlace); + +function onPlayerInteract(event) { + // get inventory + // analyze active structure items if not analyzed -- there needs to be a way to refresh this that is efficient + // find items in inventory that match items in structure + // transfer to player +} \ No newline at end of file diff --git a/StrucTool [BP]/scripts/utils.js b/Construct [BP]/scripts/utils.js similarity index 100% rename from StrucTool [BP]/scripts/utils.js rename to Construct [BP]/scripts/utils.js diff --git a/StrucTool [BP]/structures/Everything.mcstructure b/Construct [BP]/structures/Everything.mcstructure similarity index 100% rename from StrucTool [BP]/structures/Everything.mcstructure rename to Construct [BP]/structures/Everything.mcstructure diff --git a/StrucTool [BP]/structures/xmas.mcstructure b/Construct [BP]/structures/xmas.mcstructure similarity index 100% rename from StrucTool [BP]/structures/xmas.mcstructure rename to Construct [BP]/structures/xmas.mcstructure diff --git a/StrucTool [RP]/manifest.json b/Construct [RP]/manifest.json similarity index 100% rename from StrucTool [RP]/manifest.json rename to Construct [RP]/manifest.json diff --git a/Construct [RP]/pack_icon.png b/Construct [RP]/pack_icon.png new file mode 100644 index 0000000..dfa91e7 Binary files /dev/null and b/Construct [RP]/pack_icon.png differ diff --git a/StrucTool [RP]/particles/blockoverlay_xy.particle.json b/Construct [RP]/particles/blockoverlay_xy.particle.json similarity index 100% rename from StrucTool [RP]/particles/blockoverlay_xy.particle.json rename to Construct [RP]/particles/blockoverlay_xy.particle.json diff --git a/StrucTool [RP]/particles/blockoverlay_xz.particle.json b/Construct [RP]/particles/blockoverlay_xz.particle.json similarity index 100% rename from StrucTool [RP]/particles/blockoverlay_xz.particle.json rename to Construct [RP]/particles/blockoverlay_xz.particle.json diff --git a/StrucTool [RP]/particles/blockoverlay_yz.particle.json b/Construct [RP]/particles/blockoverlay_yz.particle.json similarity index 100% rename from StrucTool [RP]/particles/blockoverlay_yz.particle.json rename to Construct [RP]/particles/blockoverlay_yz.particle.json diff --git a/StrucTool [RP]/particles/outline.particle.json b/Construct [RP]/particles/outline.particle.json similarity index 100% rename from StrucTool [RP]/particles/outline.particle.json rename to Construct [RP]/particles/outline.particle.json diff --git a/StrucTool [RP]/textures/particle/white.png b/Construct [RP]/textures/particle/white.png similarity index 100% rename from StrucTool [RP]/textures/particle/white.png rename to Construct [RP]/textures/particle/white.png diff --git a/README.md b/README.md index 9ba36fb..786107a 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@
- - Canopy Extension Example Icon + + Construct Icon -

StrucTool

+

Construct

-[![Codacy Quality](https://app.codacy.com/project/badge/Grade/10040a714ad84a2f912d4dae9d3f6e57)](https://app.codacy.com/gh/ForestOfLight/StrucTool/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) +[![Codacy Quality](https://app.codacy.com/project/badge/Grade/10040a714ad84a2f912d4dae9d3f6e57)](https://app.codacy.com/gh/ForestOfLight/Construct/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) [![Minecraft - Version](https://img.shields.io/badge/Minecraft-v1.21.60_(Bedrock)-brightgreen)](https://feedback.minecraft.net/hc/en-us/sections/360001186971-Release-Changelogs) -[![GitHub License](https://img.shields.io/github/license/forestoflight/structool)](LICENSE) +[![GitHub License](https://img.shields.io/github/license/forestoflight/construct)](LICENSE) [![Discord](https://badgen.net/discord/members/9KGche8fxm?icon=discord&label=Discord&list=what)](https://discord.gg/9KGche8fxm)