Skip to content

Instantly share code, notes, and snippets.

@GeorgesOatesLarsen
Created January 7, 2017 17:42
Show Gist options
  • Save GeorgesOatesLarsen/c92c333c39ab2a2ee91639385cbaa293 to your computer and use it in GitHub Desktop.
Save GeorgesOatesLarsen/c92c333c39ab2a2ee91639385cbaa293 to your computer and use it in GitHub Desktop.
dump() {
//OLD/INTERNAL FORMAT:
//The first w*l*h*2 bytes are blocks, each of which are shorts.
//After that, the first w*l*h*0.5 bytes are block-light-levels, each half-bytes.
//Next, the first w*l*h*0.5 bytes are sky-light-levels, each half-bytes.
//Finally, the next w*l bytes are biomes.
let outputBuffer = Buffer.alloc(0);
let chunkBlocks = Chunk.l * Chunk.w * 16;
let blockLightStart = Chunk.l * Chunk.w * Chunk.h * 2;
let skyLightStart = blockLightStart + Chunk.l * Chunk.w * Chunk.h/2;
let biomestart = skyLightStart + Chunk.l * Chunk.w * Chunk.h/2;
for (let y = 0; y < 16; y++)
{
outputBuffer = Buffer.concat([outputBuffer, proto.createPacketBuffer('section', {
bitsPerBlock: 13,
palette: Buffer.alloc(0),
blockData: this.packBlockData(this.data.slice(y * chunkBlocks*2, (y + 1) * chunkBlocks*2)),
blockLight: this.data.slice(blockLightStart + y * chunkBlocks/2, (y + 1) * chunkBlocks/2),
skyLight: this.data.slice(blockLightStart + y * chunkBlocks/2, (y + 1) * chunkBlocks/2),
})]);
//Is biome data even needed? I am not certain.
}
return outputBuffer.concat([buffer, this.data.slice(biomestart, biomestart+250)]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment