diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-11-24 17:28:40 +0100 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-11-24 17:28:40 +0100 |
commit | 2f419d86060c106a4c3fdce758311d5d2ab8737f (patch) | |
tree | e682b55f442b6d82a3a3f36316bfb9b052d95b27 /init.lua | |
parent | ac41c2259fa504215f7eb8932e57b3f5f42a50ac (diff) | |
download | digcustom-2f419d86060c106a4c3fdce758311d5d2ab8737f.tar.xz |
Use diglib and lua_async
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -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") |