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},
27 {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
28 {-0.5, 0, 0, 0.5, 0.5, 0.5},
31 on_place = function(itemstack, placer, pointed_thing)
32 if pointed_thing.type ~= "node" then
36 local p0 = pointed_thing.under
37 local p1 = pointed_thing.above
38 if p0.y-1 == p1.y then
39 local fakestack = ItemStack("stairs:stair_" .. subname.."upside_down")
40 local ret = minetest.item_place(fakestack, placer, pointed_thing)
41 if ret:is_empty() then
47 -- Otherwise place regularly
48 return minetest.item_place(itemstack, placer, pointed_thing)
52 minetest.register_node(":stairs:stair_" .. subname.."upside_down", {
53 drop = "stairs:stair_" .. subname,
57 paramtype2 = "facedir",
58 is_ground_content = true,
64 {-0.5, 0, -0.5, 0.5, 0.5, 0.5},
65 {-0.5, -0.5, 0, 0.5, 0, 0.5},
71 {-0.5, 0, -0.5, 0.5, 0.5, 0.5},
72 {-0.5, -0.5, 0, 0.5, 0, 0.5},
77 minetest.register_craft({
78 output = 'stairs:stair_' .. subname .. ' 4',
81 {recipeitem, recipeitem, ""},
82 {recipeitem, recipeitem, recipeitem},
86 -- Flipped recipe for the silly minecrafters
87 minetest.register_craft({
88 output = 'stairs:stair_' .. subname .. ' 4',
91 {"", recipeitem, recipeitem},
92 {recipeitem, recipeitem, recipeitem},
97 -- Node will be called stairs:slab_<subname>
98 function stairs.register_slab(subname, recipeitem, groups, images, description, sounds)
99 minetest.register_node(":stairs:slab_" .. subname, {
100 description = description,
101 drawtype = "nodebox",
104 is_ground_content = true,
109 fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
113 fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
115 on_place = function(itemstack, placer, pointed_thing)
116 if pointed_thing.type ~= "node" then
120 -- If it's being placed on an another similar one, replace it with
124 local p0 = pointed_thing.under
125 local p1 = pointed_thing.above
126 local n0 = minetest.env:get_node(p0)
127 if n0.name == "stairs:slab_" .. subname and
133 -- Remove the slab at slabpos
134 minetest.env:remove_node(slabpos)
135 -- Make a fake stack of a single item and try to place it
136 local fakestack = ItemStack(recipeitem)
137 pointed_thing.above = slabpos
138 fakestack = minetest.item_place(fakestack, placer, pointed_thing)
139 -- If the item was taken from the fake stack, decrement original
140 if not fakestack or fakestack:is_empty() then
141 itemstack:take_item(1)
142 -- Else put old node back
144 minetest.env:set_node(slabpos, slabnode)
150 if p0.y-1 == p1.y then
151 -- Turn into full block if pointing at a existing slab
152 if n0.name == "stairs:slab_" .. subname.."upside_down" then
153 -- Remove the slab at the position of the slab
154 minetest.env:remove_node(p0)
155 -- Make a fake stack of a single item and try to place it
156 local fakestack = ItemStack(recipeitem)
157 pointed_thing.above = p0
158 fakestack = minetest.item_place(fakestack, placer, pointed_thing)
159 -- If the item was taken from the fake stack, decrement original
160 if not fakestack or fakestack:is_empty() then
161 itemstack:take_item(1)
162 -- Else put old node back
164 minetest.env:set_node(p0, n0)
169 -- Place upside down slab
170 local fakestack = ItemStack("stairs:slab_" .. subname.."upside_down")
171 local ret = minetest.item_place(fakestack, placer, pointed_thing)
172 if ret:is_empty() then
173 itemstack:take_item()
178 -- If pointing at the side of a upside down slab
179 if n0.name == "stairs:slab_" .. subname.."upside_down" and
181 -- Place upside down slab
182 local fakestack = ItemStack("stairs:slab_" .. subname.."upside_down")
183 local ret = minetest.item_place(fakestack, placer, pointed_thing)
184 if ret:is_empty() then
185 itemstack:take_item()
190 -- Otherwise place regularly
191 return minetest.item_place(itemstack, placer, pointed_thing)
195 minetest.register_node(":stairs:slab_" .. subname.."upside_down", {
196 drop = "stairs:slab_"..subname,
197 drawtype = "nodebox",
200 is_ground_content = true,
205 fixed = {-0.5, 0, -0.5, 0.5, 0.5, 0.5},
209 fixed = {-0.5, 0, -0.5, 0.5, 0.5, 0.5},
213 minetest.register_craft({
214 output = 'stairs:slab_' .. subname .. ' 6',
216 {recipeitem, recipeitem, recipeitem},
221 -- Nodes will be called stairs:{stair,slab}_<subname>
222 function stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds)
223 stairs.register_stair(subname, recipeitem, groups, images, desc_stair, sounds)
224 stairs.register_slab(subname, recipeitem, groups, images, desc_slab, sounds)
227 stairs.register_stair_and_slab("wood", "default:wood",
228 {snappy=2,choppy=2,oddly_breakable_by_hand=2},
229 {"default_wood.png"},
232 default.node_sound_wood_defaults())
234 stairs.register_stair_and_slab("stone", "default:stone",
236 {"default_stone.png"},
239 default.node_sound_stone_defaults())
241 stairs.register_stair_and_slab("cobble", "default:cobble",
243 {"default_cobble.png"},
246 default.node_sound_stone_defaults())
248 stairs.register_stair_and_slab("brick", "default:brick",
250 {"default_brick.png"},
253 default.node_sound_stone_defaults())
255 stairs.register_stair_and_slab("sandstone", "default:sandstone",
256 {crumbly=2,cracky=2},
257 {"default_sandstone.png"},
260 default.node_sound_stone_defaults())
262 stairs.register_stair_and_slab("junglewood", "default:junglewood",
263 {snappy=2,choppy=2,oddly_breakable_by_hand=2},
264 {"default_junglewood.png"},
267 default.node_sound_wood_defaults())