1
1
-- Minetest 0.4 mod: stairs
2
2
-- See README.txt for licensing and other information.
3
3
4
+
5
+ -- Global namespace for functions
6
+
4
7
stairs = {}
5
8
9
+
10
+ -- Get setting for replace ABM
11
+
12
+ local replace = minetest .setting_getbool (" enable_stairs_replace_abm" )
13
+
14
+
15
+ -- Register stairs.
6
16
-- Node will be called stairs:stair_<subname>
17
+
7
18
function stairs .register_stair (subname , recipeitem , groups , images , description , sounds )
8
19
minetest .register_node (" :stairs:stair_" .. subname , {
9
20
description = description ,
@@ -48,7 +59,7 @@ function stairs.register_stair(subname, recipeitem, groups, images, description,
48
59
param2 = minetest .dir_to_facedir (dir )
49
60
end
50
61
51
- if p0 .y - 1 == p1 .y then
62
+ if p0 .y - 1 == p1 .y then
52
63
param2 = param2 + 20
53
64
if param2 == 21 then
54
65
param2 = 23
@@ -62,10 +73,12 @@ function stairs.register_stair(subname, recipeitem, groups, images, description,
62
73
})
63
74
64
75
-- 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
69
82
70
83
minetest .register_craft ({
71
84
output = ' stairs:stair_' .. subname .. ' 6' ,
@@ -87,7 +100,10 @@ function stairs.register_stair(subname, recipeitem, groups, images, description,
87
100
})
88
101
end
89
102
103
+
104
+ -- Register slabs.
90
105
-- Node will be called stairs:slab_<subname>
106
+
91
107
function stairs .register_slab (subname , recipeitem , groups , images , description , sounds )
92
108
minetest .register_node (" :stairs:slab_" .. subname , {
93
109
description = description ,
@@ -120,7 +136,8 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
120
136
local n0_is_upside_down = (n0 .name == " stairs:slab_" .. subname and
121
137
n0 .param2 >= 20 )
122
138
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
124
141
slabpos = p0
125
142
slabnode = n0
126
143
elseif n1 .name == " stairs:slab_" .. subname then
@@ -136,7 +153,8 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
136
153
137
154
pointed_thing .above = slabpos
138
155
local success
139
- fakestack , success = minetest .item_place (fakestack , placer , pointed_thing )
156
+ fakestack , success = minetest .item_place (fakestack , placer ,
157
+ pointed_thing )
140
158
-- If the item was taken from the fake stack, decrement original
141
159
if success then
142
160
itemstack :set_count (fakestack :get_count ())
@@ -148,7 +166,7 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
148
166
end
149
167
150
168
-- Upside down slabs
151
- if p0 .y - 1 == p1 .y then
169
+ if p0 .y - 1 == p1 .y then
152
170
-- Turn into full block if pointing at a existing slab
153
171
if n0_is_upside_down then
154
172
-- Remove the slab at the position of the slab
@@ -159,7 +177,8 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
159
177
160
178
pointed_thing .above = p0
161
179
local success
162
- fakestack , success = minetest .item_place (fakestack , placer , pointed_thing )
180
+ fakestack , success = minetest .item_place (fakestack , placer ,
181
+ pointed_thing )
163
182
-- If the item was taken from the fake stack, decrement original
164
183
if success then
165
184
itemstack :set_count (fakestack :get_count ())
@@ -175,7 +194,7 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
175
194
end
176
195
177
196
-- 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
179
198
param2 = 20
180
199
end
181
200
@@ -184,10 +203,12 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
184
203
})
185
204
186
205
-- 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
191
212
192
213
minetest .register_craft ({
193
214
output = ' stairs:slab_' .. subname .. ' 6' ,
@@ -197,29 +218,41 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
197
218
})
198
219
end
199
220
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
- })
216
221
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.
217
245
-- 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 )
219
249
stairs .register_stair (subname , recipeitem , groups , images , desc_stair , sounds )
220
250
stairs .register_slab (subname , recipeitem , groups , images , desc_slab , sounds )
221
251
end
222
252
253
+
254
+ -- Register default stairs and slabs
255
+
223
256
stairs .register_stair_and_slab (" wood" , " default:wood" ,
224
257
{snappy = 2 , choppy = 2 , oddly_breakable_by_hand = 2 , flammable = 3 },
225
258
{" default_wood.png" },
@@ -290,13 +323,6 @@ stairs.register_stair_and_slab("desert_stonebrick", "default:desert_stonebrick",
290
323
" Desert Stone Brick Slab" ,
291
324
default .node_sound_stone_defaults ())
292
325
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
-
300
326
stairs .register_stair_and_slab (" sandstone" , " default:sandstone" ,
301
327
{crumbly = 2 , cracky = 2 },
302
328
{" default_sandstone.png" },
@@ -324,3 +350,45 @@ stairs.register_stair_and_slab("obsidianbrick", "default:obsidianbrick",
324
350
" Obsidian Brick Stair" ,
325
351
" Obsidian Brick Slab" ,
326
352
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