VerificationRenderer
This commit is contained in:
@@ -2,7 +2,7 @@ export const BlockVerificationLevel = Object.freeze({
|
|||||||
Unknown: 0,
|
Unknown: 0,
|
||||||
NoMatch: 1,
|
NoMatch: 1,
|
||||||
TypeMatch: 2,
|
TypeMatch: 2,
|
||||||
TypeAndStateMatch: 3,
|
Match: 3,
|
||||||
Missing: 4,
|
Missing: 4,
|
||||||
isAir: 5
|
Air: 5
|
||||||
});
|
});
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,14 +14,14 @@ export class BlockVerifier {
|
|||||||
|
|
||||||
evaluatePermutations(worldPermutation, structPermutation) {
|
evaluatePermutations(worldPermutation, structPermutation) {
|
||||||
if (this.isCorrectlyAir(worldPermutation, structPermutation))
|
if (this.isCorrectlyAir(worldPermutation, structPermutation))
|
||||||
return this.air();
|
return BlockVerificationLevel.Air;
|
||||||
if (this.isMissing(worldPermutation, structPermutation))
|
if (this.isMissing(worldPermutation, structPermutation))
|
||||||
return this.missing();
|
return BlockVerificationLevel.Missing;
|
||||||
if (this.isExactMatch(worldPermutation, structPermutation))
|
if (this.isExactMatch(worldPermutation, structPermutation))
|
||||||
return this.matchingPermutations();
|
return BlockVerificationLevel.Match;
|
||||||
if (this.isTypeMatch(worldPermutation, structPermutation))
|
if (this.isTypeMatch(worldPermutation, structPermutation))
|
||||||
return this.matchingTypes();
|
return BlockVerificationLevel.TypeMatch;
|
||||||
return this.matchingNone();
|
return BlockVerificationLevel.NoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
isCorrectlyAir(worldPermutation, structPermutation) {
|
isCorrectlyAir(worldPermutation, structPermutation) {
|
||||||
@@ -39,24 +39,4 @@ export class BlockVerifier {
|
|||||||
isExactMatch(worldPermuation, structurePermuation) {
|
isExactMatch(worldPermuation, structurePermuation) {
|
||||||
return worldPermuation.matches(structurePermuation.type.id, structurePermuation.getAllStates());
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -37,11 +37,11 @@ export class InstanceEditFormBuilder {
|
|||||||
const buildStatisticsForm = new ActionFormData()
|
const buildStatisticsForm = new ActionFormData()
|
||||||
.title(MenuFormBuilder.menuTitle)
|
.title(MenuFormBuilder.menuTitle)
|
||||||
let message = '';
|
let message = '';
|
||||||
const structureVerifier = new StructureVerifier(instance);
|
const structureVerifier = new StructureVerifier(instance, { shouldRender: true });
|
||||||
const statistics = await structureVerifier.verifyStructure();
|
const statistics = await structureVerifier.verifyStructure();
|
||||||
message += `§fStatistics for §a${instance.name}§f:\n`;
|
message += `§fStatistics for §a${instance.name}§f:\n`;
|
||||||
message += `§7Blocks: §2${instance.getTotalVolume() - statistics.correctlyAir}\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 += `§7Block State Incorrect: §e${this.getFormattedStatistic(statistics, BlockVerificationLevel.TypeMatch)}\n`;
|
||||||
message += `§7Incorrect: §c${this.getFormattedStatistic(statistics, BlockVerificationLevel.NoMatch)}\n`;
|
message += `§7Incorrect: §c${this.getFormattedStatistic(statistics, BlockVerificationLevel.NoMatch)}\n`;
|
||||||
message += `§7Missing: §c${this.getFormattedStatistic(statistics, BlockVerificationLevel.Missing)}\n`;
|
message += `§7Missing: §c${this.getFormattedStatistic(statistics, BlockVerificationLevel.Missing)}\n`;
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
import { BlockVerifier } from "./BlockVerifier";
|
import { BlockVerifier } from "./BlockVerifier";
|
||||||
import { BlockVerificationLevel } from "./BlockVerificationLevel";
|
import { BlockVerificationLevel } from "./BlockVerificationLevel";
|
||||||
|
import { BlockVerificationLevelRender } from "./BlockVerificationLevelRender";
|
||||||
|
|
||||||
export class StructureVerifier {
|
export class StructureVerifier {
|
||||||
constructor(instance) {
|
shouldRender;
|
||||||
|
isComplete;
|
||||||
|
|
||||||
|
constructor(instance, { shouldRender = false } = {}) {
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
this.blockVerificationLevels = {};
|
this.blockVerificationLevels = {};
|
||||||
this.statistics = {};
|
this.statistics = {};
|
||||||
|
this.shouldRender = shouldRender;
|
||||||
|
this.isComplete = false;
|
||||||
this.initStatistics();
|
this.initStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,10 +36,12 @@ export class StructureVerifier {
|
|||||||
*verifyBlocks() {
|
*verifyBlocks() {
|
||||||
for (const block of this.instance.getBlocks()) {
|
for (const block of this.instance.getBlocks()) {
|
||||||
const verificationLevel = this.verifyBlock(block.location);
|
const verificationLevel = this.verifyBlock(block.location);
|
||||||
if (verificationLevel !== BlockVerificationLevel.isAir)
|
if (verificationLevel !== BlockVerificationLevel.Air)
|
||||||
this.blockVerificationLevels[JSON.stringify(block.location)] = verificationLevel;
|
this.blockVerificationLevels[JSON.stringify(block.location)] = verificationLevel;
|
||||||
else
|
else
|
||||||
this.statistics.correctlyAir++;
|
this.statistics.correctlyAir++;
|
||||||
|
if (this.shouldRender)
|
||||||
|
new BlockVerificationLevelRender(this.instance.getDimension(), this.instance.toGlobalCoords(block.location), verificationLevel);
|
||||||
yield;
|
yield;
|
||||||
}
|
}
|
||||||
this.isComplete = true;
|
this.isComplete = true;
|
||||||
@@ -49,7 +57,7 @@ export class StructureVerifier {
|
|||||||
// verifyBlocks() {
|
// verifyBlocks() {
|
||||||
// for (const block of this.instance.getBlocks()) {
|
// for (const block of this.instance.getBlocks()) {
|
||||||
// const verificationLevel = this.verifyBlock(block.location);
|
// const verificationLevel = this.verifyBlock(block.location);
|
||||||
// if (verificationLevel !== BlockVerificationLevel.isAir)
|
// if (verificationLevel !== BlockVerificationLevel.Air)
|
||||||
// this.blockVerificationLevels[JSON.stringify(block.location)] = verificationLevel;
|
// this.blockVerificationLevels[JSON.stringify(block.location)] = verificationLevel;
|
||||||
// else
|
// else
|
||||||
// this.statistics.correctlyAir++;
|
// this.statistics.correctlyAir++;
|
||||||
|
|||||||
@@ -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]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-2
@@ -2,7 +2,7 @@
|
|||||||
"format_version": "1.10.0",
|
"format_version": "1.10.0",
|
||||||
"particle_effect": {
|
"particle_effect": {
|
||||||
"description": {
|
"description": {
|
||||||
"identifier": "structool:blockoverlay",
|
"identifier": "structool:blockoverlay_xz",
|
||||||
"basic_render_parameters": {
|
"basic_render_parameters": {
|
||||||
"material": "particles_blend",
|
"material": "particles_blend",
|
||||||
"texture": "textures/particle/white"
|
"texture": "textures/particle/white"
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
"facing_camera_mode": "emitter_transform_xz"
|
"facing_camera_mode": "emitter_transform_xz"
|
||||||
},
|
},
|
||||||
"minecraft:particle_appearance_tinting": {
|
"minecraft:particle_appearance_tinting": {
|
||||||
"color": [1, 0, 0, 0.5]
|
"color": [0, 0, 0, 0.5]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user