From cb47b9e395777433ec24f813bb81d23671e14a43 Mon Sep 17 00:00:00 2001
From: Alexander Weber <web.alexander@web.de>
Date: Fri, 14 Apr 2017 21:06:28 +0200
Subject: [PATCH] add support for stairs+slabs

---
 README.md   |  1 +
 depends.txt |  1 +
 init.lua    | 29 ++++++++++++++++++++++++-----
 3 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 50d2b24..8d717c4 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/depends.txt b/depends.txt
index 4ad96d5..c5f1f37 100644
--- a/depends.txt
+++ b/depends.txt
@@ -1 +1,2 @@
 default
+stairs?
diff --git a/init.lua b/init.lua
index 9b26129..a278bae 100644
--- a/init.lua
+++ b/init.lua
@@ -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,