0
0
Fork 0

Merge pull request 'Fix bug when applying another enchantment to a renamed item' (#1989) from fix-1922 into master

Reviewed-on: MineClone2/MineClone2#1989
This commit is contained in:
cora 2022-02-12 20:37:48 +00:00
commit f803a25aea
3 changed files with 11 additions and 11 deletions

View File

@ -97,8 +97,9 @@ mcl_enchanting.enchantments.efficiency = {
weight = 10, weight = 10,
description = S("Increases mining speed."), description = S("Increases mining speed."),
curse = false, curse = false,
on_enchant = function(itemstack, level) on_enchant = function()
mcl_enchanting.update_groupcaps(itemstack) -- Updating digging speed is handled by update_groupcaps which
-- is called from load_enchantments.
end, end,
requires_tool = false, requires_tool = false,
treasure = false, treasure = false,
@ -671,8 +672,8 @@ mcl_enchanting.enchantments.unbreaking = {
tool_capabilities.punch_attack_uses = tool_capabilities.punch_attack_uses * (1 + level) tool_capabilities.punch_attack_uses = tool_capabilities.punch_attack_uses * (1 + level)
itemstack:get_meta():set_tool_capabilities(tool_capabilities) itemstack:get_meta():set_tool_capabilities(tool_capabilities)
-- Unbreaking for groupcaps is handled in this function. -- Updating digging durability is handled by update_groupcaps
mcl_enchanting.update_groupcaps(itemstack) -- which is called from load_enchantments.
end, end,
requires_tool = true, requires_tool = true,
treasure = false, treasure = false,

View File

@ -14,10 +14,11 @@ end
function mcl_enchanting.unload_enchantments(itemstack) function mcl_enchanting.unload_enchantments(itemstack)
local itemdef = itemstack:get_definition() local itemdef = itemstack:get_definition()
if itemdef.tool_capabilities then
itemstack:get_meta():set_tool_capabilities(nil)
end
local meta = itemstack:get_meta() 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 if meta:get_string("name") == "" then
meta:set_string("description", "") meta:set_string("description", "")
meta:set_string("groupcaps_hash", "") meta:set_string("groupcaps_hash", "")
@ -33,6 +34,7 @@ function mcl_enchanting.load_enchantments(itemstack, enchantments)
enchantment_def.on_enchant(itemstack, level) enchantment_def.on_enchant(itemstack, level)
end end
end end
mcl_enchanting.update_groupcaps(itemstack)
end end
tt.reload_itemstack_description(itemstack) tt.reload_itemstack_description(itemstack)
end end

View File

@ -2,10 +2,7 @@ local groupcaps_cache = {}
-- Compute a hash value. -- Compute a hash value.
function compute_hash(value) function compute_hash(value)
-- minetest.get_password_hash is quite fast, even if it uses a return string.sub(minetest.sha1(minetest.serialize(value)), 1, 8)
-- 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)
end end
-- Get the groupcaps and hash for an enchanted tool. If this function is called -- Get the groupcaps and hash for an enchanted tool. If this function is called