1 --stairs - shift click to place upside down
2 for name,def in pairs(minetest.registered_nodes) do
3 if def.drawtype == "normal" and string.match(name, "main:") then
6 local def2 = table.copy(def)
7 local newname = "stairs:"..string.gsub(name, "main:", "").."_stair"
8 def2.mod_origin = "stairs"
10 def2.description = def.description.." Stair"
12 def2.paramtype = "light"
13 def2.drawtype = "nodebox"
14 def2.paramtype2 = "facedir"
15 def2.node_placement_prediction = ""
20 {-8/16, -8/16, -0/16, 8/16, 8/16, 8/16},
21 {-8/16, -8/16, -8/16, 8/16, 0/16, 8/16},
24 --ability to place stairs upside down
25 def2.on_place = function(itemstack, placer, pointed_thing)
26 local sneak = placer:get_player_control().sneak
28 local _,worked = minetest.item_place(ItemStack(newname.."_upsidedown"), placer, pointed_thing)
33 minetest.item_place(itemstack, placer, pointed_thing)
37 def2.groups["stairs"] = 1
38 minetest.register_node(newname,def2)
40 minetest.register_craft({
41 output = newname.." 6",
49 minetest.register_craft({
50 output = newname.." 6",
60 for name,def in pairs(minetest.registered_nodes) do
61 if def.drawtype == "normal" and string.match(name, "main:") then
62 local def2 = table.copy(def)
63 local newname = "stairs:"..string.gsub(name, "main:", "").."_stair_upsidedown"
64 def2.mod_origin = "stairs"
66 def2.description = def.description.." Stair"
67 def2.drop = string.gsub(newname, "_upsidedown", "")
68 def2.paramtype = "light"
69 def2.drawtype = "nodebox"
70 def2.paramtype2 = "facedir"
75 {-8/16, -8/16, -0/16, 8/16, 8/16, 8/16},
76 {-8/16, -0/16, -8/16, 8/16, 8/16, 8/16},
79 def2.groups["stairs"] = 1
80 minetest.register_node(newname,def2)
85 ------------------------------------------------------- slabs
87 local place_slab_sound = function(pos,newnode)
88 local node = minetest.registered_nodes[newnode]
89 local sound = node.sounds
92 placing = sound.placing
94 --only play the sound when is defined
95 if type(placing) == "table" then
96 minetest.sound_play(placing.name, {
99 --pitch = math.random(60,100)/100
103 --slabs - shift click to place upside down
104 for name,def in pairs(minetest.registered_nodes) do
105 if def.drawtype == "normal" and string.match(name, "main:") then
108 local def2 = table.copy(def)
109 local newname = "stairs:"..string.gsub(name, "main:", "").."_slab"
110 def2.mod_origin = "stairs"
112 def2.description = def.description.." Slab"
114 def2.paramtype = "light"
115 def2.drawtype = "nodebox"
117 def2.node_placement_prediction = ""
121 {-8/16, -8/16, -8/16, 8/16, 0/16, 8/16},
124 --we're passing in the local variables newname and name into this function
125 --calculating wether to turn a half slab into a full block
126 def2.on_place = function(itemstack, placer, pointed_thing)
127 --get all the required variables
128 local sneak = placer:get_player_control().sneak
129 local ydiff = pointed_thing.above.y-pointed_thing.under.y
130 local node_under = minetest.get_node(pointed_thing.under).name
131 local rightsideup = (newname == node_under)
132 local upsidedown = (newname.."_upsidedown" == node_under)
134 local placement_worked = false
135 --upsidedown slab placement
136 if sneak == true then
137 local _,worked = minetest.item_place(ItemStack(newname.."_upsidedown"), placer, pointed_thing)
139 itemstack:take_item()
140 placement_worked = true
142 --normal placement - (back of slab) or normal node
143 elseif (rightsideup and ydiff == -1) or (upsidedown and ydiff == 1) or (not rightsideup and not upsidedown) or ydiff == 0 then
144 local itemstack,worked = minetest.item_place(itemstack, placer, pointed_thing)
146 placement_worked = true
148 --normal slab to full slab
149 elseif rightsideup and ydiff == 1 then
150 place_slab_sound(pointed_thing.under,newname)
151 minetest.set_node(pointed_thing.under, {name = name})
152 itemstack:take_item()
153 placement_worked = true
154 --upsidedown slab to full slab
155 elseif upsidedown and ydiff == -1 then
156 place_slab_sound(pointed_thing.under,newname)
157 minetest.set_node(pointed_thing.under, {name = name})
158 itemstack:take_item()
159 placement_worked = true
162 --try to do pointed_thing above
163 if placement_worked == false then
164 local node_above = minetest.get_node(pointed_thing.above).name
165 local rightsideup = (newname == node_above)
166 local upsidedown = (newname.."_upsidedown" == node_above)
167 if rightsideup or upsidedown then
168 place_slab_sound(pointed_thing.above,newname)
169 minetest.set_node(pointed_thing.above, {name = name})
170 itemstack:take_item()
177 def2.groups["slabs"] = 1
179 minetest.register_node(newname,def2)
180 --equalize recipe 6 half slabs turn into 3 full blocks
181 minetest.register_craft({
182 output = newname.." 6",
187 minetest.register_craft({
198 for name,def in pairs(minetest.registered_nodes) do
199 if def.drawtype == "normal" and string.match(name, "main:") then
200 local def2 = table.copy(def)
201 local newname = "stairs:"..string.gsub(name, "main:", "").."_slab_upsidedown"
202 def2.mod_origin = "stairs"
204 def2.description = def.description.." Slab"
205 def2.drop = string.gsub(newname, "_upsidedown", "")
206 def2.paramtype = "light"
208 def2.drawtype = "nodebox"
212 {-8/16, -0/16, -8/16, 8/16, 8/16, 8/16},
215 def2.groups["slabs"] = 1
217 minetest.register_node(newname,def2)