]> git.lizzy.rs Git - digcustom.git/commitdiff
Use diglib and lua_async
authorElias Fleckenstein <eliasfleckenstein@web.de>
Wed, 24 Nov 2021 16:28:40 +0000 (17:28 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Wed, 24 Nov 2021 16:28:40 +0000 (17:28 +0100)
init.lua
mod.conf
settingtypes.txt

index 59b80dd56425a937787c688aeffae29bee5f71e2..f305ad8004a8f1b6a26c8547076ca02f565fba43 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -1,13 +1,18 @@
-minetest.register_globalstep(function()
-       if minetest.settings:get_bool("digcustom") then
-               local list = (minetest.settings:get("digcustom_nodes") or ""):split(",")
-               local positions = minetest.find_nodes_near(minetest.localplayer:get_pos(), 5, list, true)
-               for i, pos in ipairs(positions) do
-                       if i > 5 then break end
-                       minetest.dig_node(pos)
+async(function()
+       while true do
+               if minetest.settings:get_bool("digcustom") and minetest.localplayer then
+                       local list = (minetest.settings:get("digcustom_nodes") or ""):split(",")
+                       local node_pos = minetest.find_node_near(minetest.localplayer:get_pos(), 5, list, true)
+                       local max_time = tonumber(minetest.settings:get("digcustom_max_time")) or -1
+
+                       if node_pos then
+                               await(diglib.dig_node(node_pos, max_time))
+                       end
                end
+
+               lua_async.yield()
        end
-end)
+end)()
 
 minetest.register_list_command("digcustom", "Configue custom autodig nodes", "digcustom_nodes")
 
index 54d33084d925bcafcdd8cea649552250620202a5..e855099c52ff323af5cd7eca4c5e2d0a2595f8e7 100644 (file)
--- a/mod.conf
+++ b/mod.conf
@@ -1,3 +1,4 @@
 name = digcustom
 author = Fleckenstein
 description = A dragonfire CSM to automatically dig customizable nodes
+depends = diglib, lua_async
index 224341f3967d71ae9bbec972f4bb7e92e699eb6c..d143c0722b478104f65895ff71e508fea515b4eb 100644 (file)
@@ -1,2 +1,9 @@
+# Enable DigCustom
 digcustom (DigCustom) bool false
+
+# Nodes to dig, comma separated
 digcustom_nodes (DigCustom Nodes) string
+
+# Maximum time to spend on digging a node.
+# -1 means no limit
+digcustom_max_time (DigCustom Max Time) int -1