1 -- Minetest 0.4 mod: stairs
2 -- See README.txt for licensing and other information.
5 -- Global namespace for functions
10 -- Get setting for replace ABM
12 local replace = minetest.setting_getbool("enable_stairs_replace_abm")
16 -- Node will be called stairs:stair_<subname>
18 function stairs.register_stair(subname, recipeitem, groups, images, description, sounds)
19 minetest.register_node(":stairs:stair_" .. subname, {
20 description = description,
22 mesh = "stairs_stair.obj",
25 paramtype2 = "facedir",
26 is_ground_content = false,
32 {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
33 {-0.5, 0, 0, 0.5, 0.5, 0.5},
39 {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
40 {-0.5, 0, 0, 0.5, 0.5, 0.5},
43 on_place = function(itemstack, placer, pointed_thing)
44 if pointed_thing.type ~= "node" then
48 local p0 = pointed_thing.under
49 local p1 = pointed_thing.above
52 local placer_pos = placer:getpos()
55 x = p1.x - placer_pos.x,
56 y = p1.y - placer_pos.y,
57 z = p1.z - placer_pos.z
59 param2 = minetest.dir_to_facedir(dir)
62 if p0.y - 1 == p1.y then
66 elseif param2 == 23 then
71 return minetest.item_place(itemstack, placer, pointed_thing, param2)
77 minetest.register_node(":stairs:stair_" .. subname .. "upside_down", {
78 replace_name = "stairs:stair_" .. subname,
79 groups = {slabs_replace = 1},
83 minetest.register_craft({
84 output = 'stairs:stair_' .. subname .. ' 6',
87 {recipeitem, recipeitem, ""},
88 {recipeitem, recipeitem, recipeitem},
92 -- Flipped recipe for the silly minecrafters
93 minetest.register_craft({
94 output = 'stairs:stair_' .. subname .. ' 6',
97 {"", recipeitem, recipeitem},
98 {recipeitem, recipeitem, recipeitem},
105 -- Node will be called stairs:slab_<subname>
107 function stairs.register_slab(subname, recipeitem, groups, images, description, sounds)
108 minetest.register_node(":stairs:slab_" .. subname, {
109 description = description,
110 drawtype = "nodebox",
113 paramtype2 = "facedir",
114 is_ground_content = false,
119 fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
121 on_place = function(itemstack, placer, pointed_thing)
122 if pointed_thing.type ~= "node" then
126 -- If it's being placed on an another similar one, replace it with
130 local p0 = pointed_thing.under
131 local p1 = pointed_thing.above
132 local n0 = minetest.get_node(p0)
133 local n1 = minetest.get_node(p1)
136 local n0_is_upside_down = (n0.name == "stairs:slab_" .. subname and
139 if n0.name == "stairs:slab_" .. subname and not n0_is_upside_down and
140 p0.y + 1 == p1.y then
143 elseif n1.name == "stairs:slab_" .. subname then
148 -- Remove the slab at slabpos
149 minetest.remove_node(slabpos)
150 -- Make a fake stack of a single item and try to place it
151 local fakestack = ItemStack(recipeitem)
152 fakestack:set_count(itemstack:get_count())
154 pointed_thing.above = slabpos
156 fakestack, success = minetest.item_place(fakestack, placer,
158 -- If the item was taken from the fake stack, decrement original
160 itemstack:set_count(fakestack:get_count())
161 -- Else put old node back
163 minetest.set_node(slabpos, slabnode)
169 if p0.y - 1 == p1.y then
170 -- Turn into full block if pointing at a existing slab
171 if n0_is_upside_down then
172 -- Remove the slab at the position of the slab
173 minetest.remove_node(p0)
174 -- Make a fake stack of a single item and try to place it
175 local fakestack = ItemStack(recipeitem)
176 fakestack:set_count(itemstack:get_count())
178 pointed_thing.above = p0
180 fakestack, success = minetest.item_place(fakestack, placer,
182 -- If the item was taken from the fake stack, decrement original
184 itemstack:set_count(fakestack:get_count())
185 -- Else put old node back
187 minetest.set_node(p0, n0)
192 -- Place upside down slab
196 -- If pointing at the side of a upside down slab
197 if n0_is_upside_down and p0.y + 1 ~= p1.y then
201 return minetest.item_place(itemstack, placer, pointed_thing, param2)
207 minetest.register_node(":stairs:slab_" .. subname .. "upside_down", {
208 replace_name = "stairs:slab_".. subname,
209 groups = {slabs_replace = 1},
213 minetest.register_craft({
214 output = 'stairs:slab_' .. subname .. ' 6',
216 {recipeitem, recipeitem, recipeitem},
222 -- Optionally replace old "upside_down" nodes with new param2 versions.
223 -- Disabled by default.
226 minetest.register_abm({
227 nodenames = {"group:slabs_replace"},
230 action = function(pos, node)
231 node.name = minetest.registered_nodes[node.name].replace_name
232 node.param2 = node.param2 + 20
233 if node.param2 == 21 then
235 elseif node.param2 == 23 then
238 minetest.set_node(pos, node)
244 -- Stair/slab registration function.
245 -- Nodes will be called stairs:{stair,slab}_<subname>
247 function stairs.register_stair_and_slab(subname, recipeitem, groups, images,
248 desc_stair, desc_slab, sounds)
249 stairs.register_stair(subname, recipeitem, groups, images, desc_stair, sounds)
250 stairs.register_slab(subname, recipeitem, groups, images, desc_slab, sounds)
254 -- Register default stairs and slabs
256 stairs.register_stair_and_slab("wood", "default:wood",
257 {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
258 {"default_wood.png"},
261 default.node_sound_wood_defaults())
263 stairs.register_stair_and_slab("junglewood", "default:junglewood",
264 {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
265 {"default_junglewood.png"},
268 default.node_sound_wood_defaults())
270 stairs.register_stair_and_slab("pine_wood", "default:pine_wood",
271 {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
272 {"default_pine_wood.png"},
275 default.node_sound_wood_defaults())
277 stairs.register_stair_and_slab("acacia_wood", "default:acacia_wood",
278 {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
279 {"default_acacia_wood.png"},
282 default.node_sound_wood_defaults())
284 stairs.register_stair_and_slab("stone", "default:stone",
286 {"default_stone.png"},
289 default.node_sound_stone_defaults())
291 stairs.register_stair_and_slab("cobble", "default:cobble",
293 {"default_cobble.png"},
296 default.node_sound_stone_defaults())
298 stairs.register_stair_and_slab("stonebrick", "default:stonebrick",
300 {"default_stone_brick.png"},
303 default.node_sound_stone_defaults())
305 stairs.register_stair_and_slab("desert_stone", "default:desert_stone",
307 {"default_desert_stone.png"},
310 default.node_sound_stone_defaults())
312 stairs.register_stair_and_slab("desert_cobble", "default:desert_cobble",
314 {"default_desert_cobble.png"},
315 "Desert Cobblestone Stair",
316 "Desert Cobblestone Slab",
317 default.node_sound_stone_defaults())
319 stairs.register_stair_and_slab("desert_stonebrick", "default:desert_stonebrick",
321 {"default_desert_stone_brick.png"},
322 "Desert Stone Brick Stair",
323 "Desert Stone Brick Slab",
324 default.node_sound_stone_defaults())
326 stairs.register_stair_and_slab("sandstone", "default:sandstone",
327 {crumbly = 2, cracky = 2},
328 {"default_sandstone.png"},
331 default.node_sound_stone_defaults())
333 stairs.register_stair_and_slab("sandstonebrick", "default:sandstonebrick",
334 {crumbly = 2, cracky = 2},
335 {"default_sandstone_brick.png"},
336 "Sandstone Brick Stair",
337 "Sandstone Brick Slab",
338 default.node_sound_stone_defaults())
340 stairs.register_stair_and_slab("obsidian", "default:obsidian",
341 {cracky = 1, level = 2},
342 {"default_obsidian.png"},
345 default.node_sound_stone_defaults())
347 stairs.register_stair_and_slab("obsidianbrick", "default:obsidianbrick",
348 {cracky = 1, level = 2},
349 {"default_obsidian_brick.png"},
350 "Obsidian Brick Stair",
351 "Obsidian Brick Slab",
352 default.node_sound_stone_defaults())
354 stairs.register_stair_and_slab("brick", "default:brick",
356 {"default_brick.png"},
359 default.node_sound_stone_defaults())
361 stairs.register_stair_and_slab("straw", "farming:straw",
362 {snappy = 3, flammable = 4},
363 {"farming_straw.png"},
366 default.node_sound_leaves_defaults())
368 stairs.register_stair_and_slab("steelblock", "default:steelblock",
369 {cracky = 1, level = 2},
370 {"default_steel_block.png"},
373 default.node_sound_stone_defaults())
375 stairs.register_stair_and_slab("copperblock", "default:copperblock",
376 {cracky = 1, level = 2},
377 {"default_copper_block.png"},
378 "Copper Block Stair",
380 default.node_sound_stone_defaults())
382 stairs.register_stair_and_slab("bronzeblock", "default:bronzeblock",
383 {cracky = 1, level = 2},
384 {"default_bronze_block.png"},
385 "Bronze Block Stair",
387 default.node_sound_stone_defaults())
389 stairs.register_stair_and_slab("goldblock", "default:goldblock",
391 {"default_gold_block.png"},
394 default.node_sound_stone_defaults())