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
25 local placer_pos = placer:getpos()
27 param2 = minetest.dir_to_facedir(vector.subtract(p1, placer_pos))
30 local finepos = minetest.pointed_thing_to_face_pos(placer, pointed_thing)
31 local fpos = finepos.y % 1
33 if p0.y - 1 == p1.y or (fpos > 0 and fpos < 0.5)
34 or (fpos < -0.5 and fpos > -0.999999999) then
38 elseif param2 == 23 then
42 return minetest.item_place(itemstack, placer, pointed_thing, param2)
46 -- Node will be called stairs:stair_<subname>
48 function stairs.register_stair(subname, recipeitem, groups, images, description, sounds)
49 local stair_images = {}
50 for i, image in ipairs(images) do
51 if type(image) == "string" then
54 backface_culling = true,
56 elseif image.backface_culling == nil then -- override using any other value
57 stair_images[i] = table.copy(image)
58 stair_images[i].backface_culling = true
62 minetest.register_node(":stairs:stair_" .. subname, {
63 description = description,
65 mesh = "stairs_stair.obj",
68 paramtype2 = "facedir",
69 is_ground_content = false,
75 {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
76 {-0.5, 0, 0, 0.5, 0.5, 0.5},
82 {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
83 {-0.5, 0, 0, 0.5, 0.5, 0.5},
86 on_place = function(itemstack, placer, pointed_thing)
87 if pointed_thing.type ~= "node" then
91 return rotate_and_place(itemstack, placer, pointed_thing)
97 minetest.register_node(":stairs:stair_" .. subname .. "upside_down", {
98 replace_name = "stairs:stair_" .. subname,
99 groups = {slabs_replace = 1},
104 -- Recipe matches appearence in inventory
105 minetest.register_craft({
106 output = 'stairs:stair_' .. subname .. ' 8',
108 {"", "", recipeitem},
109 {"", recipeitem, recipeitem},
110 {recipeitem, recipeitem, recipeitem},
114 -- Use stairs to craft full blocks again (1:1)
115 minetest.register_craft({
116 output = recipeitem .. ' 3',
118 {'stairs:stair_' .. subname, 'stairs:stair_' .. subname},
119 {'stairs:stair_' .. subname, 'stairs:stair_' .. subname},
124 local baseburntime = minetest.get_craft_result({
129 if baseburntime > 0 then
130 minetest.register_craft({
132 recipe = 'stairs:stair_' .. subname,
133 burntime = math.floor(baseburntime * 0.75),
140 -- Slab facedir to placement 6d matching table
141 local slab_trans_dir = {[0] = 8, 0, 2, 1, 3, 4}
144 -- Node will be called stairs:slab_<subname>
146 function stairs.register_slab(subname, recipeitem, groups, images, description, sounds)
148 minetest.register_node(":stairs:slab_" .. subname, {
149 description = description,
150 drawtype = "nodebox",
153 paramtype2 = "facedir",
154 is_ground_content = false,
159 fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
161 on_place = function(itemstack, placer, pointed_thing)
162 local under = minetest.get_node(pointed_thing.under)
163 local wield_item = itemstack:get_name()
164 local creative_enabled = (creative and creative.is_enabled_for
165 and creative.is_enabled_for(placer:get_player_name()))
167 if under and under.name:find("stairs:slab_") then
168 -- place slab using under node orientation
169 local dir = minetest.dir_to_facedir(vector.subtract(
170 pointed_thing.above, pointed_thing.under), true)
172 local p2 = under.param2
174 -- combine two slabs if possible
175 if slab_trans_dir[math.floor(p2 / 4)] == dir
176 and wield_item == under.name then
178 if not recipeitem then
181 local player_name = placer:get_player_name()
182 if minetest.is_protected(pointed_thing.under, player_name) and not
183 minetest.check_player_privs(placer, "protection_bypass") then
184 minetest.record_protection_violation(pointed_thing.under,
188 minetest.set_node(pointed_thing.under, {name = recipeitem, param2 = p2})
189 if not creative_enabled then
190 itemstack:take_item()
195 -- Placing a slab on an upside down slab should make it right-side up.
196 if p2 >= 20 and dir == 8 then
198 -- same for the opposite case: slab below normal slab
199 elseif p2 <= 3 and dir == 4 then
203 -- else attempt to place node with proper param2
204 minetest.item_place_node(ItemStack(wield_item), placer, pointed_thing, p2)
205 if not creative_enabled then
206 itemstack:take_item()
210 return rotate_and_place(itemstack, placer, pointed_thing)
217 minetest.register_node(":stairs:slab_" .. subname .. "upside_down", {
218 replace_name = "stairs:slab_".. subname,
219 groups = {slabs_replace = 1},
224 minetest.register_craft({
225 output = 'stairs:slab_' .. subname .. ' 6',
227 {recipeitem, recipeitem, recipeitem},
231 -- Use 2 slabs to craft a full block again (1:1)
232 minetest.register_craft({
235 {'stairs:slab_' .. subname},
236 {'stairs:slab_' .. subname},
241 local baseburntime = minetest.get_craft_result({
246 if baseburntime > 0 then
247 minetest.register_craft({
249 recipe = 'stairs:slab_' .. subname,
250 burntime = math.floor(baseburntime * 0.5),
257 -- Optionally replace old "upside_down" nodes with new param2 versions.
258 -- Disabled by default.
261 minetest.register_abm({
262 label = "Slab replace",
263 nodenames = {"group:slabs_replace"},
266 action = function(pos, node)
267 node.name = minetest.registered_nodes[node.name].replace_name
268 node.param2 = node.param2 + 20
269 if node.param2 == 21 then
271 elseif node.param2 == 23 then
274 minetest.set_node(pos, node)
280 -- Node will be called stairs:stair_inner_<subname>
282 function stairs.register_stair_inner(subname, recipeitem, groups, images, description, sounds)
283 local stair_images = {}
284 for i, image in ipairs(images) do
285 if type(image) == "string" then
288 backface_culling = true,
290 elseif image.backface_culling == nil then -- override using any other value
291 stair_images[i] = table.copy(image)
292 stair_images[i].backface_culling = true
296 minetest.register_node(":stairs:stair_inner_" .. subname, {
297 description = description .. " Inner",
299 mesh = "stairs_stair_inner.obj",
300 tiles = stair_images,
302 paramtype2 = "facedir",
303 is_ground_content = false,
309 {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
310 {-0.5, 0, 0, 0.5, 0.5, 0.5},
311 {-0.5, 0, -0.5, 0, 0.5, 0},
317 {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
318 {-0.5, 0, 0, 0.5, 0.5, 0.5},
319 {-0.5, 0, -0.5, 0, 0.5, 0},
322 on_place = function(itemstack, placer, pointed_thing)
323 if pointed_thing.type ~= "node" then
327 return rotate_and_place(itemstack, placer, pointed_thing)
332 minetest.register_craft({
333 output = 'stairs:stair_inner_' .. subname .. ' 7',
335 { "", recipeitem, ""},
336 { recipeitem, "", recipeitem},
337 {recipeitem, recipeitem, recipeitem},
342 local baseburntime = minetest.get_craft_result({
347 if baseburntime > 0 then
348 minetest.register_craft({
350 recipe = 'stairs:stair_inner_' .. subname,
351 burntime = math.floor(baseburntime * 0.875),
358 -- Node will be called stairs:stair_outer_<subname>
360 function stairs.register_stair_outer(subname, recipeitem, groups, images, description, sounds)
361 local stair_images = {}
362 for i, image in ipairs(images) do
363 if type(image) == "string" then
366 backface_culling = true,
368 elseif image.backface_culling == nil then -- override using any other value
369 stair_images[i] = table.copy(image)
370 stair_images[i].backface_culling = true
374 minetest.register_node(":stairs:stair_outer_" .. subname, {
375 description = description .. " Outer",
377 mesh = "stairs_stair_outer.obj",
378 tiles = stair_images,
380 paramtype2 = "facedir",
381 is_ground_content = false,
387 {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
388 {-0.5, 0, 0, 0, 0.5, 0.5},
394 {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
395 {-0.5, 0, 0, 0, 0.5, 0.5},
398 on_place = function(itemstack, placer, pointed_thing)
399 if pointed_thing.type ~= "node" then
403 return rotate_and_place(itemstack, placer, pointed_thing)
408 minetest.register_craft({
409 output = 'stairs:stair_outer_' .. subname .. ' 6',
412 { "", recipeitem, ""},
413 {recipeitem, recipeitem, recipeitem},
418 local baseburntime = minetest.get_craft_result({
423 if baseburntime > 0 then
424 minetest.register_craft({
426 recipe = 'stairs:stair_outer_' .. subname,
427 burntime = math.floor(baseburntime * 0.625),
433 -- Stair/slab registration function.
434 -- Nodes will be called stairs:{stair,slab}_<subname>
436 function stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds)
437 stairs.register_stair(subname, recipeitem, groups, images, desc_stair, sounds)
438 stairs.register_stair_inner(subname, recipeitem, groups, images, desc_stair, sounds)
439 stairs.register_stair_outer(subname, recipeitem, groups, images, desc_stair, sounds)
440 stairs.register_slab(subname, recipeitem, groups, images, desc_slab, sounds)
443 -- Register default stairs and slabs
445 stairs.register_stair_and_slab(
448 {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
449 {"default_wood.png"},
452 default.node_sound_wood_defaults()
455 stairs.register_stair_and_slab(
457 "default:junglewood",
458 {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
459 {"default_junglewood.png"},
462 default.node_sound_wood_defaults()
465 stairs.register_stair_and_slab(
468 {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3},
469 {"default_pine_wood.png"},
472 default.node_sound_wood_defaults()
475 stairs.register_stair_and_slab(
477 "default:acacia_wood",
478 {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
479 {"default_acacia_wood.png"},
482 default.node_sound_wood_defaults()
485 stairs.register_stair_and_slab(
487 "default:aspen_wood",
488 {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3},
489 {"default_aspen_wood.png"},
492 default.node_sound_wood_defaults()
495 stairs.register_stair_and_slab(
499 {"default_stone.png"},
502 default.node_sound_stone_defaults()
505 stairs.register_stair_and_slab(
509 {"default_cobble.png"},
512 default.node_sound_stone_defaults()
515 stairs.register_stair_and_slab(
517 "default:mossycobble",
519 {"default_mossycobble.png"},
520 "Mossy Cobblestone Stair",
521 "Mossy Cobblestone Slab",
522 default.node_sound_stone_defaults()
525 stairs.register_stair_and_slab(
527 "default:stonebrick",
529 {"default_stone_brick.png"},
532 default.node_sound_stone_defaults()
535 stairs.register_stair_and_slab(
537 "default:stone_block",
539 {"default_stone_block.png"},
542 default.node_sound_stone_defaults()
545 stairs.register_stair_and_slab(
547 "default:desert_stone",
549 {"default_desert_stone.png"},
550 "Desert Stone Stair",
552 default.node_sound_stone_defaults()
555 stairs.register_stair_and_slab(
557 "default:desert_cobble",
559 {"default_desert_cobble.png"},
560 "Desert Cobblestone Stair",
561 "Desert Cobblestone Slab",
562 default.node_sound_stone_defaults()
565 stairs.register_stair_and_slab(
567 "default:desert_stonebrick",
569 {"default_desert_stone_brick.png"},
570 "Desert Stone Brick Stair",
571 "Desert Stone Brick Slab",
572 default.node_sound_stone_defaults()
575 stairs.register_stair_and_slab(
576 "desert_stone_block",
577 "default:desert_stone_block",
579 {"default_desert_stone_block.png"},
580 "Desert Stone Block Stair",
581 "Desert Stone Block Slab",
582 default.node_sound_stone_defaults()
585 stairs.register_stair_and_slab(
588 {crumbly = 1, cracky = 3},
589 {"default_sandstone.png"},
592 default.node_sound_stone_defaults()
595 stairs.register_stair_and_slab(
597 "default:sandstonebrick",
599 {"default_sandstone_brick.png"},
600 "Sandstone Brick Stair",
601 "Sandstone Brick Slab",
602 default.node_sound_stone_defaults()
605 stairs.register_stair_and_slab(
607 "default:sandstone_block",
609 {"default_sandstone_block.png"},
610 "Sandstone Block Stair",
611 "Sandstone Block Slab",
612 default.node_sound_stone_defaults()
615 stairs.register_stair_and_slab(
617 "default:desert_sandstone",
618 {crumbly = 1, cracky = 3},
619 {"default_desert_sandstone.png"},
620 "Desert Sandstone Stair",
621 "Desert Sandstone Slab",
622 default.node_sound_stone_defaults()
625 stairs.register_stair_and_slab(
626 "desert_sandstone_brick",
627 "default:desert_sandstone_brick",
629 {"default_desert_sandstone_brick.png"},
630 "Desert Sandstone Brick Stair",
631 "Desert Sandstone Brick Slab",
632 default.node_sound_stone_defaults()
635 stairs.register_stair_and_slab(
636 "desert_sandstone_block",
637 "default:desert_sandstone_block",
639 {"default_desert_sandstone_block.png"},
640 "Desert Sandstone Block Stair",
641 "Desert Sandstone Block Slab",
642 default.node_sound_stone_defaults()
645 stairs.register_stair_and_slab(
647 "default:silver_sandstone",
648 {crumbly = 1, cracky = 3},
649 {"default_silver_sandstone.png"},
650 "Silver Sandstone Stair",
651 "Silver Sandstone Slab",
652 default.node_sound_stone_defaults()
655 stairs.register_stair_and_slab(
656 "silver_sandstone_brick",
657 "default:silver_sandstone_brick",
659 {"default_silver_sandstone_brick.png"},
660 "Silver Sandstone Brick Stair",
661 "Silver Sandstone Brick Slab",
662 default.node_sound_stone_defaults()
665 stairs.register_stair_and_slab(
666 "silver_sandstone_block",
667 "default:silver_sandstone_block",
669 {"default_silver_sandstone_block.png"},
670 "Silver Sandstone Block Stair",
671 "Silver Sandstone Block Slab",
672 default.node_sound_stone_defaults()
675 stairs.register_stair_and_slab(
678 {cracky = 1, level = 2},
679 {"default_obsidian.png"},
682 default.node_sound_stone_defaults()
685 stairs.register_stair_and_slab(
687 "default:obsidianbrick",
688 {cracky = 1, level = 2},
689 {"default_obsidian_brick.png"},
690 "Obsidian Brick Stair",
691 "Obsidian Brick Slab",
692 default.node_sound_stone_defaults()
695 stairs.register_stair_and_slab(
697 "default:obsidian_block",
698 {cracky = 1, level = 2},
699 {"default_obsidian_block.png"},
700 "Obsidian Block Stair",
701 "Obsidian Block Slab",
702 default.node_sound_stone_defaults()
705 stairs.register_stair_and_slab(
709 {"default_brick.png"},
712 default.node_sound_stone_defaults()
715 stairs.register_stair_and_slab(
718 {snappy = 3, flammable = 4},
719 {"farming_straw.png"},
722 default.node_sound_leaves_defaults()
725 stairs.register_stair_and_slab(
727 "default:steelblock",
728 {cracky = 1, level = 2},
729 {"default_steel_block.png"},
732 default.node_sound_metal_defaults()
735 stairs.register_stair_and_slab(
737 "default:copperblock",
738 {cracky = 1, level = 2},
739 {"default_copper_block.png"},
740 "Copper Block Stair",
742 default.node_sound_metal_defaults()
745 stairs.register_stair_and_slab(
747 "default:bronzeblock",
748 {cracky = 1, level = 2},
749 {"default_bronze_block.png"},
750 "Bronze Block Stair",
752 default.node_sound_metal_defaults()
755 stairs.register_stair_and_slab(
759 {"default_gold_block.png"},
762 default.node_sound_metal_defaults()
765 stairs.register_stair_and_slab(
768 {cracky = 3, puts_out_fire = 1, cools_lava = 1},
772 default.node_sound_glass_defaults()
775 stairs.register_stair_and_slab(
778 {crumbly = 3, puts_out_fire = 1, cools_lava = 1, snowy = 1},
779 {"default_snow.png"},
782 default.node_sound_dirt_defaults({
783 footstep = {name = "default_snow_footstep", gain = 0.15},
784 dug = {name = "default_snow_footstep", gain = 0.2},
785 dig = {name = "default_snow_footstep", gain = 0.2}