Skip to content

Instantly share code, notes, and snippets.

@wtfaremyinitials
Created March 3, 2015 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wtfaremyinitials/42bbbb16b2d25208fb4d to your computer and use it in GitHub Desktop.
Save wtfaremyinitials/42bbbb16b2d25208fb4d to your computer and use it in GitHub Desktop.
Chunk.js
var CHUNK_SIZE = 16;
var CHUNK_HEIGHT = 256;
var Chunk = function(buf) {
if(!(this instanceof Chunk))
return new Chunk(buf);
this.data = buf || new Buffer(CHUNK_SIZE * CHUNK_SIZE * CHUNK_HEIGHT);
};
Chunk.prototype.getBlockAt = function(location) {
var position = (location.x) + (location.z * CHUNK_SIZE) + (location.y * CHUNK_HEIGHT);
var block = {
id: bitwiseStuff(this.data[position]),
data: moreBitwiseStuff(this.data[position])
};
return block;
};
module.exports = Chunk;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment