From 161dd7d379c473dd9521567cb231c15f22646a92 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Mon, 27 May 2024 08:04:22 +0000 Subject: [PATCH 01/23] Start refactor --- mods/ENVIRONMENT/mcl_weather/skycolor.lua | 537 +++++++++++----------- 1 file changed, 278 insertions(+), 259 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor.lua b/mods/ENVIRONMENT/mcl_weather/skycolor.lua index 87952845b..bc8c4d8f7 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor.lua @@ -1,10 +1,11 @@ -local mods_loaded = false +-- Constants local NIGHT_VISION_RATIO = 0.45 - local MINIMUM_LIGHT_LEVEL = 0.2 +local DEFAULT_WATER_COLOR = "#3F76E4" -local water_color = "#3F76E4" - +-- Module state +local mods_loaded = false +local water_color = DEFAULT_WATER_COLOR local mg_name = minetest.get_mapgen_setting("mg_name") function mcl_weather.set_sky_box_clear(player, sky, fog) @@ -65,7 +66,7 @@ local function get_light_modifier(time) return light_multiplier end -mcl_weather.skycolor = { +local skycolor = { -- Should be activated before do any effect. active = true, @@ -88,287 +89,305 @@ mcl_weather.skycolor = { -- Table for tracking layer order layer_names = {}, - -- To layer to colors table - add_layer = function(layer_name, layer_color, instant_update) - mcl_weather.skycolor.colors[layer_name] = layer_color - table.insert(mcl_weather.skycolor.layer_names, layer_name) - mcl_weather.skycolor.force_update = true - end, + utils = {}, +} +mcl_weather.skycolor = skycolor +local skycolor_utils = skycolor.utils - current_layer_name = function() - return mcl_weather.skycolor.layer_names[#mcl_weather.skycolor.layer_names] - end, +-- To layer to colors table +function skycolor.add_layer(layer_name, layer_color, instant_update) + mcl_weather.skycolor.colors[layer_name] = layer_color + table.insert(mcl_weather.skycolor.layer_names, layer_name) + mcl_weather.skycolor.force_update = true +end - -- Retrieve layer from colors table - retrieve_layer = function() - local last_layer = mcl_weather.skycolor.current_layer_name() - return mcl_weather.skycolor.colors[last_layer] - end, +function skycolor.current_layer_name() + return mcl_weather.skycolor.layer_names[#mcl_weather.skycolor.layer_names] +end - -- Remove layer from colors table - remove_layer = function(layer_name) - for k, name in pairs(mcl_weather.skycolor.layer_names) do - if name == layer_name then - table.remove(mcl_weather.skycolor.layer_names, k) - mcl_weather.skycolor.force_update = true - return - end +-- Retrieve layer from colors table +function skycolor.retrieve_layer() + local last_layer = mcl_weather.skycolor.current_layer_name() + return mcl_weather.skycolor.colors[last_layer] +end + +-- Remove layer from colors table +function skycolor.remove_layer(layer_name) + for k, name in pairs(mcl_weather.skycolor.layer_names) do + if name == layer_name then + table.remove(mcl_weather.skycolor.layer_names, k) + mcl_weather.skycolor.force_update = true + return end - end, + end +end - -- Wrapper for updating day/night ratio that respects night vision - override_day_night_ratio = function(player, ratio) - local meta = player:get_meta() - local has_night_vision = meta:get_int("night_vision") == 1 - local has_darkness = meta:get_int("darkness") == 1 - local is_visited_shepherd = meta:get_int("mcl_shepherd:special") == 1 - local arg - if has_darkness and not is_visited_shepherd then - if has_night_vision then arg = 0.1 - else arg = 0 end - else - -- Apply night vision only for dark sky - local is_dark = minetest.get_timeofday() > 0.8 or minetest.get_timeofday() < 0.2 or mcl_weather.state ~= "none" - local pos = player:get_pos() - local dim = mcl_worlds.pos_to_dimension(pos) - if (has_night_vision or is_visited_shepherd) and is_dark and dim ~= "nether" and dim ~= "end" then - if ratio == nil then - arg = NIGHT_VISION_RATIO - else - arg = math.max(ratio, NIGHT_VISION_RATIO) - end +-- Wrapper for updating day/night ratio that respects night vision +function skycolor.override_day_night_ratio(player, ratio) + local meta = player:get_meta() + local has_night_vision = meta:get_int("night_vision") == 1 + local has_darkness = meta:get_int("darkness") == 1 + local is_visited_shepherd = meta:get_int("mcl_shepherd:special") == 1 + local arg + if has_darkness and not is_visited_shepherd then + if has_night_vision then arg = 0.1 + else arg = 0 end + else + -- Apply night vision only for dark sky + local is_dark = minetest.get_timeofday() > 0.8 or minetest.get_timeofday() < 0.2 or mcl_weather.state ~= "none" + local pos = player:get_pos() + local dim = mcl_worlds.pos_to_dimension(pos) + if (has_night_vision or is_visited_shepherd) and is_dark and dim ~= "nether" and dim ~= "end" then + if ratio == nil then + arg = NIGHT_VISION_RATIO else - arg = ratio + arg = math.max(ratio, NIGHT_VISION_RATIO) end + else + arg = ratio end - player:override_day_night_ratio(arg) - end, + end + player:override_day_night_ratio(arg) +end - -- Update sky color. If players not specified update sky for all players. - update_sky_color = function(players) - -- Override day/night ratio as well - players = mcl_weather.skycolor.utils.get_players(players) - for _, player in ipairs(players) do - local pos = player:get_pos() - local dim = mcl_worlds.pos_to_dimension(pos) - local has_weather = (mcl_worlds.has_weather(pos) and (mcl_weather.state == "snow" or mcl_weather.state =="rain" or mcl_weather.state == "thunder") and mcl_weather.has_snow(pos)) or ((mcl_weather.state =="rain" or mcl_weather.state == "thunder") and mcl_weather.has_rain(pos)) - local checkname = minetest.get_node(vector.new(pos.x,pos.y+1.5,pos.z)).name - if minetest.get_item_group(checkname, "water") ~= 0 then +function water_sky(player) + local pos = player:get_pos() + local water_color = DEFAULT_WATER_COLOR + + local checkname = minetest.get_node(vector.new(pos.x,pos.y+1.5,pos.z)).name + if minetest.get_item_group(checkname, "water") == 0 then return end + + local biome_index = minetest.get_biome_data(player:get_pos()).biome + local biome_name = minetest.get_biome_name(biome_index) + local biome = minetest.registered_biomes[biome_name] + if biome then water_color = biome._mcl_waterfogcolor end + if not biome then water_color = "#3F76E4" end + + if checkname == "mclx_core:river_water_source" or checkname == "mclx_core:river_water_flowing" then water_color = "#0084FF" end + + return { + sky = { type = "regular", + sky_color = { + day_sky = water_color, + day_horizon = water_color, + dawn_sky = water_color, + dawn_horizon = water_color, + night_sky = water_color, + night_horizon = water_color, + indoors = water_color, + fog_sun_tint = water_color, + fog_moon_tint = water_color, + fog_tint_type = "custom" + }, + clouds = false, + } + } +end + +-- Update sky color. If players not specified update sky for all players. +function skycolor.update_sky_color(players) + -- Override day/night ratio as well + players = mcl_weather.skycolor.utils.get_players(players) + for _, player in ipairs(players) do + + local pos = player:get_pos() + local dim = mcl_worlds.pos_to_dimension(pos) + local has_weather = (mcl_worlds.has_weather(pos) and (mcl_weather.state == "snow" or mcl_weather.state =="rain" or mcl_weather.state == "thunder") and mcl_weather.has_snow(pos)) or ((mcl_weather.state =="rain" or mcl_weather.state == "thunder") and mcl_weather.has_rain(pos)) + + local res = water_sky(player) + if res and res.sky then + player:set_sky(res.sky) + end + + if dim == "overworld" then + local biomesky + local biomefog + if mg_name ~= "v6" and mg_name ~= "singlenode" then local biome_index = minetest.get_biome_data(player:get_pos()).biome local biome_name = minetest.get_biome_name(biome_index) local biome = minetest.registered_biomes[biome_name] - if biome then water_color = biome._mcl_waterfogcolor end - if not biome then water_color = "#3F76E4" end - if checkname == "mclx_core:river_water_source" or checkname == "mclx_core:river_water_flowing" then water_color = "#0084FF" end - player:set_sky({ type = "regular", - sky_color = { - day_sky = water_color, - day_horizon = water_color, - dawn_sky = water_color, - dawn_horizon = water_color, - night_sky = water_color, - night_horizon = water_color, - indoors = water_color, - fog_sun_tint = water_color, - fog_moon_tint = water_color, - fog_tint_type = "custom" - }, - clouds = false, - }) + if biome then + --minetest.log("action", string.format("Biome found for number: %s in biome: %s", tostring(biome_index), biome_name)) + biomesky = biome._mcl_skycolor + biomefog = biome._mcl_fogcolor + else + --minetest.log("action", string.format("No biome for number: %s in biome: %s", tostring(biome_index), biome_name)) + end end - if dim == "overworld" then - local biomesky - local biomefog - if mg_name ~= "v6" and mg_name ~= "singlenode" then - local biome_index = minetest.get_biome_data(player:get_pos()).biome - local biome_name = minetest.get_biome_name(biome_index) - local biome = minetest.registered_biomes[biome_name] - if biome then - --minetest.log("action", string.format("Biome found for number: %s in biome: %s", tostring(biome_index), biome_name)) - biomesky = biome._mcl_skycolor - biomefog = biome._mcl_fogcolor - else - --minetest.log("action", string.format("No biome for number: %s in biome: %s", tostring(biome_index), biome_name)) - end - end - if (mcl_weather.state == "none") then - -- Clear weather - mcl_weather.set_sky_box_clear(player,biomesky,biomefog) - player:set_sun({visible = true, sunrise_visible = true}) - player:set_moon({visible = true}) - player:set_stars({visible = true}) - mcl_weather.skycolor.override_day_night_ratio(player, nil) - elseif not has_weather then - local day_color = mcl_weather.skycolor.get_sky_layer_color(0.15) - local dawn_color = mcl_weather.skycolor.get_sky_layer_color(0.27) - local night_color = mcl_weather.skycolor.get_sky_layer_color(0.1) - mcl_weather.set_sky_color(player, { - 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, - }, - clouds = true, - }) - player:set_sun({visible = false, sunrise_visible = false}) - player:set_moon({visible = false}) - player:set_stars({visible = false}) - elseif has_weather then - -- Weather skies - 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) - mcl_weather.set_sky_color(player, { - 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, - }, - clouds = true, - }) - player:set_sun({visible = false, sunrise_visible = false}) - player:set_moon({visible = false}) - player:set_stars({visible = false}) - - local light_factor = mcl_weather.get_current_light_factor() - if mcl_weather.skycolor.current_layer_name() == "lightning" then - mcl_weather.skycolor.override_day_night_ratio(player, 1) - elseif light_factor then - local time = minetest.get_timeofday() - local light_multiplier = get_light_modifier(time) - local new_light = math.max(light_factor * light_multiplier, MINIMUM_LIGHT_LEVEL) - mcl_weather.skycolor.override_day_night_ratio(player, new_light) - else - mcl_weather.skycolor.override_day_night_ratio(player, nil) - end - end - elseif dim == "end" then - local biomesky = "#000000" - local biomefog = "#A080A0" - if mg_name ~= "v6" and mg_name ~= "singlenode" then - local biome_index = minetest.get_biome_data(player:get_pos()).biome - local biome_name = minetest.get_biome_name(biome_index) - local biome = minetest.registered_biomes[biome_name] - if biome then - --minetest.log("action", string.format("Biome found for number: %s in biome: %s", tostring(biome_index), biome_name)) - biomesky = biome._mcl_skycolor - biomefog = biome._mcl_fogcolor -- The End biomes seemingly don't use the fog colour, despite having this value according to the wiki. The sky colour is seemingly used for both sky and fog? - else - --minetest.log("action", string.format("No biome for number: %s in biome: %s", tostring(biome_index), biome_name)) - end - end - local t = "mcl_playerplus_end_sky.png" - player:set_sky({ type = "skybox", - base_color = biomesky, - textures = {t,t,t,t,t,t}, - clouds = false, - }) - player:set_sun({visible = false , sunrise_visible = false}) - player:set_moon({visible = false}) - player:set_stars({visible = false}) - mcl_weather.skycolor.override_day_night_ratio(player, 0.5) - elseif dim == "nether" then - local biomesky = "#6EB1FF" - local biomefog = "#330808" - if mg_name ~= "v6" and mg_name ~= "singlenode" then - local biome_index = minetest.get_biome_data(player:get_pos()).biome - local biome_name = minetest.get_biome_name(biome_index) - local biome = minetest.registered_biomes[biome_name] - if biome then - --minetest.log("action", string.format("Biome found for number: %s in biome: %s", tostring(biome_index), biome_name)) - biomesky = biome._mcl_skycolor -- The Nether biomes seemingly don't use the sky colour, despite having this value according to the wiki. The fog colour is used for both sky and fog. - biomefog = biome._mcl_fogcolor - else - --minetest.log("action", string.format("No biome for number: %s in biome: %s", tostring(biome_index), biome_name)) - end - end + if (mcl_weather.state == "none") then + -- Clear weather + mcl_weather.set_sky_box_clear(player,biomesky,biomefog) + player:set_sun({visible = true, sunrise_visible = true}) + player:set_moon({visible = true}) + player:set_stars({visible = true}) + mcl_weather.skycolor.override_day_night_ratio(player, nil) + elseif not has_weather then + local day_color = mcl_weather.skycolor.get_sky_layer_color(0.15) + local dawn_color = mcl_weather.skycolor.get_sky_layer_color(0.27) + local night_color = mcl_weather.skycolor.get_sky_layer_color(0.1) mcl_weather.set_sky_color(player, { type = "regular", sky_color = { - day_sky = biomefog, - day_horizon = biomefog, - dawn_sky = biomefog, - dawn_horizon = biomefog, - night_sky = biomefog, - night_horizon = biomefog, - indoors = biomefog, - fog_sun_tint = biomefog, - fog_moon_tint = biomefog, - fog_tint_type = "custom" + day_sky = day_color, + day_horizon = day_color, + dawn_sky = dawn_color, + dawn_horizon = dawn_color, + night_sky = night_color, + night_horizon = night_color, }, - clouds = false, - }) - player:set_sun({visible = false , sunrise_visible = false}) - player:set_moon({visible = false}) - player:set_stars({visible = false}) - mcl_weather.skycolor.override_day_night_ratio(player, nil) - elseif dim == "void" then - player:set_sky({ type = "plain", - base_color = "#000000", - clouds = false, + clouds = true, + }) + player:set_sun({visible = false, sunrise_visible = false}) + player:set_moon({visible = false}) + player:set_stars({visible = false}) + elseif has_weather then + -- Weather skies + 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) + mcl_weather.set_sky_color(player, { + 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, + }, + clouds = true, }) player:set_sun({visible = false, sunrise_visible = false}) player:set_moon({visible = false}) player:set_stars({visible = false}) - end - end - end, - -- Returns current layer color in {r, g, b} format - get_sky_layer_color = function(timeofday) - if #mcl_weather.skycolor.layer_names == 0 then - return nil - end - - -- min timeofday value 0; max timeofday value 1. So sky color gradient range will be between 0 and 1 * mcl_weather.skycolor.max_val. - local rounded_time = math.floor(timeofday * mcl_weather.skycolor.max_val) - local color = mcl_weather.skycolor.utils.convert_to_rgb(mcl_weather.skycolor.min_val, mcl_weather.skycolor.max_val, rounded_time, mcl_weather.skycolor.retrieve_layer()) - return color - end, - - utils = { - convert_to_rgb = function(minval, maxval, current_val, colors) - local max_index = #colors - 1 - local val = (current_val-minval) / (maxval-minval) * max_index + 1.0 - local index1 = math.floor(val) - local index2 = math.min(math.floor(val)+1, max_index + 1) - local f = val - index1 - local c1 = colors[index1] - local c2 = colors[index2] - return {r=math.floor(c1.r + f*(c2.r - c1.r)), g=math.floor(c1.g + f*(c2.g-c1.g)), b=math.floor(c1.b + f*(c2.b - c1.b))} - end, - - -- Simply getter. Ether returns user given players list or get all connected players if none provided - get_players = function(players) - if players == nil or #players == 0 then - if mods_loaded then - players = minetest.get_connected_players() - elseif players == nil then - players = {} + local light_factor = mcl_weather.get_current_light_factor() + if mcl_weather.skycolor.current_layer_name() == "lightning" then + mcl_weather.skycolor.override_day_night_ratio(player, 1) + elseif light_factor then + local time = minetest.get_timeofday() + local light_multiplier = get_light_modifier(time) + local new_light = math.max(light_factor * light_multiplier, MINIMUM_LIGHT_LEVEL) + mcl_weather.skycolor.override_day_night_ratio(player, new_light) + else + mcl_weather.skycolor.override_day_night_ratio(player, nil) end end - return players - end, - - -- Returns first player sky color. I assume that all players are in same color layout. - get_current_bg_color = function() - local players = mcl_weather.skycolor.utils.get_players(nil) - if players[1] then - return players[1]:get_sky(true).sky_color + elseif dim == "end" then + local biomesky = "#000000" + local biomefog = "#A080A0" + if mg_name ~= "v6" and mg_name ~= "singlenode" then + local biome_index = minetest.get_biome_data(player:get_pos()).biome + local biome_name = minetest.get_biome_name(biome_index) + local biome = minetest.registered_biomes[biome_name] + if biome then + --minetest.log("action", string.format("Biome found for number: %s in biome: %s", tostring(biome_index), biome_name)) + biomesky = biome._mcl_skycolor + biomefog = biome._mcl_fogcolor -- The End biomes seemingly don't use the fog colour, despite having this value according to the wiki. The sky colour is seemingly used for both sky and fog? + else + --minetest.log("action", string.format("No biome for number: %s in biome: %s", tostring(biome_index), biome_name)) + end end - return nil + local t = "mcl_playerplus_end_sky.png" + player:set_sky({ type = "skybox", + base_color = biomesky, + textures = {t,t,t,t,t,t}, + clouds = false, + }) + player:set_sun({visible = false , sunrise_visible = false}) + player:set_moon({visible = false}) + player:set_stars({visible = false}) + mcl_weather.skycolor.override_day_night_ratio(player, 0.5) + elseif dim == "nether" then + local biomesky = "#6EB1FF" + local biomefog = "#330808" + if mg_name ~= "v6" and mg_name ~= "singlenode" then + local biome_index = minetest.get_biome_data(player:get_pos()).biome + local biome_name = minetest.get_biome_name(biome_index) + local biome = minetest.registered_biomes[biome_name] + if biome then + --minetest.log("action", string.format("Biome found for number: %s in biome: %s", tostring(biome_index), biome_name)) + biomesky = biome._mcl_skycolor -- The Nether biomes seemingly don't use the sky colour, despite having this value according to the wiki. The fog colour is used for both sky and fog. + biomefog = biome._mcl_fogcolor + else + --minetest.log("action", string.format("No biome for number: %s in biome: %s", tostring(biome_index), biome_name)) + end + end + mcl_weather.set_sky_color(player, { + type = "regular", + sky_color = { + day_sky = biomefog, + day_horizon = biomefog, + dawn_sky = biomefog, + dawn_horizon = biomefog, + night_sky = biomefog, + night_horizon = biomefog, + indoors = biomefog, + fog_sun_tint = biomefog, + fog_moon_tint = biomefog, + fog_tint_type = "custom" + }, + clouds = false, + }) + player:set_sun({visible = false , sunrise_visible = false}) + player:set_moon({visible = false}) + player:set_stars({visible = false}) + mcl_weather.skycolor.override_day_night_ratio(player, nil) + elseif dim == "void" then + player:set_sky({ type = "plain", + base_color = "#000000", + clouds = false, + }) + player:set_sun({visible = false, sunrise_visible = false}) + player:set_moon({visible = false}) + player:set_stars({visible = false}) end - }, + end +end -- END function skycolor.update_sky_color(players) -} +-- Returns current layer color in {r, g, b} format +function skycolor.get_sky_layer_color(timeofday) + if #mcl_weather.skycolor.layer_names == 0 then + return nil + end + + -- min timeofday value 0; max timeofday value 1. So sky color gradient range will be between 0 and 1 * mcl_weather.skycolor.max_val. + local rounded_time = math.floor(timeofday * mcl_weather.skycolor.max_val) + local color = mcl_weather.skycolor.utils.convert_to_rgb(mcl_weather.skycolor.min_val, mcl_weather.skycolor.max_val, rounded_time, mcl_weather.skycolor.retrieve_layer()) + return color +end + +function skycolor_utils.convert_to_rgb(minval, maxval, current_val, colors) + local max_index = #colors - 1 + local val = (current_val-minval) / (maxval-minval) * max_index + 1.0 + local index1 = math.floor(val) + local index2 = math.min(math.floor(val)+1, max_index + 1) + local f = val - index1 + local c1 = colors[index1] + local c2 = colors[index2] + return {r=math.floor(c1.r + f*(c2.r - c1.r)), g=math.floor(c1.g + f*(c2.g-c1.g)), b=math.floor(c1.b + f*(c2.b - c1.b))} +end + +-- Simply getter. Ether returns user given players list or get all connected players if none provided +function skycolor_utils.get_players(players) + if players == nil or #players == 0 then + if mods_loaded then + players = minetest.get_connected_players() + elseif players == nil then + players = {} + end + end + return players +end + +-- Returns first player sky color. I assume that all players are in same color layout. +function skycolor_utils.get_current_bg_color() + local players = mcl_weather.skycolor.utils.get_players(nil) + if players[1] then + return players[1]:get_sky(true).sky_color + end + return nil +end local timer = 0 minetest.register_globalstep(function(dtime) From f2a638f8e9296cddcb1a0b7007b027e383f1a9ee Mon Sep 17 00:00:00 2001 From: teknomunk Date: Mon, 27 May 2024 10:37:42 +0000 Subject: [PATCH 02/23] Fix random crash in darkness effect in mcl_potions, finish refactoring of mcl_weather.skycolor that also makes darkness effect more reliable --- mods/ENVIRONMENT/mcl_weather/skycolor.lua | 453 +++++++++++++--------- mods/ITEMS/mcl_mobitems/init.lua | 1 + mods/ITEMS/mcl_potions/functions.lua | 2 +- 3 files changed, 261 insertions(+), 195 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor.lua b/mods/ENVIRONMENT/mcl_weather/skycolor.lua index bc8c4d8f7..5e1214e8c 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor.lua @@ -124,33 +124,16 @@ end -- Wrapper for updating day/night ratio that respects night vision function skycolor.override_day_night_ratio(player, ratio) - local meta = player:get_meta() - local has_night_vision = meta:get_int("night_vision") == 1 - local has_darkness = meta:get_int("darkness") == 1 - local is_visited_shepherd = meta:get_int("mcl_shepherd:special") == 1 - local arg - if has_darkness and not is_visited_shepherd then - if has_night_vision then arg = 0.1 - else arg = 0 end - else - -- Apply night vision only for dark sky - local is_dark = minetest.get_timeofday() > 0.8 or minetest.get_timeofday() < 0.2 or mcl_weather.state ~= "none" - local pos = player:get_pos() - local dim = mcl_worlds.pos_to_dimension(pos) - if (has_night_vision or is_visited_shepherd) and is_dark and dim ~= "nether" and dim ~= "end" then - if ratio == nil then - arg = NIGHT_VISION_RATIO - else - arg = math.max(ratio, NIGHT_VISION_RATIO) - end - else - arg = ratio - end - end - player:override_day_night_ratio(arg) + player._skycolor_day_night_ratio = ratio + skycolor.update_player_sky_color(player) + player._skycolor_day_night_ratio = nil end -function water_sky(player) + + + + +function water_sky(player, sky_data) local pos = player:get_pos() local water_color = DEFAULT_WATER_COLOR @@ -165,183 +148,265 @@ function water_sky(player) if checkname == "mclx_core:river_water_source" or checkname == "mclx_core:river_water_flowing" then water_color = "#0084FF" end - return { - sky = { type = "regular", - sky_color = { - day_sky = water_color, - day_horizon = water_color, - dawn_sky = water_color, - dawn_horizon = water_color, - night_sky = water_color, - night_horizon = water_color, - indoors = water_color, - fog_sun_tint = water_color, - fog_moon_tint = water_color, - fog_tint_type = "custom" - }, - clouds = false, - } + sky_data.sky = { type = "regular", + sky_color = { + day_sky = water_color, + day_horizon = water_color, + dawn_sky = water_color, + dawn_horizon = water_color, + night_sky = water_color, + night_horizon = water_color, + indoors = water_color, + fog_sun_tint = water_color, + fog_moon_tint = water_color, + fog_tint_type = "custom" + }, + clouds = false, } end + + + + +local dimension_handlers = {} +function dimension_handlers.overworld(player, sky_data) + local pos = player:get_pos() + local has_weather = (mcl_worlds.has_weather(pos) and (mcl_weather.state == "snow" or mcl_weather.state =="rain" or mcl_weather.state == "thunder") and mcl_weather.has_snow(pos)) or ((mcl_weather.state =="rain" or mcl_weather.state == "thunder") and mcl_weather.has_rain(pos)) + + local biomesky + local biomefog + if mg_name ~= "v6" and mg_name ~= "singlenode" then + local biome_index = minetest.get_biome_data(player:get_pos()).biome + local biome_name = minetest.get_biome_name(biome_index) + local biome = minetest.registered_biomes[biome_name] + if biome then + --minetest.log("action", string.format("Biome found for number: %s in biome: %s", tostring(biome_index), biome_name)) + biomesky = biome._mcl_skycolor + biomefog = biome._mcl_fogcolor + else + --minetest.log("action", string.format("No biome for number: %s in biome: %s", tostring(biome_index), biome_name)) + end + end + if (mcl_weather.state == "none") then + -- Clear weather + mcl_weather.set_sky_box_clear(player,biomesky,biomefog) + sky_data.sun = {visible = true, sunrise_visible = true} + sky_data.moon = {visible = true} + sky_data.stars = {visible = true} + elseif not has_weather then + local day_color = mcl_weather.skycolor.get_sky_layer_color(0.15) + 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 = { + 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, + }, + clouds = true, + } + sky_data.sun = {visible = false, sunrise_visible = false} + sky_data.moon = {visible = false} + sky_data.stars = {visible = false} + elseif has_weather then + -- Weather skies + 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, + day_horizon = day_color, + dawn_sky = dawn_color, + dawn_horizon = dawn_color, + night_sky = night_color, + night_horizon = night_color, + }, + clouds = true, + } + sky_data.sun = {visible = false, sunrise_visible = false} + sky_data.moon = {visible = false} + sky_data.stars = {visible = false} + + local light_factor = mcl_weather.get_current_light_factor() + if mcl_weather.skycolor.current_layer_name() == "lightning" then + sky_data.day_night_ratio = 1 + elseif light_factor then + local time = minetest.get_timeofday() + local light_multiplier = get_light_modifier(time) + local new_light = math.max(light_factor * light_multiplier, MINIMUM_LIGHT_LEVEL) + sky_data.day_night_ratio = new_light + end + end +end +dimension_handlers["end"] = function(player, sky_data) + local biomesky = "#000000" + local biomefog = "#A080A0" + if mg_name ~= "v6" and mg_name ~= "singlenode" then + local biome_index = minetest.get_biome_data(player:get_pos()).biome + local biome_name = minetest.get_biome_name(biome_index) + local biome = minetest.registered_biomes[biome_name] + if biome then + --minetest.log("action", string.format("Biome found for number: %s in biome: %s", tostring(biome_index), biome_name)) + biomesky = biome._mcl_skycolor + biomefog = biome._mcl_fogcolor -- The End biomes seemingly don't use the fog colour, despite having this value according to the wiki. The sky colour is seemingly used for both sky and fog? + else + --minetest.log("action", string.format("No biome for number: %s in biome: %s", tostring(biome_index), biome_name)) + end + end + local t = "mcl_playerplus_end_sky.png" + sky_data.sky = { type = "skybox", + base_color = biomesky, + textures = {t,t,t,t,t,t}, + clouds = false, + } + sky_data.sun = {visible = false , sunrise_visible = false} + sky_data.moon = {visible = false} + sky_data.stars = {visible = false} + sky_data.day_night_ratio = 0.5 +end +function dimension_handlers.nether(player, sky_data) + local biomesky = "#6EB1FF" + local biomefog = "#330808" + if mg_name ~= "v6" and mg_name ~= "singlenode" then + local biome_index = minetest.get_biome_data(player:get_pos()).biome + local biome_name = minetest.get_biome_name(biome_index) + local biome = minetest.registered_biomes[biome_name] + if biome then + --minetest.log("action", string.format("Biome found for number: %s in biome: %s", tostring(biome_index), biome_name)) + biomesky = biome._mcl_skycolor -- The Nether biomes seemingly don't use the sky colour, despite having this value according to the wiki. The fog colour is used for both sky and fog. + biomefog = biome._mcl_fogcolor + else + --minetest.log("action", string.format("No biome for number: %s in biome: %s", tostring(biome_index), biome_name)) + end + end + sky_data.sky = { + type = "regular", + sky_color = { + day_sky = biomefog, + day_horizon = biomefog, + dawn_sky = biomefog, + dawn_horizon = biomefog, + night_sky = biomefog, + night_horizon = biomefog, + indoors = biomefog, + fog_sun_tint = biomefog, + fog_moon_tint = biomefog, + fog_tint_type = "custom" + }, + clouds = false, + } + sky_data.sun = {visible = false , sunrise_visible = false} + sky_data.moon = {visible = false} + sky_data.stars = {visible = false} +end +function dimension_handlers.void(player, sky_data) + sky_data.sky = { type = "plain", + base_color = "#000000", + clouds = false, + } + sky_data.sun = {visible = false, sunrise_visible = false} + sky_data.moon = {visible = false} + sky_data.stars = {visible = false} +end + +function dimension(player, sky_data) + local pos = player:get_pos() + local dim = mcl_worlds.pos_to_dimension(pos) + + local handler = dimension_handlers[dim] + if handler then return handler(player, sky_data) end +end + + + + + +local effects_handlers = {} +function effects_handlers.darkness(player, meta, effect, sky_data) + -- No darkness effect if visited by shepherd + if meta:get_int("mcl_shepherd:special") == 1 then return end + + -- High stars + sky_data.stars = {visible = false} + + -- Minor visibility if the player has the night vision effect + if mcl_potions.has_effect(player, "night_vision") then + sky_data.day_night_ratio = 0.1 + else + sky_data.day_night_ratio = 0 + end +end +local DIM_ALLOW_NIGHT_VISION = { + overworld = true, + void = true, +} +function effects_handlers.night_vision(player, meta, effect, sky_data) + -- Apply night vision only for dark sky + if not (minetest.get_timeofday() > 0.8 or minetest.get_timeofday() < 0.2 or mcl_weather.state ~= "none") then return end + + -- Only some dimensions allow night vision + local pos = player:get_pos() + local dim = mcl_worlds.pos_to_dimension(pos) + if not DIM_ALLOW_NIGHT_VISION[dim] then return end + + -- Apply night vision + sky_data.day_night_ratio = math.max(sky_data.day_night_ratio or 0, NIGHT_VISION_RATIO) +end +local has_mcl_potions = false +local function effects(player, sky_data) + if not has_mcl_potions then + if not minetest.get_modpath("mcl_potions") then return end + has_mcl_potions = true + end + + local meta = player:get_meta() + for name,effect in pairs(mcl_potions.registered_effects) do + local effect_data = mcl_potions.get_effect(player, name) + if effect_data then + local hook = effect.mcl_weather_skycolor or effects_handlers[name] + if hook then hook(player, meta, effect_data, sky_data) end + end + end + + -- Handle night vision for shepheard + if meta:get_int("mcl_shepherd:special") == 1 then + return effects_handlers.night_vision(player, meta, {}, sky_data) + end +end + + + + +function skycolor.update_player_sky_color(player) + local sky_data = { + day_night_ratio = player._skycolor_day_night_ratio + } + + water_sky(player, sky_data) + dimension(player, sky_data) + effects(player, sky_data) + + if sky_data.sky then player:set_sky(sky_data.sky) end + if sky_data.sun then player:set_sun(sky_data.sun) end + if sky_data.moon then player:set_moon(sky_data.moon) end + if sky_data.stars then player:set_stars(sky_data.stars) end + player:override_day_night_ratio(sky_data.day_night_ratio) +end + -- Update sky color. If players not specified update sky for all players. function skycolor.update_sky_color(players) -- Override day/night ratio as well players = mcl_weather.skycolor.utils.get_players(players) + local update = skycolor.update_player_sky_color for _, player in ipairs(players) do - - local pos = player:get_pos() - local dim = mcl_worlds.pos_to_dimension(pos) - local has_weather = (mcl_worlds.has_weather(pos) and (mcl_weather.state == "snow" or mcl_weather.state =="rain" or mcl_weather.state == "thunder") and mcl_weather.has_snow(pos)) or ((mcl_weather.state =="rain" or mcl_weather.state == "thunder") and mcl_weather.has_rain(pos)) - - local res = water_sky(player) - if res and res.sky then - player:set_sky(res.sky) - end - - if dim == "overworld" then - local biomesky - local biomefog - if mg_name ~= "v6" and mg_name ~= "singlenode" then - local biome_index = minetest.get_biome_data(player:get_pos()).biome - local biome_name = minetest.get_biome_name(biome_index) - local biome = minetest.registered_biomes[biome_name] - if biome then - --minetest.log("action", string.format("Biome found for number: %s in biome: %s", tostring(biome_index), biome_name)) - biomesky = biome._mcl_skycolor - biomefog = biome._mcl_fogcolor - else - --minetest.log("action", string.format("No biome for number: %s in biome: %s", tostring(biome_index), biome_name)) - end - end - if (mcl_weather.state == "none") then - -- Clear weather - mcl_weather.set_sky_box_clear(player,biomesky,biomefog) - player:set_sun({visible = true, sunrise_visible = true}) - player:set_moon({visible = true}) - player:set_stars({visible = true}) - mcl_weather.skycolor.override_day_night_ratio(player, nil) - elseif not has_weather then - local day_color = mcl_weather.skycolor.get_sky_layer_color(0.15) - local dawn_color = mcl_weather.skycolor.get_sky_layer_color(0.27) - local night_color = mcl_weather.skycolor.get_sky_layer_color(0.1) - mcl_weather.set_sky_color(player, { - 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, - }, - clouds = true, - }) - player:set_sun({visible = false, sunrise_visible = false}) - player:set_moon({visible = false}) - player:set_stars({visible = false}) - elseif has_weather then - -- Weather skies - 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) - mcl_weather.set_sky_color(player, { - 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, - }, - clouds = true, - }) - player:set_sun({visible = false, sunrise_visible = false}) - player:set_moon({visible = false}) - player:set_stars({visible = false}) - - local light_factor = mcl_weather.get_current_light_factor() - if mcl_weather.skycolor.current_layer_name() == "lightning" then - mcl_weather.skycolor.override_day_night_ratio(player, 1) - elseif light_factor then - local time = minetest.get_timeofday() - local light_multiplier = get_light_modifier(time) - local new_light = math.max(light_factor * light_multiplier, MINIMUM_LIGHT_LEVEL) - mcl_weather.skycolor.override_day_night_ratio(player, new_light) - else - mcl_weather.skycolor.override_day_night_ratio(player, nil) - end - end - elseif dim == "end" then - local biomesky = "#000000" - local biomefog = "#A080A0" - if mg_name ~= "v6" and mg_name ~= "singlenode" then - local biome_index = minetest.get_biome_data(player:get_pos()).biome - local biome_name = minetest.get_biome_name(biome_index) - local biome = minetest.registered_biomes[biome_name] - if biome then - --minetest.log("action", string.format("Biome found for number: %s in biome: %s", tostring(biome_index), biome_name)) - biomesky = biome._mcl_skycolor - biomefog = biome._mcl_fogcolor -- The End biomes seemingly don't use the fog colour, despite having this value according to the wiki. The sky colour is seemingly used for both sky and fog? - else - --minetest.log("action", string.format("No biome for number: %s in biome: %s", tostring(biome_index), biome_name)) - end - end - local t = "mcl_playerplus_end_sky.png" - player:set_sky({ type = "skybox", - base_color = biomesky, - textures = {t,t,t,t,t,t}, - clouds = false, - }) - player:set_sun({visible = false , sunrise_visible = false}) - player:set_moon({visible = false}) - player:set_stars({visible = false}) - mcl_weather.skycolor.override_day_night_ratio(player, 0.5) - elseif dim == "nether" then - local biomesky = "#6EB1FF" - local biomefog = "#330808" - if mg_name ~= "v6" and mg_name ~= "singlenode" then - local biome_index = minetest.get_biome_data(player:get_pos()).biome - local biome_name = minetest.get_biome_name(biome_index) - local biome = minetest.registered_biomes[biome_name] - if biome then - --minetest.log("action", string.format("Biome found for number: %s in biome: %s", tostring(biome_index), biome_name)) - biomesky = biome._mcl_skycolor -- The Nether biomes seemingly don't use the sky colour, despite having this value according to the wiki. The fog colour is used for both sky and fog. - biomefog = biome._mcl_fogcolor - else - --minetest.log("action", string.format("No biome for number: %s in biome: %s", tostring(biome_index), biome_name)) - end - end - mcl_weather.set_sky_color(player, { - type = "regular", - sky_color = { - day_sky = biomefog, - day_horizon = biomefog, - dawn_sky = biomefog, - dawn_horizon = biomefog, - night_sky = biomefog, - night_horizon = biomefog, - indoors = biomefog, - fog_sun_tint = biomefog, - fog_moon_tint = biomefog, - fog_tint_type = "custom" - }, - clouds = false, - }) - player:set_sun({visible = false , sunrise_visible = false}) - player:set_moon({visible = false}) - player:set_stars({visible = false}) - mcl_weather.skycolor.override_day_night_ratio(player, nil) - elseif dim == "void" then - player:set_sky({ type = "plain", - base_color = "#000000", - clouds = false, - }) - player:set_sun({visible = false, sunrise_visible = false}) - player:set_moon({visible = false}) - player:set_stars({visible = false}) - end + update(player) end end -- END function skycolor.update_sky_color(players) diff --git a/mods/ITEMS/mcl_mobitems/init.lua b/mods/ITEMS/mcl_mobitems/init.lua index 4d92c2d43..a3155b13c 100644 --- a/mods/ITEMS/mcl_mobitems/init.lua +++ b/mods/ITEMS/mcl_mobitems/init.lua @@ -155,6 +155,7 @@ local function drink_milk_delayed(itemstack, player, pointed_thing) mcl_hunger.stop_poison(player) end mcl_potions._reset_effects(player) + mcl_weather.skycolor.update_player_sky_color(player) end -- Wrapper for handling mcl_hunger delayed eating diff --git a/mods/ITEMS/mcl_potions/functions.lua b/mods/ITEMS/mcl_potions/functions.lua index b59749d2a..b3aa232ba 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -492,7 +492,7 @@ mcl_potions.register_effect({ end, on_step = function(dtime, object, factor, duration) if object:get_meta():get_int("night_vision") ~= 1 then - local flash = EF.darkness[object].flash + local flash = EF.darkness[object].flash or 0 if flash < 0.2 then EF.darkness[object].flashdir = true elseif flash > 0.6 then EF.darkness[object].flashdir = false end flash = EF.darkness[object].flashdir and (flash + dtime) or (flash - dtime) From 820848fb2ee87f7d5717e8d0903d04acc8b2dd82 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 12 Jun 2024 20:07:32 -0500 Subject: [PATCH 03/23] Address review comments --- mods/ENVIRONMENT/mcl_weather/mod.conf | 2 +- mods/ENVIRONMENT/mcl_weather/skycolor.lua | 329 +++--------------- .../mcl_weather/skycolor/dimensions.lua | 190 ++++++++++ .../mcl_weather/skycolor/effects.lua | 57 +++ .../mcl_weather/skycolor/water.lua | 36 ++ 5 files changed, 323 insertions(+), 291 deletions(-) create mode 100644 mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua create mode 100644 mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua create mode 100644 mods/ENVIRONMENT/mcl_weather/skycolor/water.lua diff --git a/mods/ENVIRONMENT/mcl_weather/mod.conf b/mods/ENVIRONMENT/mcl_weather/mod.conf index 4f1102b7a..52c4ae7aa 100644 --- a/mods/ENVIRONMENT/mcl_weather/mod.conf +++ b/mods/ENVIRONMENT/mcl_weather/mod.conf @@ -1,5 +1,5 @@ name = mcl_weather author = xeranas description = Weather and sky handling: Rain, snow, thunderstorm, End and Nether ambience -depends = mcl_init, mcl_worlds +depends = mcl_init, mcl_worlds, mcl_playerinfo optional_depends = lightning diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor.lua b/mods/ENVIRONMENT/mcl_weather/skycolor.lua index 5e1214e8c..fcafe531c 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor.lua @@ -1,16 +1,16 @@ -- Constants +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) +local mod = mcl_weather local NIGHT_VISION_RATIO = 0.45 -local MINIMUM_LIGHT_LEVEL = 0.2 -local DEFAULT_WATER_COLOR = "#3F76E4" -- Module state local mods_loaded = false -local water_color = DEFAULT_WATER_COLOR local mg_name = minetest.get_mapgen_setting("mg_name") function mcl_weather.set_sky_box_clear(player, sky, fog) local pos = player:get_pos() - if minetest.get_item_group(minetest.get_node(vector.new(pos.x,pos.y+1.5,pos.z)).name, "water") ~= 0 then return end + if minetest.get_item_group( mcl_playerinfo[player:get_player_name()].node_head, "water") ~= 0 then return end local sc = { day_sky = "#7BA4FF", day_horizon = "#C0D8FF", @@ -48,24 +48,6 @@ function mcl_weather.set_sky_color(player, def) }) 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 - local skycolor = { -- Should be activated before do any effect. active = true, @@ -94,7 +76,7 @@ local skycolor = { mcl_weather.skycolor = skycolor local skycolor_utils = skycolor.utils --- To layer to colors table +-- Add layer to colors table function skycolor.add_layer(layer_name, layer_color, instant_update) mcl_weather.skycolor.colors[layer_name] = layer_color table.insert(mcl_weather.skycolor.layer_names, layer_name) @@ -129,269 +111,21 @@ function skycolor.override_day_night_ratio(player, ratio) player._skycolor_day_night_ratio = nil end +local skycolor_filters = {} +skycolor.filters = skycolor_filters +dofile(modpath.."/skycolor/water.lua") +dofile(modpath.."/skycolor/dimensions.lua") +dofile(modpath.."/skycolor/effects.lua") - - - -function water_sky(player, sky_data) - local pos = player:get_pos() - local water_color = DEFAULT_WATER_COLOR - - local checkname = minetest.get_node(vector.new(pos.x,pos.y+1.5,pos.z)).name - if minetest.get_item_group(checkname, "water") == 0 then return end - - local biome_index = minetest.get_biome_data(player:get_pos()).biome - local biome_name = minetest.get_biome_name(biome_index) - local biome = minetest.registered_biomes[biome_name] - if biome then water_color = biome._mcl_waterfogcolor end - if not biome then water_color = "#3F76E4" end - - if checkname == "mclx_core:river_water_source" or checkname == "mclx_core:river_water_flowing" then water_color = "#0084FF" end - - sky_data.sky = { type = "regular", - sky_color = { - day_sky = water_color, - day_horizon = water_color, - dawn_sky = water_color, - dawn_horizon = water_color, - night_sky = water_color, - night_horizon = water_color, - indoors = water_color, - fog_sun_tint = water_color, - fog_moon_tint = water_color, - fog_tint_type = "custom" - }, - clouds = false, - } -end - - - - - -local dimension_handlers = {} -function dimension_handlers.overworld(player, sky_data) - local pos = player:get_pos() - local has_weather = (mcl_worlds.has_weather(pos) and (mcl_weather.state == "snow" or mcl_weather.state =="rain" or mcl_weather.state == "thunder") and mcl_weather.has_snow(pos)) or ((mcl_weather.state =="rain" or mcl_weather.state == "thunder") and mcl_weather.has_rain(pos)) - - local biomesky - local biomefog - if mg_name ~= "v6" and mg_name ~= "singlenode" then - local biome_index = minetest.get_biome_data(player:get_pos()).biome - local biome_name = minetest.get_biome_name(biome_index) - local biome = minetest.registered_biomes[biome_name] - if biome then - --minetest.log("action", string.format("Biome found for number: %s in biome: %s", tostring(biome_index), biome_name)) - biomesky = biome._mcl_skycolor - biomefog = biome._mcl_fogcolor - else - --minetest.log("action", string.format("No biome for number: %s in biome: %s", tostring(biome_index), biome_name)) - end - end - if (mcl_weather.state == "none") then - -- Clear weather - mcl_weather.set_sky_box_clear(player,biomesky,biomefog) - sky_data.sun = {visible = true, sunrise_visible = true} - sky_data.moon = {visible = true} - sky_data.stars = {visible = true} - elseif not has_weather then - local day_color = mcl_weather.skycolor.get_sky_layer_color(0.15) - 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 = { - 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, - }, - clouds = true, - } - sky_data.sun = {visible = false, sunrise_visible = false} - sky_data.moon = {visible = false} - sky_data.stars = {visible = false} - elseif has_weather then - -- Weather skies - 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, - day_horizon = day_color, - dawn_sky = dawn_color, - dawn_horizon = dawn_color, - night_sky = night_color, - night_horizon = night_color, - }, - clouds = true, - } - sky_data.sun = {visible = false, sunrise_visible = false} - sky_data.moon = {visible = false} - sky_data.stars = {visible = false} - - local light_factor = mcl_weather.get_current_light_factor() - if mcl_weather.skycolor.current_layer_name() == "lightning" then - sky_data.day_night_ratio = 1 - elseif light_factor then - local time = minetest.get_timeofday() - local light_multiplier = get_light_modifier(time) - local new_light = math.max(light_factor * light_multiplier, MINIMUM_LIGHT_LEVEL) - sky_data.day_night_ratio = new_light - end - end -end -dimension_handlers["end"] = function(player, sky_data) - local biomesky = "#000000" - local biomefog = "#A080A0" - if mg_name ~= "v6" and mg_name ~= "singlenode" then - local biome_index = minetest.get_biome_data(player:get_pos()).biome - local biome_name = minetest.get_biome_name(biome_index) - local biome = minetest.registered_biomes[biome_name] - if biome then - --minetest.log("action", string.format("Biome found for number: %s in biome: %s", tostring(biome_index), biome_name)) - biomesky = biome._mcl_skycolor - biomefog = biome._mcl_fogcolor -- The End biomes seemingly don't use the fog colour, despite having this value according to the wiki. The sky colour is seemingly used for both sky and fog? - else - --minetest.log("action", string.format("No biome for number: %s in biome: %s", tostring(biome_index), biome_name)) - end - end - local t = "mcl_playerplus_end_sky.png" - sky_data.sky = { type = "skybox", - base_color = biomesky, - textures = {t,t,t,t,t,t}, - clouds = false, - } - sky_data.sun = {visible = false , sunrise_visible = false} - sky_data.moon = {visible = false} - sky_data.stars = {visible = false} - sky_data.day_night_ratio = 0.5 -end -function dimension_handlers.nether(player, sky_data) - local biomesky = "#6EB1FF" - local biomefog = "#330808" - if mg_name ~= "v6" and mg_name ~= "singlenode" then - local biome_index = minetest.get_biome_data(player:get_pos()).biome - local biome_name = minetest.get_biome_name(biome_index) - local biome = minetest.registered_biomes[biome_name] - if biome then - --minetest.log("action", string.format("Biome found for number: %s in biome: %s", tostring(biome_index), biome_name)) - biomesky = biome._mcl_skycolor -- The Nether biomes seemingly don't use the sky colour, despite having this value according to the wiki. The fog colour is used for both sky and fog. - biomefog = biome._mcl_fogcolor - else - --minetest.log("action", string.format("No biome for number: %s in biome: %s", tostring(biome_index), biome_name)) - end - end - sky_data.sky = { - type = "regular", - sky_color = { - day_sky = biomefog, - day_horizon = biomefog, - dawn_sky = biomefog, - dawn_horizon = biomefog, - night_sky = biomefog, - night_horizon = biomefog, - indoors = biomefog, - fog_sun_tint = biomefog, - fog_moon_tint = biomefog, - fog_tint_type = "custom" - }, - clouds = false, - } - sky_data.sun = {visible = false , sunrise_visible = false} - sky_data.moon = {visible = false} - sky_data.stars = {visible = false} -end -function dimension_handlers.void(player, sky_data) - sky_data.sky = { type = "plain", - base_color = "#000000", - clouds = false, - } - sky_data.sun = {visible = false, sunrise_visible = false} - sky_data.moon = {visible = false} - sky_data.stars = {visible = false} -end - -function dimension(player, sky_data) - local pos = player:get_pos() - local dim = mcl_worlds.pos_to_dimension(pos) - - local handler = dimension_handlers[dim] - if handler then return handler(player, sky_data) end -end - - - - - -local effects_handlers = {} -function effects_handlers.darkness(player, meta, effect, sky_data) - -- No darkness effect if visited by shepherd - if meta:get_int("mcl_shepherd:special") == 1 then return end - - -- High stars - sky_data.stars = {visible = false} - - -- Minor visibility if the player has the night vision effect - if mcl_potions.has_effect(player, "night_vision") then - sky_data.day_night_ratio = 0.1 - else - sky_data.day_night_ratio = 0 - end -end -local DIM_ALLOW_NIGHT_VISION = { - overworld = true, - void = true, -} -function effects_handlers.night_vision(player, meta, effect, sky_data) - -- Apply night vision only for dark sky - if not (minetest.get_timeofday() > 0.8 or minetest.get_timeofday() < 0.2 or mcl_weather.state ~= "none") then return end - - -- Only some dimensions allow night vision - local pos = player:get_pos() - local dim = mcl_worlds.pos_to_dimension(pos) - if not DIM_ALLOW_NIGHT_VISION[dim] then return end - - -- Apply night vision - sky_data.day_night_ratio = math.max(sky_data.day_night_ratio or 0, NIGHT_VISION_RATIO) -end -local has_mcl_potions = false -local function effects(player, sky_data) - if not has_mcl_potions then - if not minetest.get_modpath("mcl_potions") then return end - has_mcl_potions = true - end - - local meta = player:get_meta() - for name,effect in pairs(mcl_potions.registered_effects) do - local effect_data = mcl_potions.get_effect(player, name) - if effect_data then - local hook = effect.mcl_weather_skycolor or effects_handlers[name] - if hook then hook(player, meta, effect_data, sky_data) end - end - end - - -- Handle night vision for shepheard - if meta:get_int("mcl_shepherd:special") == 1 then - return effects_handlers.night_vision(player, meta, {}, sky_data) - end -end - - - - +local water_sky = skycolor.water_sky function skycolor.update_player_sky_color(player) local sky_data = { day_night_ratio = player._skycolor_day_night_ratio } - water_sky(player, sky_data) - dimension(player, sky_data) - effects(player, sky_data) + for i = 1,#skycolor_filters do + skycolor_filters[i](player, sky_data) + end if sky_data.sky then player:set_sky(sky_data.sky) end if sky_data.sun then player:set_sun(sky_data.sun) end @@ -423,17 +157,32 @@ function skycolor.get_sky_layer_color(timeofday) end function skycolor_utils.convert_to_rgb(minval, maxval, current_val, colors) - local max_index = #colors - 1 - local val = (current_val-minval) / (maxval-minval) * max_index + 1.0 - local index1 = math.floor(val) - local index2 = math.min(math.floor(val)+1, max_index + 1) - local f = val - index1 - local c1 = colors[index1] - local c2 = colors[index2] - return {r=math.floor(c1.r + f*(c2.r - c1.r)), g=math.floor(c1.g + f*(c2.g-c1.g)), b=math.floor(c1.b + f*(c2.b - c1.b))} + -- Clamp current_val to valid range + current_val = math.min(minval, current_val) + current_val = math.max(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 + + -- Get the first color's values + local index1 = math.floor(scaled_value) + local color1 = colors[index1] + local frac1 = 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) + local frac2 = 1.0 - fraction1 + local color2 = colors[index2] + + -- Interpolate between color1 and color2 + return { + 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), + } end --- Simply getter. Ether returns user given players list or get all connected players if none provided +-- Simple getter. Either returns user given players list or get all connected players if none provided function skycolor_utils.get_players(players) if players == nil or #players == 0 then if mods_loaded then @@ -445,7 +194,7 @@ function skycolor_utils.get_players(players) return players end --- Returns first player sky color. I assume that all players are in same color layout. +-- Returns the sky color of the first player, which is done assuming that all players are in same color layout. function skycolor_utils.get_current_bg_color() local players = mcl_weather.skycolor.utils.get_players(nil) if players[1] then diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua new file mode 100644 index 000000000..6b481badc --- /dev/null +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua @@ -0,0 +1,190 @@ +local MINIMUM_LIGHT_LEVEL = 0.2 +local VALID_SNOW_WEATHER_STATES = { snow = true, rain = true, thunder = true } +local VALID_RAIN_WEATHER_STATES = { rain = true, thunder = true } + +local dimension_handlers = {} +mcl_weather.skycolor.dimension_handlers = dimension_handlers + +-- 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 + +function dimension_handlers.overworld(player, sky_data) + local pos = player:get_pos() + + local biomesky + local biomefog + if mg_name ~= "v6" and mg_name ~= "singlenode" then + local biome_index = minetest.get_biome_data(player:get_pos()).biome + local biome_name = minetest.get_biome_name(biome_index) + local biome = minetest.registered_biomes[biome_name] + if biome then + --minetest.log("action", string.format("Biome found for number: %s in biome: %s", tostring(biome_index), biome_name)) + biomesky = biome._mcl_skycolor + biomefog = biome._mcl_fogcolor + else + --minetest.log("action", string.format("No biome for number: %s in biome: %s", tostring(biome_index), biome_name)) + end + end + + if mcl_weather.state == "none" then + -- Clear weather + mcl_weather.set_sky_box_clear(player,biomesky,biomefog) + sky_data.sun = {visible = true, sunrise_visible = true} + sky_data.moon = {visible = true} + sky_data.stars = {visible = true} + return + end + + -- Check if we currently have weather that affects the sky color + local has_weather = mcl_worlds.has_weather(pos) and ( + mcl_weather.has_snow(pos) and VALID_SNOW_WEATHER_STATES[mcl_weather.state] or + mcl_weather.has_rain(pos) and VALID_RAIN_WEATHER_STATES[mcl_weather.state] + ) + if has_weather then + -- Weather skies + 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, + day_horizon = day_color, + dawn_sky = dawn_color, + dawn_horizon = dawn_color, + night_sky = night_color, + night_horizon = night_color, + }, + clouds = true, + } + sky_data.sun = {visible = false, sunrise_visible = false} + sky_data.moon = {visible = false} + sky_data.stars = {visible = false} + + local light_factor = mcl_weather.get_current_light_factor() + if mcl_weather.skycolor.current_layer_name() == "lightning" then + sky_data.day_night_ratio = 1 + elseif light_factor then + local time = minetest.get_timeofday() + local light_multiplier = get_light_modifier(time) + local new_light = math.max(light_factor * light_multiplier, MINIMUM_LIGHT_LEVEL) + sky_data.day_night_ratio = new_light + end + return + end + + -- No weather that affects the sky color, use default values + local day_color = mcl_weather.skycolor.get_sky_layer_color(0.15) + 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 = { + 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, + }, + clouds = true, + } + sky_data.sun = {visible = false, sunrise_visible = false} + sky_data.moon = {visible = false} + sky_data.stars = {visible = false} +end + +-- This can't be function dimension_handlers.end() due to lua syntax +dimension_handlers["end"] = function(player, sky_data) + local biomesky = "#000000" + local biomefog = "#A080A0" + if mg_name ~= "v6" and mg_name ~= "singlenode" then + local biome_index = minetest.get_biome_data(player:get_pos()).biome + local biome_name = minetest.get_biome_name(biome_index) + local biome = minetest.registered_biomes[biome_name] + if biome then + biomesky = biome._mcl_skycolor + biomefog = biome._mcl_fogcolor -- The End biomes seemingly don't use the fog colour, despite having this value according to the wiki. The sky colour is seemingly used for both sky and fog? + end + end + local t = "mcl_playerplus_end_sky.png" + sky_data.sky = { type = "skybox", + base_color = biomesky, + textures = {t,t,t,t,t,t}, + clouds = false, + } + sky_data.sun = {visible = false , sunrise_visible = false} + sky_data.moon = {visible = false} + sky_data.stars = {visible = false} + sky_data.day_night_ratio = 0.5 +end + +function dimension_handlers.nether(player, sky_data) + local biomesky = "#6EB1FF" + local biomefog = "#330808" + if mg_name ~= "v6" and mg_name ~= "singlenode" then + local biome_index = minetest.get_biome_data(player:get_pos()).biome + local biome_name = minetest.get_biome_name(biome_index) + local biome = minetest.registered_biomes[biome_name] + if biome then + -- The Nether biomes seemingly don't use the sky colour, despite having this value according to the wiki. + -- The fog colour is used for both sky and fog. + biomesky = biome._mcl_skycolor + biomefog = biome._mcl_fogcolor + end + end + sky_data.sky = { + type = "regular", + sky_color = { + day_sky = biomefog, + day_horizon = biomefog, + dawn_sky = biomefog, + dawn_horizon = biomefog, + night_sky = biomefog, + night_horizon = biomefog, + indoors = biomefog, + fog_sun_tint = biomefog, + fog_moon_tint = biomefog, + fog_tint_type = "custom" + }, + clouds = false, + } + sky_data.sun = {visible = false , sunrise_visible = false} + sky_data.moon = {visible = false} + sky_data.stars = {visible = false} +end + +function dimension_handlers.void(player, sky_data) + sky_data.sky = { type = "plain", + base_color = "#000000", + clouds = false, + } + sky_data.sun = {visible = false, sunrise_visible = false} + sky_data.moon = {visible = false} + sky_data.stars = {visible = false} +end + +local function dimension(player, sky_data) + local pos = player:get_pos() + local dim = mcl_worlds.pos_to_dimension(pos) + + local handler = dimension_handlers[dim] + if handler then return handler(player, sky_data) end +end +table.insert(mcl_weather.skycolor.filters, dimension) + diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua new file mode 100644 index 000000000..c0a349410 --- /dev/null +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua @@ -0,0 +1,57 @@ +local DIM_ALLOW_NIGHT_VISION = { + overworld = true, + void = true, +} + +local effects_handlers = {} +local has_mcl_potions = false + +function effects_handlers.darkness(player, meta, effect, sky_data) + -- No darkness effect if visited by shepherd + if meta:get_int("mcl_shepherd:special") == 1 then return end + + -- High stars + sky_data.stars = {visible = false} + + -- Minor visibility if the player has the night vision effect + if mcl_potions.has_effect(player, "night_vision") then + sky_data.day_night_ratio = 0.1 + else + sky_data.day_night_ratio = 0 + end +end +function effects_handlers.night_vision(player, meta, effect, sky_data) + -- Apply night vision only for dark sky + if not (minetest.get_timeofday() > 0.8 or minetest.get_timeofday() < 0.2 or mcl_weather.state ~= "none") then return end + + -- Only some dimensions allow night vision + local pos = player:get_pos() + local dim = mcl_worlds.pos_to_dimension(pos) + if not DIM_ALLOW_NIGHT_VISION[dim] then return end + + -- Apply night vision + sky_data.day_night_ratio = math.max(sky_data.day_night_ratio or 0, NIGHT_VISION_RATIO) +end + +local function effects(player, sky_data) + if not has_mcl_potions then + if not minetest.get_modpath("mcl_potions") then return end + has_mcl_potions = true + end + + local meta = player:get_meta() + for name,effect in pairs(mcl_potions.registered_effects) do + local effect_data = mcl_potions.get_effect(player, name) + if effect_data then + local hook = effect.mcl_weather_skycolor or effects_handlers[name] + if hook then hook(player, meta, effect_data, sky_data) end + end + end + + -- Handle night vision for shepherd + if meta:get_int("mcl_shepherd:special") == 1 then + return effects_handlers.night_vision(player, meta, {}, sky_data) + end +end +table.insert(mcl_weather.skycolor.filters, effects) + diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua new file mode 100644 index 000000000..4dd7120be --- /dev/null +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua @@ -0,0 +1,36 @@ + +local DEFAULT_WATER_COLOR = "#3F76E4" + +local function water_sky(player, sky_data) + local pos = player:get_pos() + local water_color = DEFAULT_WATER_COLOR + + local checkname = minetest.get_node(vector.new(pos.x,pos.y+1.5,pos.z)).name + if minetest.get_item_group(checkname, "water") == 0 then return end + + local biome_index = minetest.get_biome_data(player:get_pos()).biome + local biome_name = minetest.get_biome_name(biome_index) + local biome = minetest.registered_biomes[biome_name] + if biome then water_color = biome._mcl_waterfogcolor end + if not biome then water_color = DEFAULT_WATER_COLOR end + + if checkname == "mclx_core:river_water_source" or checkname == "mclx_core:river_water_flowing" then water_color = "#0084FF" end + + sky_data.sky = { type = "regular", + sky_color = { + day_sky = water_color, + day_horizon = water_color, + dawn_sky = water_color, + dawn_horizon = water_color, + night_sky = water_color, + night_horizon = water_color, + indoors = water_color, + fog_sun_tint = water_color, + fog_moon_tint = water_color, + fog_tint_type = "custom" + }, + clouds = false, + } +end +table.insert(mcl_weather.skycolor.filters, water_sky) + From 24ff7347b22c15ae152431797f7a222ae23ed205 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 12 Jun 2024 20:12:04 -0500 Subject: [PATCH 04/23] Further cleanup --- mods/ENVIRONMENT/mcl_weather/skycolor.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor.lua b/mods/ENVIRONMENT/mcl_weather/skycolor.lua index fcafe531c..571d9480f 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor.lua @@ -9,8 +9,10 @@ local mods_loaded = false local mg_name = minetest.get_mapgen_setting("mg_name") function mcl_weather.set_sky_box_clear(player, sky, fog) - local pos = player:get_pos() - if minetest.get_item_group( mcl_playerinfo[player:get_player_name()].node_head, "water") ~= 0 then return end + -- Make sure the player's head isn't in water before changing the skybox + local node_head = mcl_playerinfo[player:get_player_name()].node_head + if minetest.get_item_group(node_head, "water") ~= 0 then return end + local sc = { day_sky = "#7BA4FF", day_horizon = "#C0D8FF", @@ -39,8 +41,10 @@ function mcl_weather.set_sky_box_clear(player, sky, fog) end function mcl_weather.set_sky_color(player, def) - local pos = player:get_pos() - if minetest.get_item_group(minetest.get_node(vector.offset(pos, 0, 1.5, 0)).name, "water") ~= 0 then return end + -- Make sure the player's head isn't in water before changing the skybox + local node_head = mcl_playerinfo[player:get_player_name()].node_head + if minetest.get_item_group(node_head, "water") ~= 0 then return end + player:set_sky({ type = def.type, sky_color = def.sky_color, From 7811e2361191a0c30d4961b3251b71269d167c77 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 12 Jun 2024 20:16:04 -0500 Subject: [PATCH 05/23] Convert to use mcl_playerinfo --- mods/ENVIRONMENT/mcl_weather/skycolor/water.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua index 4dd7120be..c1e9a5927 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua @@ -5,7 +5,7 @@ local function water_sky(player, sky_data) local pos = player:get_pos() local water_color = DEFAULT_WATER_COLOR - local checkname = minetest.get_node(vector.new(pos.x,pos.y+1.5,pos.z)).name + local checkname = mcl_playerinfo[name].node_head if minetest.get_item_group(checkname, "water") == 0 then return end local biome_index = minetest.get_biome_data(player:get_pos()).biome From cf4b1dbd1d36fafea00e0159b7dc98a57ba1a90a Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 12 Jun 2024 20:20:38 -0500 Subject: [PATCH 06/23] Remove END function comment --- mods/ENVIRONMENT/mcl_weather/skycolor.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor.lua b/mods/ENVIRONMENT/mcl_weather/skycolor.lua index 571d9480f..cf0c3f70e 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor.lua @@ -146,7 +146,7 @@ function skycolor.update_sky_color(players) for _, player in ipairs(players) do update(player) end -end -- END function skycolor.update_sky_color(players) +end -- Returns current layer color in {r, g, b} format function skycolor.get_sky_layer_color(timeofday) From 207c86b813520c6a5e34eb3887504c1bc7c89ed1 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 12 Jun 2024 20:36:19 -0500 Subject: [PATCH 07/23] Fix crash and rearrange code --- mods/ENVIRONMENT/mcl_weather/skycolor/water.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua index c1e9a5927..fd6fc12e2 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua @@ -2,13 +2,13 @@ local DEFAULT_WATER_COLOR = "#3F76E4" local function water_sky(player, sky_data) - local pos = player:get_pos() local water_color = DEFAULT_WATER_COLOR - local checkname = mcl_playerinfo[name].node_head + local checkname = mcl_playerinfo[player:get_player_name()].node_head if minetest.get_item_group(checkname, "water") == 0 then return end - local biome_index = minetest.get_biome_data(player:get_pos()).biome + local pos = player:get_pos() + local biome_index = minetest.get_biome_data(pos).biome local biome_name = minetest.get_biome_name(biome_index) local biome = minetest.registered_biomes[biome_name] if biome then water_color = biome._mcl_waterfogcolor end From 03faa7764da53494b956def99e4624e1f8312405 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 12 Jun 2024 20:37:11 -0500 Subject: [PATCH 08/23] Fix variable name (caused crash) --- mods/ENVIRONMENT/mcl_weather/skycolor.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor.lua b/mods/ENVIRONMENT/mcl_weather/skycolor.lua index cf0c3f70e..3a0d8af41 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor.lua @@ -175,7 +175,7 @@ function skycolor_utils.convert_to_rgb(minval, maxval, current_val, colors) -- Get the second color's values local index2 = math.min(index1 + 1, #colors) -- clamp to maximum color index (will occur if index1 == #colors) - local frac2 = 1.0 - fraction1 + local frac2 = 1.0 - frac1 local color2 = colors[index2] -- Interpolate between color1 and color2 From d34c804ebfa3d6cfaed09c25cc44ac6d7e9d886b Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 13 Jun 2024 05:56:10 -0500 Subject: [PATCH 09/23] Remove local mod = mcl_weather and replace accesses to variables thru mcl_weather with local variable equivalents --- mods/ENVIRONMENT/mcl_weather/skycolor.lua | 55 +++++++++++------------ 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor.lua b/mods/ENVIRONMENT/mcl_weather/skycolor.lua index 3a0d8af41..b4626b77b 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor.lua @@ -1,7 +1,6 @@ -- Constants local modname = minetest.get_current_modname() local modpath = minetest.get_modpath(modname) -local mod = mcl_weather local NIGHT_VISION_RATIO = 0.45 -- Module state @@ -82,27 +81,27 @@ local skycolor_utils = skycolor.utils -- Add layer to colors table function skycolor.add_layer(layer_name, layer_color, instant_update) - mcl_weather.skycolor.colors[layer_name] = layer_color - table.insert(mcl_weather.skycolor.layer_names, layer_name) - mcl_weather.skycolor.force_update = true + skycolor.colors[layer_name] = layer_color + table.insert(skycolor.layer_names, layer_name) + skycolor.force_update = true end function skycolor.current_layer_name() - return mcl_weather.skycolor.layer_names[#mcl_weather.skycolor.layer_names] + return skycolor.layer_names[#skycolor.layer_names] end -- Retrieve layer from colors table function skycolor.retrieve_layer() - local last_layer = mcl_weather.skycolor.current_layer_name() - return mcl_weather.skycolor.colors[last_layer] + local last_layer = skycolor.current_layer_name() + return skycolor.colors[last_layer] end -- Remove layer from colors table function skycolor.remove_layer(layer_name) - for k, name in pairs(mcl_weather.skycolor.layer_names) do + for k, name in pairs(skycolor.layer_names) do if name == layer_name then - table.remove(mcl_weather.skycolor.layer_names, k) - mcl_weather.skycolor.force_update = true + table.remove(skycolor.layer_names, k) + skycolor.force_update = true return end end @@ -141,7 +140,7 @@ end -- Update sky color. If players not specified update sky for all players. function skycolor.update_sky_color(players) -- Override day/night ratio as well - players = mcl_weather.skycolor.utils.get_players(players) + players = skycolor_utils.get_players(players) local update = skycolor.update_player_sky_color for _, player in ipairs(players) do update(player) @@ -150,14 +149,16 @@ end -- Returns current layer color in {r, g, b} format function skycolor.get_sky_layer_color(timeofday) - if #mcl_weather.skycolor.layer_names == 0 then + if #skycolor.layer_names == 0 then return nil end - -- min timeofday value 0; max timeofday value 1. So sky color gradient range will be between 0 and 1 * mcl_weather.skycolor.max_val. - local rounded_time = math.floor(timeofday * mcl_weather.skycolor.max_val) - local color = mcl_weather.skycolor.utils.convert_to_rgb(mcl_weather.skycolor.min_val, mcl_weather.skycolor.max_val, rounded_time, mcl_weather.skycolor.retrieve_layer()) - return color + -- min timeofday value 0; max timeofday value 1. So sky color gradient range will be between 0 and 1 * skycolor.max_val + local rounded_time = math.floor(timeofday * skycolor.max_val) + return skycolor_utils.convert_to_rgb( + skycolor.min_val, skycolor.max_val, + rounded_time, skycolor.retrieve_layer() + ) end function skycolor_utils.convert_to_rgb(minval, maxval, current_val, colors) @@ -200,7 +201,7 @@ end -- Returns the sky color of the first player, which is done assuming that all players are in same color layout. function skycolor_utils.get_current_bg_color() - local players = mcl_weather.skycolor.utils.get_players(nil) + local players = skycolor_utils.get_players(nil) if players[1] then return players[1]:get_sky(true).sky_color end @@ -209,33 +210,31 @@ end local timer = 0 minetest.register_globalstep(function(dtime) - if mcl_weather.skycolor.active ~= true or #minetest.get_connected_players() == 0 then + if skycolor.active ~= true or #minetest.get_connected_players() == 0 then return end - if mcl_weather.skycolor.force_update then - mcl_weather.skycolor.update_sky_color() - mcl_weather.skycolor.force_update = false + if skycolor.force_update then + skycolor.update_sky_color() + skycolor.force_update = false return end -- regular updates based on iterval timer = timer + dtime; - if timer >= mcl_weather.skycolor.update_interval then - mcl_weather.skycolor.update_sky_color() + if timer >= skycolor.update_interval then + skycolor.update_sky_color() timer = 0 end - end) local function initsky(player) - if player.set_lighting then player:set_lighting({ shadows = { intensity = tonumber(minetest.settings:get("mcl_default_shadow_intensity") or 0.33) } }) end - if (mcl_weather.skycolor.active) then - mcl_weather.skycolor.force_update = true + if (skycolor.active) then + skycolor.force_update = true end player:set_clouds(mcl_worlds:get_cloud_parameters() or {height=mcl_worlds.layer_to_y(127), speed={x=-2, z=0}, thickness=4, color="#FFF0FEF"}) @@ -245,7 +244,7 @@ minetest.register_on_joinplayer(initsky) minetest.register_on_respawnplayer(initsky) mcl_worlds.register_on_dimension_change(function(player) - mcl_weather.skycolor.update_sky_color({player}) + skycolor.update_sky_color({player}) end) minetest.register_on_mods_loaded(function() From 3b01fe20baa091dc3cda0a21b12073ce7a82a774 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 13 Jun 2024 06:10:03 -0500 Subject: [PATCH 10/23] Remove debug commented out logging, remove extra zero in 24-hour time --- mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua index 6b481badc..7f9c084c6 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua @@ -6,7 +6,7 @@ local dimension_handlers = {} mcl_weather.skycolor.dimension_handlers = dimension_handlers -- Function to work out light modifier at different times --- Noon is brightest, midnight is darkest, 0600 and 18000 is in the middle of this +-- Noon is brightest, midnight is darkest, 0600 and 1800 is in the middle of this local function get_light_modifier(time) -- 0.1 = 0.2 -- 0.4 = 0.8 @@ -33,11 +33,9 @@ function dimension_handlers.overworld(player, sky_data) local biome_name = minetest.get_biome_name(biome_index) local biome = minetest.registered_biomes[biome_name] if biome then - --minetest.log("action", string.format("Biome found for number: %s in biome: %s", tostring(biome_index), biome_name)) biomesky = biome._mcl_skycolor biomefog = biome._mcl_fogcolor else - --minetest.log("action", string.format("No biome for number: %s in biome: %s", tostring(biome_index), biome_name)) end end From ef58a9809af1300b8f5c845bc39fa93eb8847ba3 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 13 Jun 2024 06:43:31 -0500 Subject: [PATCH 11/23] Remove empty else block, fix up mg_name and add mapgen check to water.lua --- mods/ENVIRONMENT/mcl_weather/skycolor.lua | 1 - mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua | 2 +- mods/ENVIRONMENT/mcl_weather/skycolor/water.lua | 10 +++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor.lua b/mods/ENVIRONMENT/mcl_weather/skycolor.lua index b4626b77b..1e6e3198b 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor.lua @@ -5,7 +5,6 @@ local NIGHT_VISION_RATIO = 0.45 -- Module state local mods_loaded = false -local mg_name = minetest.get_mapgen_setting("mg_name") function mcl_weather.set_sky_box_clear(player, sky, fog) -- Make sure the player's head isn't in water before changing the skybox diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua index 7f9c084c6..16ae0a1d2 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua @@ -1,6 +1,7 @@ local MINIMUM_LIGHT_LEVEL = 0.2 local VALID_SNOW_WEATHER_STATES = { snow = true, rain = true, thunder = true } local VALID_RAIN_WEATHER_STATES = { rain = true, thunder = true } +local mg_name = minetest.get_mapgen_setting("mg_name") local dimension_handlers = {} mcl_weather.skycolor.dimension_handlers = dimension_handlers @@ -35,7 +36,6 @@ function dimension_handlers.overworld(player, sky_data) if biome then biomesky = biome._mcl_skycolor biomefog = biome._mcl_fogcolor - else end end diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua index fd6fc12e2..03b1115ce 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua @@ -1,5 +1,6 @@ local DEFAULT_WATER_COLOR = "#3F76E4" +local mg_name = minetest.get_mapgen_setting("mg_name") local function water_sky(player, sky_data) local water_color = DEFAULT_WATER_COLOR @@ -8,9 +9,12 @@ local function water_sky(player, sky_data) if minetest.get_item_group(checkname, "water") == 0 then return end local pos = player:get_pos() - local biome_index = minetest.get_biome_data(pos).biome - local biome_name = minetest.get_biome_name(biome_index) - local biome = minetest.registered_biomes[biome_name] + local biome = nil + if mg_name ~= "v6" and mg_name ~= "singlenode" then + local biome_index = minetest.get_biome_data(pos).biome + local biome_name = minetest.get_biome_name(biome_index) + biome = minetest.registered_biomes[biome_name] + end if biome then water_color = biome._mcl_waterfogcolor end if not biome then water_color = DEFAULT_WATER_COLOR end From cd213b75f74bb31a0f89a6cb8d0090f4991790b8 Mon Sep 17 00:00:00 2001 From: Wbjitscool Date: Tue, 14 May 2024 07:17:04 +0000 Subject: [PATCH 12/23] Update mods/ENVIRONMENT/mcl_weather/skycolor.lua adds in sunray shader support for Minetest version 5.9.0 --- mods/ENVIRONMENT/mcl_weather/skycolor.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor.lua b/mods/ENVIRONMENT/mcl_weather/skycolor.lua index 1e6e3198b..69b9f5c97 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor.lua @@ -229,11 +229,22 @@ end) local function initsky(player) if player.set_lighting then - player:set_lighting({ shadows = { intensity = tonumber(minetest.settings:get("mcl_default_shadow_intensity") or 0.33) } }) + player:set_lighting({ + shadows = { intensity = 0.33 }, + volumetric_light = { strength = 0.45 }, + exposure = { + luminance_min = -3.5, + luminance_max = -2.5, + exposure_correction = 0.35, + speed_dark_bright = 1500, + speed_bright_dark = 700, + }, + saturation = 1.1, + }) end if (skycolor.active) then - skycolor.force_update = true + mcl_weather.skycolor.force_update = true end player:set_clouds(mcl_worlds:get_cloud_parameters() or {height=mcl_worlds.layer_to_y(127), speed={x=-2, z=0}, thickness=4, color="#FFF0FEF"}) From cb097d9bcda33e1b7eb9db94b6904141263a8dfc Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 19 Jun 2024 06:53:53 -0500 Subject: [PATCH 13/23] Add minimum time between skycolor updates (default is 250ms, tracked per player) --- mods/ENVIRONMENT/mcl_weather/skycolor.lua | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor.lua b/mods/ENVIRONMENT/mcl_weather/skycolor.lua index 69b9f5c97..bca0d8234 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor.lua @@ -3,6 +3,9 @@ local modname = minetest.get_current_modname() local modpath = minetest.get_modpath(modname) local NIGHT_VISION_RATIO = 0.45 +-- Settings +local minimum_update_interval = { 250e3 } + -- Module state local mods_loaded = false @@ -119,8 +122,29 @@ dofile(modpath.."/skycolor/water.lua") dofile(modpath.."/skycolor/dimensions.lua") dofile(modpath.."/skycolor/effects.lua") +local function get_skycolor_info(player) + local player_name = player:get_player_name() + + local info = mcl_playerinfo[player_name] or {} + + local skycolor_data = info.skycolor + if not skycolor_data then + skycolor_data = {} + info.skycolor = skycolor_data + end + + return skycolor_data +end + local water_sky = skycolor.water_sky function skycolor.update_player_sky_color(player) + -- Don't update more than once every 250 milliseconds + local skycolor_data = get_skycolor_info(player) + local last_update = skycolor_data.last_update or 0 + local now_us = minetest.get_us_time() + if (now_us - last_update) < minimum_update_interval[1] then return end + skycolor_data.last_update = now_us + local sky_data = { day_night_ratio = player._skycolor_day_night_ratio } From 0e1a2cbc1e1d02df545f645f073e1a351d4545d1 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 19 Jun 2024 06:54:44 -0500 Subject: [PATCH 14/23] Correct conditions for water-air transition forced skycolor update --- mods/PLAYER/mcl_playerplus/init.lua | 31 ++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index ad1143c9d..b4fa23945 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -407,13 +407,30 @@ minetest.register_globalstep(function(dtime) set_bone_pos(player,"Body_Control", nil, vector.new(0, -player_vel_yaw + yaw, 0)) end - local underwater - if get_item_group(mcl_playerinfo[name].node_head, "water") ~= 0 and underwater ~= true then - mcl_weather.skycolor.update_sky_color() - local underwater = true - elseif get_item_group(mcl_playerinfo[name].node_head, "water") == 0 and underwater == true then - mcl_weather.skycolor.update_sky_color() - local underwater = false + local playerinfo = mcl_playerinfo[name] or {} + local plusinfo = playerinfo.mcl_playerplus + if not plusinfo then + plusinfo = {} + playerinfo.mcl_playerplus = plusinfo + end + + -- Only process if node_head changed + if plusinfo.old_node_head ~= playerinfo.node_head then + local node_head = playerinfo.node_head or "" + local old_node_head = plusinfo.old_node_head or "" + plusinfo.old_node_head = playerinfo.node_head + + minetest.log(dump({ + node_head = node_head, + old_node_head = old_node_head, + new_group = get_item_group(node_head, "water"), + old_group = get_item_group(old_node_head, "water"), + })) + + -- Update skycolor if moving in or out of water + if (get_item_group(node_head, "water") == 0) ~= (get_item_group(old_node_head, "water") == 0) then + mcl_weather.skycolor.update_sky_color() + end end elytra.last_yaw = player:get_look_horizontal() From dc074ff555a9f1e9b0d78f3d87de9856b46dbdc9 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 19 Jun 2024 08:22:20 -0500 Subject: [PATCH 15/23] Remove debug logging --- mods/PLAYER/mcl_playerplus/init.lua | 7 ------- 1 file changed, 7 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index b4fa23945..709d1d0fb 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -420,13 +420,6 @@ minetest.register_globalstep(function(dtime) local old_node_head = plusinfo.old_node_head or "" plusinfo.old_node_head = playerinfo.node_head - minetest.log(dump({ - node_head = node_head, - old_node_head = old_node_head, - new_group = get_item_group(node_head, "water"), - old_group = get_item_group(old_node_head, "water"), - })) - -- Update skycolor if moving in or out of water if (get_item_group(node_head, "water") == 0) ~= (get_item_group(old_node_head, "water") == 0) then mcl_weather.skycolor.update_sky_color() From 3667feddd31eee7cf4800379f5f0d8e9e157ef7a Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 19 Jun 2024 08:31:56 -0500 Subject: [PATCH 16/23] Address review comments --- mods/ENVIRONMENT/mcl_weather/skycolor.lua | 2 ++ mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua | 8 +++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor.lua b/mods/ENVIRONMENT/mcl_weather/skycolor.lua index bca0d8234..9beb82b64 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor.lua @@ -73,6 +73,8 @@ local skycolor = { -- number of colors while constructing gradient of user given colors max_val = 1000, + NIGHT_VISION_RATIO = NIGHT_VISION_RATIO, + -- Table for tracking layer order layer_names = {}, diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua index c0a349410..9e7680ba1 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua @@ -3,8 +3,9 @@ local DIM_ALLOW_NIGHT_VISION = { void = true, } +local NIGHT_VISION_RATIO = mcl_weather.skycolor.NIGHT_VISION_RATIO local effects_handlers = {} -local has_mcl_potions = false +local has_mcl_potions = not not minetest.get_modpath("mcl_potions") -- Coerce to boolean with "not not" function effects_handlers.darkness(player, meta, effect, sky_data) -- No darkness effect if visited by shepherd @@ -34,10 +35,7 @@ function effects_handlers.night_vision(player, meta, effect, sky_data) end local function effects(player, sky_data) - if not has_mcl_potions then - if not minetest.get_modpath("mcl_potions") then return end - has_mcl_potions = true - end + if not has_mcl_potions then return end local meta = player:get_meta() for name,effect in pairs(mcl_potions.registered_effects) do From 18266137b2654b0dcf3a7f2788a2bd659ef7ab0b Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 19 Jun 2024 08:32:21 -0500 Subject: [PATCH 17/23] Make sure clouds don't disappear when entering water --- mods/ENVIRONMENT/mcl_weather/skycolor/water.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua index 03b1115ce..ec14d8844 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/water.lua @@ -33,7 +33,7 @@ local function water_sky(player, sky_data) fog_moon_tint = water_color, fog_tint_type = "custom" }, - clouds = false, + clouds = true, } end table.insert(mcl_weather.skycolor.filters, water_sky) From 37ff699a238cd1c7053428247144516323508a6e Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 19 Jun 2024 08:33:57 -0500 Subject: [PATCH 18/23] Add line break --- mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua index 9e7680ba1..c3dd32fc7 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua @@ -21,6 +21,7 @@ function effects_handlers.darkness(player, meta, effect, sky_data) sky_data.day_night_ratio = 0 end end + function effects_handlers.night_vision(player, meta, effect, sky_data) -- Apply night vision only for dark sky if not (minetest.get_timeofday() > 0.8 or minetest.get_timeofday() < 0.2 or mcl_weather.state ~= "none") then return end From 21a88be2b2a693c662c3784a9c935a52aba59497 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 19 Jun 2024 08:49:26 -0500 Subject: [PATCH 19/23] Remove boolean coersion --- mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua index c3dd32fc7..c8b4a32af 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua @@ -5,7 +5,7 @@ local DIM_ALLOW_NIGHT_VISION = { local NIGHT_VISION_RATIO = mcl_weather.skycolor.NIGHT_VISION_RATIO local effects_handlers = {} -local has_mcl_potions = not not minetest.get_modpath("mcl_potions") -- Coerce to boolean with "not not" +local has_mcl_potions = minetest.get_modpath("mcl_potions") function effects_handlers.darkness(player, meta, effect, sky_data) -- No darkness effect if visited by shepherd From 87a48270f509623887f67d69fa3e5b3ca45d4a91 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Fri, 21 Jun 2024 19:47:33 -0500 Subject: [PATCH 20/23] Add mcl_util.to_bool --- mods/CORE/mcl_util/init.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index b6fd71673..783f5031b 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -1103,3 +1103,8 @@ function mcl_util.is_it_christmas() return false end end + +function mcl_util.to_bool(val) + if not val then return false end + return true +end From e407e2e290e5e4c84613e017d8de2a1943910912 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Fri, 21 Jun 2024 19:47:58 -0500 Subject: [PATCH 21/23] Force has_mcl_potions to boolean --- mods/ENVIRONMENT/mcl_weather/mod.conf | 2 +- mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_weather/mod.conf b/mods/ENVIRONMENT/mcl_weather/mod.conf index 52c4ae7aa..ee6f03407 100644 --- a/mods/ENVIRONMENT/mcl_weather/mod.conf +++ b/mods/ENVIRONMENT/mcl_weather/mod.conf @@ -1,5 +1,5 @@ name = mcl_weather author = xeranas description = Weather and sky handling: Rain, snow, thunderstorm, End and Nether ambience -depends = mcl_init, mcl_worlds, mcl_playerinfo +depends = mcl_init, mcl_worlds, mcl_playerinfo, mcl_util optional_depends = lightning diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua index c8b4a32af..d905d8f31 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua @@ -5,7 +5,7 @@ local DIM_ALLOW_NIGHT_VISION = { local NIGHT_VISION_RATIO = mcl_weather.skycolor.NIGHT_VISION_RATIO local effects_handlers = {} -local has_mcl_potions = minetest.get_modpath("mcl_potions") +local has_mcl_potions = mcl_util.to_bool(minetest.get_modpath("mcl_potions")) function effects_handlers.darkness(player, meta, effect, sky_data) -- No darkness effect if visited by shepherd From 09307292bce5145a8eec8837de636a448c9f0672 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 26 Jun 2024 19:51:33 -0500 Subject: [PATCH 22/23] Make sure overworld always gets a sky update regardless of weather, add assert to enforce sky color gets set every update --- mods/ENVIRONMENT/mcl_weather/skycolor.lua | 4 +- .../mcl_weather/skycolor/dimensions.lua | 44 +++++++++---------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor.lua b/mods/ENVIRONMENT/mcl_weather/skycolor.lua index 9beb82b64..19cec9eac 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor.lua @@ -155,7 +155,9 @@ function skycolor.update_player_sky_color(player) skycolor_filters[i](player, sky_data) end - if sky_data.sky then player:set_sky(sky_data.sky) end + assert(sky_data.sky) + player:set_sky(sky_data.sky) + if sky_data.sun then player:set_sun(sky_data.sun) end if sky_data.moon then player:set_moon(sky_data.moon) end if sky_data.stars then player:set_stars(sky_data.stars) end diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua index 16ae0a1d2..fcf85a7e0 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/dimensions.lua @@ -39,12 +39,29 @@ function dimension_handlers.overworld(player, sky_data) end end + -- Use overworld defaults + local day_color = mcl_weather.skycolor.get_sky_layer_color(0.15) + 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 = { + 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, + }, + clouds = true, + } + sky_data.sun = {visible = true, sunrise_visible = true} + sky_data.moon = {visible = true} + sky_data.stars = {visible = true} + if mcl_weather.state == "none" then -- Clear weather mcl_weather.set_sky_box_clear(player,biomesky,biomefog) - sky_data.sun = {visible = true, sunrise_visible = true} - sky_data.moon = {visible = true} - sky_data.stars = {visible = true} return end @@ -83,28 +100,7 @@ function dimension_handlers.overworld(player, sky_data) local new_light = math.max(light_factor * light_multiplier, MINIMUM_LIGHT_LEVEL) sky_data.day_night_ratio = new_light end - return end - - -- No weather that affects the sky color, use default values - local day_color = mcl_weather.skycolor.get_sky_layer_color(0.15) - 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 = { - 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, - }, - clouds = true, - } - sky_data.sun = {visible = false, sunrise_visible = false} - sky_data.moon = {visible = false} - sky_data.stars = {visible = false} end -- This can't be function dimension_handlers.end() due to lua syntax From aea9e6d182fee283d7aee612c03c510f2d2f45ba Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sun, 18 Aug 2024 19:32:03 -0500 Subject: [PATCH 23/23] Update comment according to https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4338#issuecomment-82713 --- mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua b/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua index d905d8f31..ce90bb13a 100644 --- a/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua +++ b/mods/ENVIRONMENT/mcl_weather/skycolor/effects.lua @@ -8,7 +8,7 @@ local effects_handlers = {} local has_mcl_potions = mcl_util.to_bool(minetest.get_modpath("mcl_potions")) function effects_handlers.darkness(player, meta, effect, sky_data) - -- No darkness effect if visited by shepherd + -- No darkness effect if is a visited shepherd if meta:get_int("mcl_shepherd:special") == 1 then return end -- High stars