From 7d3cce1c81f3bbd928bdd075ad35ad59b89d6c20 Mon Sep 17 00:00:00 2001 From: Lucas Dower Date: Sat, 4 Nov 2023 20:18:06 +0000 Subject: [PATCH] Fixed incorrect litematic exporter stride, fixes #153 --- Core/src/exporters/litematic_exporter.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Core/src/exporters/litematic_exporter.ts b/Core/src/exporters/litematic_exporter.ts index 96e347f..0dc6c03 100644 --- a/Core/src/exporters/litematic_exporter.ts +++ b/Core/src/exporters/litematic_exporter.ts @@ -103,15 +103,17 @@ export class Litematic extends IExporter { const blockBuffer = this._createBlockBuffer(blockMesh, blockMapping); const paletteSize = blockMapping.size; - const stride = Math.ceil(Math.log2(paletteSize - 1)); - ASSERT(stride >= 1, `Stride too small: ${stride}`); + ASSERT(paletteSize >= 2, `Palette too small`); + + let stride = Math.ceil(Math.log2(paletteSize)); + stride = Math.max(2, stride); const expectedLengthBits = blockBuffer.length * stride; const requiredLengthBits = ceilToNearest(expectedLengthBits, 64); const startOffsetBits = requiredLengthBits - expectedLengthBits; const requiredLengthBytes = requiredLengthBits / 8; - const buffer = new Uint8Array(requiredLengthBytes / 8); + const buffer = new Uint8Array(requiredLengthBytes); // Write first few offset bits const fullBytesToWrite = Math.floor(startOffsetBits / 8);