Put in checks to prevent repeatedly applying the same FOV modifier.

Added short circuit to remove_modifier if the modifier is not currently applied.
This commit is contained in:
Michieal 2023-12-03 09:03:01 -05:00 committed by the-real-herowl
parent 36f661743e
commit 4f3f59f4bc
1 changed files with 5 additions and 0 deletions

View File

@ -74,6 +74,9 @@ function mcl_fovapi.apply_modifier(player, modifier_name)
if mcl_fovapi.registered_modifiers[modifier_name] == nil then if mcl_fovapi.registered_modifiers[modifier_name] == nil then
return return
end end
if mcl_fovapi.applied_modifiers[player][modifier_name] and mcl_fovapi.applied_modifiers[player][modifier_name] == true then
return
end
local modifier = mcl_fovapi.registered_modifiers[modifier_name] local modifier = mcl_fovapi.registered_modifiers[modifier_name]
if modifier.on_start ~= nil then if modifier.on_start ~= nil then
@ -110,6 +113,8 @@ function mcl_fovapi.remove_modifier(player, modifier_name)
return return
end end
if mcl_fovapi.applied_modifiers[player][modifier_name] == nil then return end
if DEBUG then if DEBUG then
local name = player:get_player_name() local name = player:get_player_name()
minetest.log("FOV::Player: " .. name .. " modifier: " .. modifier_name .. "removed.") minetest.log("FOV::Player: " .. name .. " modifier: " .. modifier_name .. "removed.")