diff --git a/StrucTool [BP]/scripts/classes/BlockVerificationLevel.js b/StrucTool [BP]/scripts/classes/BlockVerificationLevel.js index cdc5a32..b5beb5a 100644 --- a/StrucTool [BP]/scripts/classes/BlockVerificationLevel.js +++ b/StrucTool [BP]/scripts/classes/BlockVerificationLevel.js @@ -2,7 +2,7 @@ export const BlockVerificationLevel = Object.freeze({ Unknown: 0, NoMatch: 1, TypeMatch: 2, - TypeAndStateMatch: 3, + Match: 3, Missing: 4, - isAir: 5 + Air: 5 }); \ No newline at end of file diff --git a/StrucTool [BP]/scripts/classes/BlockVerificationLevelRender.js b/StrucTool [BP]/scripts/classes/BlockVerificationLevelRender.js new file mode 100644 index 0000000..598150f --- /dev/null +++ b/StrucTool [BP]/scripts/classes/BlockVerificationLevelRender.js @@ -0,0 +1,59 @@ +import { MolangVariableMap } from "@minecraft/server"; +import { BlockVerificationLevel } from "./BlockVerificationLevel"; +import { Vector } from "../lib/Vector"; + +export class BlockVerificationLevelRender { + opacity = 0.5; + + constructor(dimension, globalLocation, verificationLevel) { + this.dimension = dimension; + this.location = new Vector(globalLocation.x, globalLocation.y, globalLocation.z); + this.verificationLevel = verificationLevel; + this.renderBlock(); + } + + renderBlock() { + for (const [key, value] of Object.entries(this.getParticleLocations())) { + this.dimension.spawnParticle(key, value, this.getRGBAMolang()); + } + } + + getParticleLocations() { + const bottomFace = new Vector(0, 0, 0); + const topFace = new Vector(0, 1, 0); + const leftFace = new Vector(0.5, 0.5, 0); + const rightFace = new Vector(-0.5, 0.5, 0); + const frontFace = new Vector(0, 0.5, 0.5); + const backFace = new Vector(0, 0.5, -0.5); + return { + "structool:blockerlay_xz": this.location.add(topFace), + "structool:blockerlay_xz": this.location.add(bottomFace), + "structool:blockerlay_yz": this.location.add(leftFace), + "structool:blockerlay_yz": this.location.add(rightFace), + "structool:blockerlay_xy": this.location.add(frontFace), + "structool:blockerlay_xy": this.location.add(backFace), + } + } + + getRGBAMolang() { + const rgb = this.verificationLevelToRGB(); + if (!rgb) return; + rgb.alpha = this.opacity; + return new MolangVariableMap().setColorRGBA("minecraft:particle_appearance_tinting", rgb); + } + + verificationLevelToRGB() { + switch (this.verificationLevel) { + case BlockVerificationLevel.NoMatch: + return [1, 0, 0]; + case BlockVerificationLevel.TypeMatch: + return [1, 1, 0]; + case BlockVerificationLevel.Match: + return [0, 1, 0]; + case BlockVerificationLevel.Missing: + return [0, 0, 1]; + default: + return void 0; + } + } +} \ No newline at end of file diff --git a/StrucTool [BP]/scripts/classes/BlockVerifier.js b/StrucTool [BP]/scripts/classes/BlockVerifier.js index 5ac24e9..2f2859c 100644 --- a/StrucTool [BP]/scripts/classes/BlockVerifier.js +++ b/StrucTool [BP]/scripts/classes/BlockVerifier.js @@ -14,14 +14,14 @@ export class BlockVerifier { evaluatePermutations(worldPermutation, structPermutation) { if (this.isCorrectlyAir(worldPermutation, structPermutation)) - return this.air(); + return BlockVerificationLevel.Air; if (this.isMissing(worldPermutation, structPermutation)) - return this.missing(); + return BlockVerificationLevel.Missing; if (this.isExactMatch(worldPermutation, structPermutation)) - return this.matchingPermutations(); + return BlockVerificationLevel.Match; if (this.isTypeMatch(worldPermutation, structPermutation)) - return this.matchingTypes(); - return this.matchingNone(); + return BlockVerificationLevel.TypeMatch; + return BlockVerificationLevel.NoMatch; } isCorrectlyAir(worldPermutation, structPermutation) { @@ -39,24 +39,4 @@ export class BlockVerifier { isExactMatch(worldPermuation, structurePermuation) { return worldPermuation.matches(structurePermuation.type.id, structurePermuation.getAllStates()); } - - air() { - return BlockVerificationLevel.isAir; - } - - missing() { - return BlockVerificationLevel.Missing; - } - - matchingPermutations() { - return BlockVerificationLevel.TypeAndStateMatch; - } - - matchingTypes() { - return BlockVerificationLevel.TypeMatch; - } - - matchingNone() { - return BlockVerificationLevel.NoMatch; - } } \ No newline at end of file diff --git a/StrucTool [BP]/scripts/classes/InstanceEditFormBuilder.js b/StrucTool [BP]/scripts/classes/InstanceEditFormBuilder.js index 3564309..b9463f9 100644 --- a/StrucTool [BP]/scripts/classes/InstanceEditFormBuilder.js +++ b/StrucTool [BP]/scripts/classes/InstanceEditFormBuilder.js @@ -37,11 +37,11 @@ export class InstanceEditFormBuilder { const buildStatisticsForm = new ActionFormData() .title(MenuFormBuilder.menuTitle) let message = ''; - const structureVerifier = new StructureVerifier(instance); + const structureVerifier = new StructureVerifier(instance, { shouldRender: true }); const statistics = await structureVerifier.verifyStructure(); message += `§fStatistics for §a${instance.name}§f:\n`; message += `§7Blocks: §2${instance.getTotalVolume() - statistics.correctlyAir}\n`; - message += `§7Correct: §a${this.getFormattedStatistic(statistics, BlockVerificationLevel.TypeAndStateMatch)}\n`; + message += `§7Correct: §a${this.getFormattedStatistic(statistics, BlockVerificationLevel.Match)}\n`; message += `§7Block State Incorrect: §e${this.getFormattedStatistic(statistics, BlockVerificationLevel.TypeMatch)}\n`; message += `§7Incorrect: §c${this.getFormattedStatistic(statistics, BlockVerificationLevel.NoMatch)}\n`; message += `§7Missing: §c${this.getFormattedStatistic(statistics, BlockVerificationLevel.Missing)}\n`; diff --git a/StrucTool [BP]/scripts/classes/StructureVerifier.js b/StrucTool [BP]/scripts/classes/StructureVerifier.js index f583d8c..2642127 100644 --- a/StrucTool [BP]/scripts/classes/StructureVerifier.js +++ b/StrucTool [BP]/scripts/classes/StructureVerifier.js @@ -1,11 +1,17 @@ import { BlockVerifier } from "./BlockVerifier"; import { BlockVerificationLevel } from "./BlockVerificationLevel"; +import { BlockVerificationLevelRender } from "./BlockVerificationLevelRender"; export class StructureVerifier { - constructor(instance) { + shouldRender; + isComplete; + + constructor(instance, { shouldRender = false } = {}) { this.instance = instance; this.blockVerificationLevels = {}; this.statistics = {}; + this.shouldRender = shouldRender; + this.isComplete = false; this.initStatistics(); } @@ -30,10 +36,12 @@ export class StructureVerifier { *verifyBlocks() { for (const block of this.instance.getBlocks()) { const verificationLevel = this.verifyBlock(block.location); - if (verificationLevel !== BlockVerificationLevel.isAir) + if (verificationLevel !== BlockVerificationLevel.Air) this.blockVerificationLevels[JSON.stringify(block.location)] = verificationLevel; else this.statistics.correctlyAir++; + if (this.shouldRender) + new BlockVerificationLevelRender(this.instance.getDimension(), this.instance.toGlobalCoords(block.location), verificationLevel); yield; } this.isComplete = true; @@ -49,7 +57,7 @@ export class StructureVerifier { // verifyBlocks() { // for (const block of this.instance.getBlocks()) { // const verificationLevel = this.verifyBlock(block.location); - // if (verificationLevel !== BlockVerificationLevel.isAir) + // if (verificationLevel !== BlockVerificationLevel.Air) // this.blockVerificationLevels[JSON.stringify(block.location)] = verificationLevel; // else // this.statistics.correctlyAir++; diff --git a/StrucTool [RP]/particles/blockoverlay_xy.particle.json b/StrucTool [RP]/particles/blockoverlay_xy.particle.json new file mode 100644 index 0000000..1f625e3 --- /dev/null +++ b/StrucTool [RP]/particles/blockoverlay_xy.particle.json @@ -0,0 +1,31 @@ +{ + "format_version": "1.10.0", + "particle_effect": { + "description": { + "identifier": "structool:blockoverlay_xy", + "basic_render_parameters": { + "material": "particles_blend", + "texture": "textures/particle/white" + } + }, + "components": { + "minecraft:emitter_rate_instant": { + "num_particles": 1 + }, + "minecraft:emitter_lifetime_once": { + "active_time": 1 + }, + "minecraft:emitter_shape_point": {}, + "minecraft:particle_lifetime_expression": { + "max_lifetime": 1 + }, + "minecraft:particle_appearance_billboard": { + "size": [0.5, 0.5], + "facing_camera_mode": "emitter_transform_xy" + }, + "minecraft:particle_appearance_tinting": { + "color": [0, 0, 0, 0.5] + } + } + } +} \ No newline at end of file diff --git a/StrucTool [RP]/particles/blockoverlay.particle.json b/StrucTool [RP]/particles/blockoverlay_xz.particle.json similarity index 89% rename from StrucTool [RP]/particles/blockoverlay.particle.json rename to StrucTool [RP]/particles/blockoverlay_xz.particle.json index 1694375..9bf3bbe 100644 --- a/StrucTool [RP]/particles/blockoverlay.particle.json +++ b/StrucTool [RP]/particles/blockoverlay_xz.particle.json @@ -2,7 +2,7 @@ "format_version": "1.10.0", "particle_effect": { "description": { - "identifier": "structool:blockoverlay", + "identifier": "structool:blockoverlay_xz", "basic_render_parameters": { "material": "particles_blend", "texture": "textures/particle/white" @@ -24,7 +24,7 @@ "facing_camera_mode": "emitter_transform_xz" }, "minecraft:particle_appearance_tinting": { - "color": [1, 0, 0, 0.5] + "color": [0, 0, 0, 0.5] } } } diff --git a/StrucTool [RP]/particles/blockoverlay_yz.particle.json b/StrucTool [RP]/particles/blockoverlay_yz.particle.json new file mode 100644 index 0000000..bd471e5 --- /dev/null +++ b/StrucTool [RP]/particles/blockoverlay_yz.particle.json @@ -0,0 +1,31 @@ +{ + "format_version": "1.10.0", + "particle_effect": { + "description": { + "identifier": "structool:blockoverlay_yz", + "basic_render_parameters": { + "material": "particles_blend", + "texture": "textures/particle/white" + } + }, + "components": { + "minecraft:emitter_rate_instant": { + "num_particles": 1 + }, + "minecraft:emitter_lifetime_once": { + "active_time": 1 + }, + "minecraft:emitter_shape_point": {}, + "minecraft:particle_lifetime_expression": { + "max_lifetime": 1 + }, + "minecraft:particle_appearance_billboard": { + "size": [0.5, 0.5], + "facing_camera_mode": "emitter_transform_yz" + }, + "minecraft:particle_appearance_tinting": { + "color": [0, 0, 0, 0.5] + } + } + } +} \ No newline at end of file