Add digging time support for shears/swords/hand

This commit is contained in:
Wuzzy 2017-02-26 20:50:02 +01:00
parent a4a6ec9b06
commit b05c56bcd3
1 changed files with 24 additions and 2 deletions

View File

@ -41,6 +41,7 @@ local materials = { "wood", "gold", "stone", "iron", "diamond" }
local material_divisors = { 2, 12, 4, 6, 8 } local material_divisors = { 2, 12, 4, 6, 8 }
local basegroups = { "pickaxey", "axey", "shovely" } local basegroups = { "pickaxey", "axey", "shovely" }
local minigroups = { "handy", "shearsy", "swordy" } local minigroups = { "handy", "shearsy", "swordy" }
local minigroup_divisors = { 1, 15, 1.5, 5, 15 }
mcl_autogroup = {} mcl_autogroup = {}
mcl_autogroup.digtimes = {} mcl_autogroup.digtimes = {}
@ -54,8 +55,6 @@ for g=1, #minigroups do
mcl_autogroup.digtimes[minigroups[g].."_dig"] = {} mcl_autogroup.digtimes[minigroups[g].."_dig"] = {}
end end
local overwrite = function() local overwrite = function()
for nname, ndef in pairs(minetest.registered_nodes) do for nname, ndef in pairs(minetest.registered_nodes) do
local groups_changed = false local groups_changed = false
@ -112,6 +111,29 @@ local overwrite = function()
end end
end end
end end
for m=1, #minigroups do
local minigroup = minigroups[m]
if (hardness ~= -1 and ndef.groups[minigroup]) then
local diggroup = minigroup.."_dig"
local time, validity_factor
if ndef.groups[minigroup] == 1 then
-- Valid tool
validity_factor = 1.5
else
-- Wrong tool (higher digging time)
validity_factor = 5
end
time = (hardness * validity_factor) / minigroup_divisors[m]
if time <= 0.05 then
time = 1
else
time = math.ceil(time * 20) / 20
end
table.insert(mcl_autogroup.digtimes[diggroup], time)
newgroups[diggroup] = #mcl_autogroup.digtimes[diggroup]
groups_changed = true
end
end
if groups_changed then if groups_changed then
minetest.override_item(nname, { minetest.override_item(nname, {