BlueGit

timfa questward

Files

questward / shared / definitions / tiles.js

tiles.js

tiles.js 20.4 KiB Download Raw
1import {
2 ORE_BEARING_MATERIALS,
3 oreBoulderState,
4 materialFromOreBoulderState,
5 MATERIAL_DISPLAY_NAME,
6 WoodTier,
7 WOOD_TIER_ORDER
8} from "./materialTiers.js";
9import {
10 FLOWER_COLOR_ORDER,
11 FLOWER_COLOR_DISPLAY,
12 flowerBlockState
13} from "./dyes.js";
14import {
15 HERB_ORDER,
16 HERB_DEFINITIONS,
17 herbDefinition
18} from "./herbs.js";
19import { spriteImageName, resolveState } from "./tileSprites.js";
20import { isSeasonalStumpState, SeasonId } from "../world/season.js";
21import {
22 composeNeighborConnectState,
23 definitionUsesMaterialNeighborConnect
24} from "../world/neighborConnect.js";
25
26export const GroundType = Object.freeze({
27 grass: 1,
28 wood: 2,
29 water: 3,
30 deepWater: 4,
31 dirt: 5
32});
33
34export const BlockType = Object.freeze({
35 stoneWall: 1,
36 torch: 2,
37 /** @deprecated Legacy authored block; migrated into chunk `spawners[]` on load. */
38 spawner: 3,
39 bank: 4,
40 churchAltar: 5,
41 cauldron: 6,
42 boulder: 7,
43 furnace: 8,
44 anvil: 9,
45 woodworkingBench: 10,
46 craftingBench: 11,
47 pineTree: 12,
48 marketplace: 13,
49 table: 14,
50 flower: 15,
51 cottonPlant: 16,
52 spinningWheel: 17,
53 loom: 18,
54 tailorBench: 19,
55 bountyOffice: 20,
56 barber: 23,
57 /** Folklore herbs — state is herbId (`sage`, `mint`, …); sprites in `assets/herbs/`. */
58 herbPlant: 24,
59 birchTree: 21,
60 oakTree: 22,
61 ebonyTree: 25,
62 lignumTree: 26,
63 heartwoodTree: 27,
64 elderTree: 28,
65 leatherworkingTable: 29,
66 doorway: 30
67});
68
69export const GROUND_DEFINITIONS = Object.freeze({
70 [GroundType.grass]: Object.freeze({
71 id: GroundType.grass,
72 key: "grass",
73 displayName: "Grass",
74 passable: true,
75 wades: false,
76 water: false,
77 frames: 1,
78 framesPerRow: 1,
79 animationSpeed: 0,
80 /** Outdoor grounds should expose summer/fall/winter (legacy `grass` ok for summer). */
81 outdoor: true,
82 /** Soft-terrain edge blend when the player enables Soft terrain. */
83 blendable: true
84 }),
85 [GroundType.wood]: Object.freeze({
86 id: GroundType.wood,
87 key: "wood",
88 displayName: "Wood",
89 passable: true,
90 wades: false,
91 water: false,
92 frames: 1,
93 framesPerRow: 1,
94 animationSpeed: 0,
95 outdoor: false
96 }),
97 [GroundType.water]: Object.freeze({
98 id: GroundType.water,
99 key: "water",
100 displayName: "Water",
101 passable: true,
102 wades: true,
103 water: true,
104 frames: 4,
105 framesPerRow: 4,
106 animationSpeed: 0.12,
107 outdoor: true
108 }),
109 [GroundType.deepWater]: Object.freeze({
110 id: GroundType.deepWater,
111 key: "deep-water",
112 displayName: "Deep water",
113 passable: false,
114 wades: false,
115 water: true,
116 frames: 4,
117 framesPerRow: 4,
118 animationSpeed: 0.12,
119 outdoor: true
120 }),
121 [GroundType.dirt]: Object.freeze({
122 id: GroundType.dirt,
123 key: "dirt",
124 displayName: "Dirt",
125 passable: true,
126 wades: false,
127 water: false,
128 frames: 1,
129 framesPerRow: 1,
130 animationSpeed: 0,
131 outdoor: true,
132 blendable: true
133 })
134});
135
136function treeBlockDef (id, woodTier)
137{
138 const name = MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier;
139 return Object.freeze({
140 id,
141 key: `${woodTier}-tree`,
142 displayName: `${name} tree`,
143 passable: false,
144 /** Canopy: light passes but each tree tile adds +1 falloff distance. */
145 blocksLight: "partial",
146 lightRangeTiles: 0,
147 frames: 1,
148 framesPerRow: 1,
149 animationSpeed: 0,
150 outdoor: true,
151 gatherable: true,
152 woodTier
153 });
154}
155
156export const BLOCK_DEFINITIONS = Object.freeze({
157 [BlockType.stoneWall]: Object.freeze({
158 id: BlockType.stoneWall,
159 key: "stone-wall",
160 displayName: "Stone wall",
161 passable: false,
162 lightRangeTiles: 0,
163 frames: 1,
164 framesPerRow: 1,
165 animationSpeed: 0,
166 /** Building walls count as indoor (no seasonal art required). */
167 outdoor: false
168 }),
169 [BlockType.torch]: Object.freeze({
170 id: BlockType.torch,
171 key: "torch",
172 displayName: "Torch",
173 passable: true,
174 lightRangeTiles: 8,
175 frames: 1,
176 framesPerRow: 1,
177 animationSpeed: 0,
178 outdoor: false
179 }),
180 [BlockType.spawner]: Object.freeze({
181 id: BlockType.spawner,
182 key: "spawner",
183 displayName: "Spawner",
184 passable: true,
185 lightRangeTiles: 0,
186 frames: 1,
187 framesPerRow: 1,
188 animationSpeed: 0,
189 /** Not shown in the placeable block palette; use the Spawners tab. */
190 editorHidden: true,
191 outdoor: false
192 }),
193 [BlockType.bank]: Object.freeze({
194 id: BlockType.bank,
195 key: "bank",
196 displayName: "Bank",
197 passable: false,
198 lightRangeTiles: 0,
199 frames: 1,
200 framesPerRow: 1,
201 animationSpeed: 0,
202 outdoor: false
203 }),
204 [BlockType.churchAltar]: Object.freeze({
205 id: BlockType.churchAltar,
206 key: "church-altar",
207 displayName: "Church altar",
208 passable: false,
209 lightRangeTiles: 0,
210 frames: 1,
211 framesPerRow: 1,
212 animationSpeed: 0,
213 outdoor: false
214 }),
215 [BlockType.cauldron]: Object.freeze({
216 id: BlockType.cauldron,
217 key: "cauldron",
218 displayName: "Cauldron",
219 passable: false,
220 blocksLight: false,
221 lightRangeTiles: 0,
222 frames: 1,
223 framesPerRow: 1,
224 animationSpeed: 0,
225 outdoor: false
226 }),
227 [BlockType.boulder]: Object.freeze({
228 id: BlockType.boulder,
229 key: "boulder",
230 displayName: "Boulder",
231 passable: false,
232 blocksLight: false,
233 lightRangeTiles: 0,
234 frames: 1,
235 framesPerRow: 1,
236 animationSpeed: 0,
237 /** Ore states are synthesized in the sprite catalog (tinted boulder-ore). */
238 gatherable: true,
239 outdoor: true
240 }),
241 [BlockType.furnace]: Object.freeze({
242 id: BlockType.furnace,
243 key: "furnace",
244 displayName: "Furnace",
245 passable: false,
246 blocksLight: false,
247 lightRangeTiles: 4,
248 frames: 1,
249 framesPerRow: 1,
250 animationSpeed: 0,
251 craftingStationId: "furnace",
252 outdoor: false
253 }),
254 [BlockType.anvil]: Object.freeze({
255 id: BlockType.anvil,
256 key: "anvil",
257 displayName: "Anvil",
258 passable: false,
259 blocksLight: false,
260 lightRangeTiles: 0,
261 frames: 1,
262 framesPerRow: 1,
263 animationSpeed: 0,
264 craftingStationId: "anvil",
265 outdoor: false
266 }),
267 [BlockType.woodworkingBench]: Object.freeze({
268 id: BlockType.woodworkingBench,
269 key: "woodworking-bench",
270 displayName: "Woodworking bench",
271 passable: false,
272 blocksLight: false,
273 lightRangeTiles: 0,
274 frames: 1,
275 framesPerRow: 1,
276 animationSpeed: 0,
277 craftingStationId: "woodworking-bench",
278 outdoor: false
279 }),
280 [BlockType.craftingBench]: Object.freeze({
281 id: BlockType.craftingBench,
282 key: "crafting-bench",
283 displayName: "Crafting bench",
284 passable: false,
285 blocksLight: false,
286 lightRangeTiles: 0,
287 frames: 1,
288 framesPerRow: 1,
289 animationSpeed: 0,
290 craftingStationId: "crafting-bench",
291 outdoor: false
292 }),
293 [BlockType.pineTree]: treeBlockDef(BlockType.pineTree, WoodTier.pine),
294 [BlockType.birchTree]: treeBlockDef(BlockType.birchTree, WoodTier.birch),
295 [BlockType.oakTree]: treeBlockDef(BlockType.oakTree, WoodTier.oak),
296 [BlockType.ebonyTree]: treeBlockDef(BlockType.ebonyTree, WoodTier.ebony),
297 [BlockType.lignumTree]: treeBlockDef(BlockType.lignumTree, WoodTier.lignum),
298 [BlockType.heartwoodTree]: treeBlockDef(BlockType.heartwoodTree, WoodTier.heartwood),
299 [BlockType.elderTree]: treeBlockDef(BlockType.elderTree, WoodTier.elder),
300 [BlockType.marketplace]: Object.freeze({
301 id: BlockType.marketplace,
302 key: "marketplace",
303 displayName: "Central Exchange counter",
304 passable: false,
305 /** Furniture: blocks movement but not baked/dynamic light rays. */
306 blocksLight: false,
307 lightRangeTiles: 0,
308 frames: 1,
309 framesPerRow: 1,
310 animationSpeed: 0,
311 outdoor: false,
312 /** Autotile via N/E/S/W bitmask states `"0"`…`"15"`. */
313 neighborConnect: true
314 }),
315 [BlockType.table]: Object.freeze({
316 id: BlockType.table,
317 key: "table",
318 displayName: "Table",
319 passable: false,
320 blocksLight: false,
321 blocksRangedAttacks: false,
322 lightRangeTiles: 0,
323 frames: 1,
324 framesPerRow: 1,
325 animationSpeed: 0,
326 outdoor: false,
327 /** Magenta base `0`–`15` (strip-union line tables); catalog expands `${wood}-${mask}`.
328 * Filled-rectangle corners can later add diagonal-aware sprites without replacing these. */
329 neighborConnect: true,
330 neighborConnectByMaterial: true,
331 defaultNeighborMaterial: WoodTier.pine
332 }),
333 [BlockType.flower]: Object.freeze({
334 id: BlockType.flower,
335 key: "flower",
336 displayName: "Flower",
337 passable: true,
338 blocksLight: false,
339 lightRangeTiles: 0,
340 frames: 1,
341 framesPerRow: 1,
342 animationSpeed: 0,
343 outdoor: true,
344 gatherable: true,
345 plantGather: Object.freeze({ kind: "flower", requiresClippers: false, skillId: "herbalism" })
346 }),
347 [BlockType.cottonPlant]: Object.freeze({
348 id: BlockType.cottonPlant,
349 key: "cotton-plant",
350 displayName: "Cotton plant",
351 passable: true,
352 blocksLight: false,
353 lightRangeTiles: 0,
354 frames: 1,
355 framesPerRow: 1,
356 animationSpeed: 0,
357 outdoor: true,
358 gatherable: true,
359 plantGather: Object.freeze({ kind: "cotton", requiresClippers: false, skillId: "herbalism" })
360 }),
361 [BlockType.spinningWheel]: Object.freeze({
362 id: BlockType.spinningWheel,
363 key: "spinning-wheel",
364 displayName: "Spinning wheel",
365 passable: false,
366 blocksLight: false,
367 lightRangeTiles: 0,
368 frames: 1,
369 framesPerRow: 1,
370 animationSpeed: 0,
371 craftingStationId: "spinning-wheel",
372 outdoor: false
373 }),
374 [BlockType.loom]: Object.freeze({
375 id: BlockType.loom,
376 key: "loom",
377 displayName: "Loom",
378 passable: false,
379 blocksLight: false,
380 lightRangeTiles: 0,
381 frames: 1,
382 framesPerRow: 1,
383 animationSpeed: 0,
384 craftingStationId: "loom",
385 outdoor: false
386 }),
387 [BlockType.tailorBench]: Object.freeze({
388 id: BlockType.tailorBench,
389 key: "tailor-bench",
390 displayName: "Tailor's bench",
391 passable: false,
392 blocksLight: false,
393 lightRangeTiles: 0,
394 frames: 1,
395 framesPerRow: 1,
396 animationSpeed: 0,
397 craftingStationId: "tailor-bench",
398 outdoor: false
399 }),
400 [BlockType.leatherworkingTable]: Object.freeze({
401 id: BlockType.leatherworkingTable,
402 key: "leatherworking-table",
403 displayName: "Leatherworking table",
404 passable: false,
405 blocksLight: false,
406 lightRangeTiles: 0,
407 frames: 1,
408 framesPerRow: 1,
409 animationSpeed: 0,
410 craftingStationId: "leatherworking-station",
411 outdoor: false
412 }),
413 [BlockType.bountyOffice]: Object.freeze({
414 id: BlockType.bountyOffice,
415 key: "bounty-office",
416 displayName: "Bounty office",
417 passable: false,
418 blocksLight: false,
419 lightRangeTiles: 0,
420 frames: 1,
421 framesPerRow: 1,
422 animationSpeed: 0,
423 outdoor: false
424 }),
425 [BlockType.barber]: Object.freeze({
426 id: BlockType.barber,
427 key: "barber",
428 displayName: "Barber",
429 passable: false,
430 blocksLight: false,
431 lightRangeTiles: 0,
432 frames: 1,
433 framesPerRow: 1,
434 animationSpeed: 0,
435 outdoor: false
436 }),
437 [BlockType.doorway]: Object.freeze({
438 id: BlockType.doorway,
439 key: "doorway",
440 displayName: "Doorway",
441 passable: true,
442 blocksLight: false,
443 lightRangeTiles: 0,
444 frames: 1,
445 framesPerRow: 1,
446 animationSpeed: 0,
447 outdoor: false,
448 /** Visual variants under `blocks/doorway/`. */
449 doorway: true,
450 defaultState: "door"
451 }),
452 [BlockType.herbPlant]: Object.freeze({
453 id: BlockType.herbPlant,
454 key: "herb",
455 displayName: "Herb",
456 passable: true,
457 blocksLight: false,
458 lightRangeTiles: 0,
459 frames: 1,
460 framesPerRow: 1,
461 animationSpeed: 0,
462 outdoor: true,
463 gatherable: true,
464 /** Sprites live under `assets/herbs/` (shared with items), not `blocks/herb/`. */
465 assetFolder: "herbs",
466 plantGather: Object.freeze({
467 kind: "herb",
468 requiresClippers: true,
469 skillId: "herbalism"
470 })
471 })
472});
473
474/** Grounds and real blocks the editor may place (excludes legacy/hidden entries). */
475export function listPlaceableGrounds ()
476{
477 return Object.values(GROUND_DEFINITIONS);
478}
479
480export function listPlaceableBlocks ()
481{
482 return Object.values(BLOCK_DEFINITIONS).filter((def) => !def.editorHidden);
483}
484
485/** Display name for an ore boulder state (`copper-ore` → "Copper ore boulder"). */
486export function oreBoulderDisplayName (state)
487{
488 const material = materialFromOreBoulderState(state);
489 if (!material)
490 { return null; }
491 const label = MATERIAL_DISPLAY_NAME[material] ?? material;
492 return material === "coal" ? "Coal boulder" : `${label} ore boulder`;
493}
494
495/**
496 * Hover / UI label for a gatherable resource node.
497 * Ore boulders and chopable trees; fishing / herbs can extend this later.
498 * Returns null when the block is not an active resource node.
499 */
500export function resourceNodeDisplayName (block)
501{
502 if (!block)
503 { return null; }
504 if (block.typeId === BlockType.boulder)
505 { return oreBoulderDisplayName(block.state); }
506 if (isChopableTreeBlock(block))
507 {
508 const def = BLOCK_DEFINITIONS[block.typeId];
509 return def?.displayName ?? "Tree";
510 }
511 if (block.typeId === BlockType.flower)
512 {
513 const color = FLOWER_COLOR_DISPLAY[block.state];
514 return color ? `${color} flower` : "Flower";
515 }
516 if (block.typeId === BlockType.cottonPlant)
517 { return "Cotton plant"; }
518 if (block.typeId === BlockType.herbPlant)
519 {
520 const herb = herbDefinition(block.state);
521 return herb ? herb.displayName : "Herb";
522 }
523 return null;
524}
525
526/** Wood tier for a tree block type, or null. */
527export function woodTierForTreeBlock (typeId)
528{
529 const def = BLOCK_DEFINITIONS[typeId];
530 return def?.woodTier ?? null;
531}
532
533/** True when this block is a standing (non-stump) gatherable tree. */
534export function isChopableTreeBlock (block)
535{
536 if (!block || woodTierForTreeBlock(block.typeId) == null)
537 { return false; }
538 return !isSeasonalStumpState(block.state);
539}
540
541/** Plant gather config from block def, or null. */
542export function plantGatherForBlock (block)
543{
544 if (!block)
545 { return null; }
546 const def = BLOCK_DEFINITIONS[block.typeId];
547 return def?.plantGather ?? null;
548}
549
550export function isPickablePlantBlock (block)
551{
552 return !!plantGatherForBlock(block);
553}
554
555/**
556 * Blocks baked into chunk atlas rows. Gather nodes and pickables stay as per-tile
557 * sprites so chunkDelta can hide or restyle them without rebaking the row.
558 */
559export function isChunkAtlasBakedBlock (block)
560{
561 if (!block)
562 { return false; }
563 const entry = normalizeBlock(block);
564 if (!entry)
565 { return false; }
566 const def = BLOCK_DEFINITIONS[entry.typeId];
567 if (!def || def.editorHidden)
568 { return false; }
569 if (resourceNodeDisplayName(entry))
570 { return false; }
571 if (isPickablePlantBlock(entry))
572 { return false; }
573 return true;
574}
575
576/**
577 * Editor palette cards: one entry per placeable, with boulder expanded into
578 * plain rock + each ore/coal variant (shared BlockType, distinct state).
579 * Flowers are a single card; colour is rolled when painting (and on respawn).
580 */
581export function listPlaceableBlockPaletteEntries (catalog = null)
582{
583 const entries = [];
584 for (const def of listPlaceableBlocks())
585 {
586 if (def.id === BlockType.boulder)
587 {
588 entries.push({
589 typeId: def.id,
590 state: "boulder",
591 key: def.key,
592 displayName: "Boulder",
593 spriteName: spriteImageName("block", def.key, "boulder")
594 });
595 for (const material of ORE_BEARING_MATERIALS)
596 {
597 const state = oreBoulderState(material);
598 entries.push({
599 typeId: def.id,
600 state,
601 key: def.key,
602 displayName: oreBoulderDisplayName(state) ?? state,
603 spriteName: spriteImageName("block", def.key, state)
604 });
605 }
606 continue;
607 }
608 if (def.id === BlockType.flower)
609 {
610 const state = flowerBlockState(FLOWER_COLOR_ORDER[0]);
611 entries.push({
612 typeId: def.id,
613 state,
614 key: def.key,
615 displayName: "Flower",
616 spriteName: spriteImageName("block", def.key, state)
617 });
618 continue;
619 }
620 if (def.id === BlockType.herbPlant)
621 {
622 for (const herbId of HERB_ORDER)
623 {
624 const herb = HERB_DEFINITIONS[herbId];
625 entries.push({
626 typeId: def.id,
627 state: herbId,
628 key: def.key,
629 displayName: herb?.displayName ?? herbId,
630 spriteName: spriteImageName("block", def.key, herbId)
631 });
632 }
633 continue;
634 }
635 if (def.neighborConnect)
636 {
637 if (definitionUsesMaterialNeighborConnect(def))
638 {
639 for (const material of WOOD_TIER_ORDER)
640 {
641 const state = composeNeighborConnectState(def, material, 0);
642 const label = MATERIAL_DISPLAY_NAME[material] ?? material;
643 entries.push({
644 typeId: def.id,
645 state,
646 key: def.key,
647 displayName: `${label} table`,
648 spriteName: spriteImageName("block", def.key, state)
649 });
650 }
651 continue;
652 }
653 entries.push({
654 typeId: def.id,
655 state: "0",
656 key: def.key,
657 displayName: def.displayName,
658 spriteName: spriteImageName("block", def.key, "0")
659 });
660 continue;
661 }
662 const states = catalog?.blocks?.[def.key]?.states ?? [];
663 const state = resolveState(states, def.defaultState ?? null) ?? def.defaultState ?? null;
664 entries.push({
665 typeId: def.id,
666 state,
667 key: def.key,
668 displayName: def.displayName,
669 spriteName: state
670 ? spriteImageName("block", def.key, state)
671 : spriteImageName("block", def.key, def.key)
672 });
673 }
674 return entries;
675}
676
677export function groundDefinition (typeId)
678{
679 return GROUND_DEFINITIONS[typeId] ?? null;
680}
681
682export function blockDefinition (typeId)
683{
684 return BLOCK_DEFINITIONS[typeId] ?? null;
685}
686
687export function isGroundPassable (typeId)
688{
689 const def = groundDefinition(typeId);
690 if (!def)
691 { return true; }
692 return def.passable !== false;
693}
694
695export function isWaterGround (typeId)
696{
697 return !!groundDefinition(typeId)?.water;
698}
699
700export function isWadeGround (typeId)
701{
702 return !!groundDefinition(typeId)?.wades;
703}
704
705/**
706 * Liquid water for foam / wade (shallow water freezes in winter and is solid ice).
707 * Deep water stays liquid year-round.
708 */
709export function isLiquidWaterGround (typeId, seasonId = null)
710{
711 if (!isWaterGround(typeId))
712 { return false; }
713 if (typeId === GroundType.water && seasonId === SeasonId.winter)
714 { return false; }
715 return true;
716}
717
718/** Wade clip/foam only on liquid shallow water (not winter ice). */
719export function isWadeGroundInSeason (typeId, seasonId = null)
720{
721 return isWadeGround(typeId) && isLiquidWaterGround(typeId, seasonId);
722}
723
724export function isBlockPassable (typeId)
725{
726 if (typeId == null)
727 { return true; }
728
729 const def = blockDefinition(typeId);
730 return def ? def.passable : false;
731}
732
733/**
734 * Whether a block stops ranged attack / spell line of sight.
735 * `blocksRangedAttacks`: explicit override; `craftingStationId` defaults to clear;
736 * otherwise impassable blocks block and passable blocks do not.
737 */
738export function blockBlocksRangedAttacks (typeId)
739{
740 if (typeId == null)
741 { return false; }
742 const def = blockDefinition(typeId);
743 if (!def)
744 { return true; }
745 if (def.blocksRangedAttacks === false)
746 { return false; }
747 if (def.blocksRangedAttacks === true)
748 { return true; }
749 if (def.craftingStationId)
750 { return false; }
751 return def.passable === false;
752}
753
754/**
755 * Light ray occlusion for a block tile.
756 * - `clear` (0): no effect (default for passable; set `blocksLight: false` for furniture)
757 * - `partial` (1): ray continues; each such tile adds +1 to falloff distance (2× cost)
758 * - `solid` (2): ray stops (default for impassable; set `blocksLight: true` explicitly)
759 */
760export const LightOcclusion = Object.freeze({
761 clear: 0,
762 partial: 1,
763 solid: 2
764});
765
766/**
767 * Resolve light occlusion for a block tile (type + visual state).
768 * Stumps are a runtime/editor state override: no occlusion even on tree types.
769 */
770export function blockLightOcclusionForBlock (block)
771{
772 if (!block)
773 { return LightOcclusion.clear; }
774 if (isSeasonalStumpState(block.state))
775 { return LightOcclusion.clear; }
776 return blockLightOcclusion(block.typeId ?? null);
777}
778
779/**
780 * Resolve light occlusion for a block type id.
781 * `blocksLight`: `true` | `false` | `"partial"`; omitted → solid iff `!passable`.
782 * `blocksRangedAttacks`: `true` | `false`; omitted → false when `craftingStationId` is set,
783 * otherwise blocks iff `!passable` (furniture/stations may block movement but not magic/ranged).
784 * Prefer {@link blockLightOcclusionForBlock} when block state is known.
785 */
786export function blockLightOcclusion (typeId)
787{
788 if (typeId == null)
789 { return LightOcclusion.clear; }
790 const def = blockDefinition(typeId);
791 if (!def)
792 { return LightOcclusion.solid; }
793 if (def.blocksLight === "partial")
794 { return LightOcclusion.partial; }
795 if (def.blocksLight === false)
796 { return LightOcclusion.clear; }
797 if (def.blocksLight === true)
798 { return LightOcclusion.solid; }
799 return def.passable === false ? LightOcclusion.solid : LightOcclusion.clear;
800}
801
802/** True when a block fully stops light rays (not partial canopy). */
803export function isBlockOccludingLight (typeId)
804{
805 return blockLightOcclusion(typeId) === LightOcclusion.solid;
806}
807
808export function blockLightRange (typeId)
809{
810 const def = blockDefinition(typeId);
811 return def ? def.lightRangeTiles : 0;
812}
813
814export function normalizeGround (value, fallbackTypeId = GroundType.grass)
815{
816 if (typeof value === "number")
817 { return { typeId: value, state: null }; }
818 if (value && Number.isInteger(value.typeId))
819 { return { typeId: value.typeId, state: value.state ?? null }; }
820 return { typeId: fallbackTypeId, state: null };
821}
822
823export function normalizeBlock (value)
824{
825 if (!value || !Number.isInteger(value.typeId))
826 { return null; }
827 return { typeId: value.typeId, state: value.state ?? null, config: value.config ?? null };
828}
829
830export function setBlockVisualState (block, state)
831{
832 if (!block)
833 { return null; }
834 block.state = state ?? null;
835 return block;
836}