From d898b02c8bfe192f1647533094a4dfcc85b756d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Sat, 12 Feb 2022 19:29:17 +0100 Subject: [PATCH 1/3] Fix #1922 --- mods/ITEMS/mcl_enchanting/engine.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/engine.lua b/mods/ITEMS/mcl_enchanting/engine.lua index 97a176b97..095145775 100644 --- a/mods/ITEMS/mcl_enchanting/engine.lua +++ b/mods/ITEMS/mcl_enchanting/engine.lua @@ -14,10 +14,11 @@ end function mcl_enchanting.unload_enchantments(itemstack) local itemdef = itemstack:get_definition() - if itemdef.tool_capabilities then - itemstack:get_meta():set_tool_capabilities(nil) - end local meta = itemstack:get_meta() + if itemdef.tool_capabilities then + meta:set_tool_capabilities(nil) + meta:set_string("groupcaps_hash", "") + end if meta:get_string("name") == "" then meta:set_string("description", "") meta:set_string("groupcaps_hash", "") From a6c5c8a72a569bd3c04080bdd159e8c20e315890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Sat, 12 Feb 2022 19:41:22 +0100 Subject: [PATCH 2/3] Call update_groupcaps from load_enchantments This avoids the need to call the function from on_enchant for unbreaking and efficiency. --- mods/ITEMS/mcl_enchanting/enchantments.lua | 9 +++++---- mods/ITEMS/mcl_enchanting/engine.lua | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index e876baf31..564d4b0d8 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -97,8 +97,9 @@ mcl_enchanting.enchantments.efficiency = { weight = 10, description = S("Increases mining speed."), curse = false, - on_enchant = function(itemstack, level) - mcl_enchanting.update_groupcaps(itemstack) + on_enchant = function() + -- Updating digging speed is handled by update_groupcaps which + -- is called from load_enchantments. end, requires_tool = false, treasure = false, @@ -671,8 +672,8 @@ mcl_enchanting.enchantments.unbreaking = { 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) + -- Updating digging durability is handled by update_groupcaps + -- which is called from load_enchantments. end, requires_tool = true, treasure = false, diff --git a/mods/ITEMS/mcl_enchanting/engine.lua b/mods/ITEMS/mcl_enchanting/engine.lua index 095145775..e47cf0650 100644 --- a/mods/ITEMS/mcl_enchanting/engine.lua +++ b/mods/ITEMS/mcl_enchanting/engine.lua @@ -34,6 +34,7 @@ function mcl_enchanting.load_enchantments(itemstack, enchantments) enchantment_def.on_enchant(itemstack, level) end end + mcl_enchanting.update_groupcaps(itemstack) end tt.reload_itemstack_description(itemstack) end From 4ca89cfcaee19fc2b816efc966d01827b26dc54b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Sat, 12 Feb 2022 20:08:03 +0100 Subject: [PATCH 3/3] Update groupcaps_hash function to minetest.sha1 --- mods/ITEMS/mcl_enchanting/groupcaps.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/groupcaps.lua b/mods/ITEMS/mcl_enchanting/groupcaps.lua index a445b73f2..ec8d11d21 100644 --- a/mods/ITEMS/mcl_enchanting/groupcaps.lua +++ b/mods/ITEMS/mcl_enchanting/groupcaps.lua @@ -2,10 +2,7 @@ local groupcaps_cache = {} -- Compute a hash value. function compute_hash(value) - -- minetest.get_password_hash is quite fast, even if it uses a - -- cryptographic hashing function (SHA-1). It is written in C++ and it - -- is probably hard to write a faster hashing function in Lua. - return string.sub(minetest.get_password_hash("ryvnf", minetest.serialize(value)), 1, 8) + return string.sub(minetest.sha1(minetest.serialize(value)), 1, 8) end -- Get the groupcaps and hash for an enchanted tool. If this function is called