1 -- Minetest 0.4 mod: stairs
2 -- See README.txt for licensing and other information.
6 -- Node will be called stairs:stair_<subname>
7 function stairs.register_stair(subname, recipeitem, groups, images, description, sounds)
8 minetest.register_node(":stairs:stair_" .. subname, {
9 description = description,
11 mesh = "stairs_stair.obj",
14 paramtype2 = "facedir",
15 is_ground_content = false,
21 {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
22 {-0.5, 0, 0, 0.5, 0.5, 0.5},
28 {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
29 {-0.5, 0, 0, 0.5, 0.5, 0.5},
32 on_place = function(itemstack, placer, pointed_thing)
33 if pointed_thing.type ~= "node" then
37 local p0 = pointed_thing.under
38 local p1 = pointed_thing.above
41 local placer_pos = placer:getpos()
44 x = p1.x - placer_pos.x,
45 y = p1.y - placer_pos.y,
46 z = p1.z - placer_pos.z
48 param2 = minetest.dir_to_facedir(dir)
51 if p0.y-1 == p1.y then
55 elseif param2 == 23 then
60 return minetest.item_place(itemstack, placer, pointed_thing, param2)
65 minetest.register_node(":stairs:stair_" .. subname.."upside_down", {
66 replace_name = "stairs:stair_" .. subname,
67 groups = {slabs_replace=1},
70 minetest.register_craft({
71 output = 'stairs:stair_' .. subname .. ' 6',
74 {recipeitem, recipeitem, ""},
75 {recipeitem, recipeitem, recipeitem},
79 -- Flipped recipe for the silly minecrafters
80 minetest.register_craft({
81 output = 'stairs:stair_' .. subname .. ' 6',
84 {"", recipeitem, recipeitem},
85 {recipeitem, recipeitem, recipeitem},
90 -- Node will be called stairs:slab_<subname>
91 function stairs.register_slab(subname, recipeitem, groups, images, description, sounds)
92 minetest.register_node(":stairs:slab_" .. subname, {
93 description = description,
97 paramtype2 = "facedir",
98 is_ground_content = false,
103 fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
105 on_place = function(itemstack, placer, pointed_thing)
106 if pointed_thing.type ~= "node" then
110 -- If it's being placed on an another similar one, replace it with
114 local p0 = pointed_thing.under
115 local p1 = pointed_thing.above
116 local n0 = minetest.get_node(p0)
117 local n1 = minetest.get_node(p1)
120 local n0_is_upside_down = (n0.name == "stairs:slab_" .. subname and
123 if n0.name == "stairs:slab_" .. subname and not n0_is_upside_down and p0.y+1 == p1.y then
126 elseif n1.name == "stairs:slab_" .. subname then
131 -- Remove the slab at slabpos
132 minetest.remove_node(slabpos)
133 -- Make a fake stack of a single item and try to place it
134 local fakestack = ItemStack(recipeitem)
135 fakestack:set_count(itemstack:get_count())
137 pointed_thing.above = slabpos
139 fakestack, success = minetest.item_place(fakestack, placer, pointed_thing)
140 -- If the item was taken from the fake stack, decrement original
142 itemstack:set_count(fakestack:get_count())
143 -- Else put old node back
145 minetest.set_node(slabpos, slabnode)
151 if p0.y-1 == p1.y then
152 -- Turn into full block if pointing at a existing slab
153 if n0_is_upside_down then
154 -- Remove the slab at the position of the slab
155 minetest.remove_node(p0)
156 -- Make a fake stack of a single item and try to place it
157 local fakestack = ItemStack(recipeitem)
158 fakestack:set_count(itemstack:get_count())
160 pointed_thing.above = p0
162 fakestack, success = minetest.item_place(fakestack, placer, pointed_thing)
163 -- If the item was taken from the fake stack, decrement original
165 itemstack:set_count(fakestack:get_count())
166 -- Else put old node back
168 minetest.set_node(p0, n0)
173 -- Place upside down slab
177 -- If pointing at the side of a upside down slab
178 if n0_is_upside_down and p0.y+1 ~= p1.y then
182 return minetest.item_place(itemstack, placer, pointed_thing, param2)
187 minetest.register_node(":stairs:slab_" .. subname.."upside_down", {
188 replace_name = "stairs:slab_"..subname,
189 groups = {slabs_replace=1},
192 minetest.register_craft({
193 output = 'stairs:slab_' .. subname .. ' 6',
195 {recipeitem, recipeitem, recipeitem},
200 -- Replace old "upside_down" nodes with new param2 versions
201 minetest.register_abm({
202 nodenames = {"group:slabs_replace"},
205 action = function(pos, node)
206 node.name = minetest.registered_nodes[node.name].replace_name
207 node.param2 = node.param2 + 20
208 if node.param2 == 21 then
210 elseif node.param2 == 23 then
213 minetest.set_node(pos, node)
217 -- Nodes will be called stairs:{stair,slab}_<subname>
218 function stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds)
219 stairs.register_stair(subname, recipeitem, groups, images, desc_stair, sounds)
220 stairs.register_slab(subname, recipeitem, groups, images, desc_slab, sounds)
223 stairs.register_stair_and_slab("wood", "default:wood",
224 {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
225 {"default_wood.png"},
228 default.node_sound_wood_defaults())
230 stairs.register_stair_and_slab("junglewood", "default:junglewood",
231 {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
232 {"default_junglewood.png"},
235 default.node_sound_wood_defaults())
237 stairs.register_stair_and_slab("pine_wood", "default:pine_wood",
238 {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
239 {"default_pine_wood.png"},
242 default.node_sound_wood_defaults())
244 stairs.register_stair_and_slab("acacia_wood", "default:acacia_wood",
245 {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
246 {"default_acacia_wood.png"},
249 default.node_sound_wood_defaults())
251 stairs.register_stair_and_slab("stone", "default:stone",
253 {"default_stone.png"},
256 default.node_sound_stone_defaults())
258 stairs.register_stair_and_slab("cobble", "default:cobble",
260 {"default_cobble.png"},
263 default.node_sound_stone_defaults())
265 stairs.register_stair_and_slab("stonebrick", "default:stonebrick",
267 {"default_stone_brick.png"},
270 default.node_sound_stone_defaults())
272 stairs.register_stair_and_slab("desert_stone", "default:desert_stone",
274 {"default_desert_stone.png"},
277 default.node_sound_stone_defaults())
279 stairs.register_stair_and_slab("desert_cobble", "default:desert_cobble",
281 {"default_desert_cobble.png"},
282 "Desert Cobblestone Stair",
283 "Desert Cobblestone Slab",
284 default.node_sound_stone_defaults())
286 stairs.register_stair_and_slab("desert_stonebrick", "default:desert_stonebrick",
288 {"default_desert_stone_brick.png"},
289 "Desert Stone Brick Stair",
290 "Desert Stone Brick Slab",
291 default.node_sound_stone_defaults())
293 stairs.register_stair_and_slab("brick", "default:brick",
295 {"default_brick.png"},
298 default.node_sound_stone_defaults())
300 stairs.register_stair_and_slab("sandstone", "default:sandstone",
301 {crumbly = 2, cracky = 2},
302 {"default_sandstone.png"},
305 default.node_sound_stone_defaults())
307 stairs.register_stair_and_slab("sandstonebrick", "default:sandstonebrick",
308 {crumbly = 2, cracky = 2},
309 {"default_sandstone_brick.png"},
310 "Sandstone Brick Stair",
311 "Sandstone Brick Slab",
312 default.node_sound_stone_defaults())
314 stairs.register_stair_and_slab("obsidian", "default:obsidian",
315 {cracky = 1, level = 2},
316 {"default_obsidian.png"},
319 default.node_sound_stone_defaults())
321 stairs.register_stair_and_slab("obsidianbrick", "default:obsidianbrick",
322 {cracky = 1, level = 2},
323 {"default_obsidian_brick.png"},
324 "Obsidian Brick Stair",
325 "Obsidian Brick Slab",
326 default.node_sound_stone_defaults())