BlueGit

timfa questward

Files

questward / shared / lighting / tilePassable.js

tilePassable.js

tilePassable.js 686 B Download Raw
1import { CHUNK_SIZE } from "../protocol/constants.js";
2import { isBlockPassable } from "../definitions/tiles.js";
3
4/** Passability from a chunk snapshot map keyed by "chunkX,chunkY". */
5export function makeSnapshotPassable (chunks)
6{
7 return (tileX, tileY) =>
8 {
9 const chunkX = Math.floor(tileX / CHUNK_SIZE);
10 const chunkY = Math.floor(tileY / CHUNK_SIZE);
11 const snapshot = chunks.get(`${chunkX},${chunkY}`);
12 if (!snapshot)
13 { return true; }
14 const localX = tileX - chunkX * CHUNK_SIZE;
15 const localY = tileY - chunkY * CHUNK_SIZE;
16 const index = localY * CHUNK_SIZE + localX;
17 const block = snapshot.blocks?.[index];
18 return isBlockPassable(block?.typeId ?? null);
19 };
20}