Files
claudeandClaude Opus 5.5 d128a0ddc6
test / test (push) Successful in 1m45s
Cavern biomes: glimmer grove, prism gallery, drowned grotto
The cavern layer gets its own biome table, picked per cell from two 2D
noises so biomes are patches in x and y. Each row names a floor cover,
floor flora, a ceiling chain, giant mushrooms, a pool threshold and a
spawn table (read by strata.spawn_candidates when given x).

- Glimmer grove: mycel turf, glowing glimmercaps (drop glowspores) and
  umbrel mushrooms that fell like trees and give wood.
- Prism gallery: glowing prism clusters on floors and roofs (drop prism
  shards, a material for later gear).
- Drowned grotto: silt floors, glowing dripvines up to 4 long and far
  more water pools.

Flora glows, can be walked through and drops when the block holding it
is dug; a hanging chain goes all at once. Glowspore + wood makes torches.
Names and art are original; df_caverns was only a reference for the idea.

Tests: 6 new cases in tests/caverns.lua (table, coverage, node_at scan,
a generated site per biome, flora support, felling, recipe and spawns);
the layer tests accept cavern biome nodes. 103/103 pass, no ERROR lines.

Closes #70

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 01:25:05 -05:00

150 lines
5.3 KiB
Lua

-- Strata cavern biomes (#70): floor covers, glowing flora and giant
-- mushrooms for the cavern layer. strata_mapgen's cavern biome table says
-- where each of them grows.
--
-- Flora is held by the block under it (floor flora) or over it (ceiling
-- flora). When that block is dug the flora drops; a hanging chain of
-- ceiling flora goes all at once. The engine's attached_node isn't used:
-- it would drop a vine that hangs from another vine on any neighbour update.
local S = strata.S
local PLANE_Z = strata.PLANE_Z
local GLIMMERCAP_LIGHT = 7
local PRISM_LIGHT = 5
local DRIPVINE_LIGHT = 3
local UMBREL_CAP_LIGHT = 6
local FLORA_FLOOR, FLORA_CEILING = 1, 2 -- values of group "flora"
--------------------------------------------------------------------------
-- Floor covers
--------------------------------------------------------------------------
core.register_node("strata_core:mycel_turf", {
description = S("Mycel Turf"),
tiles = {"strata_mycel_turf_top.png", "strata_slate.png", "strata_mycel_turf.png"},
groups = {cracky = 2, not_in_creative_inventory = 1},
drop = "strata_core:slate",
})
core.register_node("strata_core:silt", {
description = S("Silt Block"),
tiles = {"strata_silt.png"},
groups = {crumbly = 3},
})
--------------------------------------------------------------------------
-- Flora
--------------------------------------------------------------------------
core.register_craftitem("strata_core:glowspore", {
description = S("Glowspore"),
inventory_image = "strata_glowspore.png",
})
core.register_craftitem("strata_core:prism_shard", {
description = S("Prism Shard"),
inventory_image = "strata_prism_shard.png",
})
strata.flora = {}
--- Register a flora node. def.mount is "floor" or "ceiling"; the rest is
-- a node definition. Flora is a non-walkable plantlike node that glows
-- with def.light_source and drops def.drop (default: nothing).
function strata.register_flora(name, def)
local mount = def.mount == "ceiling" and FLORA_CEILING or FLORA_FLOOR
local groups = def.groups or {}
groups.flora = mount
groups.dig_immediate = groups.dig_immediate or 3
groups.not_in_creative_inventory = 1
core.register_node(name, {
description = def.description,
drawtype = "plantlike",
tiles = def.tiles,
inventory_image = def.inventory_image or def.tiles[1],
paramtype = "light",
sunlight_propagates = true,
walkable = false,
buildable_to = true,
light_source = def.light_source,
selection_box = def.selection_box or {type = "fixed",
fixed = {-0.35, -0.5, -0.35, 0.35, 0.3, 0.35}},
drop = def.drop or "",
groups = groups,
})
strata.flora[name] = mount == FLORA_CEILING and "ceiling" or "floor"
end
strata.register_flora("strata_core:glimmercap", {
description = S("Glimmercap"), mount = "floor",
tiles = {"strata_glimmercap.png"}, light_source = GLIMMERCAP_LIGHT,
drop = "strata_core:glowspore",
})
strata.register_flora("strata_core:prism_cluster", {
description = S("Prism Cluster"), mount = "floor",
tiles = {"strata_prism_cluster.png"}, light_source = PRISM_LIGHT,
drop = "strata_core:prism_shard",
})
strata.register_flora("strata_core:prism_cluster_hanging", {
description = S("Prism Cluster"), mount = "ceiling",
tiles = {"strata_prism_cluster.png^[transformFY"}, light_source = PRISM_LIGHT,
selection_box = {type = "fixed", fixed = {-0.35, -0.3, -0.35, 0.35, 0.5, 0.35}},
drop = "strata_core:prism_shard",
})
strata.register_flora("strata_core:dripvine", {
description = S("Dripvine"), mount = "ceiling",
tiles = {"strata_dripvine.png"}, light_source = DRIPVINE_LIGHT,
selection_box = {type = "fixed", fixed = {-0.25, -0.5, -0.25, 0.25, 0.5, 0.25}},
})
--- Whether the flora at pos still has something to hang from or stand on.
-- Ceiling flora may hang from more ceiling flora.
function strata.flora_held(pos, name)
local mount = strata.flora[name]
if mount == "ceiling" then
local above = core.get_node(vector.offset(pos, 0, 1, 0)).name
return strata.flora[above] == "ceiling" or strata.is_support(above)
end
return strata.is_support(core.get_node(vector.offset(pos, 0, -1, 0)).name)
end
local function drop_flora(pos, name)
core.remove_node(pos)
local drop = core.registered_nodes[name].drop
if drop and drop ~= "" then
core.add_item(pos, drop)
end
end
-- Dropping flora whose support went: the cell above a dug block, and the
-- chain hanging below it (or below dug ceiling flora).
core.register_on_dignode(function(pos)
if pos.z ~= PLANE_Z then
return
end
local up = vector.offset(pos, 0, 1, 0)
local name = core.get_node(up).name
if strata.flora[name] == "floor" and not strata.flora_held(up, name) then
drop_flora(up, name)
end
local p = vector.offset(pos, 0, -1, 0)
name = core.get_node(p).name
while strata.flora[name] == "ceiling" and not strata.flora_held(p, name) do
drop_flora(p, name)
p.y = p.y - 1
name = core.get_node(p).name
end
end)
--------------------------------------------------------------------------
-- Umbrel: a giant mushroom that grows like a tree (stalk drops wood)
--------------------------------------------------------------------------
strata.register_tree("strata_core:umbrel_stalk", {
description = S("Umbrel Stalk"), trunk_texture = "strata_umbrel_stalk.png", radius = 0.3,
leaves = "strata_core:umbrel_cap", leaves_description = S("Umbrel Cap"),
leaves_texture = "strata_umbrel_cap.png", leaves_light = UMBREL_CAP_LIGHT,
leaves_drawtype = "normal",
})