From c9e7e900b0a5822a1f7f63abc2f9be83d6a5a25f Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Mon, 22 Jan 2024 22:02:05 +0100 Subject: [PATCH] Added time_override to FOV API time_override can be used when applying or removing modifiers --- mods/PLAYER/mcl_fovapi/init.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mods/PLAYER/mcl_fovapi/init.lua b/mods/PLAYER/mcl_fovapi/init.lua index 92815d833..43dcfe403 100644 --- a/mods/PLAYER/mcl_fovapi/init.lua +++ b/mods/PLAYER/mcl_fovapi/init.lua @@ -75,7 +75,7 @@ minetest.register_on_respawnplayer(function(player) mcl_fovapi.remove_all_modifiers(player) end) -function mcl_fovapi.apply_modifier(player, modifier_name) +function mcl_fovapi.apply_modifier(player, modifier_name, time_override) if not player or not modifier_name then return end @@ -106,13 +106,14 @@ function mcl_fovapi.apply_modifier(player, modifier_name) minetest.log("FOV::Modifier applied to player:" .. player_name .. " modifier: " .. modifier_name) end + local time = time_override or modifier.time -- modifier apply code. if modifier.exclusive == true then -- if exclusive, reset the player's fov, and apply the new fov. if modifier.is_multiplier then player:set_fov(0, false, 0) end - player:set_fov(modifier.fov_factor, modifier.is_multiplier, modifier.time) + player:set_fov(modifier.fov_factor, modifier.is_multiplier, time) else -- not exclusive? let's apply it in the mix. local fov_factor, is_mult = player:get_fov() @@ -126,15 +127,15 @@ function mcl_fovapi.apply_modifier(player, modifier_name) fov_factor = (fov_factor + modifier.fov_factor) / 2 end if modifier.is_multiplier and is_mult then - player:set_fov(fov_factor, true, modifier.time) + player:set_fov(fov_factor, true, time) else - player:set_fov(fov_factor, false, modifier.time) + player:set_fov(fov_factor, false, time) end end end -function mcl_fovapi.remove_modifier(player, modifier_name) +function mcl_fovapi.remove_modifier(player, modifier_name, time_override) if not player or not modifier_name then return end @@ -159,9 +160,10 @@ function mcl_fovapi.remove_modifier(player, modifier_name) applied[k] = mcl_fovapi.registered_modifiers[k] end + local time = time_override or modifier.reset_time local elem = next if elem(applied) == nil then - player:set_fov(0, false, modifier.reset_time) + player:set_fov(0, false, time) return end local exc = false @@ -191,7 +193,7 @@ function mcl_fovapi.remove_modifier(player, modifier_name) fov_factor = fov_factor * x.fov_factor end end - player:set_fov(fov_factor, not non_multiplier_added, modifier.reset_time) + player:set_fov(fov_factor, not non_multiplier_added, time) end if mcl_fovapi.registered_modifiers[modifier_name].on_end then