Mark out-of-bound blocks as UNDEFINED

This commit is contained in:
Paul Mathieu
2021-12-17 15:31:00 -08:00
parent 0739abbaf2
commit d43d888194
2 changed files with 64 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
import { makeBufferFromFaces, makeFace} from "./geometry";
export const BlockType = {
UNDEFINED: 0,
AIR: 1,
DIRT: 2,
GRASS: 3,
@@ -87,6 +88,11 @@ function makeChunk(z, x) {
}
export function blockLookup(world, x, y, z) {
if (y < 0.5 || z > 255.5) {
return {
type: BlockType.UNDEFINED,
}
}
const midx = x + 0.5;
const midy = y + 0.5;
const midz = z + 0.5;
@@ -97,8 +103,7 @@ export function blockLookup(world, x, y, z) {
const chunk = world.chunkMap.get(chunki, chunkj);
if (chunk === undefined) {
return {
type: BlockType.STONE,
centerPosition: [x, y, z],
type: BlockType.UNDEFINED,
};
}
@@ -121,6 +126,9 @@ function makeChunkBuffer(gl, data, z0, x0, blockLookup) {
if (i < 0 || j < 0 || i > 15 || j > 15) {
return blockLookup(i, j, k);
}
if (k < 0 || k > 255) {
return BlockType.UNDEFINED;
}
return data[256*(16*i + j) + k];
};
const sideNeighbors = (i, j, k) =>