From c942e3fc12aee3c2b53c589c5862ecd515a3f014 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Sat, 4 Dec 2021 17:04:32 +0100 Subject: [PATCH] handle other mods not expecting nil in player meta --- player.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/player.lua b/player.lua index 95b3551..8c8434e 100644 --- a/player.lua +++ b/player.lua @@ -56,9 +56,12 @@ function creative_regions:restore_player_inventory(player, listname) end end +local DAYNIGHT_AUTO = -1 +local DAYNIGHT_UNSET = -2 + function creative_regions:save_player_day_night_ratio(player) local current_day_night_ratio = player:get_day_night_ratio() - if current_day_night_ratio == nil then current_day_night_ratio = -1 end + if current_day_night_ratio == nil then current_day_night_ratio = DAYNIGHT_AUTO end local pmeta = player:get_meta() pmeta:set_int("creative_regions_day_night_ratio", current_day_night_ratio) end @@ -67,10 +70,10 @@ function creative_regions:restore_player_day_night_ratio(player) local pmeta = player:get_meta() local current_day_night_ratio = player:get_day_night_ratio() local saved_day_night_ratio = pmeta:get_int("creative_region_day_night_ratio") - if saved_day_night_ratio ~= nil then - if saved_day_night_ratio == -1 then saved_day_night_ratio = nil end + if saved_day_night_ratio ~= nil and saved_day_night_ratio ~= DAYNIGHT_UNSET then + if saved_day_night_ratio == DAYNIGHT_AUTO then saved_day_night_ratio = nil end player:override_day_night_ratio(saved_day_night_ratio) - pmeta:set_int("creative_regions_day_night_ratio", nil) + pmeta:set_int("creative_regions_day_night_ratio", DAYNIGHT_UNSET) end return current_day_night_ratio end