Code cleanup

This commit is contained in:
Brandon 2020-07-25 20:59:26 -04:00
parent d22805cecd
commit 9dce5581be

View File

@ -17,18 +17,12 @@ minetest.register_globalstep(function(dtime)
-- Check for invisible players -- Check for invisible players
for player, vals in pairs(is_invisible) do for player, vals in pairs(is_invisible) do
if is_invisible[player] and player:get_properties() then is_invisible[player].timer = is_invisible[player].timer + dtime
is_invisible[player].timer = is_invisible[player].timer + dtime if player:get_pos() then mcl_potions._add_spawner(player, "#B0B0B0") end
if player:get_pos() then mcl_potions._add_spawner(player, "#B0B0B0") end if is_invisible[player].timer >= is_invisible[player].dur then
mcl_potions.make_invisible(player, false)
if is_invisible[player].timer >= is_invisible[player].dur then
mcl_potions.make_invisible(player, false)
is_invisible[player] = nil
end
elseif not player:get_properties() then
is_invisible[player] = nil is_invisible[player] = nil
end end
@ -37,35 +31,29 @@ minetest.register_globalstep(function(dtime)
-- Check for poisoned players -- Check for poisoned players
for player, vals in pairs(is_poisoned) do for player, vals in pairs(is_poisoned) do
if is_poisoned[player] and player:get_properties() then is_player = player:is_player()
entity = player:get_luaentity()
is_player = player:is_player() is_poisoned[player].timer = is_poisoned[player].timer + dtime
entity = player:get_luaentity() is_poisoned[player].hit_timer = (is_poisoned[player].hit_timer or 0) + dtime
is_poisoned[player].timer = is_poisoned[player].timer + dtime if player:get_pos() then mcl_potions._add_spawner(player, "#225533") end
is_poisoned[player].hit_timer = (is_poisoned[player].hit_timer or 0) + dtime
if player:get_pos() then mcl_potions._add_spawner(player, "#225533") end if is_poisoned[player].hit_timer >= is_poisoned[player].step then
if is_poisoned[player].hit_timer >= is_poisoned[player].step then if entity and entity._cmi_is_mob then
entity.health = math.max(entity.health - 1, 1)
if entity and entity._cmi_is_mob then is_poisoned[player].hit_timer = 0
entity.health = math.max(entity.health - 1, 1) elseif is_player then
is_poisoned[player].hit_timer = 0 player:set_hp( math.max(player:get_hp() - 1, 1), { type = "punch", other = "poison"})
elseif is_player then is_poisoned[player].hit_timer = 0
player:set_hp( math.max(player:get_hp() - 1, 1), { type = "punch", other = "poison"}) else -- if not player or mob then remove
is_poisoned[player].hit_timer = 0
else -- if not player or mob then remove
is_poisoned[player] = nil
end
end
if is_poisoned[player].timer >= is_poisoned[player].dur then
is_poisoned[player] = nil is_poisoned[player] = nil
end end
elseif not player:get_properties() then end
if is_poisoned[player].timer >= is_poisoned[player].dur then
is_poisoned[player] = nil is_poisoned[player] = nil
end end
@ -74,35 +62,29 @@ minetest.register_globalstep(function(dtime)
-- Check for regnerating players -- Check for regnerating players
for player, vals in pairs(is_regenerating) do for player, vals in pairs(is_regenerating) do
if is_regenerating[player] then is_player = player:is_player()
entity = player:get_luaentity()
is_player = player:is_player() is_regenerating[player].timer = is_regenerating[player].timer + dtime
entity = player:get_luaentity() is_regenerating[player].heal_timer = (is_regenerating[player].heal_timer or 0) + dtime
is_regenerating[player].timer = is_regenerating[player].timer + dtime if player:get_pos() then mcl_potions._add_spawner(player, "#A52BB2") end
is_regenerating[player].heal_timer = (is_regenerating[player].heal_timer or 0) + dtime
if player:get_pos() then mcl_potions._add_spawner(player, "#A52BB2") end if is_regenerating[player].heal_timer >= is_regenerating[player].step then
if is_regenerating[player].heal_timer >= is_regenerating[player].step then if is_player then
player:set_hp(math.min(player:get_properties().hp_max or 20, player:get_hp() + 1), { type = "set_hp", other = "regeneration" })
if is_player then is_regenerating[player].heal_timer = 0
player:set_hp(math.min(player:get_properties().hp_max or 20, player:get_hp() + 1), { type = "set_hp", other = "regeneration" }) elseif entity and entity._cmi_is_mob then
is_regenerating[player].heal_timer = 0 entity.health = math.min(entity.hp_max, entity.health + 1)
elseif entity and entity._cmi_is_mob then is_regenerating[player].heal_timer = 0
entity.health = math.min(entity.hp_max, entity.health + 1) else -- stop regenerating if not a player or mob
is_regenerating[player].heal_timer = 0
else -- stop regenerating if not a player or mob
is_regenerating[player] = nil
end
end
if is_regenerating[player].timer >= is_regenerating[player].dur then
is_regenerating[player] = nil is_regenerating[player] = nil
end end
elseif not player:get_properties() then end
if is_regenerating[player].timer >= is_regenerating[player].dur then
is_regenerating[player] = nil is_regenerating[player] = nil
end end
@ -111,7 +93,7 @@ minetest.register_globalstep(function(dtime)
-- Check for water breathing players -- Check for water breathing players
for player, vals in pairs(is_water_breathing) do for player, vals in pairs(is_water_breathing) do
if is_water_breathing[player] and player:is_player() then if player:is_player() then
is_water_breathing[player].timer = is_water_breathing[player].timer + dtime is_water_breathing[player].timer = is_water_breathing[player].timer + dtime
@ -125,7 +107,7 @@ minetest.register_globalstep(function(dtime)
is_water_breathing[player] = nil is_water_breathing[player] = nil
end end
elseif not player:is_player() then else
is_water_breathing[player] = nil is_water_breathing[player] = nil
end end
@ -134,9 +116,7 @@ minetest.register_globalstep(function(dtime)
-- Check for leaping players -- Check for leaping players
for player, vals in pairs(is_leaping) do for player, vals in pairs(is_leaping) do
if is_leaping[player] and player:get_properties() then if player:is_player() then
player = player or player:get_luaentity()
is_leaping[player].timer = is_leaping[player].timer + dtime is_leaping[player].timer = is_leaping[player].timer + dtime
@ -147,7 +127,7 @@ minetest.register_globalstep(function(dtime)
is_leaping[player] = nil is_leaping[player] = nil
end end
elseif not player:get_properties() then else
is_leaping[player] = nil is_leaping[player] = nil
end end
@ -156,9 +136,7 @@ minetest.register_globalstep(function(dtime)
-- Check for swift players -- Check for swift players
for player, vals in pairs(is_swift) do for player, vals in pairs(is_swift) do
if is_swift[player] and player:get_properties() then if player:is_player() then
player = player or player:get_luaentity()
is_swift[player].timer = is_swift[player].timer + dtime is_swift[player].timer = is_swift[player].timer + dtime
@ -169,7 +147,7 @@ minetest.register_globalstep(function(dtime)
is_swift[player] = nil is_swift[player] = nil
end end
elseif not player:get_properties() then else
is_swift[player] = nil is_swift[player] = nil
end end
@ -178,9 +156,7 @@ minetest.register_globalstep(function(dtime)
-- Check for Night Vision equipped players -- Check for Night Vision equipped players
for player, vals in pairs(is_cat) do for player, vals in pairs(is_cat) do
if is_cat[player] and player:get_properties() then if player:is_player() then
player = player or player:get_luaentity()
is_cat[player].timer = is_cat[player].timer + dtime is_cat[player].timer = is_cat[player].timer + dtime
@ -194,7 +170,7 @@ minetest.register_globalstep(function(dtime)
is_cat[player] = nil is_cat[player] = nil
end end
elseif not player:get_properties() then else
is_cat[player] = nil is_cat[player] = nil
end end
@ -203,7 +179,7 @@ minetest.register_globalstep(function(dtime)
-- Check for Fire Proof players -- Check for Fire Proof players
for player, vals in pairs(is_fire_proof) do for player, vals in pairs(is_fire_proof) do
if is_fire_proof[player] and player:get_properties() then if player:is_player() then
player = player or player:get_luaentity() player = player or player:get_luaentity()
@ -215,7 +191,7 @@ minetest.register_globalstep(function(dtime)
is_fire_proof[player] = nil is_fire_proof[player] = nil
end end
elseif not player:get_properties() then else
is_fire_proof[player] = nil is_fire_proof[player] = nil
end end
@ -224,9 +200,7 @@ minetest.register_globalstep(function(dtime)
-- Check for Weak players -- Check for Weak players
for player, vals in pairs(is_weak) do for player, vals in pairs(is_weak) do
if is_weak[player] and player:get_properties() then if player:is_player() then
player = player or player:get_luaentity()
is_weak[player].timer = is_weak[player].timer + dtime is_weak[player].timer = is_weak[player].timer + dtime
@ -236,7 +210,7 @@ minetest.register_globalstep(function(dtime)
is_weak[player] = nil is_weak[player] = nil
end end
elseif not player:get_properties() then else
is_weak[player] = nil is_weak[player] = nil
end end
@ -245,9 +219,7 @@ minetest.register_globalstep(function(dtime)
-- Check for Strong players -- Check for Strong players
for player, vals in pairs(is_strong) do for player, vals in pairs(is_strong) do
if is_strong[player] and player:get_properties() then if player:is_player() then
player = player or player:get_luaentity()
is_strong[player].timer = is_strong[player].timer + dtime is_strong[player].timer = is_strong[player].timer + dtime
@ -257,7 +229,7 @@ minetest.register_globalstep(function(dtime)
is_strong[player] = nil is_strong[player] = nil
end end
elseif not player:get_properties() then else
is_strong[player] = nil is_strong[player] = nil
end end
@ -301,8 +273,6 @@ end, true)
function mcl_potions._reset_player_effects(player) function mcl_potions._reset_player_effects(player)
player = player or player:get_luaentity()
if is_invisible[player] then if is_invisible[player] then
mcl_potions.make_invisible(player, false) mcl_potions.make_invisible(player, false)
is_invisible[player] = nil is_invisible[player] = nil