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.settings:get_bool("enable_stairs_replace_abm")
20 local function rotate_and_place(itemstack, placer, pointed_thing)
21 local p0 = pointed_thing.under
22 local p1 = pointed_thing.above
26 local placer_pos = placer:getpos()
28 param2 = minetest.dir_to_facedir(vector.subtract(p1, placer_pos))
31 local finepos = minetest.pointed_thing_to_face_pos(placer, pointed_thing)
32 local fpos = finepos.y % 1
34 if p0.y - 1 == p1.y or (fpos > 0 and fpos < 0.5)
35 or (fpos < -0.5 and fpos > -0.999999999) then
39 elseif param2 == 23 then
44 return minetest.item_place(itemstack, placer, pointed_thing, param2)
49 -- Node will be called stairs:stair_<subname>
51 function stairs.register_stair(subname, recipeitem, groups, images, description, sounds)
52 -- Set backface culling and world-aligned textures
53 local stair_images = {}
54 for i, image in ipairs(images) do
55 if type(image) == "string" then
58 backface_culling = true,
59 align_style = "world",
62 stair_images[i] = table.copy(image)
63 if stair_images[i].backface_culling == nil then
64 stair_images[i].backface_culling = true
66 if stair_images[i].align_style == nil then
67 stair_images[i].align_style = "world"
71 local new_groups = table.copy(groups)
73 minetest.register_node(":stairs:stair_" .. subname, {
74 description = description,
78 paramtype2 = "facedir",
79 is_ground_content = false,
85 {-0.5, -0.5, -0.5, 0.5, 0.0, 0.5},
86 {-0.5, 0.0, 0.0, 0.5, 0.5, 0.5},
89 on_place = function(itemstack, placer, pointed_thing)
90 if pointed_thing.type ~= "node" then
94 return rotate_and_place(itemstack, placer, pointed_thing)
100 minetest.register_node(":stairs:stair_" .. subname .. "upside_down", {
101 replace_name = "stairs:stair_" .. subname,
102 groups = {slabs_replace = 1},
107 -- Recipe matches appearence in inventory
108 minetest.register_craft({
109 output = 'stairs:stair_' .. subname .. ' 8',
111 {"", "", recipeitem},
112 {"", recipeitem, recipeitem},
113 {recipeitem, recipeitem, recipeitem},
117 -- Use stairs to craft full blocks again (1:1)
118 minetest.register_craft({
119 output = recipeitem .. ' 3',
121 {'stairs:stair_' .. subname, 'stairs:stair_' .. subname},
122 {'stairs:stair_' .. subname, 'stairs:stair_' .. subname},
127 local baseburntime = minetest.get_craft_result({
132 if baseburntime > 0 then
133 minetest.register_craft({
135 recipe = 'stairs:stair_' .. subname,
136 burntime = math.floor(baseburntime * 0.75),
143 -- Slab facedir to placement 6d matching table
144 local slab_trans_dir = {[0] = 8, 0, 2, 1, 3, 4}
148 -- Node will be called stairs:slab_<subname>
150 function stairs.register_slab(subname, recipeitem, groups, images, description, sounds)
151 -- Set world-aligned textures
152 local slab_images = {}
153 for i, image in ipairs(images) do
154 if type(image) == "string" then
157 align_style = "world",
160 slab_images[i] = table.copy(image)
161 if image.align_style == nil then
162 slab_images[i].align_style = "world"
166 local new_groups = table.copy(groups)
168 minetest.register_node(":stairs:slab_" .. subname, {
169 description = description,
170 drawtype = "nodebox",
173 paramtype2 = "facedir",
174 is_ground_content = false,
179 fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
181 on_place = function(itemstack, placer, pointed_thing)
182 local under = minetest.get_node(pointed_thing.under)
183 local wield_item = itemstack:get_name()
184 local player_name = placer and placer:get_player_name() or ""
185 local creative_enabled = (creative and creative.is_enabled_for
186 and creative.is_enabled_for(player_name))
188 if under and under.name:find("stairs:slab_") then
189 -- place slab using under node orientation
190 local dir = minetest.dir_to_facedir(vector.subtract(
191 pointed_thing.above, pointed_thing.under), true)
193 local p2 = under.param2
195 -- combine two slabs if possible
196 if slab_trans_dir[math.floor(p2 / 4)] == dir
197 and wield_item == under.name then
199 if not recipeitem then
202 if minetest.is_protected(pointed_thing.under, player_name) and not
203 minetest.check_player_privs(player_name, "protection_bypass") then
204 minetest.record_protection_violation(pointed_thing.under,
208 minetest.set_node(pointed_thing.under, {name = recipeitem, param2 = p2})
209 if not creative_enabled then
210 itemstack:take_item()
215 -- Placing a slab on an upside down slab should make it right-side up.
216 if p2 >= 20 and dir == 8 then
218 -- same for the opposite case: slab below normal slab
219 elseif p2 <= 3 and dir == 4 then
223 -- else attempt to place node with proper param2
224 minetest.item_place_node(ItemStack(wield_item), placer, pointed_thing, p2)
225 if not creative_enabled then
226 itemstack:take_item()
230 return rotate_and_place(itemstack, placer, pointed_thing)
237 minetest.register_node(":stairs:slab_" .. subname .. "upside_down", {
238 replace_name = "stairs:slab_".. subname,
239 groups = {slabs_replace = 1},
244 minetest.register_craft({
245 output = 'stairs:slab_' .. subname .. ' 6',
247 {recipeitem, recipeitem, recipeitem},
251 -- Use 2 slabs to craft a full block again (1:1)
252 minetest.register_craft({
255 {'stairs:slab_' .. subname},
256 {'stairs:slab_' .. subname},
261 local baseburntime = minetest.get_craft_result({
266 if baseburntime > 0 then
267 minetest.register_craft({
269 recipe = 'stairs:slab_' .. subname,
270 burntime = math.floor(baseburntime * 0.5),
277 -- Optionally replace old "upside_down" nodes with new param2 versions.
278 -- Disabled by default.
281 minetest.register_abm({
282 label = "Slab replace",
283 nodenames = {"group:slabs_replace"},
286 action = function(pos, node)
287 node.name = minetest.registered_nodes[node.name].replace_name
288 node.param2 = node.param2 + 20
289 if node.param2 == 21 then
291 elseif node.param2 == 23 then
294 minetest.set_node(pos, node)
300 -- Register inner stair
301 -- Node will be called stairs:stair_inner_<subname>
303 function stairs.register_stair_inner(subname, recipeitem, groups, images, description, sounds)
304 -- Set backface culling and world-aligned textures
305 local stair_images = {}
306 for i, image in ipairs(images) do
307 if type(image) == "string" then
310 backface_culling = true,
311 align_style = "world",
314 stair_images[i] = table.copy(image)
315 if stair_images[i].backface_culling == nil then
316 stair_images[i].backface_culling = true
318 if stair_images[i].align_style == nil then
319 stair_images[i].align_style = "world"
323 local new_groups = table.copy(groups)
325 minetest.register_node(":stairs:stair_inner_" .. subname, {
326 description = "Inner " .. description,
327 drawtype = "nodebox",
328 tiles = stair_images,
330 paramtype2 = "facedir",
331 is_ground_content = false,
337 {-0.5, -0.5, -0.5, 0.5, 0.0, 0.5},
338 {-0.5, 0.0, 0.0, 0.5, 0.5, 0.5},
339 {-0.5, 0.0, -0.5, 0.0, 0.5, 0.0},
342 on_place = function(itemstack, placer, pointed_thing)
343 if pointed_thing.type ~= "node" then
347 return rotate_and_place(itemstack, placer, pointed_thing)
352 minetest.register_craft({
353 output = 'stairs:stair_inner_' .. subname .. ' 7',
355 { "", recipeitem, ""},
356 { recipeitem, "", recipeitem},
357 {recipeitem, recipeitem, recipeitem},
362 local baseburntime = minetest.get_craft_result({
367 if baseburntime > 0 then
368 minetest.register_craft({
370 recipe = 'stairs:stair_inner_' .. subname,
371 burntime = math.floor(baseburntime * 0.875),
378 -- Register outer stair
379 -- Node will be called stairs:stair_outer_<subname>
381 function stairs.register_stair_outer(subname, recipeitem, groups, images, description, sounds)
382 -- Set backface culling and world-aligned textures
383 local stair_images = {}
384 for i, image in ipairs(images) do
385 if type(image) == "string" then
388 backface_culling = true,
389 align_style = "world",
392 stair_images[i] = table.copy(image)
393 if stair_images[i].backface_culling == nil then
394 stair_images[i].backface_culling = true
396 if stair_images[i].align_style == nil then
397 stair_images[i].align_style = "world"
401 local new_groups = table.copy(groups)
403 minetest.register_node(":stairs:stair_outer_" .. subname, {
404 description = "Outer " .. description,
405 drawtype = "nodebox",
406 tiles = stair_images,
408 paramtype2 = "facedir",
409 is_ground_content = false,
415 {-0.5, -0.5, -0.5, 0.5, 0.0, 0.5},
416 {-0.5, 0.0, 0.0, 0.0, 0.5, 0.5},
419 on_place = function(itemstack, placer, pointed_thing)
420 if pointed_thing.type ~= "node" then
424 return rotate_and_place(itemstack, placer, pointed_thing)
429 minetest.register_craft({
430 output = 'stairs:stair_outer_' .. subname .. ' 6',
433 { "", recipeitem, ""},
434 {recipeitem, recipeitem, recipeitem},
439 local baseburntime = minetest.get_craft_result({
444 if baseburntime > 0 then
445 minetest.register_craft({
447 recipe = 'stairs:stair_outer_' .. subname,
448 burntime = math.floor(baseburntime * 0.625),
455 -- Stair/slab registration function.
456 -- Nodes will be called stairs:{stair,slab}_<subname>
458 function stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds)
459 stairs.register_stair(subname, recipeitem, groups, images, desc_stair, sounds)
460 stairs.register_stair_inner(subname, recipeitem, groups, images, desc_stair, sounds)
461 stairs.register_stair_outer(subname, recipeitem, groups, images, desc_stair, sounds)
462 stairs.register_slab(subname, recipeitem, groups, images, desc_slab, sounds)
466 -- Register default stairs and slabs
468 stairs.register_stair_and_slab(
471 {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
472 {"default_wood.png"},
475 default.node_sound_wood_defaults()
478 stairs.register_stair_and_slab(
480 "default:junglewood",
481 {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
482 {"default_junglewood.png"},
485 default.node_sound_wood_defaults()
488 stairs.register_stair_and_slab(
491 {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3},
492 {"default_pine_wood.png"},
495 default.node_sound_wood_defaults()
498 stairs.register_stair_and_slab(
500 "default:acacia_wood",
501 {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
502 {"default_acacia_wood.png"},
505 default.node_sound_wood_defaults()
508 stairs.register_stair_and_slab(
510 "default:aspen_wood",
511 {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3},
512 {"default_aspen_wood.png"},
515 default.node_sound_wood_defaults()
518 stairs.register_stair_and_slab(
522 {"default_stone.png"},
525 default.node_sound_stone_defaults()
528 stairs.register_stair_and_slab(
532 {"default_cobble.png"},
535 default.node_sound_stone_defaults()
538 stairs.register_stair_and_slab(
540 "default:mossycobble",
542 {"default_mossycobble.png"},
543 "Mossy Cobblestone Stair",
544 "Mossy Cobblestone Slab",
545 default.node_sound_stone_defaults()
548 stairs.register_stair_and_slab(
550 "default:stonebrick",
552 {"default_stone_brick.png"},
555 default.node_sound_stone_defaults()
558 stairs.register_stair_and_slab(
560 "default:stone_block",
562 {"default_stone_block.png"},
565 default.node_sound_stone_defaults()
568 stairs.register_stair_and_slab(
570 "default:desert_stone",
572 {"default_desert_stone.png"},
573 "Desert Stone Stair",
575 default.node_sound_stone_defaults()
578 stairs.register_stair_and_slab(
580 "default:desert_cobble",
582 {"default_desert_cobble.png"},
583 "Desert Cobblestone Stair",
584 "Desert Cobblestone Slab",
585 default.node_sound_stone_defaults()
588 stairs.register_stair_and_slab(
590 "default:desert_stonebrick",
592 {"default_desert_stone_brick.png"},
593 "Desert Stone Brick Stair",
594 "Desert Stone Brick Slab",
595 default.node_sound_stone_defaults()
598 stairs.register_stair_and_slab(
599 "desert_stone_block",
600 "default:desert_stone_block",
602 {"default_desert_stone_block.png"},
603 "Desert Stone Block Stair",
604 "Desert Stone Block Slab",
605 default.node_sound_stone_defaults()
608 stairs.register_stair_and_slab(
611 {crumbly = 1, cracky = 3},
612 {"default_sandstone.png"},
615 default.node_sound_stone_defaults()
618 stairs.register_stair_and_slab(
620 "default:sandstonebrick",
622 {"default_sandstone_brick.png"},
623 "Sandstone Brick Stair",
624 "Sandstone Brick Slab",
625 default.node_sound_stone_defaults()
628 stairs.register_stair_and_slab(
630 "default:sandstone_block",
632 {"default_sandstone_block.png"},
633 "Sandstone Block Stair",
634 "Sandstone Block Slab",
635 default.node_sound_stone_defaults()
638 stairs.register_stair_and_slab(
640 "default:desert_sandstone",
641 {crumbly = 1, cracky = 3},
642 {"default_desert_sandstone.png"},
643 "Desert Sandstone Stair",
644 "Desert Sandstone Slab",
645 default.node_sound_stone_defaults()
648 stairs.register_stair_and_slab(
649 "desert_sandstone_brick",
650 "default:desert_sandstone_brick",
652 {"default_desert_sandstone_brick.png"},
653 "Desert Sandstone Brick Stair",
654 "Desert Sandstone Brick Slab",
655 default.node_sound_stone_defaults()
658 stairs.register_stair_and_slab(
659 "desert_sandstone_block",
660 "default:desert_sandstone_block",
662 {"default_desert_sandstone_block.png"},
663 "Desert Sandstone Block Stair",
664 "Desert Sandstone Block Slab",
665 default.node_sound_stone_defaults()
668 stairs.register_stair_and_slab(
670 "default:silver_sandstone",
671 {crumbly = 1, cracky = 3},
672 {"default_silver_sandstone.png"},
673 "Silver Sandstone Stair",
674 "Silver Sandstone Slab",
675 default.node_sound_stone_defaults()
678 stairs.register_stair_and_slab(
679 "silver_sandstone_brick",
680 "default:silver_sandstone_brick",
682 {"default_silver_sandstone_brick.png"},
683 "Silver Sandstone Brick Stair",
684 "Silver Sandstone Brick Slab",
685 default.node_sound_stone_defaults()
688 stairs.register_stair_and_slab(
689 "silver_sandstone_block",
690 "default:silver_sandstone_block",
692 {"default_silver_sandstone_block.png"},
693 "Silver Sandstone Block Stair",
694 "Silver Sandstone Block Slab",
695 default.node_sound_stone_defaults()
698 stairs.register_stair_and_slab(
701 {cracky = 1, level = 2},
702 {"default_obsidian.png"},
705 default.node_sound_stone_defaults()
708 stairs.register_stair_and_slab(
710 "default:obsidianbrick",
711 {cracky = 1, level = 2},
712 {"default_obsidian_brick.png"},
713 "Obsidian Brick Stair",
714 "Obsidian Brick Slab",
715 default.node_sound_stone_defaults()
718 stairs.register_stair_and_slab(
720 "default:obsidian_block",
721 {cracky = 1, level = 2},
722 {"default_obsidian_block.png"},
723 "Obsidian Block Stair",
724 "Obsidian Block Slab",
725 default.node_sound_stone_defaults()
728 stairs.register_stair_and_slab(
732 {"default_brick.png"},
735 default.node_sound_stone_defaults()
738 stairs.register_stair_and_slab(
740 "default:steelblock",
741 {cracky = 1, level = 2},
742 {"default_steel_block.png"},
745 default.node_sound_metal_defaults()
748 stairs.register_stair_and_slab(
751 {cracky = 1, level = 2},
752 {"default_tin_block.png"},
755 default.node_sound_metal_defaults()
758 stairs.register_stair_and_slab(
760 "default:copperblock",
761 {cracky = 1, level = 2},
762 {"default_copper_block.png"},
763 "Copper Block Stair",
765 default.node_sound_metal_defaults()
768 stairs.register_stair_and_slab(
770 "default:bronzeblock",
771 {cracky = 1, level = 2},
772 {"default_bronze_block.png"},
773 "Bronze Block Stair",
775 default.node_sound_metal_defaults()
778 stairs.register_stair_and_slab(
782 {"default_gold_block.png"},
785 default.node_sound_metal_defaults()
788 stairs.register_stair_and_slab(
791 {cracky = 3, puts_out_fire = 1, cools_lava = 1, slippery = 3},
795 default.node_sound_glass_defaults()
798 stairs.register_stair_and_slab(
801 {crumbly = 3, puts_out_fire = 1, cools_lava = 1, snowy = 1},
802 {"default_snow.png"},
805 default.node_sound_snow_defaults()