diff --git a/game_api.txt b/game_api.txt index 6d8b08f70a..355fd6518e 100644 --- a/game_api.txt +++ b/game_api.txt @@ -719,16 +719,24 @@ Stairs API The stairs API lets you register stairs and slabs and ensures that they are registered the same way as those delivered with Minetest Game, to keep them compatible with other mods. -`stairs.register_stair(subname, recipeitem, groups, images, description, sounds, worldaligntex)` +`stairs.register_stair_type(subname, recipeitem, groups, images, description, sounds, worldaligntex, full_description, stairtype)` * Registers a stair - * `subname`: Basically the material name (e.g. cobble) used for the stair name. Nodename pattern: "stairs:stair_subname" + * `subname`: Basically the material name (e.g. cobble) used for the stair name. + Nodename pattern: "stairs:stair_subname", "stairs:stair_inner_subname", stairs:stair_outer_subname * `recipeitem`: Item used in the craft recipe, e.g. "default:cobble", may be `nil` * `groups`: See [Known damage and digging time defining groups] * `images`: See [Tile definition] * `description`: Used for the description field in the stair's definition * `sounds`: See [#Default sounds] * `worldaligntex`: A bool to set all textures world-aligned. Default false. See [Tile definition] + * `full_description`: Overrides the description, bypassing string concatenation. This is useful for translation. (optional) + * Note: Only for inner and outer stairs. + * `stairtype`: Sets the type of stair, e.g. "inner" for inner corner stair and "outer" for outer corner stair, otherwise `nil` + +`stairs.register_stair(subname, recipeitem, groups, images, description, sounds, worldaligntex)` + + * Deprecated, remove from mods. `stairs.register_slab(subname, recipeitem, groups, images, description, sounds, worldaligntex)` @@ -743,27 +751,11 @@ delivered with Minetest Game, to keep them compatible with other mods. `stairs.register_stair_inner(subname, recipeitem, groups, images, description, sounds, worldaligntex, full_description)` - * Registers an inner corner stair - * `subname`: Basically the material name (e.g. cobble) used for the stair name. Nodename pattern: "stairs:stair_inner_subname" - * `recipeitem`: Item used in the craft recipe, e.g. "default:cobble", may be `nil` - * `groups`: See [Known damage and digging time defining groups] - * `images`: See [Tile definition] - * `description`: Used for the description field in the stair's definition with "Inner" prepended - * `sounds`: See [#Default sounds] - * `worldaligntex`: A bool to set all textures world-aligned. Default false. See [Tile definition] - * `full_description`: Overrides the description, bypassing string concatenation. This is useful for translation. (optional) + * Deprecated, remove from mods. `stairs.register_stair_outer(subname, recipeitem, groups, images, description, sounds, worldaligntex, full_description)` - * Registers an outer corner stair - * `subname`: Basically the material name (e.g. cobble) used for the stair name. Nodename pattern: "stairs:stair_outer_subname" - * `recipeitem`: Item used in the craft recipe, e.g. "default:cobble", may be `nil` - * `groups`: See [Known damage and digging time defining groups] - * `images`: See [Tile definition] - * `description`: Used for the description field in the stair's definition with "Outer" prepended - * `sounds`: See [#Default sounds] - * `worldaligntex`: A bool to set all textures world-aligned. Default false. See [Tile definition] - * `full_description`: Overrides the description, bypassing string concatenation. This is useful for translation. (optional) + * Deprecated, remove from mods. `stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds, worldaligntex)` diff --git a/mods/farming/nodes.lua b/mods/farming/nodes.lua index 051f4ef981..379db99c2b 100644 --- a/mods/farming/nodes.lua +++ b/mods/farming/nodes.lua @@ -159,12 +159,12 @@ do local images = {"farming_straw.png"} local sounds = default.node_sound_leaves_defaults() - stairs.register_stair("straw", recipe, groups, images, S("Straw Stair"), + stairs.register_stair_type("straw", recipe, groups, images, S("Straw Stair"), sounds, true) - stairs.register_stair_inner("straw", recipe, groups, images, "", - sounds, true, S("Inner Straw Stair")) - stairs.register_stair_outer("straw", recipe, groups, images, "", - sounds, true, S("Outer Straw Stair")) + stairs.register_stair_type("straw", recipe, groups, images, "", + sounds, true, S("Inner Straw Stair"), "inner") + stairs.register_stair_type("straw", recipe, groups, images, "", + sounds, true, S("Outer Straw Stair"), "outer") stairs.register_slab("straw", recipe, groups, images, S("Straw Slab"), sounds, true) end diff --git a/mods/stairs/init.lua b/mods/stairs/init.lua index e2984f66cd..6053e9fb6e 100644 --- a/mods/stairs/init.lua +++ b/mods/stairs/init.lua @@ -58,9 +58,11 @@ end -- Register stair -- Node will be called stairs:stair_ +-- Inner corner stair will be called stairs:stair_inner_ +-- Outer corner stair will be called stairs:stair_outer_ -function stairs.register_stair(subname, recipeitem, groups, images, description, - sounds, worldaligntex) +function stairs.register_stair_type(subname, recipeitem, groups, images, + description, sounds, worldaligntex, full_description, stairtype) -- Set backface culling and world-aligned textures local stair_images = {} for i, image in ipairs(images) do @@ -82,10 +84,56 @@ function stairs.register_stair(subname, recipeitem, groups, images, description, end end end + local stairdata + if stairtype == "inner" then + stairdata = {"stairs:stair_inner_", " 7", 0.875, "Inner ", + { + {"", recipeitem, ""}, + {recipeitem, "", recipeitem}, + {recipeitem, recipeitem, recipeitem}, + }, + { + {-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}, + }, + } + elseif stairtype == "outer" then + stairdata = {"stairs:stair_outer_", " 6", 0.625, "Outer ", + { + {"", recipeitem, ""}, + {recipeitem, recipeitem, recipeitem}, + }, + { + {-0.5, -0.5, -0.5, 0.5, 0.0, 0.5}, + {-0.5, 0.0, 0.0, 0.0, 0.5, 0.5}, + }, + } + else + stairdata = {"stairs:stair_", " 8", 0.75, nil, + { + {"", "", recipeitem}, + {"", recipeitem, recipeitem}, + {recipeitem, recipeitem, recipeitem}, + }, + { + {-0.5, -0.5, -0.5, 0.5, 0.0, 0.5}, + {-0.5, 0.0, 0.0, 0.5, 0.5, 0.5}, + }, + } + end local new_groups = table.copy(groups) new_groups.stair = 1 - warn_if_exists("stairs:stair_" .. subname) - minetest.register_node(":stairs:stair_" .. subname, { + local outer_or_inner = stairtype == "inner" or stairtype == "outer" + if outer_or_inner then + if full_description then + description = full_description + else + description = stairdata[4] .. description + end + end + warn_if_exists(stairdata[1] .. subname) + minetest.register_node(":" .. stairdata[1] .. subname, { description = description, drawtype = "nodebox", tiles = stair_images, @@ -96,10 +144,7 @@ function stairs.register_stair(subname, recipeitem, groups, images, description, sounds = sounds, node_box = { type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, 0.0, 0.5}, - {-0.5, 0.0, 0.0, 0.5, 0.5, 0.5}, - }, + fixed = stairdata[6], }, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then @@ -111,9 +156,9 @@ function stairs.register_stair(subname, recipeitem, groups, images, description, }) -- for replace ABM - if replace then - minetest.register_node(":stairs:stair_" .. subname .. "upside_down", { - replace_name = "stairs:stair_" .. subname, + if replace and not outer_or_inner then + minetest.register_node(":" .. stairdata[1] .. subname .. "upside_down", { + replace_name = stairdata[1] .. subname, groups = {slabs_replace = 1}, }) end @@ -121,22 +166,20 @@ function stairs.register_stair(subname, recipeitem, groups, images, description, if recipeitem then -- Recipe matches appearence in inventory minetest.register_craft({ - output = "stairs:stair_" .. subname .. " 8", - recipe = { - {"", "", recipeitem}, - {"", recipeitem, recipeitem}, - {recipeitem, recipeitem, recipeitem}, - }, + output = stairdata[1] .. subname .. stairdata[2], + recipe = stairdata[5], }) -- Use stairs to craft full blocks again (1:1) - minetest.register_craft({ - output = recipeitem .. " 3", - recipe = { - {"stairs:stair_" .. subname, "stairs:stair_" .. subname}, - {"stairs:stair_" .. subname, "stairs:stair_" .. subname}, - }, - }) + if not outer_or_inner then + minetest.register_craft({ + output = recipeitem .. " 3", + recipe = { + {stairdata[1] .. subname, stairdata[1] .. subname}, + {stairdata[1] .. subname, stairdata[1] .. subname}, + }, + }) + end -- Fuel local baseburntime = minetest.get_craft_result({ @@ -147,13 +190,23 @@ function stairs.register_stair(subname, recipeitem, groups, images, description, if baseburntime > 0 then minetest.register_craft({ type = "fuel", - recipe = "stairs:stair_" .. subname, - burntime = math.floor(baseburntime * 0.75), + recipe = stairdata[1] .. subname, + burntime = math.floor(baseburntime * stairdata[3]), }) end end end +-- Register stair +-- Node will be called stairs:stair_ + +function stairs.register_stair(subname, recipeitem, groups, images, description, + sounds, worldaligntex) + minetest.log("warning", "stairs.register_stair() is " .. + "deprecated, use stairs.register_stair_type() instead.") + return stairs.register_stair_type(subname, recipeitem, groups, images, + description, sounds, worldaligntex, nil, nil) +end -- Register slab -- Node will be called stairs:slab_ @@ -297,85 +350,10 @@ end function stairs.register_stair_inner(subname, recipeitem, groups, images, description, sounds, worldaligntex, full_description) - -- Set backface culling and world-aligned textures - local stair_images = {} - for i, image in ipairs(images) do - if type(image) == "string" then - stair_images[i] = { - name = image, - backface_culling = true, - } - if worldaligntex then - stair_images[i].align_style = "world" - end - else - stair_images[i] = table.copy(image) - if stair_images[i].backface_culling == nil then - stair_images[i].backface_culling = true - end - if worldaligntex and stair_images[i].align_style == nil then - stair_images[i].align_style = "world" - end - end - end - local new_groups = table.copy(groups) - new_groups.stair = 1 - if full_description then - description = full_description - else - description = "Inner " .. description - end - warn_if_exists("stairs:stair_inner_" .. subname) - minetest.register_node(":stairs:stair_inner_" .. subname, { - description = description, - drawtype = "nodebox", - tiles = stair_images, - paramtype = "light", - paramtype2 = "facedir", - is_ground_content = false, - groups = new_groups, - sounds = sounds, - node_box = { - type = "fixed", - fixed = { - {-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}, - }, - }, - on_place = function(itemstack, placer, pointed_thing) - if pointed_thing.type ~= "node" then - return itemstack - end - - return rotate_and_place(itemstack, placer, pointed_thing) - end, - }) - - if recipeitem then - minetest.register_craft({ - output = "stairs:stair_inner_" .. subname .. " 7", - recipe = { - {"", recipeitem, ""}, - {recipeitem, "", recipeitem}, - {recipeitem, recipeitem, recipeitem}, - }, - }) - - -- Fuel - local baseburntime = minetest.get_craft_result({ - method = "fuel", - width = 1, - items = {recipeitem} - }).time - if baseburntime > 0 then - minetest.register_craft({ - type = "fuel", - recipe = "stairs:stair_inner_" .. subname, - burntime = math.floor(baseburntime * 0.875), - }) - end - end + minetest.log("warning", "stairs.register_stair_inner() is " .. + "deprecated, use stairs.register_stair_type() instead.") + return stairs.register_stair_type(subname, recipeitem, groups, images, + description, sounds, worldaligntex, full_description, "inner") end @@ -384,83 +362,10 @@ end function stairs.register_stair_outer(subname, recipeitem, groups, images, description, sounds, worldaligntex, full_description) - -- Set backface culling and world-aligned textures - local stair_images = {} - for i, image in ipairs(images) do - if type(image) == "string" then - stair_images[i] = { - name = image, - backface_culling = true, - } - if worldaligntex then - stair_images[i].align_style = "world" - end - else - stair_images[i] = table.copy(image) - if stair_images[i].backface_culling == nil then - stair_images[i].backface_culling = true - end - if worldaligntex and stair_images[i].align_style == nil then - stair_images[i].align_style = "world" - end - end - end - local new_groups = table.copy(groups) - new_groups.stair = 1 - if full_description then - description = full_description - else - description = "Outer " .. description - end - warn_if_exists("stairs:stair_outer_" .. subname) - minetest.register_node(":stairs:stair_outer_" .. subname, { - description = description, - drawtype = "nodebox", - tiles = stair_images, - paramtype = "light", - paramtype2 = "facedir", - is_ground_content = false, - groups = new_groups, - sounds = sounds, - node_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, 0.0, 0.5}, - {-0.5, 0.0, 0.0, 0.0, 0.5, 0.5}, - }, - }, - on_place = function(itemstack, placer, pointed_thing) - if pointed_thing.type ~= "node" then - return itemstack - end - - return rotate_and_place(itemstack, placer, pointed_thing) - end, - }) - - if recipeitem then - minetest.register_craft({ - output = "stairs:stair_outer_" .. subname .. " 6", - recipe = { - {"", recipeitem, ""}, - {recipeitem, recipeitem, recipeitem}, - }, - }) - - -- Fuel - local baseburntime = minetest.get_craft_result({ - method = "fuel", - width = 1, - items = {recipeitem} - }).time - if baseburntime > 0 then - minetest.register_craft({ - type = "fuel", - recipe = "stairs:stair_outer_" .. subname, - burntime = math.floor(baseburntime * 0.625), - }) - end - end + minetest.log("warning", "stairs.register_stair_outer() is " .. + "deprecated, use stairs.register_stair_type() instead.") + return stairs.register_stair_type(subname, recipeitem, groups, images, + description, sounds, worldaligntex, full_description, "outer") end @@ -469,12 +374,12 @@ end function stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds, worldaligntex) - stairs.register_stair(subname, recipeitem, groups, images, desc_stair, - sounds, worldaligntex) - stairs.register_stair_inner(subname, recipeitem, groups, images, desc_stair, - sounds, worldaligntex) - stairs.register_stair_outer(subname, recipeitem, groups, images, desc_stair, + stairs.register_stair_type(subname, recipeitem, groups, images, desc_stair, sounds, worldaligntex) + stairs.register_stair_type(subname, recipeitem, groups, images, desc_stair, + sounds, worldaligntex, "inner") + stairs.register_stair_type(subname, recipeitem, groups, images, desc_stair, + sounds, worldaligntex, "outer") stairs.register_slab(subname, recipeitem, groups, images, desc_slab, sounds, worldaligntex) end @@ -482,12 +387,12 @@ end -- Local function so we can apply translations local function my_register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds, worldaligntex) - stairs.register_stair(subname, recipeitem, groups, images, S(desc_stair), + stairs.register_stair_type(subname, recipeitem, groups, images, S(desc_stair), sounds, worldaligntex) - stairs.register_stair_inner(subname, recipeitem, groups, images, "", - sounds, worldaligntex, S("Inner " .. desc_stair)) - stairs.register_stair_outer(subname, recipeitem, groups, images, "", - sounds, worldaligntex, S("Outer " .. desc_stair)) + stairs.register_stair_type(subname, recipeitem, groups, images, "", + sounds, worldaligntex, S("Inner " .. desc_stair), "inner") + stairs.register_stair_type(subname, recipeitem, groups, images, "", + sounds, worldaligntex, S("Outer " .. desc_stair), "outer") stairs.register_slab(subname, recipeitem, groups, images, S(desc_slab), sounds, worldaligntex) end @@ -871,7 +776,7 @@ my_register_stair_and_slab( -- Glass stair nodes need to be registered individually to utilize specialized textures. -stairs.register_stair( +stairs.register_stair_type( "glass", "default:glass", {cracky = 3}, @@ -893,7 +798,7 @@ stairs.register_slab( false ) -stairs.register_stair_inner( +stairs.register_stair_type( "glass", "default:glass", {cracky = 3}, @@ -903,10 +808,11 @@ stairs.register_stair_inner( "", default.node_sound_glass_defaults(), false, - S("Inner Glass Stair") + S("Inner Glass Stair"), + "inner" ) -stairs.register_stair_outer( +stairs.register_stair_type( "glass", "default:glass", {cracky = 3}, @@ -916,10 +822,11 @@ stairs.register_stair_outer( "", default.node_sound_glass_defaults(), false, - S("Outer Glass Stair") + S("Outer Glass Stair"), + "outer" ) -stairs.register_stair( +stairs.register_stair_type( "obsidian_glass", "default:obsidian_glass", {cracky = 3}, @@ -941,7 +848,7 @@ stairs.register_slab( false ) -stairs.register_stair_inner( +stairs.register_stair_type( "obsidian_glass", "default:obsidian_glass", {cracky = 3}, @@ -951,10 +858,11 @@ stairs.register_stair_inner( "", default.node_sound_glass_defaults(), false, - S("Inner Obsidian Glass Stair") + S("Inner Obsidian Glass Stair"), + "inner" ) -stairs.register_stair_outer( +stairs.register_stair_type( "obsidian_glass", "default:obsidian_glass", {cracky = 3}, @@ -964,7 +872,8 @@ stairs.register_stair_outer( "", default.node_sound_glass_defaults(), false, - S("Outer Obsidian Glass Stair") + S("Outer Obsidian Glass Stair"), + "outer" ) -- Dummy calls to S() to allow translation scripts to detect the strings.