1 -- Corner stairs handling
3 -- This code originally copied from the [mcstair] mod and merged into this mod.
4 -- This file is licensed under CC0.
6 mcl_stairs
.cornerstair
= {}
8 local get_stair_param
= function(node
)
9 local stair
= minetest
.get_item_group(node
.name
, "stair")
12 elseif stair
== 2 then
13 if node
.param2
< 12 then
14 return node
.param2
+ 4
16 return node
.param2
- 4
18 elseif stair
== 3 then
19 if node
.param2
< 12 then
20 return node
.param2
+ 8
22 return node
.param2
- 8
27 local get_stair_from_param
= function(param
, stairs
)
30 return {name
= stairs
[1], param2
= param
}
32 return {name
= stairs
[2], param2
= param
- 4}
34 return {name
= stairs
[3], param2
= param
- 8}
38 return {name
= stairs
[1], param2
= param
}
39 elseif param
>= 16 then
40 return {name
= stairs
[2], param2
= param
+ 4}
42 return {name
= stairs
[3], param2
= param
+ 8}
47 local stair_param_to_connect
= function(param
, ceiling
)
48 local out
= {false, false, false, false, false, false, false, false}
53 elseif param
== 1 then
56 elseif param
== 2 then
59 elseif param
== 3 then
62 elseif param
== 4 then
65 elseif param
== 5 then
68 elseif param
== 6 then
71 elseif param
== 7 then
74 elseif param
== 8 then
77 elseif param
== 9 then
80 elseif param
== 10 then
83 elseif param
== 11 then
91 elseif param
== 13 then
94 elseif param
== 14 then
97 elseif param
== 15 then
100 elseif param
== 16 then
103 elseif param
== 17 then
106 elseif param
== 18 then
109 elseif param
== 19 then
112 elseif param
== 20 then
115 elseif param
== 21 then
118 elseif param
== 22 then
121 elseif param
== 23 then
129 local stair_connect_to_param
= function(connect
, ceiling
)
132 if connect
[3] and connect
[8] then
134 elseif connect
[2] and connect
[5] then
136 elseif connect
[4] and connect
[7] then
138 elseif connect
[1] and connect
[6] then
140 elseif connect
[1] and connect
[8] then
142 elseif connect
[2] and connect
[3] then
144 elseif connect
[4] and connect
[5] then
146 elseif connect
[6] and connect
[7] then
148 elseif connect
[3] and connect
[6] then
150 elseif connect
[5] and connect
[8] then
152 elseif connect
[2] and connect
[7] then
154 elseif connect
[1] and connect
[4] then
158 if connect
[5] and connect
[8] then
160 elseif connect
[3] and connect
[6] then
162 elseif connect
[1] and connect
[4] then
164 elseif connect
[2] and connect
[7] then
166 elseif connect
[2] and connect
[3] then
168 elseif connect
[1] and connect
[8] then
170 elseif connect
[6] and connect
[7] then
172 elseif connect
[4] and connect
[5] then
174 elseif connect
[3] and connect
[8] then
176 elseif connect
[1] and connect
[6] then
178 elseif connect
[4] and connect
[7] then
180 elseif connect
[2] and connect
[5] then
188 mcl_stairs.cornerstair.add(name, stairtiles)
190 NOTE: This function is used internally. If you register a stair, this function is already called, no
191 need to call it again!
194 * name is the name of the node to make corner stairs for.
195 * stairtiles is optional, can specify textures for inner and outer stairs. 3 data types are accepted:
197 * "default": Use same textures as original node
198 * "woodlike": Take first frame of the original tiles, then take a triangle piece
199 of the texture, rotate it by 90° and overlay it over the original texture
200 * table: Specify textures explicitly. Table of tiles to override textures for
201 inner and outer stairs. Table format:
202 { tiles_def_for_outer_stair, tiles_def_for_inner_stair }
203 * nil: Equivalent to "default"
206 function mcl_stairs
.cornerstair
.add(name
, stairtiles
)
207 local node_def
= minetest
.registered_nodes
[name
]
210 if stairtiles
== "woodlike" then
211 outer_tiles
= table.copy(node_def
.tiles
)
212 inner_tiles
= table.copy(node_def
.tiles
)
214 if outer_tiles
[i
] == nil then
215 outer_tiles
[i
] = outer_tiles
[i
-1]
217 if inner_tiles
[i
] == nil then
218 inner_tiles
[i
] = inner_tiles
[i
-1]
221 local t
= node_def
.tiles
[1]
222 outer_tiles
[1] = t
.."^("..t
.."^[transformR90^mcl_stairs_turntexture.png^[makealpha:255,0,255)"
223 outer_tiles
[2] = t
.."^("..t
.."^mcl_stairs_turntexture.png^[transformR270^[makealpha:255,0,255)"
225 inner_tiles
[1] = t
.."^("..t
.."^[transformR90^(mcl_stairs_turntexture.png^[transformR180)^[makealpha:255,0,255)"
226 inner_tiles
[2] = t
.."^("..t
.."^[transformR270^(mcl_stairs_turntexture.png^[transformR90)^[makealpha:255,0,255)"
228 elseif stairtiles
== nil or stairtiles
== "default" then
229 outer_tiles
= node_def
.tiles
230 inner_tiles
= node_def
.tiles
232 outer_tiles
= stairtiles
[1]
233 inner_tiles
= stairtiles
[2]
235 local outer_groups
= table.copy(node_def
.groups
)
236 outer_groups
.not_in_creative_inventory
= 1
237 local inner_groups
= table.copy(outer_groups
)
238 outer_groups
.stair
= 2
239 outer_groups
.not_in_craft_guide
= 1
240 inner_groups
.stair
= 3
241 inner_groups
.not_in_craft_guide
= 1
242 local drop
= node_def
.drop
or name
243 local after_dig_node
= function(pos
, oldnode
)
244 local param
= get_stair_param(oldnode
)
251 local connect
= stair_param_to_connect(param
, ceiling
)
253 {pos
= {x
= pos
.x
, y
= pos
.y
, z
= pos
.z
+ 2}},
254 {pos
= {x
= pos
.x
- 1, y
= pos
.y
, z
= pos
.z
+ 1}}, {pos
= {x
= pos
.x
, y
= pos
.y
, z
= pos
.z
+ 1}}, {pos
= {x
= pos
.x
+ 1, y
= pos
.y
, z
= pos
.z
+ 1}},
255 {pos
= {x
= pos
.x
- 2, y
= pos
.y
, z
= pos
.z
}}, {pos
= {x
= pos
.x
- 1, y
= pos
.y
, z
= pos
.z
}},
256 {pos
= pos
, connect
= connect
},
257 {pos
= {x
= pos
.x
+ 1, y
= pos
.y
, z
= pos
.z
}}, {pos
= {x
= pos
.x
+ 2, y
= pos
.y
, z
= pos
.z
}},
258 {pos
= {x
= pos
.x
- 1, y
= pos
.y
, z
= pos
.z
- 1}}, {pos
= {x
= pos
.x
, y
= pos
.y
, z
= pos
.z
- 1}}, {pos
= {x
= pos
.x
+ 1, y
= pos
.y
, z
= pos
.z
- 1}},
259 {pos
= {x
= pos
.x
, y
= pos
.y
, z
= pos
.z
- 2}}
261 for i
,v
in ipairs(t
) do
262 if not v
.connect
then
263 local node
= minetest
.get_node(v
.pos
)
264 local node_def
= minetest
.registered_nodes
[node
.name
]
268 if node_def
.stairs
then
269 t
[i
].stairs
= node_def
.stairs
270 t
[i
].connect
= stair_param_to_connect(get_stair_param(node
), ceiling
)
272 t
[i
].connect
= {false, false, false, false, false, false, false, false}
276 local swap_stair
= function(index
, n1
, n2
)
277 local connect
= {false, false, false, false, false, false, false, false}
280 local node
= get_stair_from_param(stair_connect_to_param(connect
, ceiling
), t
[index
].stairs
)
281 minetest
.swap_node(t
[index
].pos
, node
)
284 if t
[7].connect
[1] and t
[3].connect
[6] then
285 if t
[3].connect
[1] and t
[1].connect
[6] then
286 if t
[2].connect
[3] then
288 elseif t
[4].connect
[7] then
291 elseif t
[3].connect
[7] then
293 elseif t
[3].connect
[3] then
296 elseif t
[7].connect
[2] and t
[3].connect
[5] then
297 if t
[3].connect
[2] and t
[1].connect
[5] then
298 if t
[4].connect
[8] then
300 elseif t
[2].connect
[4] then
303 elseif t
[3].connect
[4] then
305 elseif t
[3].connect
[8] then
311 if t
[7].connect
[3] and t
[8].connect
[8] then
312 if t
[8].connect
[3] and t
[9].connect
[8] then
313 if t
[4].connect
[5] then
315 elseif t
[12].connect
[1] then
318 elseif t
[8].connect
[1] then
320 elseif t
[8].connect
[5] then
323 elseif t
[7].connect
[4] and t
[8].connect
[7] then
324 if t
[8].connect
[4] and t
[9].connect
[7] then
325 if t
[12].connect
[2] then
327 elseif t
[4].connect
[6] then
330 elseif t
[8].connect
[6] then
332 elseif t
[8].connect
[2] then
338 if t
[7].connect
[5] and t
[11].connect
[2] then
339 if t
[11].connect
[5] and t
[13].connect
[2] then
340 if t
[12].connect
[7] then
342 elseif t
[10].connect
[3] then
345 elseif t
[11].connect
[3] then
347 elseif t
[11].connect
[7] then
350 elseif t
[7].connect
[6] and t
[11].connect
[1] then
351 if t
[11].connect
[6] and t
[13].connect
[1] then
352 if t
[10].connect
[4] then
354 elseif t
[12].connect
[8] then
357 elseif t
[11].connect
[8] then
359 elseif t
[11].connect
[4] then
365 if t
[7].connect
[7] and t
[6].connect
[4] then
366 if t
[6].connect
[7] and t
[5].connect
[4] then
367 if t
[10].connect
[1] then
369 elseif t
[2].connect
[5] then
372 elseif t
[6].connect
[5] then
374 elseif t
[6].connect
[1] then
377 elseif t
[7].connect
[8] and t
[6].connect
[3] then
378 if t
[6].connect
[8] and t
[5].connect
[3] then
379 if t
[2].connect
[6] then
381 elseif t
[10].connect
[2] then
384 elseif t
[6].connect
[2] then
386 elseif t
[6].connect
[6] then
392 minetest
.override_item(name
, {
393 stairs
= {name
, name
.."_outer", name
.."_inner"},
394 after_dig_node
= function(pos
, oldnode
) after_dig_node(pos
, oldnode
) end,
396 after_place_node
= function(pos
, placer
, itemstack
, pointed_thing
)
397 local node
= minetest
.get_node(pos
)
398 local ceiling
= false
399 if pointed_thing
.under
.y
> pointed_thing
.above
.y
then
401 if node
.param2
== 0 then node
.param2
= 20
402 elseif node
.param2
== 1 then node
.param2
= 23
403 elseif node
.param2
== 2 then node
.param2
= 22
404 elseif node
.param2
== 3 then node
.param2
= 21
407 local connect
= stair_param_to_connect(get_stair_param(node
), ceiling
)
409 {pos
= {x
= pos
.x
- 1, y
= pos
.y
, z
= pos
.z
+ 1}}, {pos
= {x
= pos
.x
, y
= pos
.y
, z
= pos
.z
+ 1}}, {pos
= {x
= pos
.x
+ 1, y
= pos
.y
, z
= pos
.z
+ 1}},
410 {pos
= {x
= pos
.x
- 1, y
= pos
.y
, z
= pos
.z
}}, {pos
= pos
, stairs
= {name
, name
.."_outer", name
.."_inner"}, connect
= connect
}, {pos
= {x
= pos
.x
+ 1, y
= pos
.y
, z
= pos
.z
}},
411 {pos
= {x
= pos
.x
- 1, y
= pos
.y
, z
= pos
.z
- 1}}, {pos
= {x
= pos
.x
, y
= pos
.y
, z
= pos
.z
- 1}}, {pos
= {x
= pos
.x
+ 1, y
= pos
.y
, z
= pos
.z
- 1}},
413 for i
,v
in ipairs(t
) do
414 if not v
.connect
then
415 local node
= minetest
.get_node(v
.pos
)
416 local node_def
= minetest
.registered_nodes
[node
.name
]
420 if node_def
.stairs
then
421 t
[i
].stairs
= node_def
.stairs
422 t
[i
].connect
= stair_param_to_connect(get_stair_param(node
), ceiling
)
424 t
[i
].connect
= {false, false, false, false, false, false, false, false}
428 local reset_node
= function(n1
, n2
)
429 local connect
= {false, false, false, false, false, false, false, false}
432 node
= get_stair_from_param(stair_connect_to_param(connect
, ceiling
), t
[5].stairs
)
434 local swap_stair
= function(index
, n1
, n2
)
435 local connect
= {false, false, false, false, false, false, false, false}
438 local node
= get_stair_from_param(stair_connect_to_param(connect
, ceiling
), t
[index
].stairs
)
439 t
[index
].connect
= connect
440 minetest
.swap_node(t
[index
].pos
, node
)
443 if t
[4].connect
[2] and t
[4].connect
[5] and t
[1].connect
[5] and not t
[7].connect
[2] then
445 elseif t
[4].connect
[1] and t
[4].connect
[6] and t
[7].connect
[1] and not t
[1].connect
[6] then
448 if t
[6].connect
[1] and t
[6].connect
[6] and t
[3].connect
[6] and not t
[9].connect
[1] then
450 elseif t
[6].connect
[2] and t
[6].connect
[5] and t
[9].connect
[2] and not t
[3].connect
[5] then
453 if t
[4].connect
[3] ~= t
[6].connect
[8] then
454 if t
[4].connect
[3] then
455 if t
[2].connect
[6] then
457 elseif t
[8].connect
[2] then
459 elseif t
[2].connect
[4] and t
[2].connect
[7] and t
[1].connect
[4] and not t
[3].connect
[7] then
462 elseif t
[2].connect
[3] and t
[2].connect
[8] and t
[3].connect
[8] and not t
[1].connect
[3] then
465 elseif t
[8].connect
[3] and t
[8].connect
[8] and t
[9].connect
[8] and not t
[7].connect
[3] then
468 elseif t
[8].connect
[4] and t
[8].connect
[7] and t
[7].connect
[4] and not t
[9].connect
[7] then
473 if t
[2].connect
[5] then
475 elseif t
[8].connect
[1] then
477 elseif t
[2].connect
[4] and t
[2].connect
[7] and t
[3].connect
[7] and not t
[1].connect
[4] then
480 elseif t
[2].connect
[3] and t
[2].connect
[8] and t
[1].connect
[3] and not t
[3].connect
[8] then
483 elseif t
[8].connect
[3] and t
[8].connect
[8] and t
[7].connect
[3] and not t
[9].connect
[8] then
486 elseif t
[8].connect
[4] and t
[8].connect
[7] and t
[9].connect
[7] and not t
[7].connect
[4] then
492 elseif connect
[2] then
493 if t
[2].connect
[4] and t
[2].connect
[7] and t
[3].connect
[7] and not t
[1].connect
[4] then
495 elseif t
[2].connect
[3] and t
[2].connect
[8] and t
[1].connect
[3] and not t
[3].connect
[8] then
498 if t
[8].connect
[3] and t
[8].connect
[8] and t
[9].connect
[8] and not t
[7].connect
[3] then
500 elseif t
[8].connect
[4] and t
[8].connect
[7] and t
[7].connect
[4] and not t
[9].connect
[7] then
503 if t
[2].connect
[5] ~= t
[8].connect
[2] then
504 if t
[2].connect
[5] then
505 if t
[6].connect
[8] then
507 elseif t
[4].connect
[4] then
509 elseif t
[6].connect
[1] and t
[6].connect
[6] and t
[3].connect
[6] and not t
[9].connect
[1] then
512 elseif t
[6].connect
[2] and t
[6].connect
[5] and t
[9].connect
[2] and not t
[3].connect
[5] then
515 elseif t
[4].connect
[2] and t
[4].connect
[5] and t
[7].connect
[2] and not t
[1].connect
[5] then
518 elseif t
[4].connect
[1] and t
[4].connect
[6] and t
[1].connect
[6] and not t
[7].connect
[1] then
523 if t
[6].connect
[7] then
525 elseif t
[4].connect
[3] then
527 elseif t
[6].connect
[1] and t
[6].connect
[6] and t
[9].connect
[1] and not t
[3].connect
[6] then
530 elseif t
[6].connect
[2] and t
[6].connect
[5] and t
[3].connect
[5] and not t
[9].connect
[2] then
533 elseif t
[4].connect
[2] and t
[4].connect
[5] and t
[1].connect
[5] and not t
[7].connect
[2] then
536 elseif t
[4].connect
[1] and t
[4].connect
[6] and t
[7].connect
[1] and not t
[1].connect
[6] then
542 elseif connect
[4] then
543 if t
[6].connect
[1] and t
[6].connect
[6] and t
[9].connect
[1] and not t
[3].connect
[6] then
545 elseif t
[6].connect
[2] and t
[6].connect
[5] and t
[3].connect
[5] and not t
[9].connect
[2] then
548 if t
[4].connect
[2] and t
[4].connect
[5] and t
[7].connect
[2] and not t
[1].connect
[5] then
550 elseif t
[4].connect
[1] and t
[4].connect
[6] and t
[1].connect
[6] and not t
[7].connect
[1] then
553 if t
[4].connect
[4] ~= t
[6].connect
[7] then
554 if t
[4].connect
[4] then
555 if t
[8].connect
[1] then
557 elseif t
[2].connect
[5] then
559 elseif t
[8].connect
[3] and t
[8].connect
[8] and t
[7].connect
[3] and not t
[9].connect
[8] then
562 elseif t
[8].connect
[4] and t
[8].connect
[7] and t
[9].connect
[7] and not t
[7].connect
[4] then
565 elseif t
[2].connect
[4] and t
[2].connect
[7] and t
[3].connect
[7] and not t
[1].connect
[4] then
568 elseif t
[2].connect
[3] and t
[2].connect
[8] and t
[1].connect
[3] and not t
[3].connect
[8] then
573 if t
[8].connect
[2] then
575 elseif t
[2].connect
[6] then
577 elseif t
[8].connect
[3] and t
[8].connect
[8] and t
[9].connect
[8] and not t
[7].connect
[3] then
580 elseif t
[8].connect
[4] and t
[8].connect
[7] and t
[7].connect
[4] and not t
[9].connect
[7] then
583 elseif t
[2].connect
[4] and t
[2].connect
[7] and t
[1].connect
[4] and not t
[3].connect
[7] then
586 elseif t
[2].connect
[3] and t
[2].connect
[8] and t
[3].connect
[8] and not t
[1].connect
[3] then
592 elseif connect
[1] then
593 if t
[8].connect
[3] and t
[8].connect
[8] and t
[7].connect
[3] and not t
[9].connect
[8] then
595 elseif t
[8].connect
[4] and t
[8].connect
[7] and t
[9].connect
[7] and not t
[7].connect
[4] then
598 if t
[2].connect
[4] and t
[2].connect
[7] and t
[1].connect
[4] and not t
[3].connect
[7] then
600 elseif t
[2].connect
[3] and t
[2].connect
[8] and t
[3].connect
[8] and not t
[1].connect
[3] then
603 if t
[2].connect
[6] ~= t
[8].connect
[1] then
604 if t
[2].connect
[6] then
605 if t
[4].connect
[3] then
607 elseif t
[6].connect
[7] then
609 elseif t
[4].connect
[2] and t
[4].connect
[5] and t
[1].connect
[5] and not t
[7].connect
[2] then
612 elseif t
[4].connect
[1] and t
[4].connect
[6] and t
[7].connect
[1] and not t
[1].connect
[6] then
615 elseif t
[6].connect
[1] and t
[6].connect
[6] and t
[9].connect
[1] and not t
[3].connect
[6] then
618 elseif t
[6].connect
[2] and t
[6].connect
[5] and t
[3].connect
[5] and not t
[9].connect
[2] then
623 if t
[4].connect
[4] then
625 elseif t
[6].connect
[8] then
627 elseif t
[4].connect
[2] and t
[4].connect
[5] and t
[7].connect
[2] and not t
[1].connect
[5] then
630 elseif t
[4].connect
[1] and t
[4].connect
[6] and t
[1].connect
[6] and not t
[7].connect
[1] then
633 elseif t
[6].connect
[1] and t
[6].connect
[6] and t
[3].connect
[6] and not t
[9].connect
[1] then
636 elseif t
[6].connect
[2] and t
[6].connect
[5] and t
[9].connect
[2] and not t
[3].connect
[5] then
643 minetest
.swap_node(pos
, node
)
646 minetest
.register_node(":"..name
.."_outer", {
647 description
= node_def
.description
,
648 _doc_items_create_entry
= false,
649 drawtype
= "nodebox",
652 paramtype2
= "facedir",
653 is_ground_content
= false,
654 groups
= outer_groups
,
655 sounds
= node_def
.sounds
,
659 {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
660 {-0.5, 0, 0, 0, 0.5, 0.5}
664 stairs
= {name
, name
.."_outer", name
.."_inner"},
665 after_dig_node
= function(pos
, oldnode
) after_dig_node(pos
, oldnode
) end,
666 _mcl_hardness
= node_def
._mcl_hardness
,
668 minetest
.register_node(":"..name
.."_inner", {
669 description
= node_def
.description
,
670 _doc_items_create_entry
= false,
671 drawtype
= "nodebox",
674 paramtype2
= "facedir",
675 is_ground_content
= false,
676 groups
= inner_groups
,
677 sounds
= node_def
.sounds
,
681 {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
682 {-0.5, 0, 0, 0.5, 0.5, 0.5},
683 {-0.5, 0, -0.5, 0, 0.5, 0}
687 stairs
= {name
, name
.."_outer", name
.."_inner"},
688 after_dig_node
= function(pos
, oldnode
) after_dig_node(pos
, oldnode
) end,
689 _mcl_hardness
= node_def
._mcl_hardness
,
692 if minetest
.get_modpath("doc") then
693 doc
.add_entry_alias("nodes", name
, "nodes", name
.."_inner")
694 doc
.add_entry_alias("nodes", name
, "nodes", name
.."_outer")