Move entire sky color code into mcl_weather

This commit is contained in:
Wuzzy 2017-11-24 01:39:52 +01:00
parent d55928fe95
commit 06ef86ddd3
3 changed files with 38 additions and 65 deletions

View file

@ -1 +1 @@
Weather: Rain, snow, thunderstorm. Weather and sky handling: Rain, snow, thunderstorm, End and Nether ambience

View file

@ -6,7 +6,7 @@ mcl_weather.skycolor = {
force_update = true, force_update = true,
-- Update interval. -- Update interval.
update_interval = 15, update_interval = 0.5,
-- Main sky colors: starts from midnight to midnight. -- Main sky colors: starts from midnight to midnight.
-- Please do not set directly. Use add_layer instead. -- Please do not set directly. Use add_layer instead.
@ -69,18 +69,19 @@ mcl_weather.skycolor = {
-- Update sky color. If players not specified update sky for all players. -- Update sky color. If players not specified update sky for all players.
update_sky_color = function(players) update_sky_color = function(players)
local color = mcl_weather.skycolor.current_sky_layer_color()
if (color == nil) then
mcl_weather.skycolor.set_default_sky()
return
end
-- Override day/night ratio as well -- Override day/night ratio as well
players = mcl_weather.skycolor.utils.get_players(players) players = mcl_weather.skycolor.utils.get_players(players)
local color = mcl_weather.skycolor.current_sky_layer_color()
for _, player in ipairs(players) do for _, player in ipairs(players) do
local pos = player:get_pos() local pos = player:get_pos()
local _, dim = mcl_util.y_to_layer(pos.y) local _, dim = mcl_util.y_to_layer(pos.y)
if dim == "overworld" then if dim == "overworld" then
if (color == nil) then
-- No sky layers
player:set_sky(nil, "regular")
player:override_day_night_ratio(nil)
else
-- Weather skies
player:set_sky(color, "plain", nil, true) player:set_sky(color, "plain", nil, true)
local lf = mcl_weather.get_current_light_factor() local lf = mcl_weather.get_current_light_factor()
@ -100,7 +101,16 @@ mcl_weather.skycolor = {
player:override_day_night_ratio(nil) player:override_day_night_ratio(nil)
end end
end end
-- Other dimensions are handled in mcl_playerplus elseif dim == "end" then
local t = "mcl_playerplus_end_sky.png"
player:set_sky("#000000", "skybox", {t,t,t,t,t,t}, false)
player:override_day_night_ratio(0.5)
elseif dim == "nether" then
player:set_sky("#300808", "plain", nil, false)
player:override_day_night_ratio(nil)
elseif dim == "void" then
player:set_sky("#000000", "plain", nil, false)
end
end end
end, end,
@ -119,11 +129,6 @@ mcl_weather.skycolor = {
-- Initialy used only on -- Initialy used only on
update_transition_sky_color = function() update_transition_sky_color = function()
if #mcl_weather.skycolor.layer_names == 0 then
mcl_weather.skycolor.set_default_sky()
return
end
local multiplier = 100 local multiplier = 100
local rounded_time = math.floor(mcl_weather.skycolor.transition_timer * multiplier) local rounded_time = math.floor(mcl_weather.skycolor.transition_timer * multiplier)
if rounded_time >= mcl_weather.skycolor.transition_time * multiplier then if rounded_time >= mcl_weather.skycolor.transition_time * multiplier then
@ -143,21 +148,6 @@ mcl_weather.skycolor = {
end end
end, end,
-- Reset sky color to game default. If players not specified update sky for all players.
-- Could be sometimes useful but not recomended to use in general case as there may be other color layers
-- which needs to preserve.
set_default_sky = function(players)
local players = mcl_weather.skycolor.utils.get_players(players)
for _, player in ipairs(players) do
local pos = player:getpos()
local _, dim = mcl_util.y_to_layer(pos.y)
if dim == "overworld" then
player:set_sky(nil, "regular", nil, true)
player:override_day_night_ratio(nil)
end
end
end,
init_transition = function() init_transition = function()
-- sadly default sky returns unpredictible colors so transition mode becomes usable only for user defined color layers -- sadly default sky returns unpredictible colors so transition mode becomes usable only for user defined color layers
-- Here '2' means that one color layer existed before new added and transition is posible. -- Here '2' means that one color layer existed before new added and transition is posible.

View file

@ -153,25 +153,8 @@ minetest.register_globalstep(function(dtime)
end end
end end
-- Apply black sky in the Void and deal Void damage -- Deal Void damage
local void, void_deadly = mcl_util.is_in_void(pos) local void, void_deadly = mcl_util.is_in_void(pos)
local _, dim = mcl_util.y_to_layer(pos.y)
-- Set dimension skies.
-- FIXME: Sky handling in MCL2 is held together with lots of duct tape.
-- This only works beause mcl_weather currently does not touch the sky for players below the height used for this check.
-- There should be a real skybox API.
if dim == "void" then
player:set_sky("#000000", "plain", nil, false)
elseif dim == "end" then
local t = "mcl_playerplus_end_sky.png"
player:set_sky("#000000", "skybox", {t,t,t,t,t,t}, false)
player:override_day_night_ratio(0.5)
elseif dim == "nether" then
player:set_sky("#300808", "plain", nil, false)
player:override_day_night_ratio(nil)
else
mcl_weather.skycolor.update_sky_color({player})
end
if void_deadly then if void_deadly then
-- Player is deep into the void, deal void damage -- Player is deep into the void, deal void damage
if player:get_hp() > 0 then if player:get_hp() > 0 then