1 -- Minetest 0.4 mod: stairs
2 -- See README.txt for licensing and other information.
5 -- Global namespace for functions
10 -- Register aliases for new pine node names
12 minetest.register_alias("stairs:stair_pinewood", "stairs:stair_pine_wood")
13 minetest.register_alias("stairs:slab_pinewood", "stairs:slab_pine_wood")
16 -- Get setting for replace ABM
18 local replace = minetest.setting_getbool("enable_stairs_replace_abm")
22 -- Node will be called stairs:stair_<subname>
24 function stairs.register_stair(subname, recipeitem, groups, images, description, sounds)
26 minetest.register_node(":stairs:stair_" .. subname, {
27 description = description,
29 mesh = "stairs_stair.obj",
32 paramtype2 = "facedir",
33 is_ground_content = false,
39 {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
40 {-0.5, 0, 0, 0.5, 0.5, 0.5},
46 {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
47 {-0.5, 0, 0, 0.5, 0.5, 0.5},
50 on_place = function(itemstack, placer, pointed_thing)
51 if pointed_thing.type ~= "node" then
55 local p0 = pointed_thing.under
56 local p1 = pointed_thing.above
59 local placer_pos = placer:getpos()
62 x = p1.x - placer_pos.x,
63 y = p1.y - placer_pos.y,
64 z = p1.z - placer_pos.z
66 param2 = minetest.dir_to_facedir(dir)
69 if p0.y - 1 == p1.y then
73 elseif param2 == 23 then
78 return minetest.item_place(itemstack, placer, pointed_thing, param2)
84 minetest.register_node(":stairs:stair_" .. subname .. "upside_down", {
85 replace_name = "stairs:stair_" .. subname,
86 groups = {slabs_replace = 1},
90 minetest.register_craft({
91 output = 'stairs:stair_' .. subname .. ' 6',
94 {recipeitem, recipeitem, ""},
95 {recipeitem, recipeitem, recipeitem},
99 -- Flipped recipe for the silly minecrafters
100 minetest.register_craft({
101 output = 'stairs:stair_' .. subname .. ' 6',
103 {"", "", recipeitem},
104 {"", recipeitem, recipeitem},
105 {recipeitem, recipeitem, recipeitem},
112 -- Node will be called stairs:slab_<subname>
114 function stairs.register_slab(subname, recipeitem, groups, images, description, sounds)
116 minetest.register_node(":stairs:slab_" .. subname, {
117 description = description,
118 drawtype = "nodebox",
121 paramtype2 = "facedir",
122 is_ground_content = false,
127 fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
129 on_place = function(itemstack, placer, pointed_thing)
130 if pointed_thing.type ~= "node" then
134 -- If it's being placed on an another similar one, replace it with
138 local p0 = pointed_thing.under
139 local p1 = pointed_thing.above
140 local n0 = minetest.get_node(p0)
141 local n1 = minetest.get_node(p1)
144 local n0_is_upside_down = (n0.name == "stairs:slab_" .. subname and
147 if n0.name == "stairs:slab_" .. subname and not n0_is_upside_down and
148 p0.y + 1 == p1.y then
151 elseif n1.name == "stairs:slab_" .. subname then
156 -- Remove the slab at slabpos
157 minetest.remove_node(slabpos)
158 -- Make a fake stack of a single item and try to place it
159 local fakestack = ItemStack(recipeitem)
160 fakestack:set_count(itemstack:get_count())
162 pointed_thing.above = slabpos
164 fakestack, success = minetest.item_place(fakestack, placer,
166 -- If the item was taken from the fake stack, decrement original
168 itemstack:set_count(fakestack:get_count())
169 -- Else put old node back
171 minetest.set_node(slabpos, slabnode)
177 if p0.y - 1 == p1.y then
178 -- Turn into full block if pointing at a existing slab
179 if n0_is_upside_down then
180 -- Remove the slab at the position of the slab
181 minetest.remove_node(p0)
182 -- Make a fake stack of a single item and try to place it
183 local fakestack = ItemStack(recipeitem)
184 fakestack:set_count(itemstack:get_count())
186 pointed_thing.above = p0
188 fakestack, success = minetest.item_place(fakestack, placer,
190 -- If the item was taken from the fake stack, decrement original
192 itemstack:set_count(fakestack:get_count())
193 -- Else put old node back
195 minetest.set_node(p0, n0)
200 -- Place upside down slab
204 -- If pointing at the side of a upside down slab
205 if n0_is_upside_down and p0.y + 1 ~= p1.y then
209 return minetest.item_place(itemstack, placer, pointed_thing, param2)
215 minetest.register_node(":stairs:slab_" .. subname .. "upside_down", {
216 replace_name = "stairs:slab_".. subname,
217 groups = {slabs_replace = 1},
221 minetest.register_craft({
222 output = 'stairs:slab_' .. subname .. ' 6',
224 {recipeitem, recipeitem, recipeitem},
230 -- Optionally replace old "upside_down" nodes with new param2 versions.
231 -- Disabled by default.
234 minetest.register_abm({
235 nodenames = {"group:slabs_replace"},
238 action = function(pos, node)
239 node.name = minetest.registered_nodes[node.name].replace_name
240 node.param2 = node.param2 + 20
241 if node.param2 == 21 then
243 elseif node.param2 == 23 then
246 minetest.set_node(pos, node)
252 -- Stair/slab registration function.
253 -- Nodes will be called stairs:{stair,slab}_<subname>
255 function stairs.register_stair_and_slab(subname, recipeitem, groups, images,
256 desc_stair, desc_slab, sounds)
257 stairs.register_stair(subname, recipeitem, groups, images, desc_stair, sounds)
258 stairs.register_slab(subname, recipeitem, groups, images, desc_slab, sounds)
262 -- Register default stairs and slabs
264 stairs.register_stair_and_slab("wood", "default:wood",
265 {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
266 {"default_wood.png"},
269 default.node_sound_wood_defaults())
271 stairs.register_stair_and_slab("junglewood", "default:junglewood",
272 {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
273 {"default_junglewood.png"},
276 default.node_sound_wood_defaults())
278 stairs.register_stair_and_slab("pine_wood", "default:pine_wood",
279 {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
280 {"default_pine_wood.png"},
283 default.node_sound_wood_defaults())
285 stairs.register_stair_and_slab("acacia_wood", "default:acacia_wood",
286 {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
287 {"default_acacia_wood.png"},
290 default.node_sound_wood_defaults())
292 stairs.register_stair_and_slab("aspen_wood", "default:aspen_wood",
293 {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
294 {"default_aspen_wood.png"},
297 default.node_sound_wood_defaults())
299 stairs.register_stair_and_slab("stone", "default:stone",
301 {"default_stone.png"},
304 default.node_sound_stone_defaults())
306 stairs.register_stair_and_slab("cobble", "default:cobble",
308 {"default_cobble.png"},
311 default.node_sound_stone_defaults())
313 stairs.register_stair_and_slab("stonebrick", "default:stonebrick",
315 {"default_stone_brick.png"},
318 default.node_sound_stone_defaults())
320 stairs.register_stair_and_slab("desert_stone", "default:desert_stone",
322 {"default_desert_stone.png"},
325 default.node_sound_stone_defaults())
327 stairs.register_stair_and_slab("desert_cobble", "default:desert_cobble",
329 {"default_desert_cobble.png"},
330 "Desert Cobblestone Stair",
331 "Desert Cobblestone Slab",
332 default.node_sound_stone_defaults())
334 stairs.register_stair_and_slab("desert_stonebrick", "default:desert_stonebrick",
336 {"default_desert_stone_brick.png"},
337 "Desert Stone Brick Stair",
338 "Desert Stone Brick Slab",
339 default.node_sound_stone_defaults())
341 stairs.register_stair_and_slab("sandstone", "default:sandstone",
342 {crumbly = 2, cracky = 2},
343 {"default_sandstone.png"},
346 default.node_sound_stone_defaults())
348 stairs.register_stair_and_slab("sandstonebrick", "default:sandstonebrick",
349 {crumbly = 2, cracky = 2},
350 {"default_sandstone_brick.png"},
351 "Sandstone Brick Stair",
352 "Sandstone Brick Slab",
353 default.node_sound_stone_defaults())
355 stairs.register_stair_and_slab("obsidian", "default:obsidian",
356 {cracky = 1, level = 2},
357 {"default_obsidian.png"},
360 default.node_sound_stone_defaults())
362 stairs.register_stair_and_slab("obsidianbrick", "default:obsidianbrick",
363 {cracky = 1, level = 2},
364 {"default_obsidian_brick.png"},
365 "Obsidian Brick Stair",
366 "Obsidian Brick Slab",
367 default.node_sound_stone_defaults())
369 stairs.register_stair_and_slab("brick", "default:brick",
371 {"default_brick.png"},
374 default.node_sound_stone_defaults())
376 stairs.register_stair_and_slab("straw", "farming:straw",
377 {snappy = 3, flammable = 4},
378 {"farming_straw.png"},
381 default.node_sound_leaves_defaults())
383 stairs.register_stair_and_slab("steelblock", "default:steelblock",
384 {cracky = 1, level = 2},
385 {"default_steel_block.png"},
388 default.node_sound_stone_defaults())
390 stairs.register_stair_and_slab("copperblock", "default:copperblock",
391 {cracky = 1, level = 2},
392 {"default_copper_block.png"},
393 "Copper Block Stair",
395 default.node_sound_stone_defaults())
397 stairs.register_stair_and_slab("bronzeblock", "default:bronzeblock",
398 {cracky = 1, level = 2},
399 {"default_bronze_block.png"},
400 "Bronze Block Stair",
402 default.node_sound_stone_defaults())
404 stairs.register_stair_and_slab("goldblock", "default:goldblock",
406 {"default_gold_block.png"},
409 default.node_sound_stone_defaults())