add stairs api (#56)

This commit is contained in:
wsor4035
2025-10-25 19:09:44 -04:00
committed by GitHub
parent 5a778586c9
commit 99d43ea54b
10 changed files with 148 additions and 12 deletions

8
src/stairs.lua Normal file
View File

@@ -0,0 +1,8 @@
local filename = xcompat.gameid
--if we dont have a stairs file for the game, use xcompat_agnostic
if not xcompat.utilities.file_exists(xcompat.modpath .. "/src/stairs/" .. filename .. ".lua") then
filename = "xcompat_agnostic"
end
return dofile(xcompat.modpath .. "/src/stairs/" .. filename .. ".lua")

View File

@@ -0,0 +1,25 @@
local function register(name, _)
local splitName = name:split(":")
local sName = splitName[2]
local groups = core.registered_nodes[name].groups
groups.stairable = 1
core.override_item(name, {groups = groups})
local flStairNameOverrides = {
["stair_inner"] = "inner_stair",
["stair_outer"] = "outer_stair"
}
for _, type in pairs({"slab", "stair", "stair_inner", "stair_outer"}) do
minetest.register_alias(
splitName[1] .. ":" .. type .. "_" .. sName,
splitName[1] .. ":" .. sName .. "_" .. (flStairNameOverrides[type] or type)
)
end
end
return {register = register}

19
src/stairs/minetest.lua Normal file
View File

@@ -0,0 +1,19 @@
local function register(name, def)
local splitName = name:split(":")
local sName = splitName[2]
stairs.register_stair_and_slab(
sName,
nil,
def.groups,
def.tiles,
def.description,
def.sounds
)
for _, type in pairs({"slab", "stair", "stair_inner", "stair_outer"}) do
minetest.register_alias(splitName[1] .. ":" .. type .. "_" .. sName, "stairs:" .. type .. "_" .. sName)
end
end
return {register = register}

View File

@@ -0,0 +1,48 @@
local stairtable = {
{
"slab",
{-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
{
"stair",
{
{-0.5, -0.5, -0.5, 0.5, 0.0, 0.5},
{-0.5, 0.0, 0.0, 0.5, 0.5, 0.5},
},
},
{
"stair_inner",
{
{-0.5, -0.5, -0.5, 0.5, 0.0, 0.5},
{-0.5, 0.0, 0.0, 0.5, 0.5, 0.5},
{-0.5, 0.0, -0.5, 0.0, 0.5, 0.0},
},
},
{
"stair_outer",
{
{-0.5, -0.5, -0.5, 0.5, 0.0, 0.5},
{-0.5, 0.0, 0.0, 0.0, 0.5, 0.5},
},
},
}
local function register(name, def)
for _, sdef in pairs(stairtable) do
local split = name:split(":")
local ndef = table.copy(def)
local item_name = ":" .. sdef[1] .. "_" .. split[2]
ndef.description = def.description .. " " .. string.gsub(sdef[1], "_", " ")
ndef.paramtype, ndef.paramtype2 = "light", "facedir"
ndef.drawtype = "nodebox"
ndef.node_box = {
type = "fixed",
fixed = sdef[2],
}
minetest.register_node(":" .. split[1] .. item_name, ndef)
end
end
return {register = register}