BlueGit

timfa questward

Files

questward / shared / definitions / tiles.js

tiles.js

Dirt, smooth terrain blend
timfa Tim Falken · pushed by timfa · 2 months ago
a40fc03d History
tiles.js 19.8 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 * Editor palette cards: one entry per placeable, with boulder expanded into
557 * plain rock + each ore/coal variant (shared BlockType, distinct state).
558 * Flowers are a single card; colour is rolled when painting (and on respawn).
559 */
560export function listPlaceableBlockPaletteEntries (catalog = null)
561{
562 const entries = [];
563 for (const def of listPlaceableBlocks())
564 {
565 if (def.id === BlockType.boulder)
566 {
567 entries.push({
568 typeId: def.id,
569 state: "boulder",
570 key: def.key,
571 displayName: "Boulder",
572 spriteName: spriteImageName("block", def.key, "boulder")
573 });
574 for (const material of ORE_BEARING_MATERIALS)
575 {
576 const state = oreBoulderState(material);
577 entries.push({
578 typeId: def.id,
579 state,
580 key: def.key,
581 displayName: oreBoulderDisplayName(state) ?? state,
582 spriteName: spriteImageName("block", def.key, state)
583 });
584 }
585 continue;
586 }
587 if (def.id === BlockType.flower)
588 {
589 const state = flowerBlockState(FLOWER_COLOR_ORDER[0]);
590 entries.push({
591 typeId: def.id,
592 state,
593 key: def.key,
594 displayName: "Flower",
595 spriteName: spriteImageName("block", def.key, state)
596 });
597 continue;
598 }
599 if (def.id === BlockType.herbPlant)
600 {
601 for (const herbId of HERB_ORDER)
602 {
603 const herb = HERB_DEFINITIONS[herbId];
604 entries.push({
605 typeId: def.id,
606 state: herbId,
607 key: def.key,
608 displayName: herb?.displayName ?? herbId,
609 spriteName: spriteImageName("block", def.key, herbId)
610 });
611 }
612 continue;
613 }
614 if (def.neighborConnect)
615 {
616 if (definitionUsesMaterialNeighborConnect(def))
617 {
618 for (const material of WOOD_TIER_ORDER)
619 {
620 const state = composeNeighborConnectState(def, material, 0);
621 const label = MATERIAL_DISPLAY_NAME[material] ?? material;
622 entries.push({
623 typeId: def.id,
624 state,
625 key: def.key,
626 displayName: `${label} table`,
627 spriteName: spriteImageName("block", def.key, state)
628 });
629 }
630 continue;
631 }
632 entries.push({
633 typeId: def.id,
634 state: "0",
635 key: def.key,
636 displayName: def.displayName,
637 spriteName: spriteImageName("block", def.key, "0")
638 });
639 continue;
640 }
641 const states = catalog?.blocks?.[def.key]?.states ?? [];
642 const state = resolveState(states, def.defaultState ?? null) ?? def.defaultState ?? null;
643 entries.push({
644 typeId: def.id,
645 state,
646 key: def.key,
647 displayName: def.displayName,
648 spriteName: state
649 ? spriteImageName("block", def.key, state)
650 : spriteImageName("block", def.key, def.key)
651 });
652 }
653 return entries;
654}
655
656export function groundDefinition (typeId)
657{
658 return GROUND_DEFINITIONS[typeId] ?? null;
659}
660
661export function blockDefinition (typeId)
662{
663 return BLOCK_DEFINITIONS[typeId] ?? null;
664}
665
666export function isGroundPassable (typeId)
667{
668 const def = groundDefinition(typeId);
669 if (!def)
670 { return true; }
671 return def.passable !== false;
672}
673
674export function isWaterGround (typeId)
675{
676 return !!groundDefinition(typeId)?.water;
677}
678
679export function isWadeGround (typeId)
680{
681 return !!groundDefinition(typeId)?.wades;
682}
683
684/**
685 * Liquid water for foam / wade (shallow water freezes in winter and is solid ice).
686 * Deep water stays liquid year-round.
687 */
688export function isLiquidWaterGround (typeId, seasonId = null)
689{
690 if (!isWaterGround(typeId))
691 { return false; }
692 if (typeId === GroundType.water && seasonId === SeasonId.winter)
693 { return false; }
694 return true;
695}
696
697/** Wade clip/foam only on liquid shallow water (not winter ice). */
698export function isWadeGroundInSeason (typeId, seasonId = null)
699{
700 return isWadeGround(typeId) && isLiquidWaterGround(typeId, seasonId);
701}
702
703export function isBlockPassable (typeId)
704{
705 if (typeId == null)
706 { return true; }
707
708 const def = blockDefinition(typeId);
709 return def ? def.passable : false;
710}
711
712/**
713 * Whether a block stops ranged attack / spell line of sight.
714 * `blocksRangedAttacks`: explicit override; `craftingStationId` defaults to clear;
715 * otherwise impassable blocks block and passable blocks do not.
716 */
717export function blockBlocksRangedAttacks (typeId)
718{
719 if (typeId == null)
720 { return false; }
721 const def = blockDefinition(typeId);
722 if (!def)
723 { return true; }
724 if (def.blocksRangedAttacks === false)
725 { return false; }
726 if (def.blocksRangedAttacks === true)
727 { return true; }
728 if (def.craftingStationId)
729 { return false; }
730 return def.passable === false;
731}
732
733/**
734 * Light ray occlusion for a block tile.
735 * - `clear` (0): no effect (default for passable; set `blocksLight: false` for furniture)
736 * - `partial` (1): ray continues; each such tile adds +1 to falloff distance (2× cost)
737 * - `solid` (2): ray stops (default for impassable; set `blocksLight: true` explicitly)
738 */
739export const LightOcclusion = Object.freeze({
740 clear: 0,
741 partial: 1,
742 solid: 2
743});
744
745/**
746 * Resolve light occlusion for a block tile (type + visual state).
747 * Stumps are a runtime/editor state override: no occlusion even on tree types.
748 */
749export function blockLightOcclusionForBlock (block)
750{
751 if (!block)
752 { return LightOcclusion.clear; }
753 if (isSeasonalStumpState(block.state))
754 { return LightOcclusion.clear; }
755 return blockLightOcclusion(block.typeId ?? null);
756}
757
758/**
759 * Resolve light occlusion for a block type id.
760 * `blocksLight`: `true` | `false` | `"partial"`; omitted → solid iff `!passable`.
761 * `blocksRangedAttacks`: `true` | `false`; omitted → false when `craftingStationId` is set,
762 * otherwise blocks iff `!passable` (furniture/stations may block movement but not magic/ranged).
763 * Prefer {@link blockLightOcclusionForBlock} when block state is known.
764 */
765export function blockLightOcclusion (typeId)
766{
767 if (typeId == null)
768 { return LightOcclusion.clear; }
769 const def = blockDefinition(typeId);
770 if (!def)
771 { return LightOcclusion.solid; }
772 if (def.blocksLight === "partial")
773 { return LightOcclusion.partial; }
774 if (def.blocksLight === false)
775 { return LightOcclusion.clear; }
776 if (def.blocksLight === true)
777 { return LightOcclusion.solid; }
778 return def.passable === false ? LightOcclusion.solid : LightOcclusion.clear;
779}
780
781/** True when a block fully stops light rays (not partial canopy). */
782export function isBlockOccludingLight (typeId)
783{
784 return blockLightOcclusion(typeId) === LightOcclusion.solid;
785}
786
787export function blockLightRange (typeId)
788{
789 const def = blockDefinition(typeId);
790 return def ? def.lightRangeTiles : 0;
791}
792
793export function normalizeGround (value, fallbackTypeId = GroundType.grass)
794{
795 if (typeof value === "number")
796 { return { typeId: value, state: null }; }
797 if (value && Number.isInteger(value.typeId))
798 { return { typeId: value.typeId, state: value.state ?? null }; }
799 return { typeId: fallbackTypeId, state: null };
800}
801
802export function normalizeBlock (value)
803{
804 if (!value || !Number.isInteger(value.typeId))
805 { return null; }
806 return { typeId: value.typeId, state: value.state ?? null, config: value.config ?? null };
807}
808
809export function setBlockVisualState (block, state)
810{
811 if (!block)
812 { return null; }
813 block.state = state ?? null;
814 return block;
815}