Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example showing how to unpack minecraft chunks into 32x32x32 cubes
var ndarray = require("ndarray")
var ops = require("ndarray-ops")
//Given a voxel.js chunk, its y coordinate in blocks and the 4 minecraft chunks it intersects unpack them into the voxel.js component
function unpackMinecraft(y_coord, voxeljs_chunk, mc_chunk00, mc_chunk01, mc_chunk10, mc_chunk_11) {
var varray = ndarray(voxeljs_chunk, [32,32,32])
var mc00 = ndarray(mc_chunk00, [16,128,16], [128, 1, 16*128])
var mc01 = ndarray(mc_chunk01, [16,128,16], [128, 1, 16*128])
var mc10 = ndarray(mc_chunk10, [16,128,16], [128, 1, 16*128])
var mc11 = ndarray(mc_chunk11, [16,128,16], [128, 1, 16*128])
ops.assign(varray.hi(16,32,16), mc00.lo(0, y, 0).hi(16, 16, 16))
ops.assign(varray.lo(0,0,16).hi(16,32,16), mc01.lo(0, y, 0).hi(16, 16, 16))
ops.assign(varray.lo(16,0,0).hi(16,32,16), mc10.lo(0, y, 0).hi(16, 16, 16))
ops.assign(varray.lo(16,0,16), mc11.lo(0, y, 0).hi(16, 16, 16))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.