1
0
Fork 0

Integrate fire resistance

formspec-v4
Elias 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,37 +93,43 @@ function mcl_damage.finish_reason(mcl_reason)
end
function mcl_damage.from_mt(mt_reason)
if mt_reason._mcl_chached_reason then
return mt_reason._mcl_chached_reason
end
local mcl_reason
if mt_reason._mcl_reason then
return mt_reason._mcl_reason
end
mcl_reason = mt_reason._mcl_reason
else
mcl_reason = {type = "generic"}
local mcl_reason = {type = "generic"}
if mt_reason._mcl_type then
mcl_reason.type = mt_reason._mcl_type
elseif mt_reason.type == "fall" then
mcl_reason.type = "fall"
elseif mt_reason.type == "drown" then
mcl_reason.type = "drown"
elseif mt_reason.type == "punch" then
mcl_damage.from_punch(mcl_reason, mt_reason.object)
elseif mt_reason.type == "node_damage" and mt_reason.node then
if minetest.get_item_group(mt_reason.node, "fire") > 0 then
mcl_reason.type = "in_fire"
if mt_reason._mcl_type then
mcl_reason.type = mt_reason._mcl_type
elseif mt_reason.type == "fall" then
mcl_reason.type = "fall"
elseif mt_reason.type == "drown" then
mcl_reason.type = "drown"
elseif mt_reason.type == "punch" then
mcl_damage.from_punch(mcl_reason, mt_reason.object)
elseif mt_reason.type == "node_damage" and mt_reason.node then
if minetest.get_item_group(mt_reason.node, "fire") > 0 then
mcl_reason.type = "in_fire"
end
if minetest.get_item_group(mt_reason.node, "lava") > 0 then
mcl_reason.type = "lava"
end
end
if minetest.get_item_group(mt_reason.node, "lava") > 0 then
mcl_reason.type = "lava"
end
end
for key, value in pairs(mt_reason) do
if key:find("_mcl_") == 1 then
mcl_reason[key:sub(6, #key)] = value
for key, value in pairs(mt_reason) do
if key:find("_mcl_") == 1 then
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
return 0
else
return hp_change
end
else
return hp_change
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
end
end, true)
end, -50)