Files
claudeandClaude Opus 5.5 779fbe8c30
test / test (push) Successful in 1m59s
Underworld: ash floors and pockets, a lava sea, emberite ore
- Layer rows can name a floor cover, soft pockets and a sea row. The
  underworld uses ash for both, and every cave cell at or below
  WORLD_BOTTOM + 28 is lava: a sea that is held in on every side, so it
  doesn't flow when woken.
- Emberite ore in basalt (about 1.5% of the layer): glows, group
  level 4, so no current pickaxe (maxlevel 3) digs it. It waits for the
  top pre-hard-mode pickaxe in v0.5.
- Ruined towers move to the structure framework (#24).

Tests: 3 new cases in tests/underworld.lua (emberite tool gate, the lava
sea, ash floors/pockets and ore share); the layer tests accept the
underworld's ash. 109/109 pass, no ERROR lines.

Closes #25

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

532 lines
17 KiB
Lua

-- Strata core: shared constants, terrain nodes, items and tools.
--
-- The world is played on a single vertical plane (z = PLANE_Z) viewed from
-- the side. The layer directly behind it (z = WALL_Z) holds background walls,
-- Terraria-style. Everything else along z is scenery or invisible helpers.
strata = rawget(_G, "strata") or {}
strata.PLANE_Z = 0 -- gameplay plane: blocks, players, mobs
strata.WALL_Z = 1 -- background wall layer
-- The camera sits CAMERA_DIST in front of the plane. Distance and FOV are
-- one pair: the FOV is derived so the plane shows VIEW_HEIGHT nodes from top
-- to bottom whatever the distance. Further back means the view turns less
-- to aim at the edge of reach, and less perspective distortion (#71).
local CAMERA_DIST_DEFAULT = 44
local CAMERA_DIST_MIN, CAMERA_DIST_MAX = 16, 80
strata.VIEW_HEIGHT = 21.5
strata.CAMERA_DIST = math.floor(math.max(CAMERA_DIST_MIN, math.min(CAMERA_DIST_MAX,
tonumber(core.settings:get("strata_camera_distance")) or CAMERA_DIST_DEFAULT)))
strata.CAMERA_FOV = 2 * math.deg(math.atan(strata.VIEW_HEIGHT / 2 / strata.CAMERA_DIST))
strata.REACH = 5.5 -- how far (nodes) a player can dig/place from their avatar
strata.POINT_RANGE = strata.CAMERA_DIST + 8 -- item pointing range (from camera)
local S = core.get_translator("strata_core")
strata.S = S
dofile(core.get_modpath("strata_core") .. "/feedback.lua")
-- Overwritten by strata_player; returns the avatar position of a player.
function strata.get_avatar_pos(name)
return nil
end
--------------------------------------------------------------------------
-- Helper nodes
--------------------------------------------------------------------------
-- Invisible, light-dimming filler placed in front of / behind underground
-- parts of the plane so that sunlight fades with depth.
core.register_node("strata_core:shadow", {
description = "Shadow (internal)",
drawtype = "airlike",
paramtype = "light",
sunlight_propagates = false,
walkable = false,
pointable = false,
diggable = false,
buildable_to = false,
drop = "",
groups = {not_in_creative_inventory = 1},
})
-- Invisible but pointable backdrop at z = WALL_Z where there is no wall.
-- It gives the crosshair something to hit so blocks can be placed in "empty"
-- cells of the plane (pointed_thing.above lands on z = PLANE_Z).
core.register_node("strata_core:backdrop", {
description = "Backdrop (internal)",
drawtype = "airlike",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
pointable = true,
diggable = false,
buildable_to = false,
drop = "",
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, -0.49},
},
groups = {not_in_creative_inventory = 1},
})
--------------------------------------------------------------------------
-- Terrain
--------------------------------------------------------------------------
core.register_node("strata_core:dirt", {
description = S("Dirt Block"),
tiles = {"strata_dirt.png"},
groups = {crumbly = 3, soil = 1},
})
core.register_node("strata_core:grass", {
description = S("Grass Block"),
tiles = {"strata_grass_top.png", "strata_dirt.png", "strata_grass.png"},
groups = {crumbly = 3, soil = 1, not_in_creative_inventory = 1},
drop = "strata_core:dirt",
})
core.register_node("strata_core:stone", {
description = S("Stone Block"),
tiles = {"strata_stone.png"},
groups = {cracky = 3},
})
core.register_node("strata_core:sand", {
description = S("Sand Block"),
tiles = {"strata_sand.png"},
groups = {crumbly = 3, falling_node = 1},
})
core.register_node("strata_core:copper_ore", {
description = S("Copper Ore"),
tiles = {"strata_copper_ore.png"},
groups = {cracky = 3, ore = 1},
})
core.register_node("strata_core:iron_ore", {
description = S("Iron Ore"),
tiles = {"strata_iron_ore.png"},
groups = {cracky = 2, ore = 1},
})
-- Deeper layers (see strata_mapgen). Harder stone needs a better pickaxe.
core.register_node("strata_core:slate", {
description = S("Slate Block"),
tiles = {"strata_slate.png"},
groups = {cracky = 2},
})
core.register_node("strata_core:basalt", {
description = S("Basalt Block"),
tiles = {"strata_basalt.png"},
groups = {cracky = 1},
})
-- Ore veins in slate drop the same ore as the ones in stone.
core.register_node("strata_core:slate_copper_ore", {
description = S("Copper Ore"),
tiles = {"strata_slate_copper_ore.png"},
groups = {cracky = 2, ore = 1, not_in_creative_inventory = 1},
drop = "strata_core:copper_ore",
})
core.register_node("strata_core:slate_iron_ore", {
description = S("Iron Ore"),
tiles = {"strata_slate_iron_ore.png"},
groups = {cracky = 2, ore = 1, not_in_creative_inventory = 1},
drop = "strata_core:iron_ore",
})
-- The side edges of a finite world (#23): an invisible wall nothing digs.
core.register_node("strata_core:world_edge", {
description = "World Edge (internal)",
drawtype = "airlike",
paramtype = "light",
sunlight_propagates = true,
walkable = true,
pointable = false,
diggable = false,
buildable_to = false,
drop = "",
groups = {unbreakable = 1, not_in_creative_inventory = 1},
on_blast = function() end,
})
-- Underworld (#25). Emberite has group level 4: every pickaxe so far has
-- maxlevel 3, so it waits for the top pre-hard-mode pickaxe (v0.5).
core.register_node("strata_core:ash", {
description = S("Ash Block"),
tiles = {"strata_ash.png"},
groups = {crumbly = 3},
})
core.register_node("strata_core:emberite_ore", {
description = S("Emberite Ore"),
tiles = {"strata_emberite_ore.png"},
paramtype = "light",
light_source = 4,
groups = {cracky = 1, level = 4, ore = 1},
})
-- The floor of the world. Nothing digs it.
core.register_node("strata_core:bedrock", {
description = S("Bedrock"),
tiles = {"strata_bedrock.png"},
groups = {unbreakable = 1, not_in_creative_inventory = 1},
diggable = false,
drop = "",
on_blast = function() end,
})
core.register_node("strata_core:wood", {
description = S("Wood"),
tiles = {"strata_wood.png"},
groups = {choppy = 3, wood = 1},
})
-- Biome blocks (see strata_mapgen's biome table).
core.register_node("strata_core:snow", {
description = S("Snow Block"),
tiles = {"strata_snow.png"},
groups = {crumbly = 3},
})
core.register_node("strata_core:ice", {
description = S("Ice Block"),
tiles = {"strata_ice.png"},
groups = {cracky = 3, slippery = 3},
})
core.register_node("strata_core:sandstone", {
description = S("Sandstone Block"),
tiles = {"strata_sandstone.png"},
groups = {cracky = 3},
})
core.register_node("strata_core:mud", {
description = S("Mud Block"),
tiles = {"strata_mud.png"},
groups = {crumbly = 3, soil = 1},
})
core.register_node("strata_core:jungle_grass", {
description = S("Jungle Grass Block"),
tiles = {"strata_jungle_grass_top.png", "strata_mud.png", "strata_jungle_grass.png"},
groups = {crumbly = 3, soil = 1, not_in_creative_inventory = 1},
drop = "strata_core:mud",
})
-- Trees can be walked through, like in Terraria. Chopping any trunk node
-- fells everything above it, and the canopy around the top goes with it.
-- Each kind registers a trunk ("<name>") and its leaves ("<leaves>"); the
-- trunk's _strata_leaves and _strata_canopy say what to clear and how far.
-- Optional: def.drop (default wood), def.canopy, def.leaves_light and
-- def.leaves_drawtype (giant mushrooms in caverns.lua use them).
function strata.register_tree(name, def)
core.register_node(name, {
description = def.description,
tiles = {def.trunk_texture},
drawtype = "nodebox",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
node_box = {type = "fixed", fixed = {-def.radius, -0.5, -def.radius, def.radius, 0.5, def.radius}},
groups = {choppy = 2, tree = 1, not_in_creative_inventory = 1},
drop = def.drop or "strata_core:wood",
_strata_leaves = def.leaves,
_strata_canopy = def.canopy or 3,
after_dig_node = function(pos, oldnode, oldmeta, digger)
strata.fell_tree(pos, digger, oldnode.name)
end,
})
core.register_node(def.leaves, {
description = def.leaves_description,
tiles = {def.leaves_texture},
drawtype = def.leaves_drawtype or "allfaces_optional",
paramtype = "light",
sunlight_propagates = true,
light_source = def.leaves_light,
walkable = false,
drop = "",
groups = {choppy = 3, leaves = 1, not_in_creative_inventory = 1},
})
end
strata.register_tree("strata_core:tree", {
description = S("Tree Trunk"), trunk_texture = "strata_tree.png", radius = 0.35,
leaves = "strata_core:leaves", leaves_description = S("Leaves"),
leaves_texture = "strata_leaves.png",
})
strata.register_tree("strata_core:frostpine_tree", {
description = S("Frostpine Trunk"), trunk_texture = "strata_frostpine_tree.png", radius = 0.3,
leaves = "strata_core:frostpine_needles", leaves_description = S("Frostpine Needles"),
leaves_texture = "strata_frostpine_needles.png",
})
strata.register_tree("strata_core:redheart_tree", {
description = S("Redheart Trunk"), trunk_texture = "strata_redheart_tree.png", radius = 0.42,
leaves = "strata_core:redheart_leaves", leaves_description = S("Redheart Leaves"),
leaves_texture = "strata_redheart_leaves.png", canopy = 4,
})
function strata.fell_tree(pos, digger, trunk)
trunk = trunk or "strata_core:tree"
local tdef = core.registered_nodes[trunk] or {}
local leaves = tdef._strata_leaves or "strata_core:leaves"
local reach = tdef._strata_canopy or 3
local inv = digger and digger:is_player() and digger:get_inventory()
local p = vector.new(pos)
local top = vector.new(pos)
local count = 0
while true do
p.y = p.y + 1
if core.get_node(p).name ~= trunk then
break
end
core.remove_node(p)
top = vector.new(p)
count = count + 1
end
-- cones hang leaves well below the top, so clear down the felled trunk too
for dx = -reach, reach do
for y = pos.y, top.y + reach do
local lp = vector.new(top.x + dx, y, top.z)
if core.get_node(lp).name == leaves then
core.remove_node(lp)
end
end
end
if count > 0 then
local stack = ItemStack((tdef.drop or "strata_core:wood") .. " " .. count)
local left = inv and inv:add_item("main", stack) or stack
if not left:is_empty() then
core.add_item(pos, left)
end
end
end
--------------------------------------------------------------------------
-- Background walls (z = WALL_Z). Removed with a hammer.
--------------------------------------------------------------------------
local function wall_on_place(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" or not placer or not placer:is_player() then
return itemstack
end
local name = placer:get_player_name()
local target = vector.new(pointed_thing.under.x, pointed_thing.under.y, strata.WALL_Z)
if core.get_node(target).name ~= "strata_core:backdrop" then
return itemstack
end
if core.is_protected(target, name) or not strata.has_wall_support(target) then
return itemstack
end
core.set_node(target, {name = itemstack:get_name()})
strata.play_place_sound(target, itemstack:get_name())
if not core.is_creative_enabled(name) then
itemstack:take_item()
end
return itemstack
end
function strata.register_wall(name, desc, texture, sound_set)
core.register_node(name, {
description = desc,
tiles = {texture},
groups = {wall = 3},
sounds = strata.node_sounds(sound_set or "stone"),
node_placement_prediction = "",
on_place = wall_on_place,
after_dig_node = function(pos)
core.set_node(pos, {name = "strata_core:backdrop"})
end,
})
end
strata.register_wall("strata_core:wall_dirt", S("Dirt Wall"), "strata_wall_dirt.png", "dirt")
strata.register_wall("strata_core:wall_stone", S("Stone Wall"), "strata_wall_stone.png")
strata.register_wall("strata_core:wall_slate", S("Slate Wall"), "strata_wall_slate.png")
strata.register_wall("strata_core:wall_basalt", S("Basalt Wall"), "strata_wall_basalt.png")
strata.register_wall("strata_core:wall_wood", S("Wood Wall"), "strata_wall_wood.png", "wood")
strata.register_wall("strata_core:wall_snow", S("Snow Wall"), "strata_wall_snow.png", "dirt")
strata.register_wall("strata_core:wall_ice", S("Ice Wall"), "strata_wall_ice.png")
strata.register_wall("strata_core:wall_sandstone", S("Sandstone Wall"), "strata_wall_sandstone.png")
strata.register_wall("strata_core:wall_mud", S("Mud Wall"), "strata_wall_mud.png", "dirt")
--------------------------------------------------------------------------
-- Furniture and crafting stations
--------------------------------------------------------------------------
-- Torches are registered in placement.lua (they mount on blocks and walls).
core.register_node("strata_core:workbench", {
description = S("Work Bench"),
tiles = {"strata_workbench.png"},
drawtype = "nodebox",
paramtype = "light",
node_box = {type = "fixed", fixed = {
{-0.5, 0.2, -0.5, 0.5, 0.5, 0.5},
{-0.45, -0.5, -0.45, -0.25, 0.2, 0.45},
{0.25, -0.5, -0.45, 0.45, 0.2, 0.45},
}},
groups = {choppy = 3, crafting_station = 1},
})
core.register_node("strata_core:furnace", {
description = S("Furnace"),
tiles = {"strata_furnace.png", "strata_furnace.png", "strata_furnace.png",
"strata_furnace.png", "strata_furnace.png", "strata_furnace_front.png"},
light_source = 8,
groups = {cracky = 3, crafting_station = 1},
})
core.register_node("strata_core:anvil", {
description = S("Iron Anvil"),
tiles = {"strata_anvil.png"},
drawtype = "nodebox",
paramtype = "light",
node_box = {type = "fixed", fixed = {
{-0.5, 0.1, -0.3, 0.5, 0.5, 0.3},
{-0.2, -0.3, -0.2, 0.2, 0.1, 0.2},
{-0.4, -0.5, -0.3, 0.4, -0.3, 0.3},
}},
groups = {cracky = 2, crafting_station = 1},
})
dofile(core.get_modpath("strata_core") .. "/building.lua")
dofile(core.get_modpath("strata_core") .. "/furniture.lua")
dofile(core.get_modpath("strata_core") .. "/placement.lua")
dofile(core.get_modpath("strata_core") .. "/liquids.lua")
dofile(core.get_modpath("strata_core") .. "/caverns.lua")
--------------------------------------------------------------------------
-- Materials
--------------------------------------------------------------------------
core.register_craftitem("strata_core:gel", {
description = S("Gel"),
inventory_image = "strata_gel.png",
})
core.register_craftitem("strata_core:copper_bar", {
description = S("Copper Bar"),
inventory_image = "strata_copper_bar.png",
})
core.register_craftitem("strata_core:iron_bar", {
description = S("Iron Bar"),
inventory_image = "strata_iron_bar.png",
})
--------------------------------------------------------------------------
-- Tools. Terraria tools never break, so uses = 0.
--------------------------------------------------------------------------
core.register_item(":", {
type = "none",
wield_image = "strata_hand.png",
wield_scale = {x = 1, y = 1, z = 2.5},
range = strata.POINT_RANGE,
tool_capabilities = {
full_punch_interval = 0.5,
max_drop_level = 0,
groupcaps = {},
damage_groups = {fleshy = 1},
},
})
local tiers = {
-- material, pickaxe power, speed multiplier, sword damage, shortsword damage
{name = "wood", desc = "Wooden", pick = nil, speed = 1.3, sword = 7, short = nil},
{name = "copper", desc = "Copper", pick = 2, speed = 1.0, sword = 8, short = 5},
{name = "iron", desc = "Iron", pick = 1, speed = 0.8, sword = 10, short = 7},
}
local function times(levels, base, speed)
local t = {}
for level = levels, 3 do
t[level] = base * speed * (1 + (3 - level) * 0.6)
end
return t
end
for _, tier in ipairs(tiers) do
local m = tier.name
if tier.pick then
core.register_tool("strata_core:" .. m .. "_pickaxe", {
description = S(tier.desc .. " Pickaxe"),
inventory_image = "strata_" .. m .. "_pickaxe.png",
range = strata.POINT_RANGE,
tool_capabilities = {
full_punch_interval = 0.6,
max_drop_level = 1,
groupcaps = {
cracky = {times = times(tier.pick, 0.55, tier.speed), uses = 0, maxlevel = 3},
crumbly = {times = {[3] = 0.35 * tier.speed}, uses = 0, maxlevel = 3},
},
damage_groups = {fleshy = 3},
},
})
core.register_tool("strata_core:" .. m .. "_axe", {
description = S(tier.desc .. " Axe"),
inventory_image = "strata_" .. m .. "_axe.png",
range = strata.POINT_RANGE,
tool_capabilities = {
full_punch_interval = 0.7,
max_drop_level = 1,
groupcaps = {
choppy = {times = times(2, 0.5, tier.speed), uses = 0, maxlevel = 3},
},
damage_groups = {fleshy = 4},
},
})
end
core.register_tool("strata_core:" .. m .. "_hammer", {
description = S(tier.desc .. " Hammer"),
inventory_image = "strata_" .. m .. "_hammer.png",
range = strata.POINT_RANGE,
tool_capabilities = {
full_punch_interval = 0.8,
max_drop_level = 1,
groupcaps = {
wall = {times = {[3] = 0.3 * tier.speed}, uses = 0, maxlevel = 3},
},
damage_groups = {fleshy = 4},
},
})
core.register_tool("strata_core:" .. m .. "_sword", {
description = S(tier.desc .. " Broadsword"),
inventory_image = "strata_" .. m .. "_sword.png",
range = strata.POINT_RANGE,
tool_capabilities = {
full_punch_interval = 0.55,
max_drop_level = 0,
groupcaps = {},
damage_groups = {fleshy = tier.sword},
},
})
if tier.short then
core.register_tool("strata_core:" .. m .. "_shortsword", {
description = S(tier.desc .. " Shortsword"),
inventory_image = "strata_" .. m .. "_shortsword.png",
range = strata.POINT_RANGE,
tool_capabilities = {
full_punch_interval = 0.4,
max_drop_level = 0,
groupcaps = {},
damage_groups = {fleshy = tier.short},
},
})
end
end
-- The camera sits CAMERA_DIST nodes in front of the plane, so every item
-- must be able to point that far. Reach from the avatar is enforced
-- separately (see strata_player).
core.register_on_mods_loaded(function()
for name, def in pairs(core.registered_items) do
if (def.range or 4) < strata.POINT_RANGE then
core.override_item(name, {range = strata.POINT_RANGE})
end
end
end)