diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index df6105d5..fa3bc3ed 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -770,6 +770,11 @@ mcl_enchanting.enchantments.unbreaking = { description = S("Increases item durability."), curse = false, on_enchant = function(itemstack, level) + local name = itemstack:get_name() + if not minetest.registered_tools[name].tool_capabilities then + return + end + local tool_capabilities = itemstack:get_tool_capabilities() tool_capabilities.punch_attack_uses = tool_capabilities.punch_attack_uses * (1 + level) itemstack:get_meta():set_tool_capabilities(tool_capabilities) diff --git a/mods/ITEMS/mcl_enchanting/engine.lua b/mods/ITEMS/mcl_enchanting/engine.lua index e185164f..1bd8cc5e 100644 --- a/mods/ITEMS/mcl_enchanting/engine.lua +++ b/mods/ITEMS/mcl_enchanting/engine.lua @@ -12,7 +12,7 @@ end function mcl_enchanting.unload_enchantments(itemstack) local itemdef = itemstack:get_definition() if itemdef.tool_capabilities then - itemstack:get_meta():set_tool_capabilities(itemdef.tool_capabilities) + itemstack:get_meta():set_tool_capabilities(nil) end local meta = itemstack:get_meta() if meta:get_string("name") == "" then diff --git a/mods/ITEMS/mcl_enchanting/groupcaps.lua b/mods/ITEMS/mcl_enchanting/groupcaps.lua index 1a4f8fd1..0bc1b8e2 100644 --- a/mods/ITEMS/mcl_enchanting/groupcaps.lua +++ b/mods/ITEMS/mcl_enchanting/groupcaps.lua @@ -45,12 +45,17 @@ 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 + local name = itemstack:get_name() + if not minetest.registered_tools[name].tool_capabilities then return end - local name = itemstack:get_name() local efficiency = mcl_enchanting.get_enchantment(itemstack, "efficiency") + local unbreaking = mcl_enchanting.get_enchantment(itemstack, "unbreaking") + if unbreaking == 0 and efficiency == 0 then + return + end + local groupcaps = get_efficiency_groupcaps(name, efficiency) local hash = itemstack:get_meta():get_string("groupcaps_hash") @@ -60,7 +65,6 @@ function mcl_enchanting.update_groupcaps(itemstack) -- 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