From 167b8c4bedd6574f5a5036265c363e8b82b5df36 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Sat, 4 Dec 2021 16:31:50 +0100 Subject: [PATCH] disable custom day_night_ratio in survival --- player.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/player.lua b/player.lua index 0b70719..95b3551 100644 --- a/player.lua +++ b/player.lua @@ -56,6 +56,25 @@ function creative_regions:restore_player_inventory(player, listname) end end +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 + local pmeta = player:get_meta() + pmeta:set_int("creative_regions_day_night_ratio", current_day_night_ratio) +end + +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 + player:override_day_night_ratio(saved_day_night_ratio) + pmeta:set_int("creative_regions_day_night_ratio", nil) + end + return current_day_night_ratio +end + function creative_regions:player_enter_region(player, new_privs_table, initialize) local name = player:get_player_name() local has_creative = minetest.check_player_privs(name, {creative=true}) @@ -116,6 +135,7 @@ function creative_regions:player_enter_region(player, new_privs_table, initializ -- player:get_meta():set_string("hunger_ng:hunger_disabled", 1) hunger_ng.configure_hunger(name, 'disable') end + creative_regions:restore_player_day_night_ratio(player) elseif new_mode == "arena" then local inv = player:get_inventory() inv:set_list("main", {}) @@ -123,6 +143,8 @@ function creative_regions:player_enter_region(player, new_privs_table, initializ if minetest.get_modpath("hunger_ng") then hunger_ng.configure_hunger(name, 'enable') end + creative_regions:save_player_day_night_ratio(player) + player:override_day_night_ratio(nil) end end