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},
91 minetest.register_craft({
92 output = 'stairs:stair_' .. subname .. ' 8',
95 {recipeitem, recipeitem, ""},
96 {recipeitem, recipeitem, recipeitem},
100 -- Flipped recipe for the silly minecrafters
101 minetest.register_craft({
102 output = 'stairs:stair_' .. subname .. ' 8',
104 {"", "", recipeitem},
105 {"", recipeitem, recipeitem},
106 {recipeitem, recipeitem, recipeitem},
111 local baseburntime = minetest.get_craft_result({
116 if baseburntime > 0 then
117 minetest.register_craft({
119 recipe = 'stairs:stair_' .. subname,
120 burntime = math.floor(baseburntime * 0.75),
127 -- Slab facedir to placement 6d matching table
128 local slab_trans_dir = {[0] = 8, 0, 2, 1, 3, 4}
129 -- Slab facedir when placing initial slab against other surface
130 local slab_trans_dir_place = {[0] = 0, 20, 12, 16, 4, 8}
133 -- Node will be called stairs:slab_<subname>
135 function stairs.register_slab(subname, recipeitem, groups, images, description, sounds)
137 minetest.register_node(":stairs:slab_" .. subname, {
138 description = description,
139 drawtype = "nodebox",
142 paramtype2 = "facedir",
143 is_ground_content = false,
148 fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
150 on_place = function(itemstack, placer, pointed_thing)
151 local under = minetest.get_node(pointed_thing.under)
152 local wield_item = itemstack:get_name()
154 if under and wield_item == under.name then
155 -- place slab using under node orientation
156 local dir = minetest.dir_to_facedir(vector.subtract(
157 pointed_thing.above, pointed_thing.under), true)
159 local p2 = under.param2
161 -- combine two slabs if possible
162 if slab_trans_dir[math.floor(p2 / 4)] == dir then
163 if not recipeitem then
166 local player_name = placer:get_player_name()
167 if minetest.is_protected(pointed_thing.under, player_name) and not
168 minetest.check_player_privs(placer, "protection_bypass") then
169 minetest.record_protection_violation(pointed_thing.under,
173 minetest.set_node(pointed_thing.under, {name = recipeitem, param2 = p2})
174 if not minetest.setting_getbool("creative_mode") then
175 itemstack:take_item()
180 -- Placing a slab on an upside down slab should make it right-side up.
181 if p2 >= 20 and dir == 8 then
183 -- same for the opposite case: slab below normal slab
184 elseif p2 <= 3 and dir == 4 then
188 -- else attempt to place node with proper param2
189 minetest.item_place_node(ItemStack(wield_item), placer, pointed_thing, p2)
190 if not minetest.setting_getbool("creative_mode") then
191 itemstack:take_item()
195 -- place slab using look direction of player
196 local dir = minetest.dir_to_wallmounted(vector.subtract(
197 pointed_thing.above, pointed_thing.under), true)
199 local rot = slab_trans_dir_place[dir]
200 if rot == 0 or rot == 20 then
201 rot = rot + minetest.dir_to_facedir(placer:get_look_dir())
204 return minetest.item_place(itemstack, placer, pointed_thing, rot)
211 minetest.register_node(":stairs:slab_" .. subname .. "upside_down", {
212 replace_name = "stairs:slab_".. subname,
213 groups = {slabs_replace = 1},
218 minetest.register_craft({
219 output = 'stairs:slab_' .. subname .. ' 6',
221 {recipeitem, recipeitem, recipeitem},
226 local baseburntime = minetest.get_craft_result({
231 if baseburntime > 0 then
232 minetest.register_craft({
234 recipe = 'stairs:slab_' .. subname,
235 burntime = math.floor(baseburntime * 0.5),
242 -- Optionally replace old "upside_down" nodes with new param2 versions.
243 -- Disabled by default.
246 minetest.register_abm({
247 label = "Slab replace",
248 nodenames = {"group:slabs_replace"},
251 action = function(pos, node)
252 node.name = minetest.registered_nodes[node.name].replace_name
253 node.param2 = node.param2 + 20
254 if node.param2 == 21 then
256 elseif node.param2 == 23 then
259 minetest.set_node(pos, node)
265 -- Stair/slab registration function.
266 -- Nodes will be called stairs:{stair,slab}_<subname>
268 function stairs.register_stair_and_slab(subname, recipeitem,
269 groups, images, desc_stair, desc_slab, sounds)
270 stairs.register_stair(subname, recipeitem, groups, images, desc_stair, sounds)
271 stairs.register_slab(subname, recipeitem, groups, images, desc_slab, sounds)
275 -- Register default stairs and slabs
277 stairs.register_stair_and_slab(
280 {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
281 {"default_wood.png"},
284 default.node_sound_wood_defaults()
287 stairs.register_stair_and_slab(
289 "default:junglewood",
290 {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
291 {"default_junglewood.png"},
294 default.node_sound_wood_defaults()
297 stairs.register_stair_and_slab(
300 {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3},
301 {"default_pine_wood.png"},
304 default.node_sound_wood_defaults()
307 stairs.register_stair_and_slab(
309 "default:acacia_wood",
310 {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
311 {"default_acacia_wood.png"},
314 default.node_sound_wood_defaults()
317 stairs.register_stair_and_slab(
319 "default:aspen_wood",
320 {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3},
321 {"default_aspen_wood.png"},
324 default.node_sound_wood_defaults()
327 stairs.register_stair_and_slab(
331 {"default_stone.png"},
334 default.node_sound_stone_defaults()
337 stairs.register_stair_and_slab(
341 {"default_cobble.png"},
344 default.node_sound_stone_defaults()
347 stairs.register_stair_and_slab(
351 {"default_mossycobble.png"},
352 "Mossy Cobblestone Stair",
353 "Mossy Cobblestone Slab",
354 default.node_sound_stone_defaults()
357 stairs.register_stair_and_slab(
359 "default:stonebrick",
361 {"default_stone_brick.png"},
364 default.node_sound_stone_defaults()
367 stairs.register_stair_and_slab(
369 "default:stone_block",
371 {"default_stone_block.png"},
374 default.node_sound_stone_defaults()
377 stairs.register_stair_and_slab(
379 "default:desert_stone",
381 {"default_desert_stone.png"},
382 "Desert Stone Stair",
384 default.node_sound_stone_defaults()
387 stairs.register_stair_and_slab(
389 "default:desert_cobble",
391 {"default_desert_cobble.png"},
392 "Desert Cobblestone Stair",
393 "Desert Cobblestone Slab",
394 default.node_sound_stone_defaults()
397 stairs.register_stair_and_slab(
399 "default:desert_stonebrick",
401 {"default_desert_stone_brick.png"},
402 "Desert Stone Brick Stair",
403 "Desert Stone Brick Slab",
404 default.node_sound_stone_defaults()
407 stairs.register_stair_and_slab(
408 "desert_stone_block",
409 "default:desert_stone_block",
411 {"default_desert_stone_block.png"},
412 "Desert Stone Block Stair",
413 "Desert Stone Block Slab",
414 default.node_sound_stone_defaults()
417 stairs.register_stair_and_slab(
420 {crumbly = 1, cracky = 3},
421 {"default_sandstone.png"},
424 default.node_sound_stone_defaults()
427 stairs.register_stair_and_slab(
429 "default:sandstonebrick",
431 {"default_sandstone_brick.png"},
432 "Sandstone Brick Stair",
433 "Sandstone Brick Slab",
434 default.node_sound_stone_defaults()
437 stairs.register_stair_and_slab(
439 "default:sandstone_block",
441 {"default_sandstone_block.png"},
442 "Sandstone Block Stair",
443 "Sandstone Block Slab",
444 default.node_sound_stone_defaults()
447 stairs.register_stair_and_slab(
450 {cracky = 1, level = 2},
451 {"default_obsidian.png"},
454 default.node_sound_stone_defaults()
457 stairs.register_stair_and_slab(
459 "default:obsidianbrick",
460 {cracky = 1, level = 2},
461 {"default_obsidian_brick.png"},
462 "Obsidian Brick Stair",
463 "Obsidian Brick Slab",
464 default.node_sound_stone_defaults()
467 stairs.register_stair_and_slab(
469 "default:obsidian_block",
470 {cracky = 1, level = 2},
471 {"default_obsidian_block.png"},
472 "Obsidian Block Stair",
473 "Obsidian Block Slab",
474 default.node_sound_stone_defaults()
477 stairs.register_stair_and_slab(
481 {"default_brick.png"},
484 default.node_sound_stone_defaults()
487 stairs.register_stair_and_slab(
490 {snappy = 3, flammable = 4},
491 {"farming_straw.png"},
494 default.node_sound_leaves_defaults()
497 stairs.register_stair_and_slab(
499 "default:steelblock",
500 {cracky = 1, level = 2},
501 {"default_steel_block.png"},
504 default.node_sound_metal_defaults()
507 stairs.register_stair_and_slab(
509 "default:copperblock",
510 {cracky = 1, level = 2},
511 {"default_copper_block.png"},
512 "Copper Block Stair",
514 default.node_sound_metal_defaults()
517 stairs.register_stair_and_slab(
519 "default:bronzeblock",
520 {cracky = 1, level = 2},
521 {"default_bronze_block.png"},
522 "Bronze Block Stair",
524 default.node_sound_metal_defaults()
527 stairs.register_stair_and_slab(
531 {"default_gold_block.png"},
534 default.node_sound_metal_defaults()