From 2ca0ccd8fea52c8e83f935a6b6170cd9a13af563 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sun, 29 Sep 2024 12:11:59 -0500 Subject: [PATCH 1/7] Fix fog tint in overworld, apply memory leak fix from rain.lua to snow.lua and thunder.lua --- .../mcl_weather/skycolor/dimensions.lua | 3 +++ mods/ENVIRONMENT/mcl_weather/snow.lua | 16 +++++++++------- mods/ENVIRONMENT/mcl_weather/thunder.lua | 16 +++++++++------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua index fcf85a7e0..6113ad851 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua @@ -52,6 +52,9 @@ function dimension_handlers.overworld(player, sky_data) dawn_horizon = dawn_color, night_sky = night_color, night_horizon = night_color, + fog_sun_tint = "#ff5f33", + fog_moon_tint = nil, + fog_tint_type = "custom", }, clouds = true, } diff --git a/mods/ENVIRONMENT/mcl_weather/snow.lua b/mods/ENVIRONMENT/mcl_weather/snow.lua index 9ff2605df..73c65c3da 100644 --- a/mods/ENVIRONMENT/mcl_weather/snow.lua +++ b/mods/ENVIRONMENT/mcl_weather/snow.lua @@ -75,13 +75,15 @@ function mcl_weather.has_snow(pos) end function mcl_weather.snow.set_sky_box() - mcl_weather.skycolor.add_layer( - "weather-pack-snow-sky", - {{r=0, g=0, b=0}, - {r=85, g=86, b=86}, - {r=135, g=135, b=135}, - {r=85, g=86, b=86}, - {r=0, g=0, b=0}}) + if mcl_weather.skycolor.current_layer_name() ~= "weather-pack-snow-sky" then + mcl_weather.skycolor.add_layer( + "weather-pack-snow-sky", + {{r=0, g=0, b=0}, + {r=85, g=86, b=86}, + {r=135, g=135, b=135}, + {r=85, g=86, b=86}, + {r=0, g=0, b=0}}) + end mcl_weather.skycolor.active = true for _, player in pairs(get_connected_players()) do player:set_clouds({color="#ADADADE8"}) diff --git a/mods/ENVIRONMENT/mcl_weather/thunder.lua b/mods/ENVIRONMENT/mcl_weather/thunder.lua index c594cde37..1431e423d 100644 --- a/mods/ENVIRONMENT/mcl_weather/thunder.lua +++ b/mods/ENVIRONMENT/mcl_weather/thunder.lua @@ -23,13 +23,15 @@ minetest.register_globalstep(function(dtime) mcl_weather.rain.make_weather() if mcl_weather.thunder.init_done == false then - mcl_weather.skycolor.add_layer("weather-pack-thunder-sky", { - {r=0, g=0, b=0}, - {r=40, g=40, b=40}, - {r=85, g=86, b=86}, - {r=40, g=40, b=40}, - {r=0, g=0, b=0}, - }) + if mcl_weather.skycolor.current_layer_name() ~= "weather-pack-thunder-sky" then + mcl_weather.skycolor.add_layer("weather-pack-thunder-sky", { + {r=0, g=0, b=0}, + {r=40, g=40, b=40}, + {r=85, g=86, b=86}, + {r=40, g=40, b=40}, + {r=0, g=0, b=0}, + }) + end mcl_weather.skycolor.active = true for _, player in pairs(get_connected_players()) do player:set_clouds({color="#3D3D3FE8"}) From 2145470f639416f105809abb1a7db92f553d42f9 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sun, 29 Sep 2024 12:25:18 -0500 Subject: [PATCH 2/7] Fix clouds during rain->clear weather transition --- mods/ENVIRONMENT/mcl_weather/rain.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/mods/ENVIRONMENT/mcl_weather/rain.lua b/mods/ENVIRONMENT/mcl_weather/rain.lua index ed6c2c5fb..9307dd64c 100644 --- a/mods/ENVIRONMENT/mcl_weather/rain.lua +++ b/mods/ENVIRONMENT/mcl_weather/rain.lua @@ -157,6 +157,7 @@ function mcl_weather.rain.clear() mcl_weather.rain.remove_sound(player) mcl_weather.rain.remove_player(player) mcl_weather.remove_spawners_player(player) + player:set_clouds({color="#FFF0EF"}) end end From 96a03b1923a1e5be294cbabfcd69515d7670891e Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sun, 29 Sep 2024 17:01:28 -0500 Subject: [PATCH 3/7] Remove posibility of nil sky colors in overworld, add line break --- .../mcl_weather/skycolor/dimensions.lua | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua index 6113ad851..6a8856434 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua @@ -46,12 +46,12 @@ function dimension_handlers.overworld(player, sky_data) sky_data.sky = { type = "regular", sky_color = { - day_sky = day_color, - day_horizon = day_color, - dawn_sky = dawn_color, - dawn_horizon = dawn_color, - night_sky = night_color, - night_horizon = night_color, + day_sky = day_color or "#7BA4FF", + day_horizon = day_color or "#C0D8FF", + dawn_sky = dawn_color or "7BA4FF", + dawn_horizon = dawn_color or "#C0D8FF", + night_sky = night_color or "000000", + night_horizon = night_color or "4A6790", fog_sun_tint = "#ff5f33", fog_moon_tint = nil, fog_tint_type = "custom", @@ -81,12 +81,12 @@ function dimension_handlers.overworld(player, sky_data) sky_data.sky = { type = "regular", sky_color = { - day_sky = day_color, - day_horizon = day_color, - dawn_sky = dawn_color, - dawn_horizon = dawn_color, - night_sky = night_color, - night_horizon = night_color, + day_sky = day_color or "#7BA4FF", + day_horizon = day_color or "#C0D8FF", + dawn_sky = dawn_color or "7BA4FF", + dawn_horizon = dawn_color or "#C0D8FF", + night_sky = night_color or "000000", + night_horizon = night_color or "4A6790", }, clouds = true, } @@ -167,7 +167,8 @@ function dimension_handlers.nether(player, sky_data) end function dimension_handlers.void(player, sky_data) - sky_data.sky = { type = "plain", + sky_data.sky = { + type = "plain", base_color = "#000000", clouds = false, } From f6c3f4bd1601c5fe497a966b603d1c91e2efbff8 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sun, 29 Sep 2024 18:33:04 -0500 Subject: [PATCH 4/7] Correct value clamping --- mods/ENVIRONMENT/mcl_weather/skycolor.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor.lua b/mods/ENVIRONMENT/mcl_weather/skycolor.lua index 19cec9eac..fdf7c33c8 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor.lua @@ -190,8 +190,8 @@ end function skycolor_utils.convert_to_rgb(minval, maxval, current_val, colors) -- Clamp current_val to valid range - current_val = math.min(minval, current_val) - current_val = math.max(maxval, current_val) + current_val = math.max(minval, current_val) + current_val = math.min(maxval, current_val) -- Rescale current_val from a number between minval and maxval to a number between 1 and #colors local scaled_value = (current_val - minval) / (maxval - minval) * (#colors - 1) + 1.0 From 7807093b50bf91f6828938571b632cfe793e1216 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sat, 5 Oct 2024 10:15:53 -0500 Subject: [PATCH 5/7] Another correction to color interpolation, change day color from layer position 0.15 to 0.50 --- mods/ENVIRONMENT/mcl_weather/skycolor.lua | 26 +++++++++++++++++-- .../mcl_weather/skycolor/dimensions.lua | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor.lua b/mods/ENVIRONMENT/mcl_weather/skycolor.lua index fdf7c33c8..eb217b3b2 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor.lua @@ -2,6 +2,7 @@ local modname = minetest.get_current_modname() local modpath = minetest.get_modpath(modname) local NIGHT_VISION_RATIO = 0.45 +local DEBUG = false -- Settings local minimum_update_interval = { 250e3 } @@ -199,7 +200,7 @@ function skycolor_utils.convert_to_rgb(minval, maxval, current_val, colors) -- Get the first color's values local index1 = math.floor(scaled_value) local color1 = colors[index1] - local frac1 = scaled_value - index1 + local frac1 = 1.0 - (scaled_value - index1) -- Get the second color's values local index2 = math.min(index1 + 1, #colors) -- clamp to maximum color index (will occur if index1 == #colors) @@ -207,11 +208,32 @@ function skycolor_utils.convert_to_rgb(minval, maxval, current_val, colors) local color2 = colors[index2] -- Interpolate between color1 and color2 - return { + local res = { r = math.floor(frac1 * color1.r + frac2 * color2.r), g = math.floor(frac1 * color1.g + frac2 * color2.g), b = math.floor(frac1 * color1.b + frac2 * color2.b), } + + if DEBUG then + minetest.log(dump({ + minval = minval, + maxval = maxval, + current_val = current_val, + colors = colors, + res = res, + scaled_value = scaled_value, + + frac1 = frac1, + index1 = index1, + color1 = color1, + + frac2 = frac2, + index2 = index2, + color2 = color2, + })) + end + + return res end -- Simple getter. Either returns user given players list or get all connected players if none provided diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua index 6a8856434..5596e756e 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua @@ -40,7 +40,7 @@ function dimension_handlers.overworld(player, sky_data) end -- Use overworld defaults - local day_color = mcl_weather.skycolor.get_sky_layer_color(0.15) + local day_color = mcl_weather.skycolor.get_sky_layer_color(0.5) local dawn_color = mcl_weather.skycolor.get_sky_layer_color(0.27) local night_color = mcl_weather.skycolor.get_sky_layer_color(0.1) sky_data.sky = { From 66c3c014a148d1ec82d7794f9d464d87645caa7e Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sat, 5 Oct 2024 19:18:19 -0500 Subject: [PATCH 6/7] Make sure fog tints are preserved during weather is present --- .../mcl_weather/skycolor/dimensions.lua | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua index 5596e756e..0ac0e26b1 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua @@ -78,18 +78,14 @@ function dimension_handlers.overworld(player, sky_data) local day_color = mcl_weather.skycolor.get_sky_layer_color(0.5) local dawn_color = mcl_weather.skycolor.get_sky_layer_color(0.75) local night_color = mcl_weather.skycolor.get_sky_layer_color(0) - sky_data.sky = { - type = "regular", - sky_color = { - day_sky = day_color or "#7BA4FF", - day_horizon = day_color or "#C0D8FF", - dawn_sky = dawn_color or "7BA4FF", - dawn_horizon = dawn_color or "#C0D8FF", - night_sky = night_color or "000000", - night_horizon = night_color or "4A6790", - }, - clouds = true, - } + table.update(sky_data.sky.sky_color,{ + day_sky = day_color or "#7BA4FF", + day_horizon = day_color or "#C0D8FF", + dawn_sky = dawn_color or "7BA4FF", + dawn_horizon = dawn_color or "#C0D8FF", + night_sky = night_color or "000000", + night_horizon = night_color or "4A6790", + }) sky_data.sun = {visible = false, sunrise_visible = false} sky_data.moon = {visible = false} sky_data.stars = {visible = false} From e864cc19ed16f5e645cc79723bafbf73f18ce8b3 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sat, 5 Oct 2024 19:36:15 -0500 Subject: [PATCH 7/7] Make fog_tint_type = "default" when weather is present to match behavior at 0.87.2 --- mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua index 0ac0e26b1..671ead2bb 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua @@ -85,6 +85,7 @@ function dimension_handlers.overworld(player, sky_data) dawn_horizon = dawn_color or "#C0D8FF", night_sky = night_color or "000000", night_horizon = night_color or "4A6790", + fog_tint_type = "default", }) sky_data.sun = {visible = false, sunrise_visible = false} sky_data.moon = {visible = false}