From ef48e4097c5288ffc31a71411b7e9b742adbea80 Mon Sep 17 00:00:00 2001 From: ForestOfLight Date: Fri, 6 Jun 2025 02:29:56 -0700 Subject: [PATCH 1/2] Change renderer selection criteria --- Construct[BP]/scripts/classes/Render/VerificationRenderer.js | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Construct[BP]/scripts/classes/Render/VerificationRenderer.js b/Construct[BP]/scripts/classes/Render/VerificationRenderer.js index 707d272..37b10a1 100644 --- a/Construct[BP]/scripts/classes/Render/VerificationRenderer.js +++ b/Construct[BP]/scripts/classes/Render/VerificationRenderer.js @@ -98,6 +98,6 @@ export class VerificationRenderer { shouldUseLargeStructureRendering() { const bounds = this.instance.getActiveBounds(); - return bounds.min.volume(bounds.max) > 300; + return this.instance.hasLayerSelected() || bounds.min.volume(bounds.max) > 300; } } \ No newline at end of file diff --git a/README.md b/README.md index e99e60f..f5581c4 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ --- -Give yourself the tools to ease the survival building process with Construct: an addon designed to help you transfer your builds from creative to survival. Construct offers these convenient features and several more: +Give yourself the tools to ease the survival building process with Construct, an addon designed to help you transfer your builds from creative to survival. Construct offers these convenient features and several more: - **Layered Building**: Build structures in layers. - **Block Validation**: Highlights incorrect blocks. From fbf895b9e6052d8cb2c6bf38964cc15a5fdd67f7 Mon Sep 17 00:00:00 2001 From: ForestOfLight Date: Fri, 6 Jun 2025 02:59:12 -0700 Subject: [PATCH 2/2] Attempt to fix all player offline memory leak --- .../classes/Instance/StructureInstance.js | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Construct[BP]/scripts/classes/Instance/StructureInstance.js b/Construct[BP]/scripts/classes/Instance/StructureInstance.js index 1af87d6..e3fa942 100644 --- a/Construct[BP]/scripts/classes/Instance/StructureInstance.js +++ b/Construct[BP]/scripts/classes/Instance/StructureInstance.js @@ -3,7 +3,7 @@ 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 { world, system, TicksPerSecond } from "@minecraft/server"; import { InstanceNotPlacedError } from "../Errors/InstanceNotPlacedError"; import { StructureMaterials } from "../Materials/StructureMaterials"; import { VerificationRenderer } from "../Render/VerificationRenderer"; @@ -20,6 +20,7 @@ export class StructureInstance { this.structure = new Structure(structureId); this.options = new InstanceOptions(instanceName, structureId); this.refreshBox(); + this.subscribeToEvents(); } delete() { @@ -50,6 +51,10 @@ export class StructureInstance { this.materials.refresh(); } + subscribeToEvents() { + this.disableInstanceWhenNoPlayersOnline(); + } + getName() { return this.options.instanceName; } @@ -240,6 +245,24 @@ export class StructureInstance { this.setLayer(this.options.currentLayer - 1); } + disableInstanceWhenNoPlayersOnline() { + // This prevents a memory leak when no players are online. + world.beforeEvents.playerLeave.subscribe(event => { + system.run(() => { + if (world.getAllPlayers().length === 0) { + this.disable(); + this.shouldEnableOnJoin = true; + } + }) + }); + world.afterEvents.playerJoin.subscribe(event => { + if (this.shouldEnableOnJoin) { + this.enable(); + this.shouldEnableOnJoin = false; + } + }); + } + toGlobalCoords(structureLocation) { return Vector.from(structureLocation).add(this.options.worldLocation); }