diff --git a/mods/ITEMS/mcl_stairs/API.md b/mods/ITEMS/mcl_stairs/API.md index 6c91754b..13b2300d 100644 --- a/mods/ITEMS/mcl_stairs/API.md +++ b/mods/ITEMS/mcl_stairs/API.md @@ -10,7 +10,7 @@ Register platinum stair and slab based on node `example:platinum`: mcl_stairs.register_stair_and_slab_simple("platinum", "example:platinum", "Platinum Stair", "Platinum Slab", "Double Platinum Slab") ``` -## `mcl_stairs.register_stair_and_slab_simple(subname, sourcenode, desc_stair, desc_slab, double_description, corner_stair_texture_override)` +## `mcl_stairs.register_stair_and_slab_simple(name, sourcenode, desc_stair, desc_slab, double_description, corner_stair_texture_override)` Register a simple stair and a slab. The stair and slab will inherit all attributes from `sourcenode`. The `sourcenode` is also used as the item for crafting recipes. This function is meant for simple nodes; if you need more flexibility, use one of the other functions instead. @@ -18,14 +18,14 @@ This function is meant for simple nodes; if you need more flexibility, use one o See `register_stair` and `register_slab` for the itemstrings of the registered nodes. ### Parameters -* `subname`: Name fragment for node itemstrings (see `register_stair` and `register_slab`) +* `name`: Name for node itemstrings (see `register_stair` and `register_slab`) * `sourcenode`: The node on which this stair is based on * `desc_stair`: Description of stair node * `desc_slab`: Description of slab node * `double_description`: Description of double slab node * `corner_stair_texture_override`: Optional, see `register_stair` -## `mcl_stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds, hardness, double_description, corner_stair_texture_override)` +## `mcl_stairs.register_stair_and_slab(name, recipeitem, groups, images, desc_stair, desc_slab, sounds, hardness, double_description, corner_stair_texture_override)` Register a simple stair and a slab, plus crafting recipes. In this function, you need to specify most things explicitly. ### Parameters @@ -33,17 +33,26 @@ Register a simple stair and a slab, plus crafting recipes. In this function, you * `desc_slab`: Description of slab node * Other parameters: Same as for `register_stair` and `register_slab` -## `mcl_stairs.register_stair(subname, recipeitem, groups, images, description, sounds, hardness, corner_stair_texture_override)` +## `mcl_stairs.register_stair(name, recipeitem, groups, images, description, sounds, hardness, corner_stair_texture_override)` Registers a stair. This also includes the inner and outer corner stairs, they are added automatically. Also adds crafting recipes. +If `name` contains no colon, the itemstrings for the registered nodes will be of the form: + +* `mcl_stairs:stair_`: Normal stair +* `mcl_stairs:stair__inner`: Inner stair +* `mcl_stairs:stair__outer`: Outer stair + +If `name` contains a colon, the string is split at the colon into `modname` and `subname`. The itemstrings for the registered nodes will be of the form: -* `mcl_stairs:stair_`: Normal stair -* `mcl_stairs:stair__inner`: Inner stair -* `mcl_stairs:stair__outer`: Outer stair +* `:stair_`: Normal stair +* `:stair__inner`: Inner stair +* `:stair__outer`: Outer stair + +In the latter case, item aliases are registered for stairs registered using the colon-less form. ### Parameters -* `subname`: Name fragment for node itemstrings (see above) +* `name`: Name fragment for node itemstrings (see above) * `recipeitem`: Item for crafting recipe. Use `group:` prefix to use a group instead * `groups`: Groups used for stair * `images`: Textures @@ -68,14 +77,29 @@ It can be one of the following data types: { tiles_def_for_outer_stair, tiles_def_for_inner_stair } * nil: Equivalent to "default" -## `mcl_stairs.register_slab(subname, recipeitem, groups, images, description, sounds, hardness, double_description)` +## `mcl_stairs.register_slab(name, recipeitem, groups, images, description, sounds, hardness, double_description)` Registers a slab and a corresponding double slab. Also adds crafting recipe. The itemstrings for the registered nodes will be of the form: -* `mcl_stairs:slab_`: Slab -* `mcl_stairs:slab__top`: Upper slab, used internally -* `mcl_stairs:slab__double`: Double slab +* `mcl_stairs:slab_`: Slab +* `mcl_stairs:slab__top`: Upper slab, used internally +* `mcl_stairs:slab__double`: Double slab + +If `name` contains no colon, the itemstrings for the registered nodes will be of the form: + +* `mcl_stairs:slab_`: Normal stair +* `mcl_stairs:slab__top`: Inner stair +* `mcl_stairs:slab__double`: Outer stair + +If `name` contains a colon, the string is split at the colon into `modname` and `subname`. +The itemstrings for the registered nodes will be of the form: + +* `:slab_`: Normal stair +* `:slab__top`: Inner stair +* `:slab__double`: Outer stair + +In the latter case, item aliases are registered for slabs registered using the colon-less form. ### Parameters * `double_description`: Node description/tooltip for double slab diff --git a/mods/ITEMS/mcl_stairs/api.lua b/mods/ITEMS/mcl_stairs/api.lua index aecf1083..ca13f9f9 100644 --- a/mods/ITEMS/mcl_stairs/api.lua +++ b/mods/ITEMS/mcl_stairs/api.lua @@ -67,10 +67,40 @@ local function place_stair(itemstack, placer, pointed_thing) return minetest.item_place(itemstack, placer, pointed_thing, param2) end --- Register stairs. --- Node will be called mcl_stairs:stair_ +local function get_modname_and_subname(name) + local modname, subname + if nil == string.find(name, ":") then + modname, subname = "mcl_stairs", name + else + modname, subname = string.gmatch(name, "(.*):(.*)")() + end + return modname, subname +end -function mcl_stairs.register_stair(subname, recipeitem, groups, images, description, sounds, blast_resistance, hardness, corner_stair_texture_override) +local modname, subname = get_modname_and_subname("air") +assert( "mcl_stairs" == modname ) +assert( "air" == subname ) + +local modname, subname = get_modname_and_subname("default:stone") +assert( "default" == modname ) +assert( "stone" == subname ) + +-- Register aliases for backwards compatiblity with unprefixed API usage + +local function register_mcl_stairs_alias(name) + local modname, subname = string.gmatch(name, "(.*):(.*)")() + assert( nil ~= modname ) + assert( nil ~= subname ) + if "mcl_stairs" ~= modname then + local old_name = "mcl_stairs:" .. subname + minetest.register_alias(old_name, name) + end +end + +-- Register stairs. +-- Node will be called mcl_stairs:stair_ or :stair_ + +function mcl_stairs.register_stair(name, recipeitem, groups, images, description, sounds, blast_resistance, hardness, corner_stair_texture_override) groups.stair = 1 groups.building_block = 1 @@ -92,7 +122,9 @@ function mcl_stairs.register_stair(subname, recipeitem, groups, images, descript end end - minetest.register_node(":mcl_stairs:stair_" .. subname, { + local modname, subname = get_modname_and_subname(name) + local stair = modname .. ":stair_" .. subname + minetest.register_node(":" .. stair, { description = description, _doc_items_longdesc = S("Stairs are useful to reach higher places by walking over them; jumping is not required. Placing stairs in a corner pattern will create corner stairs. Stairs placed on the ceiling or at the upper half of the side of a block will be placed upside down."), drawtype = "mesh", @@ -152,10 +184,11 @@ function mcl_stairs.register_stair(subname, recipeitem, groups, images, descript _mcl_blast_resistance = blast_resistance, _mcl_hardness = hardness, }) + register_mcl_stairs_alias(stair) if recipeitem then minetest.register_craft({ - output = 'mcl_stairs:stair_' .. subname .. ' 4', + output = modname .. ':stair_' .. subname .. ' 4', recipe = { {recipeitem, "", ""}, {recipeitem, recipeitem, ""}, @@ -165,7 +198,7 @@ function mcl_stairs.register_stair(subname, recipeitem, groups, images, descript -- Flipped recipe minetest.register_craft({ - output = 'mcl_stairs:stair_' .. subname .. ' 4', + output = modname .. ':stair_' .. subname .. ' 4', recipe = { {"", "", recipeitem}, {"", recipeitem, recipeitem}, @@ -174,7 +207,7 @@ function mcl_stairs.register_stair(subname, recipeitem, groups, images, descript }) end - mcl_stairs.cornerstair.add("mcl_stairs:stair_"..subname, corner_stair_texture_override) + mcl_stairs.cornerstair.add(modname .. ":stair_" .. subname, corner_stair_texture_override) end @@ -182,12 +215,14 @@ end local slab_trans_dir = {[0] = 8, 0, 2, 1, 3, 4} -- Register slabs. --- Node will be called mcl_stairs:slab_ +-- Node will be called mcl_stairs:slab_ or :slab_ -- double_description: NEW argument, not supported in Minetest Game -- double_description: Description of double slab -function mcl_stairs.register_slab(subname, recipeitem, groups, images, description, sounds, blast_resistance, hardness, double_description) - local lower_slab = "mcl_stairs:slab_"..subname +function mcl_stairs.register_slab(name, recipeitem, groups, images, description, sounds, blast_resistance, hardness, double_description) + local modname, subname = get_modname_and_subname(name) + + local lower_slab = modname .. ":slab_" .. subname local upper_slab = lower_slab.."_top" local double_slab = lower_slab.."_double" @@ -281,6 +316,7 @@ function mcl_stairs.register_slab(subname, recipeitem, groups, images, descripti } minetest.register_node(":"..lower_slab, slabdef) + register_mcl_stairs_alias(lower_slab) -- Register the upper slab. -- Using facedir is not an option, as this would rotate the textures as well and would make @@ -314,6 +350,7 @@ function mcl_stairs.register_slab(subname, recipeitem, groups, images, descripti fixed = {-0.5, 0, -0.5, 0.5, 0.5, 0.5}, } minetest.register_node(":"..upper_slab, topdef) + register_mcl_stairs_alias(upper_slab) -- Double slab node @@ -332,6 +369,7 @@ function mcl_stairs.register_slab(subname, recipeitem, groups, images, descripti drop = lower_slab .. " 2", _mcl_hardness = hardness, }) + register_mcl_stairs_alias(double_slab) if recipeitem then minetest.register_craft({ @@ -351,18 +389,18 @@ end -- Stair/slab registration function. --- Nodes will be called mcl_stairs:{stair,slab}_ +-- Nodes will be called mcl_stairs:{stair,slab}_ or :{stair,slab}_ -function mcl_stairs.register_stair_and_slab(subname, recipeitem, +function mcl_stairs.register_stair_and_slab(name, recipeitem, groups, images, desc_stair, desc_slab, sounds, blast_resistance, hardness, double_description, corner_stair_texture_override) - mcl_stairs.register_stair(subname, recipeitem, groups, images, desc_stair, sounds, blast_resistance, hardness, corner_stair_texture_override) - mcl_stairs.register_slab(subname, recipeitem, groups, images, desc_slab, sounds, blast_resistance, hardness, double_description) + mcl_stairs.register_stair(name, recipeitem, groups, images, desc_stair, sounds, blast_resistance, hardness, corner_stair_texture_override) + mcl_stairs.register_slab(name, recipeitem, groups, images, desc_slab, sounds, blast_resistance, hardness, double_description) end -- Very simple registration function -- Makes stair and slab out of a source node -function mcl_stairs.register_stair_and_slab_simple(subname, sourcenode, desc_stair, desc_slab, desc_double_slab, corner_stair_texture_override) +function mcl_stairs.register_stair_and_slab_simple(name, sourcenode, desc_stair, desc_slab, desc_double_slab, corner_stair_texture_override) local def = minetest.registered_nodes[sourcenode] local groups = {} -- Only allow a strict set of groups to be added to stairs and slabs for more predictable results @@ -372,6 +410,6 @@ function mcl_stairs.register_stair_and_slab_simple(subname, sourcenode, desc_sta groups[allowed_groups[a]] = def.groups[allowed_groups[a]] end end - mcl_stairs.register_stair_and_slab(subname, sourcenode, groups, def.tiles, desc_stair, desc_slab, def.sounds, def._mcl_blast_resistance, def._mcl_hardness, desc_double_slab, corner_stair_texture_override) + mcl_stairs.register_stair_and_slab(name, sourcenode, groups, def.tiles, desc_stair, desc_slab, def.sounds, def._mcl_blast_resistance, def._mcl_hardness, desc_double_slab, corner_stair_texture_override) end