forked from VoxeLibre/VoxeLibre
Integrate fire resistance
This commit is contained in:
parent
fede04eaa6
commit
edc89898bb
|
@ -5,7 +5,7 @@ mcl_damage = {
|
||||||
types = {
|
types = {
|
||||||
in_fire = {is_fire = true},
|
in_fire = {is_fire = true},
|
||||||
lightning_bolt = {is_lightning = true},
|
lightning_bolt = {is_lightning = true},
|
||||||
on_fire = {is_fire = true},
|
on_fire = {is_fire = true, bypasses_armor = true},
|
||||||
lava = {is_fire = true},
|
lava = {is_fire = true},
|
||||||
hot_floor = {is_fire = true},
|
hot_floor = {is_fire = true},
|
||||||
in_wall = {bypasses_armor = true},
|
in_wall = {bypasses_armor = true},
|
||||||
|
@ -93,37 +93,43 @@ function mcl_damage.finish_reason(mcl_reason)
|
||||||
end
|
end
|
||||||
|
|
||||||
function mcl_damage.from_mt(mt_reason)
|
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
|
if mt_reason._mcl_reason then
|
||||||
return mt_reason._mcl_reason
|
mcl_reason = mt_reason._mcl_reason
|
||||||
end
|
else
|
||||||
|
mcl_reason = {type = "generic"}
|
||||||
|
|
||||||
local mcl_reason = {type = "generic"}
|
if mt_reason._mcl_type then
|
||||||
|
mcl_reason.type = mt_reason._mcl_type
|
||||||
if mt_reason._mcl_type then
|
elseif mt_reason.type == "fall" then
|
||||||
mcl_reason.type = mt_reason._mcl_type
|
mcl_reason.type = "fall"
|
||||||
elseif mt_reason.type == "fall" then
|
elseif mt_reason.type == "drown" then
|
||||||
mcl_reason.type = "fall"
|
mcl_reason.type = "drown"
|
||||||
elseif mt_reason.type == "drown" then
|
elseif mt_reason.type == "punch" then
|
||||||
mcl_reason.type = "drown"
|
mcl_damage.from_punch(mcl_reason, mt_reason.object)
|
||||||
elseif mt_reason.type == "punch" then
|
elseif mt_reason.type == "node_damage" and mt_reason.node then
|
||||||
mcl_damage.from_punch(mcl_reason, mt_reason.object)
|
if minetest.get_item_group(mt_reason.node, "fire") > 0 then
|
||||||
elseif mt_reason.type == "node_damage" and mt_reason.node then
|
mcl_reason.type = "in_fire"
|
||||||
if minetest.get_item_group(mt_reason.node, "fire") > 0 then
|
end
|
||||||
mcl_reason.type = "in_fire"
|
if minetest.get_item_group(mt_reason.node, "lava") > 0 then
|
||||||
|
mcl_reason.type = "lava"
|
||||||
|
end
|
||||||
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
|
for key, value in pairs(mt_reason) do
|
||||||
if key:find("_mcl_") == 1 then
|
if key:find("_mcl_") == 1 then
|
||||||
mcl_reason[key:sub(6, #key)] = value
|
mcl_reason[key:sub(6, #key)] = value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
mcl_damage.finish_reason(mcl_reason)
|
mcl_damage.finish_reason(mcl_reason)
|
||||||
mt_reason._mcl_reason = mcl_reason
|
mt_reason._mcl_cached_reason = mcl_reason
|
||||||
|
|
||||||
return mcl_reason
|
return mcl_reason
|
||||||
end
|
end
|
||||||
|
|
|
@ -137,22 +137,10 @@ function mcl_burning.tick(obj, dtime, storage)
|
||||||
if storage.fire_damage_timer >= 1 then
|
if storage.fire_damage_timer >= 1 then
|
||||||
storage.fire_damage_timer = 0
|
storage.fire_damage_timer = 0
|
||||||
|
|
||||||
local hp = mcl_util.get_hp(obj)
|
local luaentity = obj:get_luaentity()
|
||||||
|
|
||||||
if hp > 0 then
|
if not luaentity or not luaentity.fire_damage_resistant then
|
||||||
local do_damage = true
|
mcl_util.deal_damage(obj, 1, {type = "on_fire"})
|
||||||
|
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -344,37 +344,12 @@ minetest.register_globalstep(function(dtime)
|
||||||
|
|
||||||
end)
|
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
|
-- Prevent damage to player with Fire Resistance enabled
|
||||||
minetest.register_on_player_hpchange(function(player, hp_change, reason)
|
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
|
||||||
if EF.fire_proof[player] and hp_change < 0 then
|
return 0
|
||||||
-- 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
|
|
||||||
end
|
end
|
||||||
|
end, -50)
|
||||||
end, true)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue