-- =================================================================== local enable_moontest = minetest.setting_getbool ("enable_moon" ) or minetest.setting_getbool ("enable_moontest" ) codersky = {} codersky.name = nil codersky.cspec = nil local pos = { x=0, y=0, z=0 } -- =================================================================== local spaceskybox = { "sky_pos_y.jpg" , "sky_neg_y.jpg" , "sky_pos_z.jpg" , "sky_neg_z.jpg" , "sky_neg_x.jpg" , "sky_pos_x.jpg" , } local earthskyday = { "dayblank.png" , "dayblank.png" , "daycloud.jpg" , "daycloud.jpg" , "daycloud.jpg" , "daycloud.jpg" , } local earthskynight = { "earth_night_pos_y.jpg" , "earth_night_neg_y.jpg" , "earth_night_pos_z.jpg" , "earth_night_neg_z.jpg" , "earth_night_neg_x.jpg" , "earth_night_pos_x.jpg" , } -- =================================================================== local function current_hour() return math.mod (math.floor (minetest.get_timeofday() * 24 + 0.5), 24) end -- =================================================================== local function current_time() return math.floor (minetest.get_timeofday() * 24000) end -- =================================================================== codersky.set_sky = function (player, newspec, newname) if newspec ~= nil then codersky.cspec = { r=newspec.r, g=newspec.g, b=newspec.b } newname = nil end if newname == "skybox" then -- player:set_sky (nil, "skybox", spaceskybox) player:set_sky ({ clouds = false , base_color = { a=0, r=5, g=5, b=5 } , type = "skybox" , textures = spaceskybox , }) elseif (newname == "regular") or (codersky.cspec == nil) then player:set_sky (nil, "regular", nil) codersky.cspec = nil else player:set_sky (codersky.cspec, "plain", nil) end end -- =================================================================== codersky.update_skybox = function (player) local name = player:get_player_name() local pos = player:getpos() local gpbn = minetest.get_player_by_name (name) if not gpbn then return end local is_space = upper_realms.is_outer_space (pos.y) if rawget (_G, "earthgen") ~= nil and type (earthgen) == "table" and pos.y >= earthgen.REALM_HEIGHT_MINPOINT and pos.y < earthgen.REALM_HEIGHT_MAXPOINT then -- local ov = player:get_physics_override() -- ov.gravity = 1 -- player:set_physics_override (ov) local mttime = current_time() local isnight = false if (mttime >= 19360) or (mttime <= 5000) then isnight = true end if isnight then -- Night runs 7:36pm to 5:00am = about 9.5 hours -- 5 lunar positions, so about 2 hours each -- Initial position is overhead earthskynight [1] = "earth_night_pos_y.jpg" earthskynight [5] = "earth_night_neg_x.jpg" if (mttime >= 19000) and (mttime < 21000) then earthskynight[1] = "earth_night_pos_y_moon_middle.jpg" end -- 9:00pm to 11:00pm if (mttime >= 21000) and (mttime <= 23000) then earthskynight [1] = "earth_night_pos_y_moon_upper.jpg" end -- 11:01pm to 1:00am if (mttime > 23000) or (mttime <= 1000) then earthskynight [5] = "earth_night_neg_x_moon_upper.jpg" end -- 1:01am to 3:00am if (mttime > 1000) and (mttime <= 3000) then earthskynight [5] = "earth_night_neg_x_moon_middle.jpg" end -- 3:01am on if (mttime > 3000) and (mttime <= 6000) then earthskynight [5] = "earth_night_neg_x_moon_lower.jpg" end player:set_sky (nil, "skybox", earthskynight) else -- Day runs 5:00am to 7:36pm -- About 15 hours and 5 positions, so 3 hours each -- 5:00am to 8:00am earthskyday [1] = "dayblank.png" earthskyday [6] = "daycloud.jpg" if (mttime > 4000) and (mttime < 8000) then earthskyday [6] = "daymoon-lower.jpg" end if (mttime >= 8000) and (mttime <= 11000) then earthskyday [6] = "daymoon-middle.jpg" end if (mttime > 11000) and (mttime <= 14000) then earthskyday [6] = "daymoon-upper.jpg" end if (mttime > 14000) and (mttime <= 17000) then earthskyday [1] = "daymoon-lower.jpg" end if (mttime > 17000) and (mttime <= 20000) then earthskyday [1] = "daymoon-middle.jpg" end player:set_sky (nil, "skybox", earthskyday) end elseif is_space then -- local ov = player:get_physics_override() -- ov.gravity = 0.2 -- player:set_physics_override (ov) player:set_sky (nil, "skybox", spaceskybox) else -- local ov = player:get_physics_override() -- ov.gravity = 1 -- player:set_physics_override (ov) if (pos.y <= 1000) then codersky.set_sky (player, nil, nil) else player:set_sky (nil, "regular", nil) end end end -- =================================================================== local time = 0 minetest.register_globalstep (function (dtime) time = time + dtime if time <= 1 then return end for _, player in ipairs (minetest.get_connected_players()) do time = 0 codersky.update_skybox (player) end end) -- =================================================================== minetest.register_on_leaveplayer (function (player) local name = player:get_player_name() if name then codersky.set_sky (player, nil, "regular", true) end end)