Use mod name prefix in stairs & slabs API

This commit is contained in:
Nils Dagsson Moskopp 2022-04-27 03:10:53 +02:00
parent 1ce88e7528
commit e410359b42
Signed by untrusted user who does not match committer: erlehmann
GPG Key ID: A3BC671C35191080
2 changed files with 90 additions and 28 deletions

View File

@ -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_<name>`: Normal stair
* `mcl_stairs:stair_<name>_inner`: Inner stair
* `mcl_stairs:stair_<name>_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_<subname>`: Normal stair
* `mcl_stairs:stair_<subname>_inner`: Inner stair
* `mcl_stairs:stair_<subname>_outer`: Outer stair
* `<modname>:stair_<subname>`: Normal stair
* `<modname>:stair_<subname>_inner`: Inner stair
* `<modname>:stair_<subname>_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_<subname>`: Slab
* `mcl_stairs:slab_<subname>_top`: Upper slab, used internally
* `mcl_stairs:slab_<subname>_double`: Double slab
* `mcl_stairs:slab_<name>`: Slab
* `mcl_stairs:slab_<name>_top`: Upper slab, used internally
* `mcl_stairs:slab_<name>_double`: Double slab
If `name` contains no colon, the itemstrings for the registered nodes will be of the form:
* `mcl_stairs:slab_<name>`: Normal stair
* `mcl_stairs:slab_<name>_top`: Inner stair
* `mcl_stairs:slab_<name>_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:
* `<modname>:slab_<subname>`: Normal stair
* `<modname>:slab_<subname>_top`: Inner stair
* `<modname>:slab_<subname>_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

View File

@ -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_<subname>
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_<name> or <modname>:stair_<subname>
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_<subname>
-- Node will be called mcl_stairs:slab_<name> or <modname>:slab_<subname>
-- 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}_<subname>
-- Nodes will be called mcl_stairs:{stair,slab}_<name> or <modname>:{stair,slab}_<subname>
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