diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index ca936c3192..df6105d52d 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -771,11 +771,11 @@ mcl_enchanting.enchantments.unbreaking = { curse = false, on_enchant = function(itemstack, level) local tool_capabilities = itemstack:get_tool_capabilities() - for group, capability in pairs(tool_capabilities.groupcaps) do - capability.uses = capability.uses * (1 + level) - end tool_capabilities.punch_attack_uses = tool_capabilities.punch_attack_uses * (1 + level) itemstack:get_meta():set_tool_capabilities(tool_capabilities) + + -- Unbreaking for groupcaps is handled in this function. + mcl_enchanting.update_groupcaps(itemstack) end, requires_tool = true, treasure = false, diff --git a/mods/ITEMS/mcl_enchanting/engine.lua b/mods/ITEMS/mcl_enchanting/engine.lua index ea69d1868b..30e4a9a863 100644 --- a/mods/ITEMS/mcl_enchanting/engine.lua +++ b/mods/ITEMS/mcl_enchanting/engine.lua @@ -17,6 +17,7 @@ function mcl_enchanting.unload_enchantments(itemstack) local meta = itemstack:get_meta() if meta:get_string("name") == "" then meta:set_string("description", "") + meta:set_string("groupcaps_hash", "") end end diff --git a/mods/ITEMS/mcl_enchanting/groupcaps.lua b/mods/ITEMS/mcl_enchanting/groupcaps.lua index 3750295477..1a4f8fd141 100644 --- a/mods/ITEMS/mcl_enchanting/groupcaps.lua +++ b/mods/ITEMS/mcl_enchanting/groupcaps.lua @@ -50,13 +50,21 @@ function mcl_enchanting.update_groupcaps(itemstack) end local name = itemstack:get_name() - local level = mcl_enchanting.get_enchantment(itemstack, "efficiency") - local groupcaps = get_efficiency_groupcaps(name, level) + local efficiency = mcl_enchanting.get_enchantment(itemstack, "efficiency") + local groupcaps = get_efficiency_groupcaps(name, efficiency) local hash = itemstack:get_meta():get_string("groupcaps_hash") if not hash or hash ~= groupcaps.hash then local tool_capabilities = itemstack:get_tool_capabilities() tool_capabilities.groupcaps = groupcaps.values + + -- Increase the number of uses depending on the unbreaking level + -- of the tool. + local unbreaking = mcl_enchanting.get_enchantment(itemstack, "unbreaking") + for group, capability in pairs(tool_capabilities.groupcaps) do + capability.uses = capability.uses * (1 + unbreaking) + end + itemstack:get_meta():set_tool_capabilities(tool_capabilities) itemstack:get_meta():set_string("groupcaps_hash", groupcaps.hash) end