Skip to content

Commit

Permalink
added (optional) support for 6d facedir in dir_to_facedir and added f…
Browse files Browse the repository at this point in the history
…acedir_to_dir
  • Loading branch information
hdastwb authored and RealBadAngel committed Jul 23, 2013
1 parent 0b4b9e7 commit a0f5b70
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
62 changes: 60 additions & 2 deletions builtin/item.lua
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions doc/lua_api.txt
Expand Up @@ -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)
Expand Down

0 comments on commit a0f5b70

Please sign in to comment.