From 99d43ea54bf7bc4e1d4673ee1b1a52a550f835e0 Mon Sep 17 00:00:00 2001 From: wsor4035 <24964441+wsor4035@users.noreply.github.com> Date: Sat, 25 Oct 2025 19:09:44 -0400 Subject: [PATCH] add stairs api (#56) --- .luacheckrc | 5 ++++ LICENSE | 2 +- README.md | 20 ++++++------- doc/stairs.md | 30 ++++++++++++++++++++ init.lua | 1 + mod.conf | 2 +- src/stairs.lua | 8 ++++++ src/stairs/farlands_reloaded.lua | 25 +++++++++++++++++ src/stairs/minetest.lua | 19 +++++++++++++ src/stairs/xcompat_agnostic.lua | 48 ++++++++++++++++++++++++++++++++ 10 files changed, 148 insertions(+), 12 deletions(-) create mode 100644 doc/stairs.md create mode 100644 src/stairs.lua create mode 100644 src/stairs/farlands_reloaded.lua create mode 100644 src/stairs/minetest.lua create mode 100644 src/stairs/xcompat_agnostic.lua diff --git a/.luacheckrc b/.luacheckrc index e46563b..ad507bf 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,9 +1,13 @@ globals = { "minetest", + "core", "xcompat", } read_globals = { + string = {fields = {"split"}}, + table = {fields = {"copy", "getn"}}, + "default", "mcl_sounds", "ks_sounds", @@ -18,4 +22,5 @@ read_globals = { "player_api", "mcl_player", "fl_player", + "stairs", } diff --git a/LICENSE b/LICENSE index b04a486..c5bae1d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ -MIT Copyright 2021-2024 wsor4035 +MIT Copyright 2021-2025 wsor4035, mt-mods and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/README.md b/README.md index e3d1e26..83f25bf 100644 --- a/README.md +++ b/README.md @@ -15,16 +15,16 @@ See the respective sub apis doc file in /doc for detailed documentation. ## Directly supported games and mods -| Games | Sounds | Materials | Textures | Player | -| ----------------- | --------- | --------- | --------- | ------ | -| Minetest Game | x | x | x | x | -| MineClone2 | x | x | | x | -| Mineclonia | x | x | | x | -| Hades Revisited | x | x | | | -| Farlands Reloaded | x | x | x | x | -| Exile | x | | | | -| KSurvive 2 | x | | | | -| Forgotten Lands | x | | | | +| Games | Sounds | Materials | Textures | Player | Stairs | +| ----------------- | --------- | --------- | --------- | ------ | ------ | +| Minetest Game | x | x | x | x | x | +| MineClone2 | x | x | | x | | +| Mineclonia | x | x | | x | | +| Hades Revisited | x | x | | | | +| Farlands Reloaded | x | x | x | x | x | +| Exile | x | | | | | +| KSurvive 2 | x | | | | | +| Forgotten Lands | x | | | | | For functions see /doc/functions.md for the specifics relating to the function diff --git a/doc/stairs.md b/doc/stairs.md new file mode 100644 index 0000000..1ff986b --- /dev/null +++ b/doc/stairs.md @@ -0,0 +1,30 @@ +you can use this via `xcompat.stairs.register(nodename, def)` + +an example would be: +```lua +xcompat.stairs.register( + "xcompat_stairs_test:fake_node", + core.registered_nodes["xcompat_stairs_test:fake_node"] +) +``` + +if the game you are running on isnt supported (see readme), +it falls back to using a polyfill. each backend adds aliases +to the polyfill, mainly so that if we add a future backend +that ran on polyfill, everything keeps working (yay) + +at this time stairsplus/moreblocks compatibility/upgrading +isnt supported, however should be added in the future. for +now, in your mod code do something like the following: + +```lua +if core.registered_modes("moreblocks") then + --call stairs plus +else + xcompat.stairs.register(node, def) +end +``` + +that way in the future nothing will break when support is +added and at your convince the first part of the if can be +removed \ No newline at end of file diff --git a/init.lua b/init.lua index 883b0d3..2ef6558 100644 --- a/init.lua +++ b/init.lua @@ -12,6 +12,7 @@ xcompat.materials = dofile(modpath .. "/src/materials.lua") xcompat.textures = dofile(modpath .. "/src/textures.lua") xcompat.functions = dofile(modpath .. "/src/functions.lua") xcompat.player = dofile(modpath .. "/src/player.lua") +xcompat.stairs = dofile(modpath .. "/src/stairs.lua") local function validate_sound(key) if key and xcompat.sounds[key] then diff --git a/mod.conf b/mod.conf index cdecf52..1e7d1f1 100644 --- a/mod.conf +++ b/mod.conf @@ -1,3 +1,3 @@ name = xcompat description = Provides cross compatibility between mods and games for sounds and crafting materials. -optional_depends = default, fl_stone, fl_trees, mcl_sounds, hades_sounds, ks_sounds, nodes_nature, fl_topsoil, fl_trees, mcl_core, farming, x_farming, sounds, mtt, player_api, mcl_player, fl_player +optional_depends = default, fl_stone, fl_trees, mcl_sounds, hades_sounds, ks_sounds, nodes_nature, fl_topsoil, fl_trees, mcl_core, farming, x_farming, sounds, mtt, player_api, mcl_player, fl_player, stairs diff --git a/src/stairs.lua b/src/stairs.lua new file mode 100644 index 0000000..6f8e59e --- /dev/null +++ b/src/stairs.lua @@ -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") \ No newline at end of file diff --git a/src/stairs/farlands_reloaded.lua b/src/stairs/farlands_reloaded.lua new file mode 100644 index 0000000..91605a3 --- /dev/null +++ b/src/stairs/farlands_reloaded.lua @@ -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} \ No newline at end of file diff --git a/src/stairs/minetest.lua b/src/stairs/minetest.lua new file mode 100644 index 0000000..ebfc5bc --- /dev/null +++ b/src/stairs/minetest.lua @@ -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} \ No newline at end of file diff --git a/src/stairs/xcompat_agnostic.lua b/src/stairs/xcompat_agnostic.lua new file mode 100644 index 0000000..eb96394 --- /dev/null +++ b/src/stairs/xcompat_agnostic.lua @@ -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} \ No newline at end of file