From 9eea8b441386deaacddda04fc516b59d69d8f930 Mon Sep 17 00:00:00 2001 From: ForestOfLight Date: Mon, 17 Mar 2025 00:52:43 -0700 Subject: [PATCH] make showStructBlockInfo not a rule --- README.md | 12 +++++----- scripts/classes/BlockInfo.js | 24 +++++++++++++++++++ scripts/main.js | 4 +++- scripts/rules/showStructBlockInfo.js | 35 ---------------------------- 4 files changed, 33 insertions(+), 42 deletions(-) create mode 100644 scripts/classes/BlockInfo.js diff --git a/README.md b/README.md index 1573aa2..e467fef 100644 --- a/README.md +++ b/README.md @@ -30,14 +30,14 @@ Removes a structure. ## Roadmap -- [ ] Add new structures by pasting a string -- [ ] Make a viewable material list +- [ ] place structure **(in progress)** +- [x] easyPlace rule +- [x] Make a viewable material list +- [ ] Make automatic material gathering from inventories +- [ ] structure movement & rotation - [ ] structuraMode & holoprintMode rules for ease of use -- [ ] Make automatic material grabbing from inventories -- [ ] structure placement (ghost and solid) -- [ ] easyPlace rule -- [ ] more litematica features! - [ ] send structure as a scriptevent so that other addons can use it +- [ ] more litematica features! ## Issues & Suggestions diff --git a/scripts/classes/BlockInfo.js b/scripts/classes/BlockInfo.js new file mode 100644 index 0000000..5d6c30c --- /dev/null +++ b/scripts/classes/BlockInfo.js @@ -0,0 +1,24 @@ +import { system, world } from '@minecraft/server'; +import { Raycaster } from '../classes/Raycaster'; + +system.runInterval(() => { + for (const player of world.getAllPlayers()) { + if (!player) + continue; + showStructureBlockInfo(player); + } +}); + +function showStructureBlockInfo(player) { + const block = Raycaster.getTargetedStructureBlock(player, { isFirst: true, collideWithWorldBlocks: true }); + if (!block) + return; + player.onScreenDisplay.setActionBar({ text: getFormattedBlockInfo(block.permutation) }); +} + +function getFormattedBlockInfo(block) { + const states = block.getAllStates(); + if (Object.keys(states).length === 0) + return `Structure:\n§a${block.type.id}`; + return `Structure:\n§a${block.type.id}\n§7${JSON.stringify(block.getAllStates())}`; +} \ No newline at end of file diff --git a/scripts/main.js b/scripts/main.js index da757bb..9b6d634 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,7 +1,9 @@ // Rules import './rules/easyPlace'; import './rules/fastEasyPlace'; -import './rules/showStructBlockInfo'; // Commands import './commands/struct'; + +// Other +import './classes/BlockInfo'; diff --git a/scripts/rules/showStructBlockInfo.js b/scripts/rules/showStructBlockInfo.js index 208ce2a..e69de29 100644 --- a/scripts/rules/showStructBlockInfo.js +++ b/scripts/rules/showStructBlockInfo.js @@ -1,35 +0,0 @@ -import { Rule } from '../lib/canopy/CanopyExtension'; -import { extension } from '../config'; -import { system, world } from '@minecraft/server'; -import { Raycaster } from '../classes/Raycaster'; - -let runner = void 0; -const showStructBlockInfo = new Rule({ - identifier: 'showStructBlockInfo', - description: { text: 'Shows block and state info for structure blocks you are looking at.' }, - onEnableCallback: () => { runner = system.runInterval(onTick); }, - onDisableCallback: () => { system.clearRun(runner); } -}) -extension.addRule(showStructBlockInfo); - -function onTick() { - for (const player of world.getAllPlayers()) { - if (!player) - continue; - showStructureBlockInfo(player); - } -} - -function showStructureBlockInfo(player) { - const block = Raycaster.getTargetedStructureBlock(player, { isFirst: true, collideWithWorldBlocks: true }); - if (!block) - return; - player.onScreenDisplay.setActionBar({ text: getFormattedBlockInfo(block.permutation) }); -} - -function getFormattedBlockInfo(block) { - const states = block.getAllStates(); - if (Object.keys(states).length === 0) - return `Structure:\n§a${block.type.id}`; - return `Structure:\n§a${block.type.id}\n§7${JSON.stringify(block.getAllStates())}`; -} \ No newline at end of file