1 -- Minetest 0.4 mod: stairs
2 -- See README.txt for licensing and other information.
6 -- Node will be called stairs:stair_<subname>
7 function stairs.register_stair(subname, recipeitem, groups, images, description, sounds)
8 minetest.register_node(":stairs:stair_" .. subname, {
9 description = description,
13 paramtype2 = "facedir",
14 is_ground_content = true,
20 {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
21 {-0.5, 0, 0, 0.5, 0.5, 0.5},
24 on_place = function(itemstack, placer, pointed_thing)
25 if pointed_thing.type ~= "node" then
29 local p0 = pointed_thing.under
30 local p1 = pointed_thing.above
33 local placer_pos = placer:getpos()
36 x = p1.x - placer_pos.x,
37 y = p1.y - placer_pos.y,
38 z = p1.z - placer_pos.z
40 param2 = minetest.dir_to_facedir(dir)
43 if p0.y-1 == p1.y then
47 elseif param2 == 23 then
52 return minetest.item_place(itemstack, placer, pointed_thing, param2)
57 minetest.register_node(":stairs:stair_" .. subname.."upside_down", {
58 replace_name = "stairs:stair_" .. subname,
59 groups = {slabs_replace=1},
62 minetest.register_craft({
63 output = 'stairs:stair_' .. subname .. ' 4',
66 {recipeitem, recipeitem, ""},
67 {recipeitem, recipeitem, recipeitem},
71 -- Flipped recipe for the silly minecrafters
72 minetest.register_craft({
73 output = 'stairs:stair_' .. subname .. ' 4',
76 {"", recipeitem, recipeitem},
77 {recipeitem, recipeitem, recipeitem},
82 -- Node will be called stairs:slab_<subname>
83 function stairs.register_slab(subname, recipeitem, groups, images, description, sounds)
84 minetest.register_node(":stairs:slab_" .. subname, {
85 description = description,
89 paramtype2 = "facedir",
90 is_ground_content = true,
95 fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
97 on_place = function(itemstack, placer, pointed_thing)
98 if pointed_thing.type ~= "node" then
102 -- If it's being placed on an another similar one, replace it with
106 local p0 = pointed_thing.under
107 local p1 = pointed_thing.above
108 local n0 = minetest.get_node(p0)
109 local n1 = minetest.get_node(p1)
112 local n0_is_upside_down = (n0.name == "stairs:slab_" .. subname and
115 if n0.name == "stairs:slab_" .. subname and not n0_is_upside_down and p0.y+1 == p1.y then
118 elseif n1.name == "stairs:slab_" .. subname then
123 -- Remove the slab at slabpos
124 minetest.remove_node(slabpos)
125 -- Make a fake stack of a single item and try to place it
126 local fakestack = ItemStack(recipeitem)
127 fakestack:set_count(itemstack:get_count())
129 pointed_thing.above = slabpos
131 fakestack, success = minetest.item_place(fakestack, placer, pointed_thing)
132 -- If the item was taken from the fake stack, decrement original
134 itemstack:set_count(fakestack:get_count())
135 -- Else put old node back
137 minetest.set_node(slabpos, slabnode)
143 if p0.y-1 == p1.y then
144 -- Turn into full block if pointing at a existing slab
145 if n0_is_upside_down then
146 -- Remove the slab at the position of the slab
147 minetest.remove_node(p0)
148 -- Make a fake stack of a single item and try to place it
149 local fakestack = ItemStack(recipeitem)
150 fakestack:set_count(itemstack:get_count())
152 pointed_thing.above = p0
154 fakestack, success = minetest.item_place(fakestack, placer, pointed_thing)
155 -- If the item was taken from the fake stack, decrement original
157 itemstack:set_count(fakestack:get_count())
158 -- Else put old node back
160 minetest.set_node(p0, n0)
165 -- Place upside down slab
169 -- If pointing at the side of a upside down slab
170 if n0_is_upside_down and p0.y+1 ~= p1.y then
174 return minetest.item_place(itemstack, placer, pointed_thing, param2)
179 minetest.register_node(":stairs:slab_" .. subname.."upside_down", {
180 replace_name = "stairs:slab_"..subname,
181 groups = {slabs_replace=1},
184 minetest.register_craft({
185 output = 'stairs:slab_' .. subname .. ' 6',
187 {recipeitem, recipeitem, recipeitem},
192 -- Replace old "upside_down" nodes with new param2 versions
193 minetest.register_abm({
194 nodenames = {"group:slabs_replace"},
197 action = function(pos, node)
198 node.name = minetest.registered_nodes[node.name].replace_name
199 node.param2 = node.param2 + 20
200 if node.param2 == 21 then
202 elseif node.param2 == 23 then
205 minetest.set_node(pos, node)
209 -- Nodes will be called stairs:{stair,slab}_<subname>
210 function stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds)
211 stairs.register_stair(subname, recipeitem, groups, images, desc_stair, sounds)
212 stairs.register_slab(subname, recipeitem, groups, images, desc_slab, sounds)
215 stairs.register_stair_and_slab("wood", "default:wood",
216 {snappy=2,choppy=2,oddly_breakable_by_hand=2,flammable=3},
217 {"default_wood.png"},
220 default.node_sound_wood_defaults())
222 stairs.register_stair_and_slab("stone", "default:stone",
224 {"default_stone.png"},
227 default.node_sound_stone_defaults())
229 stairs.register_stair_and_slab("cobble", "default:cobble",
231 {"default_cobble.png"},
234 default.node_sound_stone_defaults())
236 stairs.register_stair_and_slab("brick", "default:brick",
238 {"default_brick.png"},
241 default.node_sound_stone_defaults())
243 stairs.register_stair_and_slab("sandstone", "default:sandstone",
244 {crumbly=2,cracky=2},
245 {"default_sandstone.png"},
248 default.node_sound_stone_defaults())
250 stairs.register_stair_and_slab("junglewood", "default:junglewood",
251 {snappy=2,choppy=2,oddly_breakable_by_hand=2,flammable=3},
252 {"default_junglewood.png"},
255 default.node_sound_wood_defaults())
257 stairs.register_stair_and_slab("stonebrick", "default:stonebrick",
259 {"default_stone_brick.png"},
262 default.node_sound_stone_defaults())