@@ -17,6 +17,30 @@ minetest.register_alias("stairs:slab_pinewood", "stairs:slab_pine_wood")
17
17
18
18
local replace = minetest .setting_getbool (" enable_stairs_replace_abm" )
19
19
20
+ local function rotate_and_place (itemstack , placer , pointed_thing )
21
+ local p0 = pointed_thing .under
22
+ local p1 = pointed_thing .above
23
+ local param2 = 0
24
+
25
+ local placer_pos = placer :getpos ()
26
+ if placer_pos then
27
+ param2 = minetest .dir_to_facedir (vector .subtract (p1 , placer_pos ))
28
+ end
29
+
30
+ local finepos = minetest .pointed_thing_to_face_pos (placer , pointed_thing )
31
+ local fpos = finepos .y % 1
32
+
33
+ if p0 .y - 1 == p1 .y or (fpos > 0 and fpos < 0.5 )
34
+ or (fpos < - 0.5 and fpos > - 0.999999999 ) then
35
+ param2 = param2 + 20
36
+ if param2 == 21 then
37
+ param2 = 23
38
+ elseif param2 == 23 then
39
+ param2 = 21
40
+ end
41
+ end
42
+ return minetest .item_place (itemstack , placer , pointed_thing , param2 )
43
+ end
20
44
21
45
-- Register stairs.
22
46
-- Node will be called stairs:stair_<subname>
@@ -52,30 +76,7 @@ function stairs.register_stair(subname, recipeitem, groups, images, description,
52
76
return itemstack
53
77
end
54
78
55
- local p0 = pointed_thing .under
56
- local p1 = pointed_thing .above
57
- local param2 = 0
58
-
59
- local placer_pos = placer :getpos ()
60
- if placer_pos then
61
- local dir = {
62
- x = p1 .x - placer_pos .x ,
63
- y = p1 .y - placer_pos .y ,
64
- z = p1 .z - placer_pos .z
65
- }
66
- param2 = minetest .dir_to_facedir (dir )
67
- end
68
-
69
- if p0 .y - 1 == p1 .y then
70
- param2 = param2 + 20
71
- if param2 == 21 then
72
- param2 = 23
73
- elseif param2 == 23 then
74
- param2 = 21
75
- end
76
- end
77
-
78
- return minetest .item_place (itemstack , placer , pointed_thing , param2 )
79
+ return rotate_and_place (itemstack , placer , pointed_thing )
79
80
end ,
80
81
})
81
82
126
127
127
128
-- Slab facedir to placement 6d matching table
128
129
local slab_trans_dir = {[0 ] = 8 , 0 , 2 , 1 , 3 , 4 }
129
- -- Slab facedir when placing initial slab against other surface
130
- local slab_trans_dir_place = {[0 ] = 0 , 20 , 12 , 16 , 4 , 8 }
131
130
132
131
-- Register slabs.
133
132
-- Node will be called stairs:slab_<subname>
@@ -153,15 +152,17 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
153
152
local creative_enabled = (creative and creative .is_enabled_for
154
153
and creative .is_enabled_for (placer :get_player_name ()))
155
154
156
- if under and wield_item == under .name then
155
+ if under and under .name : find ( " stairs:slab_ " ) then
157
156
-- place slab using under node orientation
158
157
local dir = minetest .dir_to_facedir (vector .subtract (
159
158
pointed_thing .above , pointed_thing .under ), true )
160
159
161
160
local p2 = under .param2
162
161
163
162
-- combine two slabs if possible
164
- if slab_trans_dir [math.floor (p2 / 4 )] == dir then
163
+ if slab_trans_dir [math.floor (p2 / 4 )] == dir
164
+ and wield_item == under .name then
165
+
165
166
if not recipeitem then
166
167
return itemstack
167
168
end
@@ -194,16 +195,7 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
194
195
end
195
196
return itemstack
196
197
else
197
- -- place slab using look direction of player
198
- local dir = minetest .dir_to_wallmounted (vector .subtract (
199
- pointed_thing .above , pointed_thing .under ), true )
200
-
201
- local rot = slab_trans_dir_place [dir ]
202
- if rot == 0 or rot == 20 then
203
- rot = rot + minetest .dir_to_facedir (placer :get_look_dir ())
204
- end
205
-
206
- return minetest .item_place (itemstack , placer , pointed_thing , rot )
198
+ return rotate_and_place (itemstack , placer , pointed_thing )
207
199
end
208
200
end ,
209
201
})
0 commit comments