decoupled verification rendering from the verifier with much better animations

This commit is contained in:
ForestOfLight
2025-06-06 01:31:49 -07:00
Unverified
parent 709eccef8c
commit f8bbc659fb
11 changed files with 171 additions and 51 deletions
@@ -148,6 +148,11 @@ export class InstanceForm {
this.player.sendMessage('§cA verification is already in progress. Please wait until it finishes.');
return;
}
throw e;
}
if (!statsForm) {
this.player.sendMessage('§cFailed to build statistics form.');
return;
}
statsForm.form.show(this.player).then((response) => {
if (response.canceled && response.cancelationReason === FormCancelationReason.UserBusy)
@@ -160,11 +165,7 @@ export class InstanceForm {
if (response.canceled)
return;
this.instance.setVerifierEnabled(response.formValues[0]);
if (response.formValues[1])
this.instance.setVerifierDistance(5);
else
this.instance.setVerifierDistance(0);
this.instance.setLayer(parseInt(response.formValues[2]));
this.instance.setLayer(parseInt(response.formValues[1]));
});
}
@@ -3,10 +3,9 @@ import { MenuFormBuilder } from '../MenuFormBuilder';
import { StructureVerifier } from '../Verifier/StructureVerifier';
import { StructureStatistics } from '../Structure/StructureStatistics';
import { EntityComponentTypes, TicksPerSecond } from '@minecraft/server';
import { BlockVerificationLevel } from '../Enums/BlockVerificationLevel';
export class InstanceFormBuilder {
static structureVerifier;
static buildInstance(instance, options) {
const location = instance.getLocation();
const form = new ActionFormData()
@@ -33,10 +32,9 @@ export class InstanceFormBuilder {
.title(MenuFormBuilder.menuTitle)
if (this.structureVerifier)
throw new Error('StructureVerifier is already running.');
this.structureVerifier = new StructureVerifier(instance, { isEnabled: true, trackPlayerDistance: 0, intervalOrLifetime: 30 * TicksPerSecond, isStandalone: true });
const verification = await this.structureVerifier.verifyStructure();
const structureVerifier = new StructureVerifier(instance, { isEnabled: true, particleLifetime: 1*TicksPerSecond, isStandalone: true });
const verification = await structureVerifier.verifyStructure(true);
const statistics = new StructureStatistics(instance, verification);
this.structureVerifier = void 0;
const statsMessage = statistics.getMessage();
buildStatisticsForm.body(statsMessage);
return { form: buildStatisticsForm, stats: statsMessage };
@@ -46,7 +44,6 @@ export class InstanceFormBuilder {
return new ModalFormData()
.title(MenuFormBuilder.menuTitle)
.toggle('Block Validation', { defaultValue: instance.options.verifier.isEnabled, tooltip: 'Shows missing and incorrect block overlay.' })
.toggle('Distance-Based Block Validation', { defaultValue: instance.verifier.getTrackPlayerDistance() !== 0, tooltip: `If enabled, the verifier will only check within ${instance.verifier.getTrackPlayerDistance()} blocks of the player. This should stay enabled unless your structure is very small or in layer mode.` })
.slider("Layer", 0, instance.getMaxLayer(), { defaultValue: instance.getLayer(), valueStep: 1, tooltip: 'Changes the active layer. Use 0 for all layers.' })
.submitButton('§2Apply');
}
@@ -13,7 +13,7 @@ export class InstanceOptions extends Option {
verifier = {
isEnabled: true,
trackPlayerDistance: 5,
intervalOrLifetime: 10
particleLifetime: 10
};
static getInstanceStrucetureId(instanceName) {
@@ -1,17 +1,19 @@
import { Vector } from "../../lib/Vector";
import { StructureOutliner } from "../Structure/StructureOutliner";
import { StructureOutliner } from "../Render/StructureOutliner";
import { StructureVerifier } from "../Verifier/StructureVerifier";
import { Structure } from "../Structure/Structure";
import { InstanceOptions } from "./InstanceOptions";
import { TicksPerSecond } from "@minecraft/server";
import { InstanceNotPlacedError } from "../Errors/InstanceNotPlacedError";
import { StructureMaterials } from "../Materials/StructureMaterials";
import { VerificationRenderer } from "../Render/VerificationRenderer";
export class StructureInstance {
options;
structure = void 0;
verifier = void 0;
outliner = void 0;
verifier = void 0;
verificationRenderer = void 0;
materials = void 0;
constructor(instanceName, structureId) {
@@ -27,6 +29,7 @@ export class StructureInstance {
delete this.structure;
delete this.outliner;
delete this.verifier;
delete this.verificationRenderer;
delete this.materials;
}
@@ -36,11 +39,14 @@ export class StructureInstance {
if (!this.outliner)
this.outliner = new StructureOutliner(this);
if (!this.verifier)
this.verifier = new StructureVerifier(this, { isEnabled: this.options.verifier.isEnabled, trackPlayerDistance: this.options.verifier.trackPlayerDistance });
this.verifier = new StructureVerifier(this, { isEnabled: this.options.verifier.isEnabled });
if (!this.verificationRenderer)
this.verificationRenderer = new VerificationRenderer(this);
if (!this.materials)
this.materials = new StructureMaterials(this);
this.outliner.refresh();
this.verifier.refresh();
this.verificationRenderer.refresh();
this.materials.refresh();
}
@@ -57,7 +63,7 @@ export class StructureInstance {
}
getDimension() {
return this.options.getDimension();
return this.options?.getDimension();
}
getLayer() {
@@ -206,17 +212,18 @@ export class StructureInstance {
setVerifierEnabled(enable) {
this.options.setVerifierEnabled(enable);
this.verifier.refresh();
this.verificationRenderer.refresh();
}
setVerifierDistance(distance) {
this.options.setVerifierDistance(distance);
if (this.options.verifier.trackPlayerDistance === 0) {
const bounds = this.getBounds();
this.options.verifier.intervalOrLifetime = Math.max(bounds.min.volume(bounds.max) / TicksPerSecond, 2*TicksPerSecond);
this.options.verifier.particleLifetime = Math.max(bounds.min.volume(bounds.max) / TicksPerSecond, 2*TicksPerSecond);
} else {
this.options.verifier.intervalOrLifetime = 10;
this.options.verifier.particleLifetime = 10;
}
this.verifier.refresh();
this.verificationRenderer.refresh();
}
increaseLayer() {