]> git.lizzy.rs Git - elidragon_v2.git/commitdiff
Add util API
authorElias Fleckenstein <eliasfleckenstein@web.de>
Fri, 19 Feb 2021 09:47:16 +0000 (10:47 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Fri, 19 Feb 2021 09:47:16 +0000 (10:47 +0100)
mods/elidragon_util/init.lua [new file with mode: 0644]
mods/elidragon_util/mod.conf [new file with mode: 0644]

diff --git a/mods/elidragon_util/init.lua b/mods/elidragon_util/init.lua
new file mode 100644 (file)
index 0000000..143a925
--- /dev/null
@@ -0,0 +1,28 @@
+local util = {}
+
+function util.get_far_node(pos)
+       local node = minetest.get_node(pos)
+       if node.name ~= "ignore" then
+               return node
+       end
+       minetest.get_voxel_manip():read_from_map(pos, pos)
+       return minetest.get_node(pos)
+end
+
+function util.find_free_position_near(pos)
+       local tries = {
+               {x =  1, y =  0, z =  0},
+               {x = -1, y =  0, z =  0},
+               {x =  0, y =  0, z =  1},
+               {x =  0, y =  0, z = -1},
+       }
+       for _, d in ipairs(tries) do
+               local p = vector.add(pos, d)
+               if not minetest.registered_nodes[minetest.get_node(p).name].walkable then
+                       return p, true
+               end
+       end
+       return pos, false
+end  
+
+elidragon.util = util
diff --git a/mods/elidragon_util/mod.conf b/mods/elidragon_util/mod.conf
new file mode 100644 (file)
index 0000000..fbd9adf
--- /dev/null
@@ -0,0 +1,4 @@
+name = elidragon_util
+author = Fleckenstein
+description = Contains utility functions used by Elidragon mods
+depends = elidragon