Integrate fire resistance

This commit is contained in:
Lizzy Fleckenstein 2021-04-25 20:51:13 +02:00
parent fede04eaa6
commit edc89898bb
3 changed files with 37 additions and 68 deletions

View File

@ -5,7 +5,7 @@ mcl_damage = {
types = {
in_fire = {is_fire = true},
lightning_bolt = {is_lightning = true},
on_fire = {is_fire = true},
on_fire = {is_fire = true, bypasses_armor = true},
lava = {is_fire = true},
hot_floor = {is_fire = true},
in_wall = {bypasses_armor = true},
@ -93,11 +93,16 @@ function mcl_damage.finish_reason(mcl_reason)
end
function mcl_damage.from_mt(mt_reason)
if mt_reason._mcl_reason then
return mt_reason._mcl_reason
if mt_reason._mcl_chached_reason then
return mt_reason._mcl_chached_reason
end
local mcl_reason = {type = "generic"}
local mcl_reason
if mt_reason._mcl_reason then
mcl_reason = mt_reason._mcl_reason
else
mcl_reason = {type = "generic"}
if mt_reason._mcl_type then
mcl_reason.type = mt_reason._mcl_type
@ -121,9 +126,10 @@ function mcl_damage.from_mt(mt_reason)
mcl_reason[key:sub(6, #key)] = value
end
end
end
mcl_damage.finish_reason(mcl_reason)
mt_reason._mcl_reason = mcl_reason
mt_reason._mcl_cached_reason = mcl_reason
return mcl_reason
end

View File

@ -137,22 +137,10 @@ function mcl_burning.tick(obj, dtime, storage)
if storage.fire_damage_timer >= 1 then
storage.fire_damage_timer = 0
local hp = mcl_util.get_hp(obj)
local luaentity = obj:get_luaentity()
if hp > 0 then
local do_damage = true
if obj:is_player() then
if mcl_potions.player_has_effect(obj, "fire_proof") then
do_damage = false
end
elseif obj:get_luaentity().fire_damage_resistant then
do_damage = false
end
if do_damage then
mcl_util.deal_damage(obj, 1, {reason = "on_fire"})
end
if not luaentity or not luaentity.fire_damage_resistant then
mcl_util.deal_damage(obj, 1, {type = "on_fire"})
end
end
end

View File

@ -344,37 +344,12 @@ minetest.register_globalstep(function(dtime)
end)
local is_fire_node = { ["mcl_core:lava_flowing"]=true,
["mcl_core:lava_source"]=true,
["mcl_fire:eternal_fire"]=true,
["mcl_fire:fire"]=true,
["mcl_nether:magma"]=true,
["mcl_nether:nether_lava_source"]=true,
["mcl_nether:nether_lava_flowing"]=true,
["mcl_nether:nether_lava_source"]=true
}
-- Prevent damage to player with Fire Resistance enabled
minetest.register_on_player_hpchange(function(player, hp_change, reason)
if EF.fire_proof[player] and hp_change < 0 then
-- This is a bit forced, but it assumes damage is taken by fire and avoids it
-- also assumes any change in hp happens between calls to this function
-- it's worth noting that you don't take damage from players in this case...
local player_info = mcl_playerinfo[player:get_player_name()]
if is_fire_node[player_info.node_head] or is_fire_node[player_info.node_feet] or is_fire_node[player_info.node_stand] then
mcl_damage.register_modifier(function(obj, damage, reason)
if EF.fire_proof[obj] and not reason.flags.bypasses_magic and reason.flags.is_fire then
return 0
else
return hp_change
end
else
return hp_change
end
end, true)
end, -50)