Separate old and new sky apis

This commit is contained in:
kay27 2022-01-24 02:37:43 +04:00
parent 8079d3bc9d
commit da9fa916e8
2 changed files with 73 additions and 20 deletions

View File

@ -5,3 +5,12 @@ end
function vector.offset(v,x,y,z) function vector.offset(v,x,y,z)
return vector.add(v,{x=x,y=y,z=z}) return vector.add(v,{x=x,y=y,z=z})
end end
--[[
minetest.register_on_joinplayer(function(ObjectRef, last_login)
if not ObjectRef.set_moon then
function ObjectRef.set_moon()
end
end
end)
]]

View File

@ -1,6 +1,46 @@
local mods_loaded = false local mods_loaded = false
local NIGHT_VISION_RATIO = 0.45 local NIGHT_VISION_RATIO = 0.45
local function set_sky(player, def)
if player.set_sun then
-- new api
player:set_sky(def)
else
-- TODO
-- old api
end
end
local function set_sun(player, def)
if player.set_sun then
-- new api
player:set_sun(def)
else
-- TODO
-- old api
end
end
local function set_moon(player, def)
if player.set_sun then
-- new api
player:set_moon(def)
else
-- TODO
-- old api
end
end
local function set_stars(player, def)
if player.set_sun then
-- new api
player:set_stars(def)
else
-- TODO
-- old api
end
end
mcl_weather.skycolor = { mcl_weather.skycolor = {
-- Should be activated before do any effect. -- Should be activated before do any effect.
active = true, active = true,
@ -83,7 +123,7 @@ mcl_weather.skycolor = {
if dim == "overworld" then if dim == "overworld" then
if (mcl_weather.state == "none") then if (mcl_weather.state == "none") then
-- Clear weather -- Clear weather
player:set_sky({ set_sky(player, {
type = "regular", type = "regular",
sky_color = { sky_color = {
day_sky = "#92B9FF", day_sky = "#92B9FF",
@ -95,16 +135,17 @@ mcl_weather.skycolor = {
}, },
clouds = true, clouds = true,
}) })
player:set_sun({visible = true, sunrise_visible = true}) set_sun(player, {visible = true, sunrise_visible = true})
player:set_moon({visible = true}) set_moon(player, {visible = true})
player:set_stars({visible = true}) set_stars(player, {visible = true})
mcl_weather.skycolor.override_day_night_ratio(player, nil) mcl_weather.skycolor.override_day_night_ratio(player, nil)
else else
-- Weather skies -- Weather skies
local day_color = mcl_weather.skycolor.get_sky_layer_color(0.5) 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 dawn_color = mcl_weather.skycolor.get_sky_layer_color(0.75)
local night_color = mcl_weather.skycolor.get_sky_layer_color(0) local night_color = mcl_weather.skycolor.get_sky_layer_color(0)
player:set_sky({ type = "regular", set_sky(player, {
type = "regular",
sky_color = { sky_color = {
day_sky = day_color, day_sky = day_color,
day_horizon = day_color, day_horizon = day_color,
@ -115,9 +156,9 @@ mcl_weather.skycolor = {
}, },
clouds = true, clouds = true,
}) })
player:set_sun({visible = false, sunrise_visible = false}) set_sun(player, {visible = false, sunrise_visible = false})
player:set_moon({visible = false}) set_moon(player, {visible = false})
player:set_stars({visible = false}) set_stars(player, {visible = false})
local lf = mcl_weather.get_current_light_factor() local lf = mcl_weather.get_current_light_factor()
if mcl_weather.skycolor.current_layer_name() == "lightning" then if mcl_weather.skycolor.current_layer_name() == "lightning" then
@ -136,32 +177,35 @@ mcl_weather.skycolor = {
end end
elseif dim == "end" then elseif dim == "end" then
local t = "mcl_playerplus_end_sky.png" local t = "mcl_playerplus_end_sky.png"
player:set_sky({ type = "skybox", set_sky(player, {
type = "skybox",
base_color = "#000000", base_color = "#000000",
textures = {t,t,t,t,t,t}, textures = {t,t,t,t,t,t},
clouds = false, clouds = false,
}) })
player:set_sun({visible = false , sunrise_visible = false}) set_sun(player, {visible = false , sunrise_visible = false})
player:set_moon({visible = false}) set_moon(player, {visible = false})
player:set_stars({visible = false}) set_stars(player, {visible = false})
mcl_weather.skycolor.override_day_night_ratio(player, 0.5) mcl_weather.skycolor.override_day_night_ratio(player, 0.5)
elseif dim == "nether" then elseif dim == "nether" then
player:set_sky({ type = "plain", set_sky(player, {
type = "plain",
base_color = "#300808", base_color = "#300808",
clouds = false, clouds = false,
}) })
player:set_sun({visible = false , sunrise_visible = false}) set_sun(player, {visible = false , sunrise_visible = false})
player:set_moon({visible = false}) set_moon(player, {visible = false})
player:set_stars({visible = false}) set_stars(player, {visible = false})
mcl_weather.skycolor.override_day_night_ratio(player, nil) mcl_weather.skycolor.override_day_night_ratio(player, nil)
elseif dim == "void" then elseif dim == "void" then
player:set_sky({ type = "plain", set_sky(player, {
type = "plain",
base_color = "#000000", base_color = "#000000",
clouds = false, clouds = false,
}) })
player:set_sun({visible = false, sunrise_visible = false}) set_sun(player, {visible = false, sunrise_visible = false})
player:set_moon({visible = false}) set_moon(player, {visible = false})
player:set_stars({visible = false}) set_stars(player, {visible = false})
end end
end end
end, end,