From c434a41decd325a4cca779454e2e116d9b215175 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 22 Nov 2017 01:09:41 +0100 Subject: [PATCH] Refactor and tweak sky light overwrite --- mods/ENVIRONMENT/weather_pack/rain.lua | 4 +--- mods/ENVIRONMENT/weather_pack/skycolor.lua | 22 ++++++++----------- mods/ENVIRONMENT/weather_pack/snow.lua | 2 +- mods/ENVIRONMENT/weather_pack/thunder.lua | 5 +---- .../ENVIRONMENT/weather_pack/weather_core.lua | 4 ++-- 5 files changed, 14 insertions(+), 23 deletions(-) diff --git a/mods/ENVIRONMENT/weather_pack/rain.lua b/mods/ENVIRONMENT/weather_pack/rain.lua index 099d8d38a..1ae87f05d 100644 --- a/mods/ENVIRONMENT/weather_pack/rain.lua +++ b/mods/ENVIRONMENT/weather_pack/rain.lua @@ -39,7 +39,6 @@ rain.set_sky_box = function() skycolor.active = true for _, player in pairs(minetest.get_connected_players()) do player:set_clouds({color="#5D5D5FE8"}) - player:override_day_night_ratio(0.8) end end end @@ -146,7 +145,6 @@ rain.clear = function() for _, player in ipairs(minetest.get_connected_players()) do rain.remove_sound(player) rain.remove_player(player) - player:override_day_night_ratio(nil) end end @@ -180,7 +178,7 @@ end if weather.reg_weathers.rain == nil then weather.reg_weathers.rain = { chance = 15, - day_night_ratio = 0.8, + light_factor = 0.7, clear = rain.clear } end diff --git a/mods/ENVIRONMENT/weather_pack/skycolor.lua b/mods/ENVIRONMENT/weather_pack/skycolor.lua index e5059e92a..080ec4fcd 100644 --- a/mods/ENVIRONMENT/weather_pack/skycolor.lua +++ b/mods/ENVIRONMENT/weather_pack/skycolor.lua @@ -80,21 +80,17 @@ skycolor = { if dim == "overworld" then player:set_sky(color, "plain", nil, true) - local dnn = weather.get_current_day_night_ratio() - if dnn then + local lf = weather.get_current_light_factor() + if lf then local w = minetest.get_timeofday() - if w > 0.5 then - w = 2*(1 - w) - else - w = 1 - (1 - 2*w) - end - if w > dnn then - -- FIXME: This color will cause a sharp brightness change. - -- The correct ratio value needs to be calculated. - player:override_day_night_ratio(dnn) - else - player:override_day_night_ratio(nil) + local light = (w * (lf*2)) + if light > 1 then + light = 1 - (light - 1) end + + light = (light * lf) + 0.15 + + player:override_day_night_ratio(light) else player:override_day_night_ratio(nil) end diff --git a/mods/ENVIRONMENT/weather_pack/snow.lua b/mods/ENVIRONMENT/weather_pack/snow.lua index 2bf55efb7..e1de8f0d1 100644 --- a/mods/ENVIRONMENT/weather_pack/snow.lua +++ b/mods/ENVIRONMENT/weather_pack/snow.lua @@ -84,7 +84,7 @@ end) if weather.reg_weathers.snow == nil then weather.reg_weathers.snow = { chance = 10, - day_night_ratio = 0.8, + light_factor = 0.7, clear = snow.clear } end diff --git a/mods/ENVIRONMENT/weather_pack/thunder.lua b/mods/ENVIRONMENT/weather_pack/thunder.lua index 70636e08f..9fdd81124 100644 --- a/mods/ENVIRONMENT/weather_pack/thunder.lua +++ b/mods/ENVIRONMENT/weather_pack/thunder.lua @@ -44,9 +44,6 @@ thunder.clear = function() rain.clear() skycolor.remove_layer("weather-pack-thunder-sky") skycolor.remove_layer("lightning") - for _, player in pairs(minetest.get_connected_players()) do - player:override_day_night_ratio(nil) - end thunder.init_done = false end @@ -54,7 +51,7 @@ end if weather.reg_weathers.thunder == nil then weather.reg_weathers.thunder = { chance = 5, - day_night_ratio = 0.33333, + light_factor = 0.33333, clear = thunder.clear, min_duration = 120, max_duration = 600, diff --git a/mods/ENVIRONMENT/weather_pack/weather_core.lua b/mods/ENVIRONMENT/weather_pack/weather_core.lua index ed2874aeb..b47b120a9 100644 --- a/mods/ENVIRONMENT/weather_pack/weather_core.lua +++ b/mods/ENVIRONMENT/weather_pack/weather_core.lua @@ -38,11 +38,11 @@ weather.get_rand_end_time = function(min_duration, max_duration) end end -weather.get_current_day_night_ratio = function() +weather.get_current_light_factor = function() if weather.state == "none" then return nil else - return weather.reg_weathers[weather.state].day_night_ratio + return weather.reg_weathers[weather.state].light_factor end end