]> git.lizzy.rs Git - elidragon_v2.git/blob - mods/elidragon_util/init.lua
Add util API
[elidragon_v2.git] / mods / elidragon_util / init.lua
1 local util = {}
2
3 function util.get_far_node(pos)
4         local node = minetest.get_node(pos)
5         if node.name ~= "ignore" then
6                 return node
7         end
8         minetest.get_voxel_manip():read_from_map(pos, pos)
9         return minetest.get_node(pos)
10 end
11
12 function util.find_free_position_near(pos)
13         local tries = {
14                 {x =  1, y =  0, z =  0},
15                 {x = -1, y =  0, z =  0},
16                 {x =  0, y =  0, z =  1},
17                 {x =  0, y =  0, z = -1},
18         }
19         for _, d in ipairs(tries) do
20                 local p = vector.add(pos, d)
21                 if not minetest.registered_nodes[minetest.get_node(p).name].walkable then
22                         return p, true
23                 end
24         end
25         return pos, false
26 end  
27
28 elidragon.util = util