From 939229cb213de3e031cabaebc43e7bcfd6c4a88e Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Sun, 25 Apr 2021 13:29:22 +0200 Subject: [PATCH] Fix on_equip crash --- mods/ITEMS/mcl_armor/api.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/mods/ITEMS/mcl_armor/api.lua b/mods/ITEMS/mcl_armor/api.lua index d56e3188de..4d66868076 100644 --- a/mods/ITEMS/mcl_armor/api.lua +++ b/mods/ITEMS/mcl_armor/api.lua @@ -53,15 +53,18 @@ function mcl_armor.equip(itemstack, obj, swap) if element then local old_stack = inv:get_stack("armor", element.index) - local new_stack - - if swap then - new_stack = itemstack - itemstack = old_stack - end if swap or old_stack:is_empty() then - inv:set_stack("armor", element.index, new_stack or itemstack:take_item()) + local new_stack + + if swap then + new_stack = itemstack + itemstack = old_stack + else + new_stack = itemstack:take_item() + end + + inv:set_stack("armor", element.index, new_stack) mcl_armor.on_equip(new_stack, obj) end end