From 5d9bb7cacd485f0cd9335758dacdd6196971e8bf Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Wed, 14 Apr 2021 19:06:11 +0200 Subject: [PATCH] Fix armor not actually protecting lol --- mods/CORE/mcl_damage/init.lua | 5 +++-- mods/ITEMS/mcl_armor/damage.lua | 14 +++++--------- mods/ITEMS/mcl_armor/player.lua | 4 +++- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/mods/CORE/mcl_damage/init.lua b/mods/CORE/mcl_damage/init.lua index 927ce6771..83c6d83af 100644 --- a/mods/CORE/mcl_damage/init.lua +++ b/mods/CORE/mcl_damage/init.lua @@ -39,7 +39,7 @@ function minetest.register_on_player_hpchange(func, modifier) end function mcl_damage.register_modifier(func, priority) - table.insert(mcl_damage, {func = func, priority = priority or 0}) + table.insert(mcl_damage.modifiers, {func = func, priority = priority or 0}) end function mcl_damage.get_mcl_damage_reason(mt_reason) @@ -86,8 +86,9 @@ function mcl_damage.get_mcl_damage_reason(mt_reason) end mcl_reason.source = mcl_reason.source or mcl_reason.direct - mcl_reason.flags = mcl_damage.types[mcl_reason.type] + + return mcl_reason end function mcl_damage.register_type(name, def) diff --git a/mods/ITEMS/mcl_armor/damage.lua b/mods/ITEMS/mcl_armor/damage.lua index 9dce824ea..35ae0eb30 100644 --- a/mods/ITEMS/mcl_armor/damage.lua +++ b/mods/ITEMS/mcl_armor/damage.lua @@ -24,9 +24,9 @@ function mcl_armor.damage_modifier(obj, hp_change, reason) if inv then for name, element in pairs(mcl_armor.elements) do - local itemstack = inventory:get_stack("armor", element.index) - if not stack:is_empty() then - local itemname = stack:get_name() + local itemstack = inv:get_stack("armor", element.index) + if not itemstack:is_empty() then + local itemname = itemstack:get_name() local enchantments = mcl_enchanting.get_enchantments(itemstack) if not flags.bypasses_armor then @@ -34,7 +34,7 @@ function mcl_armor.damage_modifier(obj, hp_change, reason) toughness = toughness + minetest.get_item_group(itemname, "mcl_armor_toughness") mcl_util.use_item_durability(itemstack, uses) - inventory:set_stack("armor", element.index, itemstack) + inv:set_stack("armor", element.index, itemstack) end if not flags.bypasses_magic then @@ -90,14 +90,10 @@ function mcl_armor.damage_modifier(obj, hp_change, reason) local thorns_item = thorns_pieces[math.random(#thorns_pieces)] mcl_util.use_item_durability(thorns_item.itemstack, 2) - inventory:set_stack("armor", thorns_item.index, thorns_item.itemstack) + inv:set_stack("armor", thorns_item.index, thorns_item.itemstack) end mcl_armor.update(obj) return -math.floor(damage + 0.5) end - -mcl_damage.register_modifier(function(player, hp_change, _, reason) - return mcl_armor.damage_modifier(player, hp_change, reason) -end) diff --git a/mods/ITEMS/mcl_armor/player.lua b/mods/ITEMS/mcl_armor/player.lua index a00429040..776d22dd6 100644 --- a/mods/ITEMS/mcl_armor/player.lua +++ b/mods/ITEMS/mcl_armor/player.lua @@ -140,4 +140,6 @@ minetest.register_on_joinplayer(function(player) end) end) - +mcl_damage.register_modifier(function(player, hp_change, _, reason) + return mcl_armor.damage_modifier(player, hp_change, reason) +end)