add support for stairs+slabs

This commit is contained in:
Alexander Weber 2017-04-14 21:06:28 +02:00
parent bab685ede4
commit cb47b9e395
3 changed files with 26 additions and 5 deletions

View File

@ -60,6 +60,7 @@ newsupermario_ice_packed.png newsupermario_nether_brick.png
## customnode.add_nodes_from_textures(def)
def.descr_prefix - prefix added to all generated node descriptions. If not defined the modname will be used
def.check_prefix - Additional prefix if not all textures should be processed
def.add_stairs_slabs - Adds stairs and slabs for nodes with specific variants. Default value is "brick,cobblestone,ice,iron,sandstone,stone". false means disable, true means for all variants
## Textures name convention

View File

@ -1 +1,2 @@
default
stairs?

View File

@ -14,13 +14,32 @@ function customnode.add_nodes_from_textures(conf)
conf can contains the next attributes:
conf.descr_prefix - Additional prefix to the node description
conf.check_prefix - Enhance the prefix check to modname_addprefix_ instead of default modname_
conf.add_stairs_slabs - generate stairs and slabs from stairs mod in addition to the node
]]
if not conf.add_stairs_slabs then
conf.add_stairs_slabs = "brick,cobblestone,ice,sandstone,stone"
end
local customnode_list = customnode.get_nodelist_by_textures(conf.check_prefix)
for name, generator in pairs(customnode_list) do
local nodedef = generator:get_nodedef(conf)
if nodedef then
minetest.register_node(nodedef.name, nodedef)
if minetest.global_exists("stairs") and conf.add_stairs_slabs ~= false then
if conf.add_stairs_slabs == true or (type(conf.add_stairs_slabs) == "string" and string.find(conf.add_stairs_slabs, generator.variant)) then
stairs.register_stair_and_slab(
generator.modname.."_"..generator:get_name(),
nodedef.name,
table.copy(nodedef.groups),
table.copy(nodedef.tiles),
nodedef.description.." Stair",
nodedef.description.." Stone Slab",
table.copy(nodedef.sounds)
)
end
end
end
end
end
@ -169,7 +188,7 @@ customnode.register_generator("default", {
get_nodedef = function(self, conf)
self.conf = conf
local nodedef = self:get_template()
nodedef.name = self:get_name()
nodedef.name = self.modname..":"..self:get_name()
nodedef.description = self:get_description()
nodedef.tiles = self:get_tiles()
nodedef.sounds = self:get_sounds()
@ -189,15 +208,15 @@ customnode.register_generator("default", {
get_name = function(self)
if not self.basename then
if self.variant == "default" then
return self.modname..":"..self.modname
return self.modname
else
return self.modname..":"..self.variant
return self.variant
end
else
if self.variant == "default" then
return self.modname..":"..self.basename
return self.basename
else
return self.modname..":"..self.variant.."_"..self.basename
return self.variant.."_"..self.basename
end
end
end,