diff options
-rw-r--r-- | builtin/item.lua | 62 | ||||
-rw-r--r-- | doc/lua_api.txt | 6 |
2 files changed, 64 insertions, 4 deletions
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 diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 1890682fd..b0281bee7 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1270,8 +1270,10 @@ minetest.inventorycube(img1, img2, img3) ^ Returns a string for making an image of a cube (useful as an item image) minetest.get_pointed_thing_position(pointed_thing, above) ^ Get position of a pointed_thing (that you can get from somewhere) -minetest.dir_to_facedir(dir) -^ Convert a vector to a facedir value, used in param2 for paramtype2="facedir" +minetest.dir_to_facedir(dir, is6d) +^ Convert a vector to a facedir value, used in param2 for paramtype2="facedir"; passing something non-nil/false for the optional second parameter causes it to take the y component into account +minetest.facedir_to_dir(facedir) +^ Convert a facedir back into a vector aimed directly out the "back" of a node minetest.dir_to_wallmounted(dir) ^ Convert a vector to a wallmounted value, used for paramtype2="wallmounted" minetest.get_node_drops(nodename, toolname) |