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 -- Stair/slab registration function.
281 -- Nodes will be called stairs:{stair,slab}_<subname>
283 function stairs.register_stair_and_slab(subname, recipeitem,
284 groups, images, desc_stair, desc_slab, sounds)
285 stairs.register_stair(subname, recipeitem, groups, images, desc_stair, sounds)
286 stairs.register_slab(subname, recipeitem, groups, images, desc_slab, sounds)
290 -- Register default stairs and slabs
292 stairs.register_stair_and_slab(
295 {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
296 {"default_wood.png"},
299 default.node_sound_wood_defaults()
302 stairs.register_stair_and_slab(
304 "default:junglewood",
305 {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
306 {"default_junglewood.png"},
309 default.node_sound_wood_defaults()
312 stairs.register_stair_and_slab(
315 {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3},
316 {"default_pine_wood.png"},
319 default.node_sound_wood_defaults()
322 stairs.register_stair_and_slab(
324 "default:acacia_wood",
325 {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
326 {"default_acacia_wood.png"},
329 default.node_sound_wood_defaults()
332 stairs.register_stair_and_slab(
334 "default:aspen_wood",
335 {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3},
336 {"default_aspen_wood.png"},
339 default.node_sound_wood_defaults()
342 stairs.register_stair_and_slab(
346 {"default_stone.png"},
349 default.node_sound_stone_defaults()
352 stairs.register_stair_and_slab(
356 {"default_cobble.png"},
359 default.node_sound_stone_defaults()
362 stairs.register_stair_and_slab(
364 "default:mossycobble",
366 {"default_mossycobble.png"},
367 "Mossy Cobblestone Stair",
368 "Mossy Cobblestone Slab",
369 default.node_sound_stone_defaults()
372 stairs.register_stair_and_slab(
374 "default:stonebrick",
376 {"default_stone_brick.png"},
379 default.node_sound_stone_defaults()
382 stairs.register_stair_and_slab(
384 "default:stone_block",
386 {"default_stone_block.png"},
389 default.node_sound_stone_defaults()
392 stairs.register_stair_and_slab(
394 "default:desert_stone",
396 {"default_desert_stone.png"},
397 "Desert Stone Stair",
399 default.node_sound_stone_defaults()
402 stairs.register_stair_and_slab(
404 "default:desert_cobble",
406 {"default_desert_cobble.png"},
407 "Desert Cobblestone Stair",
408 "Desert Cobblestone Slab",
409 default.node_sound_stone_defaults()
412 stairs.register_stair_and_slab(
414 "default:desert_stonebrick",
416 {"default_desert_stone_brick.png"},
417 "Desert Stone Brick Stair",
418 "Desert Stone Brick Slab",
419 default.node_sound_stone_defaults()
422 stairs.register_stair_and_slab(
423 "desert_stone_block",
424 "default:desert_stone_block",
426 {"default_desert_stone_block.png"},
427 "Desert Stone Block Stair",
428 "Desert Stone Block Slab",
429 default.node_sound_stone_defaults()
432 stairs.register_stair_and_slab(
435 {crumbly = 1, cracky = 3},
436 {"default_sandstone.png"},
439 default.node_sound_stone_defaults()
442 stairs.register_stair_and_slab(
444 "default:sandstonebrick",
446 {"default_sandstone_brick.png"},
447 "Sandstone Brick Stair",
448 "Sandstone Brick Slab",
449 default.node_sound_stone_defaults()
452 stairs.register_stair_and_slab(
454 "default:sandstone_block",
456 {"default_sandstone_block.png"},
457 "Sandstone Block Stair",
458 "Sandstone Block Slab",
459 default.node_sound_stone_defaults()
462 stairs.register_stair_and_slab(
464 "default:desert_sandstone",
465 {crumbly = 1, cracky = 3},
466 {"default_desert_sandstone.png"},
467 "Desert Sandstone Stair",
468 "Desert Sandstone Slab",
469 default.node_sound_stone_defaults()
472 stairs.register_stair_and_slab(
473 "desert_sandstone_brick",
474 "default:desert_sandstone_brick",
476 {"default_desert_sandstone_brick.png"},
477 "Desert Sandstone Brick Stair",
478 "Desert Sandstone Brick Slab",
479 default.node_sound_stone_defaults()
482 stairs.register_stair_and_slab(
483 "desert_sandstone_block",
484 "default:desert_sandstone_block",
486 {"default_desert_sandstone_block.png"},
487 "Desert Sandstone Block Stair",
488 "Desert Sandstone Block Slab",
489 default.node_sound_stone_defaults()
492 stairs.register_stair_and_slab(
494 "default:silver_sandstone",
495 {crumbly = 1, cracky = 3},
496 {"default_silver_sandstone.png"},
497 "Silver Sandstone Stair",
498 "Silver Sandstone Slab",
499 default.node_sound_stone_defaults()
502 stairs.register_stair_and_slab(
503 "silver_sandstone_brick",
504 "default:silver_sandstone_brick",
506 {"default_silver_sandstone_brick.png"},
507 "Silver Sandstone Brick Stair",
508 "Silver Sandstone Brick Slab",
509 default.node_sound_stone_defaults()
512 stairs.register_stair_and_slab(
513 "silver_sandstone_block",
514 "default:silver_sandstone_block",
516 {"default_silver_sandstone_block.png"},
517 "Silver Sandstone Block Stair",
518 "Silver Sandstone Block Slab",
519 default.node_sound_stone_defaults()
522 stairs.register_stair_and_slab(
525 {cracky = 1, level = 2},
526 {"default_obsidian.png"},
529 default.node_sound_stone_defaults()
532 stairs.register_stair_and_slab(
534 "default:obsidianbrick",
535 {cracky = 1, level = 2},
536 {"default_obsidian_brick.png"},
537 "Obsidian Brick Stair",
538 "Obsidian Brick Slab",
539 default.node_sound_stone_defaults()
542 stairs.register_stair_and_slab(
544 "default:obsidian_block",
545 {cracky = 1, level = 2},
546 {"default_obsidian_block.png"},
547 "Obsidian Block Stair",
548 "Obsidian Block Slab",
549 default.node_sound_stone_defaults()
552 stairs.register_stair_and_slab(
556 {"default_brick.png"},
559 default.node_sound_stone_defaults()
562 stairs.register_stair_and_slab(
565 {snappy = 3, flammable = 4},
566 {"farming_straw.png"},
569 default.node_sound_leaves_defaults()
572 stairs.register_stair_and_slab(
574 "default:steelblock",
575 {cracky = 1, level = 2},
576 {"default_steel_block.png"},
579 default.node_sound_metal_defaults()
582 stairs.register_stair_and_slab(
584 "default:copperblock",
585 {cracky = 1, level = 2},
586 {"default_copper_block.png"},
587 "Copper Block Stair",
589 default.node_sound_metal_defaults()
592 stairs.register_stair_and_slab(
594 "default:bronzeblock",
595 {cracky = 1, level = 2},
596 {"default_bronze_block.png"},
597 "Bronze Block Stair",
599 default.node_sound_metal_defaults()
602 stairs.register_stair_and_slab(
606 {"default_gold_block.png"},
609 default.node_sound_metal_defaults()
612 stairs.register_stair_and_slab(
615 {cracky = 3, puts_out_fire = 1, cools_lava = 1},
619 default.node_sound_glass_defaults()
622 stairs.register_stair_and_slab(
625 {crumbly = 3, puts_out_fire = 1, cools_lava = 1, snowy = 1},
626 {"default_snow.png"},
629 default.node_sound_dirt_defaults({
630 footstep = {name = "default_snow_footstep", gain = 0.15},
631 dug = {name = "default_snow_footstep", gain = 0.2},
632 dig = {name = "default_snow_footstep", gain = 0.2}