import { ORE_BEARING_MATERIALS, oreBoulderState, materialFromOreBoulderState, MATERIAL_DISPLAY_NAME, isGemstoneMaterial, WoodTier, WOOD_TIER_ORDER } from "./materialTiers.js"; import { FLOWER_COLOR_ORDER, FLOWER_COLOR_DISPLAY, flowerBlockState } from "./dyes.js"; import { HERB_ORDER, HERB_DEFINITIONS, herbDefinition } from "./herbs.js"; import { spriteImageName, defaultStateForType } from "./tileSprites.js"; import { isSeasonalStumpState, SeasonId } from "../world/season.js"; import { composeNeighborConnectState, definitionUsesMaterialNeighborConnect, definitionUsesNamedNeighborConnect, parseNeighborConnectMaskFromState } from "../world/neighborConnect.js"; import { composeDoorState, doorPaletteDisplayName, isDoorPassageOpen } from "../world/doors.js"; /** * Average sprite colour for a ground or block, including per-state colours when * states use different art. Populated from the sprite catalog at load. * Pixels with alpha <= AVERAGE_COLOR_ALPHA_THRESHOLD (16) are ignored. */ export { AVERAGE_COLOR_ALPHA_THRESHOLD, installTileAverageColors, groundAverageColor, blockAverageColor } from "../render/tileAverageColors.js"; export const GroundType = Object.freeze({ grass: 1, wood: 2, water: 3, deepWater: 4, dirt: 5, path: 6, sand: 7, lava: 8 }); export const BlockType = Object.freeze({ stoneWall: 1, torch: 2, /** @deprecated Legacy authored block; migrated into chunk `spawners[]` on load. */ spawner: 3, bank: 4, churchAltar: 5, cauldron: 6, boulder: 7, furnace: 8, anvil: 9, woodworkingBench: 10, craftingBench: 11, pineTree: 12, marketplace: 13, table: 14, flower: 15, cottonPlant: 16, spinningWheel: 17, loom: 18, tailorBench: 19, bountyOffice: 20, barber: 23, /** Folklore herbs — state is herbId (`sage`, `mint`, …); sprites in `assets/herbs/`. */ herbPlant: 24, birchTree: 21, oakTree: 22, ebonyTree: 25, lignumTree: 26, heartwoodTree: 27, elderTree: 28, leatherworkingTable: 29, doorway: 30, campfire: 31, oven: 32, fishingSpot: 33, jeweleringStation: 34, flaxPlant: 35, silkCocoon: 36, fence: 37, stoneWallThin: 38, /** Former thick smooth stone wall (39) removed — id left unused. */ smoothStoneWallThin: 40, brickWall: 41, brickWallThin: 42, woodWall: 43, woodWallThin: 44, cliff: 45, cliffThin: 46, /** Wooden door — state `${wood}-${n|s}-${open|closed}`; tall magenta-tint sprite. */ door: 47, /** Solid black tile: blocks movement, not light or ranged LoS. */ void: 48 }); export const GROUND_DEFINITIONS = Object.freeze({ [GroundType.grass]: Object.freeze({ id: GroundType.grass, key: "grass", displayName: "Grass", passable: true, wades: false, water: false, frames: 1, framesPerRow: 1, animationSpeed: 0, /** Outdoor grounds should expose summer/fall/winter (legacy `grass` ok for summer). */ outdoor: true, /** Soft-terrain edge blend when the player enables Soft terrain. */ blendable: true }), [GroundType.wood]: Object.freeze({ id: GroundType.wood, key: "wood", displayName: "Wood", passable: true, wades: false, water: false, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: false }), [GroundType.water]: Object.freeze({ id: GroundType.water, key: "water", displayName: "Water", passable: true, wades: true, water: true, frames: 1, framesPerRow: 1, animationSpeed: 0, /** Per-tile procedural caustic shader; never atlas-baked. */ proceduralWaves: true, outdoor: true }), [GroundType.deepWater]: Object.freeze({ id: GroundType.deepWater, key: "deep-water", displayName: "Deep water", passable: false, wades: false, water: true, frames: 1, framesPerRow: 1, animationSpeed: 0, proceduralWaves: true, outdoor: true }), [GroundType.dirt]: Object.freeze({ id: GroundType.dirt, key: "dirt", displayName: "Dirt", passable: true, wades: false, water: false, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: true, blendable: true }), [GroundType.path]: Object.freeze({ id: GroundType.path, key: "path", displayName: "Path", passable: true, wades: false, water: false, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: true, blendable: true, /** Running here costs half stamina; A* prefers these slightly out of combat. */ pathSurface: true }), [GroundType.sand]: Object.freeze({ id: GroundType.sand, key: "sand", displayName: "Sand", passable: true, wades: false, water: false, frames: 1, framesPerRow: 1, animationSpeed: 0, /** Same look year-round; wet edge is baked toward sand-wet beside liquid water. */ outdoor: false, blendable: true, /** Client bakes a wet shoreline toward `sand-wet` (not a placeable state). */ wetShore: true }), [GroundType.lava]: Object.freeze({ id: GroundType.lava, key: "lava", displayName: "Lava", passable: false, wades: false, water: false, lava: true, frames: 1, framesPerRow: 1, animationSpeed: 0, /** Per-tile procedural heat shader; never atlas-baked. */ proceduralWaves: true, /** Half a torch (torch is 8). */ lightRangeTiles: 4, outdoor: true }) }); function treeBlockDef (id, woodTier) { const name = MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier; return Object.freeze({ id, key: `${woodTier}-tree`, displayName: `${name} tree`, passable: false, /** Canopy: light passes but each tree tile adds +1 falloff distance. */ blocksLight: "partial", lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: true, gatherable: true, woodTier }); } export const BLOCK_DEFINITIONS = Object.freeze({ [BlockType.stoneWall]: Object.freeze({ id: BlockType.stoneWall, key: "thick-stone-wall", displayName: "Thick stone wall", passable: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, /** Building walls count as indoor (no seasonal art required). */ outdoor: false, /** Autotile via named cardinal states (`thick-stone-wall`, `thick-stone-wall-esw`, …). */ neighborConnect: true, neighborConnectNamed: true }), [BlockType.stoneWallThin]: Object.freeze({ id: BlockType.stoneWallThin, key: "thin-stone-wall", displayName: "Thin stone wall", passable: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: false, neighborConnect: true, neighborConnectNamed: true }), [BlockType.smoothStoneWallThin]: Object.freeze({ id: BlockType.smoothStoneWallThin, key: "thin-smooth-stone-wall", displayName: "Thin smooth stone wall", passable: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: false, neighborConnect: true, neighborConnectNamed: true }), [BlockType.brickWall]: Object.freeze({ id: BlockType.brickWall, key: "thick-brick-wall", displayName: "Thick brick wall", passable: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: false, neighborConnect: true, neighborConnectNamed: true }), [BlockType.brickWallThin]: Object.freeze({ id: BlockType.brickWallThin, key: "thin-brick-wall", displayName: "Thin brick wall", passable: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: false, neighborConnect: true, neighborConnectNamed: true }), [BlockType.woodWall]: Object.freeze({ id: BlockType.woodWall, key: "thick-wood-wall", displayName: "Thick wood wall", passable: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: false, /** Magenta face-lit masks `0`–`15`; catalog expands `${wood}-${mask}`. */ neighborConnect: true, neighborConnectByMaterial: true, defaultNeighborMaterial: WoodTier.pine }), [BlockType.woodWallThin]: Object.freeze({ id: BlockType.woodWallThin, key: "thin-wood-wall", displayName: "Thin wood wall", passable: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: false, neighborConnect: true, neighborConnectByMaterial: true, defaultNeighborMaterial: WoodTier.pine }), [BlockType.cliff]: Object.freeze({ id: BlockType.cliff, key: "thick-cliff", displayName: "Thick cliff", passable: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: true, neighborConnect: true, neighborConnectNamed: true, /** * Magenta top faces are replaced at draw time by a dedicated per-tile * cliff shader that samples the chunk ground atlas (1:1 UV, soft-terrain * blend included). These blocks are not baked into chunk atlas rows. */ cliffGroundTop: true }), [BlockType.cliffThin]: Object.freeze({ id: BlockType.cliffThin, key: "thin-cliff", displayName: "Thin cliff", passable: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: true, neighborConnect: true, neighborConnectNamed: true, /** @see {@link BlockType.cliff} `cliffGroundTop` */ cliffGroundTop: true }), [BlockType.torch]: Object.freeze({ id: BlockType.torch, key: "torch", displayName: "Torch", passable: true, lightRangeTiles: 8, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: false }), [BlockType.spawner]: Object.freeze({ id: BlockType.spawner, key: "spawner", displayName: "Spawner", passable: true, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, /** Not shown in the placeable block palette; use the Spawners tab. */ editorHidden: true, outdoor: false }), [BlockType.bank]: Object.freeze({ id: BlockType.bank, key: "bank", displayName: "Bank", passable: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: false }), [BlockType.churchAltar]: Object.freeze({ id: BlockType.churchAltar, key: "church-altar", displayName: "Church altar", passable: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: false }), [BlockType.cauldron]: Object.freeze({ id: BlockType.cauldron, key: "cauldron", displayName: "Cauldron", passable: false, blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: false }), [BlockType.boulder]: Object.freeze({ id: BlockType.boulder, key: "boulder", displayName: "Boulder", passable: false, blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, /** Ore states are synthesized in the sprite catalog (tinted boulder-ore). */ gatherable: true, outdoor: true }), [BlockType.furnace]: Object.freeze({ id: BlockType.furnace, key: "furnace", displayName: "Furnace", passable: false, blocksLight: false, lightRangeTiles: 4, frames: 1, framesPerRow: 1, animationSpeed: 0, craftingStationId: "furnace", outdoor: false }), [BlockType.campfire]: Object.freeze({ id: BlockType.campfire, key: "campfire", displayName: "Campfire", passable: true, blocksLight: false, blocksRangedAttacks: false, lightRangeTiles: 4, frames: 1, framesPerRow: 1, animationSpeed: 0, craftingStationId: "fireplace", /** State is wood tier id; tinted like logs. Bloom companion is fire only. */ tintFromTier: true, /** Lit/expires at runtime — per-tile draw, not chunk atlas (see chunk-delta). */ perTileBlock: true, outdoor: true }), [BlockType.oven]: Object.freeze({ id: BlockType.oven, key: "oven", displayName: "Oven", passable: false, blocksLight: false, lightRangeTiles: 2, frames: 1, framesPerRow: 1, animationSpeed: 0, craftingStationId: "oven", outdoor: false }), [BlockType.fishingSpot]: Object.freeze({ id: BlockType.fishingSpot, key: "fishing-spot", displayName: "Fishing spot", passable: true, blocksLight: false, blocksRangedAttacks: false, lightRangeTiles: 0, /** Ripple / splash strip (temp art; 3 frames). */ frames: 3, framesPerRow: 3, animationSpeed: 0.18, outdoor: true, /** Requires water / deepWater under the tile (editor + server). */ requiresWater: true }), [BlockType.anvil]: Object.freeze({ id: BlockType.anvil, key: "anvil", displayName: "Anvil", passable: false, blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, craftingStationId: "anvil", outdoor: false }), [BlockType.jeweleringStation]: Object.freeze({ id: BlockType.jeweleringStation, key: "jewelering-station", displayName: "Jewelering station", passable: false, blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, craftingStationId: "jewelering-station", outdoor: false }), [BlockType.woodworkingBench]: Object.freeze({ id: BlockType.woodworkingBench, key: "woodworking-bench", displayName: "Woodworking bench", passable: false, blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, craftingStationId: "woodworking-bench", outdoor: false }), [BlockType.craftingBench]: Object.freeze({ id: BlockType.craftingBench, key: "crafting-bench", displayName: "Crafting bench", passable: false, blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, craftingStationId: "crafting-bench", outdoor: false }), [BlockType.pineTree]: treeBlockDef(BlockType.pineTree, WoodTier.pine), [BlockType.birchTree]: treeBlockDef(BlockType.birchTree, WoodTier.birch), [BlockType.oakTree]: treeBlockDef(BlockType.oakTree, WoodTier.oak), [BlockType.ebonyTree]: treeBlockDef(BlockType.ebonyTree, WoodTier.ebony), [BlockType.lignumTree]: treeBlockDef(BlockType.lignumTree, WoodTier.lignum), [BlockType.heartwoodTree]: treeBlockDef(BlockType.heartwoodTree, WoodTier.heartwood), [BlockType.elderTree]: treeBlockDef(BlockType.elderTree, WoodTier.elder), [BlockType.marketplace]: Object.freeze({ id: BlockType.marketplace, key: "marketplace", displayName: "Central Exchange counter", passable: false, /** Furniture: blocks movement but not baked/dynamic light rays. */ blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: false, /** Autotile via N/E/S/W bitmask states `"0"`…`"15"`. */ neighborConnect: true }), [BlockType.table]: Object.freeze({ id: BlockType.table, key: "table", displayName: "Table", passable: false, blocksLight: false, blocksRangedAttacks: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: false, /** Magenta base `0`–`15` (strip-union line tables); catalog expands `${wood}-${mask}`. * Filled-rectangle corners can later add diagonal-aware sprites without replacing these. */ neighborConnect: true, neighborConnectByMaterial: true, defaultNeighborMaterial: WoodTier.pine }), [BlockType.fence]: Object.freeze({ id: BlockType.fence, key: "fence", displayName: "Fence", passable: false, blocksLight: false, blocksRangedAttacks: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: true, /** Magenta base `0`–`15`; catalog expands `${wood}-${mask}` like tables. */ neighborConnect: true, neighborConnectByMaterial: true, defaultNeighborMaterial: WoodTier.pine }), [BlockType.flower]: Object.freeze({ id: BlockType.flower, key: "flower", displayName: "Flower", passable: true, blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: true, gatherable: true, plantGather: Object.freeze({ kind: "flower", requiresClippers: false, skillId: "herbalism" }) }), [BlockType.cottonPlant]: Object.freeze({ id: BlockType.cottonPlant, key: "cotton-plant", displayName: "Cotton plant", passable: true, blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: true, gatherable: true, plantGather: Object.freeze({ kind: "cotton", requiresClippers: false, skillId: "herbalism" }) }), [BlockType.flaxPlant]: Object.freeze({ id: BlockType.flaxPlant, key: "flax-plant", displayName: "Flax plant", passable: true, blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: true, gatherable: true, plantGather: Object.freeze({ kind: "flax", requiresClippers: true, /** Linen-rank clippers or better (steel↔linen). */ minClothTier: "linen", skillId: "herbalism" }) }), [BlockType.silkCocoon]: Object.freeze({ id: BlockType.silkCocoon, key: "silk-cocoon", displayName: "Silk cocoon", passable: true, blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: true, gatherable: true, plantGather: Object.freeze({ kind: "silk", requiresClippers: true, /** Silk-rank clippers or better (adamantium↔silk). */ minClothTier: "silk", skillId: "herbalism" }) }), [BlockType.spinningWheel]: Object.freeze({ id: BlockType.spinningWheel, key: "spinning-wheel", displayName: "Spinning wheel", passable: false, blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, craftingStationId: "spinning-wheel", outdoor: false }), [BlockType.loom]: Object.freeze({ id: BlockType.loom, key: "loom", displayName: "Loom", passable: false, blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, craftingStationId: "loom", outdoor: false }), [BlockType.tailorBench]: Object.freeze({ id: BlockType.tailorBench, key: "tailor-bench", displayName: "Tailor's bench", passable: false, blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, craftingStationId: "tailor-bench", outdoor: false }), [BlockType.leatherworkingTable]: Object.freeze({ id: BlockType.leatherworkingTable, key: "leatherworking-table", displayName: "Leatherworking table", passable: false, blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, craftingStationId: "leatherworking-station", outdoor: false }), [BlockType.bountyOffice]: Object.freeze({ id: BlockType.bountyOffice, key: "bounty-office", displayName: "Bounty office", passable: false, blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: false }), [BlockType.barber]: Object.freeze({ id: BlockType.barber, key: "barber", displayName: "Barber", passable: false, blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: false }), [BlockType.doorway]: Object.freeze({ id: BlockType.doorway, key: "doorway", displayName: "Doorway", passable: true, blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: false, /** Visual variants under `blocks/doorway/`. */ doorway: true, defaultState: "door" }), [BlockType.door]: Object.freeze({ id: BlockType.door, key: "door", displayName: "Door", /** Resting by default; passage when flipped from resting (see isDoorPassageOpen). */ passable: false, /** * Light/LoS follow passage-open via {@link blockLightOcclusionForBlock} / * {@link blockBlocksRangedAttacks} — not this static flag. */ blocksLight: true, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: false, /** Wooden door — not a dimension portal (`doorway`). */ door: true, tintFromTier: true, /** Tall tinted sprite; state flips at runtime — never chunk-atlas baked. */ perTileBlock: true, defaultState: "pine-s-closed" }), [BlockType.herbPlant]: Object.freeze({ id: BlockType.herbPlant, key: "herb", displayName: "Herb", passable: true, blocksLight: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: true, gatherable: true, /** Sprites live under `assets/herbs/` (shared with items), not `blocks/herb/`. */ assetFolder: "herbs", plantGather: Object.freeze({ kind: "herb", requiresClippers: true, skillId: "herbalism" }) }), [BlockType.void]: Object.freeze({ id: BlockType.void, key: "void", displayName: "Void", passable: false, /** Movement blocker only — light and ranged LoS pass through. */ blocksLight: false, blocksRangedAttacks: false, lightRangeTiles: 0, frames: 1, framesPerRow: 1, animationSpeed: 0, outdoor: false }) }); /** Grounds and real blocks the editor may place (excludes legacy/hidden entries). */ export function listPlaceableGrounds () { return Object.values(GROUND_DEFINITIONS); } export function listPlaceableBlocks () { return Object.values(BLOCK_DEFINITIONS).filter((def) => !def.editorHidden); } /** Display name for an ore boulder state (`copper-ore` → "Copper ore boulder"). */ export function oreBoulderDisplayName (state) { const material = materialFromOreBoulderState(state); if (!material) { return null; } const label = MATERIAL_DISPLAY_NAME[material] ?? material; if (material === "coal") { return "Coal boulder"; } if (isGemstoneMaterial(material)) { return `${label} boulder`; } return `${label} ore boulder`; } /** * Hover / UI label for a gatherable resource node. * Ore boulders and chopable trees; fishing / herbs can extend this later. * Returns null when the block is not an active resource node. */ export function resourceNodeDisplayName (block) { if (!block) { return null; } if (block.typeId === BlockType.fishingSpot && block.state !== "exhausted") { return "Fishing spot"; } if (block.typeId === BlockType.boulder) { return oreBoulderDisplayName(block.state); } if (isChopableTreeBlock(block)) { const def = BLOCK_DEFINITIONS[block.typeId]; return def?.displayName ?? "Tree"; } if (block.typeId === BlockType.flower) { const color = FLOWER_COLOR_DISPLAY[block.state]; return color ? `${color} flower` : "Flower"; } if (block.typeId === BlockType.cottonPlant) { return "Cotton plant"; } if (block.typeId === BlockType.flaxPlant) { return "Flax plant"; } if (block.typeId === BlockType.silkCocoon) { return "Silk cocoon"; } if (block.typeId === BlockType.herbPlant) { const herb = herbDefinition(block.state); return herb ? herb.displayName : "Herb"; } return null; } /** Wood tier for a tree block type, or null. */ export function woodTierForTreeBlock (typeId) { const def = BLOCK_DEFINITIONS[typeId]; return def?.woodTier ?? null; } /** True when this block is a standing (non-stump) gatherable tree. */ export function isChopableTreeBlock (block) { if (!block || woodTierForTreeBlock(block.typeId) == null) { return false; } return !isSeasonalStumpState(block.state); } /** Plant gather config from block def, or null. */ export function plantGatherForBlock (block) { if (!block) { return null; } const def = BLOCK_DEFINITIONS[block.typeId]; return def?.plantGather ?? null; } export function isPickablePlantBlock (block) { return !!plantGatherForBlock(block); } /** * Blocks baked into chunk atlas rows. Gather nodes and pickables stay as per-tile * sprites so chunkDelta can hide or restyle them without rebaking the row. */ export function isChunkAtlasBakedBlock (block) { if (!block) { return false; } const entry = normalizeBlock(block); if (!entry) { return false; } const def = BLOCK_DEFINITIONS[entry.typeId]; if (!def || def.editorHidden) { return false; } if (def.perTileBlock) { return false; } if (def.door) { return false; } /** Cliff tops need a dedicated per-tile ground-sample shader, not the row atlas. */ if (def.cliffGroundTop) { return false; } if (resourceNodeDisplayName(entry)) { return false; } if (isPickablePlantBlock(entry)) { return false; } return true; } /** * Editor palette cards: one entry per placeable, with boulder expanded into * plain rock + each ore/coal variant (shared BlockType, distinct state). * Flowers are a single card; colour is rolled when painting (and on respawn). */ export function listPlaceableBlockPaletteEntries (catalog = null) { const entries = []; for (const def of listPlaceableBlocks()) { if (def.id === BlockType.boulder) { entries.push({ typeId: def.id, state: "boulder", key: def.key, displayName: "Boulder", spriteName: spriteImageName("block", def.key, "boulder") }); for (const material of ORE_BEARING_MATERIALS) { const state = oreBoulderState(material); entries.push({ typeId: def.id, state, key: def.key, displayName: oreBoulderDisplayName(state) ?? state, spriteName: spriteImageName("block", def.key, state) }); } continue; } if (def.id === BlockType.flower) { const state = flowerBlockState(FLOWER_COLOR_ORDER[0]); entries.push({ typeId: def.id, state, key: def.key, displayName: "Flower", spriteName: spriteImageName("block", def.key, state) }); continue; } if (def.id === BlockType.herbPlant) { for (const herbId of HERB_ORDER) { const herb = HERB_DEFINITIONS[herbId]; entries.push({ typeId: def.id, state: herbId, key: def.key, displayName: herb?.displayName ?? herbId, spriteName: spriteImageName("block", def.key, herbId) }); } continue; } if (def.door) { for (const material of WOOD_TIER_ORDER) { const state = composeDoorState(material, "s", false); entries.push({ typeId: def.id, state, key: def.key, displayName: doorPaletteDisplayName(state).replace(/ \(S closed\)$/u, ""), spriteName: spriteImageName("block", def.key, state) }); } continue; } if (def.neighborConnect) { if (definitionUsesMaterialNeighborConnect(def)) { for (const material of WOOD_TIER_ORDER) { const state = composeNeighborConnectState(def, material, 0); const label = MATERIAL_DISPLAY_NAME[material] ?? material; const noun = String(def.displayName ?? def.key).toLowerCase(); entries.push({ typeId: def.id, state, key: def.key, displayName: `${label} ${noun}`, spriteName: spriteImageName("block", def.key, state) }); } continue; } entries.push({ typeId: def.id, state: definitionUsesNamedNeighborConnect(def) ? def.key : "0", key: def.key, displayName: def.displayName, spriteName: spriteImageName( "block", def.key, definitionUsesNamedNeighborConnect(def) ? def.key : "0" ) }); continue; } const state = defaultStateForType(catalog, "block", def.key); entries.push({ typeId: def.id, state, key: def.key, displayName: def.displayName, spriteName: state ? spriteImageName("block", def.key, state) : spriteImageName("block", def.key, def.key) }); } return entries; } export function groundDefinition (typeId) { return GROUND_DEFINITIONS[typeId] ?? null; } export function blockDefinition (typeId) { return BLOCK_DEFINITIONS[typeId] ?? null; } export function isGroundPassable (typeId) { const def = groundDefinition(typeId); if (!def) { return true; } return def.passable !== false; } export function isWaterGround (typeId) { return !!groundDefinition(typeId)?.water; } export function isLavaGround (typeId) { return !!groundDefinition(typeId)?.lava; } /** * Ground contribution to light-ray occlusion. * Water / lava stay optically clear — only movement is blocked (lava also emits light). */ export function groundLightOcclusion (typeId) { if (isWaterGround(typeId) || isLavaGround(typeId)) { return LightOcclusion.clear; } if (!isGroundPassable(typeId)) { return LightOcclusion.solid; } return LightOcclusion.clear; } /** Authored ground-emitted light range (lava, …). */ export function groundLightRange (typeId) { return groundDefinition(typeId)?.lightRangeTiles ?? 0; } export function isWadeGround (typeId) { return !!groundDefinition(typeId)?.wades; } /** * Liquid water for foam / wade (shallow water freezes in winter and is solid ice). * Deep water stays liquid year-round. */ export function isLiquidWaterGround (typeId, seasonId = null) { if (!isWaterGround(typeId)) { return false; } if (typeId === GroundType.water && seasonId === SeasonId.winter) { return false; } return true; } /** Wade clip/foam only on liquid shallow water (not winter ice). */ export function isWadeGroundInSeason (typeId, seasonId = null) { return isWadeGround(typeId) && isLiquidWaterGround(typeId, seasonId); } /** * Neighbor continues a fluid coastline (no foam / shore peek toward it). * Missing tiles (cross-chunk pending), same fluid, and non-blendable floors * (wood, …) count as continuous — the fluid “runs under” to the quad edge. * Blendable land, ice, and other distinct fluids still get a coast. * * @param {number | null | undefined} neighborTypeId * @param {(typeId: number) => boolean} isSameFluid */ export function fluidCoastContinues (neighborTypeId, isSameFluid) { if (neighborTypeId == null) { return true; } if (typeof isSameFluid === "function" && isSameFluid(neighborTypeId)) { return true; } if (isWaterGround(neighborTypeId) || isLavaGround(neighborTypeId)) { return false; } return !GROUND_DEFINITIONS[neighborTypeId]?.blendable; } export function isBlockPassable (typeId, state = null) { if (typeId == null) { return true; } const def = blockDefinition(typeId); if (!def) { return false; } if (def.door) { /** Without config, authored state is resting → not yet held for passage. */ return isDoorPassageOpen({ typeId, state, config: null }); } return def.passable; } /** * Whether a block stops ranged attack / spell line of sight. * `blocksRangedAttacks`: explicit override; `craftingStationId` defaults to clear; * otherwise impassable blocks block and passable blocks do not. */ export function blockBlocksRangedAttacks (typeId, state = null, block = null) { if (typeId == null) { return false; } const def = blockDefinition(typeId); if (!def) { return true; } if (def.door) { const entry = block && typeof block === "object" ? block : { typeId, state, config: null }; return !isDoorPassageOpen(entry); } if (def.blocksRangedAttacks === false) { return false; } if (def.blocksRangedAttacks === true) { return true; } if (def.craftingStationId) { return false; } return def.passable === false; } /** * Light ray occlusion for a block tile. * - `clear` (0): no effect (default for passable; set `blocksLight: false` for furniture) * - `partial` (1): ray continues; each such tile adds +1 to falloff distance (2× cost) * - `solid` (2): ray stops (default for impassable; set `blocksLight: true` explicitly) */ export const LightOcclusion = Object.freeze({ clear: 0, partial: 1, solid: 2 }); /** * Resolve light occlusion for a block tile (type + visual state). * Stumps are a runtime/editor state override: no occlusion even on tree types. */ export function blockLightOcclusionForBlock (block) { if (!block) { return LightOcclusion.clear; } if (isSeasonalStumpState(block.state)) { return LightOcclusion.clear; } const def = blockDefinition(block.typeId ?? null); if (def?.door) { return isDoorPassageOpen(block) ? LightOcclusion.clear : LightOcclusion.solid; } return blockLightOcclusion(block.typeId ?? null); } /** * Resolve light occlusion for a block type id. * `blocksLight`: `true` | `false` | `"partial"`; omitted → solid iff `!passable`. * `blocksRangedAttacks`: `true` | `false`; omitted → false when `craftingStationId` is set, * otherwise blocks iff `!passable` (furniture/stations may block movement but not magic/ranged). * Prefer {@link blockLightOcclusionForBlock} when block state is known. */ export function blockLightOcclusion (typeId) { if (typeId == null) { return LightOcclusion.clear; } const def = blockDefinition(typeId); if (!def) { return LightOcclusion.solid; } if (def.blocksLight === "partial") { return LightOcclusion.partial; } if (def.blocksLight === false) { return LightOcclusion.clear; } if (def.blocksLight === true) { return LightOcclusion.solid; } return def.passable === false ? LightOcclusion.solid : LightOcclusion.clear; } /** True when a block fully stops light rays (not partial canopy). */ export function isBlockOccludingLight (typeId) { return blockLightOcclusion(typeId) === LightOcclusion.solid; } export function blockLightRange (typeId) { const def = blockDefinition(typeId); return def ? def.lightRangeTiles : 0; } export function normalizeGround (value, fallbackTypeId = GroundType.grass) { if (typeof value === "number") { return { typeId: value, state: null }; } if (value && Number.isInteger(value.typeId)) { return { typeId: value.typeId, state: value.state ?? null }; } return { typeId: fallbackTypeId, state: null }; } export function normalizeBlock (value) { if (!value || !Number.isInteger(value.typeId)) { return null; } let state = value.state ?? null; const def = BLOCK_DEFINITIONS[value.typeId]; if (def && definitionUsesNamedNeighborConnect(def) && state != null) { const mask = parseNeighborConnectMaskFromState(state, def); state = composeNeighborConnectState(def, state, mask); } return { typeId: value.typeId, state, config: value.config ?? null }; } export function setBlockVisualState (block, state) { if (!block) { return null; } block.state = state ?? null; return block; }