Block verifier correct

This commit is contained in:
ForestOfLight
2025-04-15 02:23:21 -07:00
Unverified
parent 567abd0f5f
commit 296af63134
7 changed files with 85 additions and 34 deletions
+15 -9
View File
@@ -1,19 +1,20 @@
import { BlockVerificationLevel } from "./BlockVerificationLevel";
export class BlockVerifier {
constructor(block, structure) {
constructor(block, instance) {
this.block = block;
this.blockLocationInStructure = structure.toStructureCoords(block.location);
this.structure = structure;
this.instance = instance;
this.blockLocationInStructure = instance.toStructureCoords(block.location);
}
verify() {
const worldPermutation = this.block.permutation;
const structPermutation = this.structure.getBlock(this.blockLocationInStructure);
return this.evaluatePermutations(worldPermutation, structPermutation);
const structPermutation = this.instance.getBlock(this.blockLocationInStructure);
return this.evaluatePermutations(this.block.permutation, structPermutation);
}
evaluatePermutations(worldPermutation, structPermutation) {
if (this.isCorrectlyAir(worldPermutation, structPermutation))
return this.air();
if (this.isMissing(worldPermutation, structPermutation))
return this.missing();
if (this.isExactMatch(worldPermutation, structPermutation))
@@ -23,6 +24,10 @@ export class BlockVerifier {
return this.matchingNone();
}
isCorrectlyAir(worldPermutation, structPermutation) {
return worldPermutation.type.id === "minecraft:air" && structPermutation.type.id === "minecraft:air";
}
isMissing(worldPermutation, structPermutation) {
return worldPermutation.type.id === "minecraft:air" && structPermutation.type.id !== "minecraft:air";
}
@@ -35,22 +40,23 @@ export class BlockVerifier {
return worldPermuation.matches(structurePermuation.type.id, structurePermuation.getAllStates());
}
air() {
return BlockVerificationLevel.isAir;
}
missing() {
return BlockVerificationLevel.Missing;
}
matchingPermutations() {
console.warn(`Block ${this.block.typeId} matches structure block ${structPermutation.typeId}`);
return BlockVerificationLevel.TypeAndStateMatch;
}
matchingTypes() {
console.warn(`Block ${this.block.typeId} matches structure block ${structPermutation.typeId}`);
return BlockVerificationLevel.TypeMatch;
}
matchingNone() {
console.warn(`Block ${this.block.typeId} does not match structure block ${structPermutation.typeId}`);
return BlockVerificationLevel.NoMatch;
}
}