Make water protection optional, default true

This can save a `global_step` regisration if neither fire or water
protection are enabled.
This commit is contained in:
stujones11 2017-03-31 21:18:29 +01:00
parent 23e4d5114f
commit 1fdff7adaa
3 changed files with 41 additions and 32 deletions

@ -63,6 +63,9 @@ armor_heal_multiplier = 1
-- eg: armor_radiation_multiplier = 0 will completely disable radiation protection.
armor_radiation_multiplier = 1
-- Enable water protection (periodically restores breath when activated)
armor_water_protect = true
-- Enable fire protection (defaults true if using ethereal mod)
armor_fire_protect = false
@ -97,6 +100,7 @@ See armor.lua, technic_armor and shields mods for more examples.
Default groups:
Elements: armor_head, armor_torso, armor_legs, armor_feet
attributes: armor_heal, armor_fire, armor_water
Physics: physics_jump, physics_speed, physics_gravity
Durability: armor_use

@ -66,6 +66,7 @@ armor.config = {
material_gold = true,
material_mithril = true,
material_crystal = true,
water_protect = true,
fire_protect = minetest.get_modpath("ethereal") ~= nil
}

@ -323,6 +323,7 @@ else
print ("[3d_armor] Fire Nodes disabled")
end
if armor.config.water_protect == true or armor.config.fire_protect == true then
minetest.register_globalstep(function(dtime)
armor.timer = armor.timer + dtime
if armor.timer < armor.config.update_time then
@ -332,15 +333,17 @@ minetest.register_globalstep(function(dtime)
local name = player:get_player_name()
local pos = player:getpos()
local hp = player:get_hp()
if not name or not pos or not hp then
return
end
-- water breathing
if name and armor.def[name].water > 0 then
if player:get_breath() < 10 then
if armor.config.water_protect == true then
if armor.def[name].water > 0 and player:get_breath() < 10 then
player:set_breath(10)
end
end
-- fire protection
if armor.config.fire_protect == true
and name and pos and hp then
if armor.config.fire_protect == true then
pos.y = pos.y + 1.4 -- head level
local node_head = minetest.get_node(pos).name
pos.y = pos.y - 1.2 -- feet level
@ -360,3 +363,4 @@ minetest.register_globalstep(function(dtime)
end
armor.timer = 0
end)
end