1
0
Fork 0

Fix rain light levels so that day rain is brighter and night rain is darker

This commit is contained in:
ancientmarinerdev 2023-03-27 03:38:49 +01:00 committed by Gitea
parent 2426570871
commit 61a4595c1b
1 changed files with 22 additions and 27 deletions

View File

@ -1,6 +1,8 @@
local mods_loaded = false local mods_loaded = false
local NIGHT_VISION_RATIO = 0.45 local NIGHT_VISION_RATIO = 0.45
local MINIMUM_LIGHT_LEVEL = 0.2
local water_color = "#3F76E4" local water_color = "#3F76E4"
local mg_name = minetest.get_mapgen_setting("mg_name") local mg_name = minetest.get_mapgen_setting("mg_name")
@ -45,6 +47,24 @@ function mcl_weather.set_sky_color(player, def)
}) })
end end
-- Function to work out light modifier at different times
-- Noon is brightest, midnight is darkest, 0600 and 18000 is in the middle of this
local function get_light_modifier(time)
-- 0.1 = 0.2
-- 0.4 = 0.8
-- 0.5 = 1
-- 0.6 = 0.8
-- 0.9 = 0.2
local light_multiplier = time * 2
if time > 0.5 then
light_multiplier = 2 * (1 - time)
else
light_multiplier = time / 0.5
end
return light_multiplier
end
mcl_weather.skycolor = { mcl_weather.skycolor = {
-- Should be activated before do any effect. -- Should be activated before do any effect.
active = true, active = true,
@ -216,33 +236,8 @@ mcl_weather.skycolor = {
mcl_weather.skycolor.override_day_night_ratio(player, 1) mcl_weather.skycolor.override_day_night_ratio(player, 1)
elseif light_factor then elseif light_factor then
local time = minetest.get_timeofday() local time = minetest.get_timeofday()
-- 0.5 = 1 local light_multiplier = get_light_modifier(time)
-- 0 = 0 local new_light = math.max(light_factor * light_multiplier, MINIMUM_LIGHT_LEVEL)
-- 0.99 = 0
-- greater than 0.5, is
-- less than 0.5 = time / 0.5
-- 0.6 = 0.8
-- 0.9 = 0.2
-- 0.6 = 0.4
-- 0.9 = 0.1
-- 2 * (1 - time)
local light_multiplier = time * 2
if time > 0.5 then
light_multiplier = 2 * (1 - time)
else
light_multiplier = time / 0.5
end
local minimum_light_level = 0.10
minetest.log("New light_multiplier: " .. tostring(light_multiplier))
local new_light = (light_factor * (light_multiplier * (1-minimum_light_level))) + minimum_light_level
minetest.log("new_light: " .. tostring(new_light))
mcl_weather.skycolor.override_day_night_ratio(player, new_light) mcl_weather.skycolor.override_day_night_ratio(player, new_light)
else else
mcl_weather.skycolor.override_day_night_ratio(player, nil) mcl_weather.skycolor.override_day_night_ratio(player, nil)