Skip to content

Instantly share code, notes, and snippets.

@lucasdamianjohnson
Last active November 27, 2021 17:12
Show Gist options
  • Save lucasdamianjohnson/bbe9d8a6a324f1c022f63d76a5c8cf38 to your computer and use it in GitHub Desktop.
Save lucasdamianjohnson/bbe9d8a6a324f1c022f63d76a5c8cf38 to your computer and use it in GitHub Desktop.
Byte Set Example TypeScript
const chunk : number[][][] = [];
const blockBytes : number[] = [];
for(const x of chunk.keys()) {
for(const z of chunk[x].keys()) {
for(const y of chunk[x][z].keys()) {
const block = chunk[x][z][y];
if(!block)continue;
let blockByte = 0;
if(!chunk[x][z][y + 1]) {
blockByte = setBit(blockByte,0,1);
}
if(!chunk[x][z][y - 1]) {
blockByte = setBit(blockByte,1,1);
}
if(!chunk[x + 1][z][y]) {
blockByte = setBit(blockByte,2,1);
}
if(!chunk[x - 1][z][y]) {
blockByte = setBit(blockByte,3,1);
}
if(!chunk[x][z + 1][y]) {
blockByte = setBit(blockByte,4,1);
}
if(!chunk[x][z - 1][y]) {
blockByte = setBit(blockByte,5,1);
}
blockBytes.push(blockByte);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment