import { CHUNK_SIZE } from "../protocol/constants.js"; import { isBlockOccludingLight, isGroundPassable, normalizeGround } from "../definitions/tiles.js"; /** * Light-ray clearance from a chunk snapshot map keyed by "chunkX,chunkY". * Uses {@link isBlockOccludingLight} (not movement passability), so furniture * with `blocksLight: false` does not cast night shade shadows. */ export function makeSnapshotPassable (chunks) { return (tileX, tileY) => { const chunkX = Math.floor(tileX / CHUNK_SIZE); const chunkY = Math.floor(tileY / CHUNK_SIZE); const snapshot = chunks.get(`${chunkX},${chunkY}`); if (!snapshot) { return true; } const localX = tileX - chunkX * CHUNK_SIZE; const localY = tileY - chunkY * CHUNK_SIZE; const index = localY * CHUNK_SIZE + localX; const ground = normalizeGround(snapshot.grounds?.[index]); if (!isGroundPassable(ground.typeId)) { return false; } const block = snapshot.blocks?.[index]; return !isBlockOccludingLight(block?.typeId ?? null); }; }