Fix crash when digging nodes with fishing rod

Previously the game would crash when digging nodes with a tool which
does not have tool_capabilities in their item definition.
master
Elias Åström 2021-03-21 12:18:24 +01:00
parent 34af6a2cc3
commit b57c94df88
2 changed files with 8 additions and 1 deletions

View File

@ -178,6 +178,10 @@ end
-- Add the groupcaps from a field in "_mcl_diggroups" to the groupcaps of a
-- tool.
local function add_groupcaps(toolname, groupcaps, groupcaps_def, efficiency)
if not groupcaps_def then
return
end
for g, capsdef in pairs(groupcaps_def) do
local mult = capsdef.speed or 1
local uses = capsdef.uses
@ -196,7 +200,6 @@ local function add_groupcaps(toolname, groupcaps, groupcaps_def, efficiency)
groupcaps[g .. "_dig"] = get_groupcap(g, level > 0, mult, efficiency, uses)
end
end
return groupcaps
end
-- Checks if the given node would drop its useful drop if dug by a given tool.

View File

@ -45,6 +45,10 @@ end
-- To make it more efficient it will first check a hash value to determine if
-- the tool needs to be updated.
function mcl_enchanting.update_groupcaps(itemstack)
if not itemstack:get_meta():get("tool_capabilities") then
return
end
local name = itemstack:get_name()
local level = mcl_enchanting.get_enchantment(itemstack, "efficiency")
local groupcaps = get_efficiency_groupcaps(name, level)