3 function diglib.calculate_dig_time(toolcaps, groups)
6 for group, groupdef in pairs(toolcaps.groupcaps) do
7 local level = groups[group]
10 local tm = groupdef.times[level]
12 if tm and (not best_time or best_time > tm) then
21 function diglib.get_dig_time(pos)
22 local node = minetest.get_node_or_nil(pos)
23 local nodedef = node and minetest.get_node_def(node.name)
24 local groups = nodedef and nodedef.groups
30 local player = minetest.localplayer
31 local wielditem = player and player:get_wielded_item()
32 local toolcaps = wielditem and wielditem:get_tool_capabilities()
33 local tool_time = toolcaps and diglib.calculate_dig_time(toolcaps, groups)
35 local inv = minetest.get_inventory("current_player")
36 local hand = inv and inv.hand and inv.hand[1] or ItemStack("")
37 local hand_toolcaps = hand and hand:get_tool_capabilities()
38 local hand_time = hand_toolcaps and diglib.calculate_dig_time(hand_toolcaps, groups)
40 local tm = math.min(tool_time or math.huge, hand_time or math.huge)
42 if tm == math.huge then
49 diglib.dig_node = async(function(pos, max_time)
50 local tm = diglib.get_dig_time(pos)
51 if not tm or max_time and max_time > 0 and tm > max_time then
55 local debug_msgs = minetest.settings:get_bool("diglib_debug")
58 print("start_digging", pos.x, pos.y, pos.z)
60 minetest.interact("start_digging", {type = "node", under = pos, above = pos})
65 lua_async.sleep(tm * 1000)
68 print("digging_completed", pos.x, pos.y, pos.z)
70 minetest.interact("digging_completed", {type = "node", under = pos, above = pos})