1
0
Fork 0

Fix armor being taken even if it cannot be equipped

This commit is contained in:
Lizzy Fleckenstein 2021-04-22 13:52:02 +02:00
parent 222104b3cb
commit f9c2d710e2
1 changed files with 8 additions and 5 deletions

View File

@ -43,22 +43,25 @@ function mcl_armor.equip(itemstack, obj, swap)
return itemstack return itemstack
end end
local element = mcl_armor.elements[def._mcl_armor_element or ""]
local inv = mcl_util.get_inventory(obj, true) local inv = mcl_util.get_inventory(obj, true)
if element and inv then if not inv or inv:get_size("armor") == 0 then
return itemstack
end
local element = mcl_armor.elements[def._mcl_armor_element or ""]
if element then
local old_stack = inv:get_stack("armor", element.index) local old_stack = inv:get_stack("armor", element.index)
local new_stack local new_stack
if swap then if swap then
new_stack = itemstack new_stack = itemstack
itemstack = old_stack itemstack = old_stack
else
new_stack = itemstack:take_item()
end end
if swap or old_stack:is_empty() then if swap or old_stack:is_empty() then
inv:set_stack("armor", element.index, new_stack) inv:set_stack("armor", element.index, new_stack or itemstack:take_item())
mcl_armor.on_equip(new_stack, obj) mcl_armor.on_equip(new_stack, obj)
end end
end end