Skip to content

Commit 450543f

Browse files
committedAug 14, 2015
Stairs: Add straw and metal blocks
Make replace ABM optional, disabled by default
1 parent b7a1426 commit 450543f

File tree

3 files changed

+111
-38
lines changed

3 files changed

+111
-38
lines changed
 

‎minetest.conf.example

+4
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@
2222

2323
# The radius of a TNT explosion
2424
#tnt_radius = 3
25+
26+
# Enable the stairs mod ABM that replaces the old 'upside down'
27+
# stair and slab nodes in old maps with the new param2 versions.
28+
#enable_stairs_replace_abm = false

‎mods/stairs/depends.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
default
2+
farming

‎mods/stairs/init.lua

+106-38
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
-- Minetest 0.4 mod: stairs
22
-- See README.txt for licensing and other information.
33

4+
5+
-- Global namespace for functions
6+
47
stairs = {}
58

9+
10+
-- Get setting for replace ABM
11+
12+
local replace = minetest.setting_getbool("enable_stairs_replace_abm")
13+
14+
15+
-- Register stairs.
616
-- Node will be called stairs:stair_<subname>
17+
718
function stairs.register_stair(subname, recipeitem, groups, images, description, sounds)
819
minetest.register_node(":stairs:stair_" .. subname, {
920
description = description,
@@ -48,7 +59,7 @@ function stairs.register_stair(subname, recipeitem, groups, images, description,
4859
param2 = minetest.dir_to_facedir(dir)
4960
end
5061

51-
if p0.y-1 == p1.y then
62+
if p0.y - 1 == p1.y then
5263
param2 = param2 + 20
5364
if param2 == 21 then
5465
param2 = 23
@@ -62,10 +73,12 @@ function stairs.register_stair(subname, recipeitem, groups, images, description,
6273
})
6374

6475
-- for replace ABM
65-
minetest.register_node(":stairs:stair_" .. subname.."upside_down", {
66-
replace_name = "stairs:stair_" .. subname,
67-
groups = {slabs_replace=1},
68-
})
76+
if replace then
77+
minetest.register_node(":stairs:stair_" .. subname .. "upside_down", {
78+
replace_name = "stairs:stair_" .. subname,
79+
groups = {slabs_replace = 1},
80+
})
81+
end
6982

7083
minetest.register_craft({
7184
output = 'stairs:stair_' .. subname .. ' 6',
@@ -87,7 +100,10 @@ function stairs.register_stair(subname, recipeitem, groups, images, description,
87100
})
88101
end
89102

103+
104+
-- Register slabs.
90105
-- Node will be called stairs:slab_<subname>
106+
91107
function stairs.register_slab(subname, recipeitem, groups, images, description, sounds)
92108
minetest.register_node(":stairs:slab_" .. subname, {
93109
description = description,
@@ -120,7 +136,8 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
120136
local n0_is_upside_down = (n0.name == "stairs:slab_" .. subname and
121137
n0.param2 >= 20)
122138

123-
if n0.name == "stairs:slab_" .. subname and not n0_is_upside_down and p0.y+1 == p1.y then
139+
if n0.name == "stairs:slab_" .. subname and not n0_is_upside_down and
140+
p0.y + 1 == p1.y then
124141
slabpos = p0
125142
slabnode = n0
126143
elseif n1.name == "stairs:slab_" .. subname then
@@ -136,7 +153,8 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
136153

137154
pointed_thing.above = slabpos
138155
local success
139-
fakestack, success = minetest.item_place(fakestack, placer, pointed_thing)
156+
fakestack, success = minetest.item_place(fakestack, placer,
157+
pointed_thing)
140158
-- If the item was taken from the fake stack, decrement original
141159
if success then
142160
itemstack:set_count(fakestack:get_count())
@@ -148,7 +166,7 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
148166
end
149167

150168
-- Upside down slabs
151-
if p0.y-1 == p1.y then
169+
if p0.y - 1 == p1.y then
152170
-- Turn into full block if pointing at a existing slab
153171
if n0_is_upside_down then
154172
-- Remove the slab at the position of the slab
@@ -159,7 +177,8 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
159177

160178
pointed_thing.above = p0
161179
local success
162-
fakestack, success = minetest.item_place(fakestack, placer, pointed_thing)
180+
fakestack, success = minetest.item_place(fakestack, placer,
181+
pointed_thing)
163182
-- If the item was taken from the fake stack, decrement original
164183
if success then
165184
itemstack:set_count(fakestack:get_count())
@@ -175,7 +194,7 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
175194
end
176195

177196
-- If pointing at the side of a upside down slab
178-
if n0_is_upside_down and p0.y+1 ~= p1.y then
197+
if n0_is_upside_down and p0.y + 1 ~= p1.y then
179198
param2 = 20
180199
end
181200

@@ -184,10 +203,12 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
184203
})
185204

186205
-- for replace ABM
187-
minetest.register_node(":stairs:slab_" .. subname.."upside_down", {
188-
replace_name = "stairs:slab_"..subname,
189-
groups = {slabs_replace=1},
190-
})
206+
if replace then
207+
minetest.register_node(":stairs:slab_" .. subname .. "upside_down", {
208+
replace_name = "stairs:slab_".. subname,
209+
groups = {slabs_replace = 1},
210+
})
211+
end
191212

192213
minetest.register_craft({
193214
output = 'stairs:slab_' .. subname .. ' 6',
@@ -197,29 +218,41 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
197218
})
198219
end
199220

200-
-- Replace old "upside_down" nodes with new param2 versions
201-
minetest.register_abm({
202-
nodenames = {"group:slabs_replace"},
203-
interval = 8,
204-
chance = 1,
205-
action = function(pos, node)
206-
node.name = minetest.registered_nodes[node.name].replace_name
207-
node.param2 = node.param2 + 20
208-
if node.param2 == 21 then
209-
node.param2 = 23
210-
elseif node.param2 == 23 then
211-
node.param2 = 21
212-
end
213-
minetest.set_node(pos, node)
214-
end,
215-
})
216221

222+
-- Optionally replace old "upside_down" nodes with new param2 versions.
223+
-- Disabled by default.
224+
225+
if replace then
226+
minetest.register_abm({
227+
nodenames = {"group:slabs_replace"},
228+
interval = 8,
229+
chance = 1,
230+
action = function(pos, node)
231+
node.name = minetest.registered_nodes[node.name].replace_name
232+
node.param2 = node.param2 + 20
233+
if node.param2 == 21 then
234+
node.param2 = 23
235+
elseif node.param2 == 23 then
236+
node.param2 = 21
237+
end
238+
minetest.set_node(pos, node)
239+
end,
240+
})
241+
end
242+
243+
244+
-- Stair/slab registration function.
217245
-- Nodes will be called stairs:{stair,slab}_<subname>
218-
function stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab, sounds)
246+
247+
function stairs.register_stair_and_slab(subname, recipeitem, groups, images,
248+
desc_stair, desc_slab, sounds)
219249
stairs.register_stair(subname, recipeitem, groups, images, desc_stair, sounds)
220250
stairs.register_slab(subname, recipeitem, groups, images, desc_slab, sounds)
221251
end
222252

253+
254+
-- Register default stairs and slabs
255+
223256
stairs.register_stair_and_slab("wood", "default:wood",
224257
{snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, flammable = 3},
225258
{"default_wood.png"},
@@ -290,13 +323,6 @@ stairs.register_stair_and_slab("desert_stonebrick", "default:desert_stonebrick",
290323
"Desert Stone Brick Slab",
291324
default.node_sound_stone_defaults())
292325

293-
stairs.register_stair_and_slab("brick", "default:brick",
294-
{cracky = 3},
295-
{"default_brick.png"},
296-
"Brick Stair",
297-
"Brick Slab",
298-
default.node_sound_stone_defaults())
299-
300326
stairs.register_stair_and_slab("sandstone", "default:sandstone",
301327
{crumbly = 2, cracky = 2},
302328
{"default_sandstone.png"},
@@ -324,3 +350,45 @@ stairs.register_stair_and_slab("obsidianbrick", "default:obsidianbrick",
324350
"Obsidian Brick Stair",
325351
"Obsidian Brick Slab",
326352
default.node_sound_stone_defaults())
353+
354+
stairs.register_stair_and_slab("brick", "default:brick",
355+
{cracky = 3},
356+
{"default_brick.png"},
357+
"Brick Stair",
358+
"Brick Slab",
359+
default.node_sound_stone_defaults())
360+
361+
stairs.register_stair_and_slab("straw", "farming:straw",
362+
{snappy = 3, flammable = 4},
363+
{"farming_straw.png"},
364+
"Straw Stair",
365+
"Straw Slab",
366+
default.node_sound_leaves_defaults())
367+
368+
stairs.register_stair_and_slab("steelblock", "default:steelblock",
369+
{cracky = 1, level = 2},
370+
{"default_steel_block.png"},
371+
"Steel Block Stair",
372+
"Steel Block Slab",
373+
default.node_sound_stone_defaults())
374+
375+
stairs.register_stair_and_slab("copperblock", "default:copperblock",
376+
{cracky = 1, level = 2},
377+
{"default_copper_block.png"},
378+
"Copper Block Stair",
379+
"Copper Block Slab",
380+
default.node_sound_stone_defaults())
381+
382+
stairs.register_stair_and_slab("bronzeblock", "default:bronzeblock",
383+
{cracky = 1, level = 2},
384+
{"default_bronze_block.png"},
385+
"Bronze Block Stair",
386+
"Bronze Block Slab",
387+
default.node_sound_stone_defaults())
388+
389+
stairs.register_stair_and_slab("goldblock", "default:goldblock",
390+
{cracky = 1},
391+
{"default_gold_block.png"},
392+
"Gold Block Stair",
393+
"Gold Block Slab",
394+
default.node_sound_stone_defaults())

0 commit comments

Comments
 (0)
Please sign in to comment.