From a0f5b70568c1140085cba2e2d8d83b6ae6912ed1 Mon Sep 17 00:00:00 2001 From: hdastwb Date: Tue, 16 Jul 2013 20:50:41 -0400 Subject: added (optional) support for 6d facedir in dir_to_facedir and added facedir_to_dir --- builtin/item.lua | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) (limited to 'builtin/item.lua') diff --git a/builtin/item.lua b/builtin/item.lua index b8381515a..9105d8c0c 100644 --- a/builtin/item.lua +++ b/builtin/item.lua @@ -34,8 +34,45 @@ function minetest.get_pointed_thing_position(pointed_thing, above) end end -function minetest.dir_to_facedir(dir) - if math.abs(dir.x) > math.abs(dir.z) then +function minetest.dir_to_facedir(dir, is6d) + --account for y if requested + if is6d and math.abs(dir.y) > math.abs(dir.x) and math.abs(dir.y) > math.abs(dir.z) then + + --from above + if dir.y < 0 then + if math.abs(dir.x) > math.abs(dir.z) then + if dir.x < 0 then + return 19 + else + return 13 + end + else + if dir.z < 0 then + return 10 + else + return 4 + end + end + + --from below + else + if math.abs(dir.x) > math.abs(dir.z) then + if dir.x < 0 then + return 15 + else + return 17 + end + else + if dir.z < 0 then + return 6 + else + return 8 + end + end + end + + --otherwise, place horizontally + elseif math.abs(dir.x) > math.abs(dir.z) then if dir.x < 0 then return 3 else @@ -50,6 +87,27 @@ function minetest.dir_to_facedir(dir) end end +function minetest.facedir_to_dir(facedir) + --a table of possible dirs + return ({{x=0, y=0, z=1}, + {x=1, y=0, z=0}, + {x=0, y=0, z=-1}, + {x=-1, y=0, z=0}, + {x=0, y=-1, z=0}, + {x=0, y=1, z=0}}) + + --indexed into by a table of correlating facedirs + [({[0]=1, 2, 3, 4, + 5, 2, 6, 4, + 6, 2, 5, 4, + 1, 5, 3, 6, + 1, 6, 3, 5, + 1, 4, 3, 2}) + + --indexed into by the facedir in question + [facedir]] +end + function minetest.dir_to_wallmounted(dir) if math.abs(dir.y) > math.max(math.abs(dir.x), math.abs(dir.z)) then if dir.y < 0 then -- cgit v1.2.3