Skip to content

Commit e6d0d77

Browse files
MarkuBuparamat
authored andcommittedApr 11, 2017
Stairs: Improve stair and slab rotation on placement
Slabs are placed horizontal instead of vertical, even if they are placed on a wall. Slabs are rotated automatically if they are placed to another slab, no matter which material. Slabs are placed at the lower position if the placer points into the lower half of the pointed node and to the upper position if pointed to the upper half. Stairs are placed normal if the placer points to the lower half of the pointed node and rotated upside down if pointed to the upper half.
1 parent 8d43b98 commit e6d0d77

File tree

1 file changed

+30
-38
lines changed

1 file changed

+30
-38
lines changed
 

‎mods/stairs/init.lua

+30-38
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@ minetest.register_alias("stairs:slab_pinewood", "stairs:slab_pine_wood")
1717

1818
local replace = minetest.setting_getbool("enable_stairs_replace_abm")
1919

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
2044

2145
-- Register stairs.
2246
-- Node will be called stairs:stair_<subname>
@@ -52,30 +76,7 @@ function stairs.register_stair(subname, recipeitem, groups, images, description,
5276
return itemstack
5377
end
5478

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)
7980
end,
8081
})
8182

@@ -126,8 +127,6 @@ end
126127

127128
-- Slab facedir to placement 6d matching table
128129
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}
131130

132131
-- Register slabs.
133132
-- Node will be called stairs:slab_<subname>
@@ -153,15 +152,17 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
153152
local creative_enabled = (creative and creative.is_enabled_for
154153
and creative.is_enabled_for(placer:get_player_name()))
155154

156-
if under and wield_item == under.name then
155+
if under and under.name:find("stairs:slab_") then
157156
-- place slab using under node orientation
158157
local dir = minetest.dir_to_facedir(vector.subtract(
159158
pointed_thing.above, pointed_thing.under), true)
160159

161160
local p2 = under.param2
162161

163162
-- 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+
165166
if not recipeitem then
166167
return itemstack
167168
end
@@ -194,16 +195,7 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
194195
end
195196
return itemstack
196197
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)
207199
end
208200
end,
209201
})

0 commit comments

Comments
 (0)