Skip to content

Instantly share code, notes, and snippets.

View GeorgesOatesLarsen's full-sized avatar

Georges Oates Larsen GeorgesOatesLarsen

View GitHub Profile
@GeorgesOatesLarsen
GeorgesOatesLarsen / readChunk_1_9.js
Last active January 7, 2017 14:49 — forked from rom1504/readChunk_1_9.js
read 1.9 chunk using protodef
const fs=require("fs");
var Chunk = require('prismarine-chunk')("1.8");
var Vec3 = require("vec3");
// based on http://wiki.vg/SMP_Map_Format#Format
// testing data from https://download.rom1504.fr/minecraft/chunks/chunks-1.9/
// see http://lunarco.de/minecraft/chunks/ for explanations
// also see https://gist.github.com/Gjum/0375b643ec13a42ab3c0
// and https://github.com/SpockBotMC/SpockBot/blob/0535c31/spockbot/plugins/tools/smpmap.py
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);
packBlockData(rawdata, bitsPerBlock)
{
let blockCount = Chunk.l * Chunk.w * 16;
let resultantBuffer = Buffer.alloc(blockCount * bitsPerBlock/8);
for (let block = 0; block < blockCount; block++) {
//Determine the start-bit for the block.
let bit = block * bitsPerBlock;
//Determine the start-byte for that bit.
let targetlong = Math.floor(bit/64);
//We write backwards from the end of the long. First, we determine the local writing start.
Block {
type: 9,
metadata: 0,
light: 0,
skyLight: 0,
biome:
Biome {
id: 0,
color: 112,
name: 'Ocean',