Fix get_possible_enchantments to not return incompatible enchantments, even if treasure enchantments are allowed

This commit is contained in:
Lizzy Fleckenstein 2021-12-07 15:47:23 +01:00
parent 92686e5412
commit 261faafb7c
Signed by: LizzyFleckenstein03
GPG Key ID: 06927A5199D6C9B2
1 changed files with 4 additions and 4 deletions

View File

@ -123,7 +123,7 @@ function mcl_enchanting.can_enchant(itemstack, enchantment, level)
if itemname == "" then if itemname == "" then
return false, "item missing" return false, "item missing"
end end
local supported, primary = mcl_enchanting.item_supports_enchantment(itemstack:get_name(), enchantment) local supported, primary = mcl_enchanting.item_supports_enchantment(itemname, enchantment)
if not supported then if not supported then
return false, "item not supported" return false, "item not supported"
end end
@ -298,8 +298,8 @@ end
function mcl_enchanting.get_possible_enchantments(itemstack, enchantment_level, treasure) function mcl_enchanting.get_possible_enchantments(itemstack, enchantment_level, treasure)
local possible_enchantments, weights, accum_weight = {}, {}, 0 local possible_enchantments, weights, accum_weight = {}, {}, 0
for enchantment, enchantment_def in pairs(mcl_enchanting.enchantments) do for enchantment, enchantment_def in pairs(mcl_enchanting.enchantments) do
local _, _, _, primary = mcl_enchanting.can_enchant(itemstack, enchantment, 1) local can_enchant, _, _, primary = mcl_enchanting.can_enchant(itemstack, enchantment, 1)
if primary or treasure then if can_enchant and (primary or treasure) then
table.insert(possible_enchantments, enchantment) table.insert(possible_enchantments, enchantment)
accum_weight = accum_weight + enchantment_def.weight accum_weight = accum_weight + enchantment_def.weight
weights[enchantment] = accum_weight weights[enchantment] = accum_weight