Browse Source

handle other mods not expecting nil in player meta

main
Hendrik Langer 3 years ago
parent
commit
c942e3fc12
  1. 11
      player.lua

11
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

Loading…
Cancel
Save