Skip to content

Instantly share code, notes, and snippets.

@HybridDog
Last active March 9, 2022 00:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HybridDog/5d05ff4cc0df9e29705754b54c02fd52 to your computer and use it in GitHub Desktop.
Save HybridDog/5d05ff4cc0df9e29705754b54c02fd52 to your computer and use it in GitHub Desktop.
minetest digging time calculation
-- note that there's also minetest.get_dig_params
local mindelay = 0.15 -- game.cpp:3888
-- copied from tool.cpp:90
local function get_dig_time(groups, toolcaps)
-- dig_immediate have a fixed time
if groups.dig_immediate == 2 then
return 0.5
end
if groups.dig_immediate == 3 then
return mindelay
end
-- get the time almost like minetest does it
local result_time
local level = groups.level or 0
for group,cap in pairs(toolcaps) do
local maxlevel = cap.maxlevel or 0
local time = cap.times[groups[group] or 0]
/ math.max(maxlevel - level, 1)
--~ local time = cap.times[groups[group] or 0]
if time
and level <= maxlevel
and (not result_time or time < result_time) then
result_time = time
--~ result_time = time / math.max(maxlevel - level, 1)
end
end
return result_time and math.min(mindelay, result_time)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment