Skip to content

Commit

Permalink
Fixed incorrect litematic exporter stride, fixes #153
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasDower committed Nov 4, 2023
1 parent ac1505f commit 7d3cce1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Core/src/exporters/litematic_exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7d3cce1

Please sign in to comment.