forked from MineClone5/MineClone5
Move entire sky color code into mcl_weather
This commit is contained in:
parent
d55928fe95
commit
06ef86ddd3
|
@ -1 +1 @@
|
||||||
Weather: Rain, snow, thunderstorm.
|
Weather and sky handling: Rain, snow, thunderstorm, End and Nether ambience
|
||||||
|
|
|
@ -4,9 +4,9 @@ mcl_weather.skycolor = {
|
||||||
|
|
||||||
-- To skip update interval
|
-- To skip update interval
|
||||||
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,38 +69,48 @@ 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
|
||||||
player:set_sky(color, "plain", nil, true)
|
if (color == nil) then
|
||||||
|
-- No sky layers
|
||||||
local lf = mcl_weather.get_current_light_factor()
|
player:set_sky(nil, "regular")
|
||||||
if mcl_weather.skycolor.current_layer_name() == "lightning" then
|
|
||||||
player:override_day_night_ratio(1)
|
|
||||||
elseif lf then
|
|
||||||
local w = minetest.get_timeofday()
|
|
||||||
local light = (w * (lf*2))
|
|
||||||
if light > 1 then
|
|
||||||
light = 1 - (light - 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
light = (light * lf) + 0.15
|
|
||||||
|
|
||||||
player:override_day_night_ratio(light)
|
|
||||||
else
|
|
||||||
player:override_day_night_ratio(nil)
|
player:override_day_night_ratio(nil)
|
||||||
|
else
|
||||||
|
-- Weather skies
|
||||||
|
player:set_sky(color, "plain", nil, true)
|
||||||
|
|
||||||
|
local lf = mcl_weather.get_current_light_factor()
|
||||||
|
if mcl_weather.skycolor.current_layer_name() == "lightning" then
|
||||||
|
player:override_day_night_ratio(1)
|
||||||
|
elseif lf then
|
||||||
|
local w = minetest.get_timeofday()
|
||||||
|
local light = (w * (lf*2))
|
||||||
|
if light > 1 then
|
||||||
|
light = 1 - (light - 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
light = (light * lf) + 0.15
|
||||||
|
|
||||||
|
player:override_day_night_ratio(light)
|
||||||
|
else
|
||||||
|
player:override_day_night_ratio(nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
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
|
||||||
-- Other dimensions are handled in mcl_playerplus
|
|
||||||
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.
|
||||||
|
@ -205,7 +195,7 @@ mcl_weather.skycolor = {
|
||||||
local players = mcl_weather.skycolor.utils.get_players(nil)
|
local players = mcl_weather.skycolor.utils.get_players(nil)
|
||||||
for _, player in ipairs(players) do
|
for _, player in ipairs(players) do
|
||||||
return player:get_sky()
|
return player:get_sky()
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue