From 173f8a0bcadeedfa237b9d9fbaf6d28783e1dca9 Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Thu, 13 Jun 2024 13:21:36 +0200 Subject: [PATCH] Effect loading fixes (#4425) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4425 Reviewed-by: Mikita Wiśniewski Co-authored-by: the-real-herowl Co-committed-by: the-real-herowl --- mods/ITEMS/mcl_potions/functions.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mods/ITEMS/mcl_potions/functions.lua b/mods/ITEMS/mcl_potions/functions.lua index 0d71ab481..a1c838814 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -456,6 +456,10 @@ mcl_potions.register_effect({ object:get_meta():set_int("night_vision", 1) mcl_weather.skycolor.update_sky_color({object}) end, + on_load = function(object, factor) + object:get_meta():set_int("night_vision", 1) + mcl_weather.skycolor.update_sky_color({object}) + end, on_step = function(dtime, object, factor, duration) mcl_weather.skycolor.update_sky_color({object}) end, @@ -1525,6 +1529,11 @@ function mcl_potions._load_player_effects(player) local loaded = minetest.deserialize(meta:get_string("mcl_potions:_EF_"..name)) if loaded then EF[name][player] = loaded + end + if EF[name][player] then -- this is needed because of legacy effects loaded separately + if effect.uses_factor and type(EF[name][player].factor) ~= "number" then + EF[name][player].factor = effect.level_to_factor(1) + end if effect.on_load then effect.on_load(player, EF[name][player].factor) end @@ -1542,6 +1551,9 @@ function mcl_potions._load_entity_effects(entity) local loaded = entity._mcl_potions["_EF_"..name] if loaded then EF[name][object] = loaded + if effect.uses_factor and not loaded.factor then + EF[name][object].factor = effect.level_to_factor(1) + end if effect.on_load then effect.on_load(object, EF[name][object].factor) end