2017-02-26 18:44:48 +01:00
|
|
|
local materials = { "wood", "gold", "stone", "iron", "diamond" }
|
|
|
|
local material_divisors = { 2, 12, 4, 6, 8 }
|
|
|
|
local basegroups = { "pickaxey", "axey", "shovely" }
|
|
|
|
local minigroups = { "handy", "shearsy", "swordy" }
|
|
|
|
|
|
|
|
mcl_autogroup = {}
|
|
|
|
mcl_autogroup.digtimes = {}
|
2017-02-25 16:19:24 +01:00
|
|
|
|
2017-02-26 18:44:48 +01:00
|
|
|
for m=1, #materials do
|
|
|
|
for g=1, #basegroups do
|
|
|
|
mcl_autogroup.digtimes[basegroups[g].."_dig_"..materials[m]] = {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for g=1, #minigroups do
|
|
|
|
mcl_autogroup.digtimes[minigroups[g].."_dig"] = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
local overwrite = function()
|
2017-02-10 06:01:20 +01:00
|
|
|
for nname, ndef in pairs(minetest.registered_nodes) do
|
2017-02-25 16:19:24 +01:00
|
|
|
local groups_changed = false
|
|
|
|
local newgroups = table.copy(ndef.groups)
|
|
|
|
if (nname ~= "ignore") then
|
|
|
|
-- Automatically assign the “solid” group for solid nodes
|
|
|
|
if (ndef.walkable == nil or ndef.walkable == true)
|
|
|
|
and (ndef.collision_box == nil or ndef.collision_box.type == "regular")
|
|
|
|
and (ndef.node_box == nil or ndef.node_box.type == "regular")
|
|
|
|
and (ndef.groups.falling_node == 0 or ndef.groups.falling_node == nil)
|
|
|
|
and (ndef.groups.not_solid == 0 or ndef.groups.not_solid == nil) then
|
|
|
|
newgroups.solid = 1
|
|
|
|
groups_changed = true
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Hack in digging times
|
|
|
|
local hardness = ndef._mcl_hardness
|
|
|
|
if not hardness then
|
|
|
|
hardness = 0
|
|
|
|
end
|
|
|
|
-- Handle pickaxey, axey and shovely, and also handy indirectly
|
|
|
|
for _, basegroup in pairs(basegroups) do
|
|
|
|
if (hardness ~= -1 and ndef.groups[basegroup]) then
|
|
|
|
for g=1,#materials do
|
|
|
|
local diggroup = basegroup.."_dig_"..materials[g]
|
|
|
|
local time, validity_factor
|
|
|
|
if g >= ndef.groups[basegroup] then
|
|
|
|
-- Valid tool
|
|
|
|
validity_factor = 1.5
|
|
|
|
else
|
|
|
|
-- Wrong tool (higher digging time)
|
|
|
|
validity_factor = 5
|
|
|
|
end
|
|
|
|
time = (hardness * validity_factor) / material_divisors[g]
|
|
|
|
if time <= 0.05 then
|
|
|
|
time = 1
|
|
|
|
else
|
2017-02-26 18:44:48 +01:00
|
|
|
time = math.ceil(time * 20) / 20
|
2017-02-25 16:19:24 +01:00
|
|
|
end
|
2017-02-26 18:44:48 +01:00
|
|
|
table.insert(mcl_autogroup.digtimes[diggroup], time)
|
|
|
|
newgroups[diggroup] = #mcl_autogroup.digtimes[diggroup]
|
2017-02-25 16:19:24 +01:00
|
|
|
groups_changed = true
|
|
|
|
end
|
|
|
|
if not ndef.groups.handy then
|
|
|
|
local time = hardness * 5
|
|
|
|
if time <= 0.05 then
|
2017-02-26 18:44:48 +01:00
|
|
|
time = 0
|
2017-02-25 16:19:24 +01:00
|
|
|
else
|
2017-02-26 18:44:48 +01:00
|
|
|
time = math.ceil(time * 20) / 20
|
2017-02-25 16:19:24 +01:00
|
|
|
end
|
2017-02-26 18:44:48 +01:00
|
|
|
table.insert(mcl_autogroup.digtimes.handy_dig, time)
|
|
|
|
newgroups.handy_dig = #mcl_autogroup.digtimes.handy_dig
|
|
|
|
groups_changed = true
|
2017-02-25 16:19:24 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if groups_changed then
|
|
|
|
minetest.override_item(nname, {
|
|
|
|
groups = newgroups
|
|
|
|
})
|
|
|
|
end
|
2017-02-10 06:01:20 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
overwrite()
|