2D liquids: water and lava that flow only on the plane #22

Closed
opened 2026-11-07 18:28:30 +00:00 by claude · 1 comment
Member

Engine liquids flow in 3D and would leak toward the camera (z<0 is air above ground). Options: (a) put an invisible non-floodable barrier at z=−1 and z=2 wherever liquid exists, or (b) a custom cellular liquid simulation on the plane with a level in param2, like Terraria. Must also handle buckets, swimming physics for the avatar, breath and drowning, lava damage, and obsidian-style interactions. Mapgen places pools and underground lakes.

Engine liquids flow in 3D and would leak toward the camera (z<0 is air above ground). Options: (a) put an invisible non-floodable barrier at z=−1 and z=2 wherever liquid exists, or (b) a custom cellular liquid simulation on the plane with a level in param2, like Terraria. Must also handle buckets, swimming physics for the avatar, breath and drowning, lava damage, and obsidian-style interactions. Mapgen places pools and underground lakes.
claude added this to the v0.3 World & Biomes milestone 2026-11-07 18:28:30 +00:00
claude added the
priority
high
type
feature
area/worldgen
labels 2026-11-07 18:28:30 +00:00
eric added this to the Strata Roadmap project 2026-11-07 18:36:39 +00:00
eric closed this issue 2026-11-14 06:22:27 +00:00
Author
Member

Done in 3f5c0c6, using option (b): a custom cellular simulation on the plane.

What changed

  • strata_core/liquids.lua: strata.register_liquid. Water and lava are leveled nodeboxes with a level from 1 to 64 in param2 (no engine liquidtype), so nothing flows off z = 0. Each 0.15 s tick, every active cell does three things in order. It reacts with a touching liquid (lava next to water becomes Ashglass, cracky 1). It falls up to 3 rows or tops up the cell below. Then it shares its level evenly with lower neighbours on either side. Volume is conserved. Lava is viscous (it moves on every 4th tick) and glows at 12.
  • Cells wake when something is placed or dug next to them, when a neighbour changes, and through an LBM when their block loads with somewhere to flow. Code that changes plane cells with set_node should call strata.liquid_wake(pos).
  • Liquids are buildable_to, so a block placed into water displaces it.
  • Buckets: 3 iron bars at an anvil. Right-click the backdrop or wall behind a cell. Filling needs at least half a cell of liquid; pouring puts down a full cell.
  • Mapgen (mg.pool_liquid): cave cells fill with liquid where the "pool" noise is high for the whole run down to a solid floor, at most 6 rows deep, so most generated pools sit still. Water appears in the surface, underground and cavern layers (about 11% of open underground cells). Lava appears in the underworld (about 8%).
  • Swimming (strata_player/swim.lua): walking is slower and gravity lower, sinking is capped, and holding jump swims up, with a bigger hop at the surface to climb out. Landing in liquid cancels fall damage. The avatar has its own breath bar: water uses one bubble every 0.7 s, then drowning deals 20 HP/s. Lava deals 60 HP/s. The engine breath bar is hidden.

Tests: 8 new cases in tests/liquids.lua:

  • flow, settling and volume
  • spilling through a dug wall
  • ashglass
  • buckets
  • generated pools resting on a floor
  • sinking, swimming and breath
  • lava damage and breath regain

The layer tests now treat liquid as open cave and allow lava's glow. 94/94 pass locally with zero ERROR lines. The first CI run (20064) was evicted during apt install; run 20065 retests it.

Needs a check in the client: how the semi-transparent water and the lava read from the camera, how swimming feels, and where the breath bar sits.

Follow-ups: #73 (liquid sounds and effects) and #74 (creatures and dropped items in liquids).

Done in 3f5c0c6, using option (b): a custom cellular simulation on the plane. **What changed** - `strata_core/liquids.lua`: `strata.register_liquid`. Water and lava are `leveled` nodeboxes with a level from 1 to 64 in param2 (no engine liquidtype), so nothing flows off z = 0. Each 0.15 s tick, every active cell does three things in order. It reacts with a touching liquid (lava next to water becomes **Ashglass**, cracky 1). It falls up to 3 rows or tops up the cell below. Then it shares its level evenly with lower neighbours on either side. Volume is conserved. Lava is viscous (it moves on every 4th tick) and glows at 12. - Cells wake when something is placed or dug next to them, when a neighbour changes, and through an LBM when their block loads with somewhere to flow. Code that changes plane cells with `set_node` should call `strata.liquid_wake(pos)`. - Liquids are `buildable_to`, so a block placed into water displaces it. - **Buckets:** 3 iron bars at an anvil. Right-click the backdrop or wall behind a cell. Filling needs at least half a cell of liquid; pouring puts down a full cell. - **Mapgen** (`mg.pool_liquid`): cave cells fill with liquid where the "pool" noise is high for the whole run down to a solid floor, at most 6 rows deep, so most generated pools sit still. Water appears in the surface, underground and cavern layers (about 11% of open underground cells). Lava appears in the underworld (about 8%). - **Swimming** (`strata_player/swim.lua`): walking is slower and gravity lower, sinking is capped, and holding jump swims up, with a bigger hop at the surface to climb out. Landing in liquid cancels fall damage. The avatar has its own breath bar: water uses one bubble every 0.7 s, then drowning deals 20 HP/s. Lava deals 60 HP/s. The engine breath bar is hidden. **Tests:** 8 new cases in `tests/liquids.lua`: - flow, settling and volume - spilling through a dug wall - ashglass - buckets - generated pools resting on a floor - sinking, swimming and breath - lava damage and breath regain The layer tests now treat liquid as open cave and allow lava's glow. 94/94 pass locally with zero ERROR lines. The first CI run (20064) was evicted during `apt install`; run 20065 retests it. **Needs a check in the client:** how the semi-transparent water and the lava read from the camera, how swimming feels, and where the breath bar sits. **Follow-ups:** #73 (liquid sounds and effects) and #74 (creatures and dropped items in liquids).
Sign in to join this conversation.