From dacafd8f137eb529d761a3524433c565dab65fbf Mon Sep 17 00:00:00 2001 From: Aaron Suen Date: Sat, 22 Apr 2023 21:22:31 -0400 Subject: [PATCH] Retire time-of-day warning/hack This was supposed to prevent shadows from showing up in certain pre-release versions of MT before shadows were off by default for the official release. It's no longer necessary as shadows are now properly controlled by the API. --- mods/nc_player_sky/init.lua | 86 ++++++++++++++++++++++++++++++-- mods/nc_player_sky/skybox.lua | 85 ------------------------------- mods/nc_player_sky/timeofday.lua | 37 -------------- 3 files changed, 82 insertions(+), 126 deletions(-) delete mode 100644 mods/nc_player_sky/skybox.lua delete mode 100644 mods/nc_player_sky/timeofday.lua diff --git a/mods/nc_player_sky/init.lua b/mods/nc_player_sky/init.lua index 40c3dad5..164b56e9 100644 --- a/mods/nc_player_sky/init.lua +++ b/mods/nc_player_sky/init.lua @@ -1,9 +1,87 @@ -- LUALOCALS < --------------------------------------------------------- -local include, nodecore - = include, nodecore +local math, minetest, nodecore, pairs, string, vector + = math, minetest, nodecore, pairs, string, vector +local math_ceil, math_floor, math_log, string_gsub + = math.ceil, math.floor, math.log, string.gsub -- LUALOCALS > --------------------------------------------------------- nodecore.amcoremod() -include("timeofday") -include("skybox") +local basetextures = {} +for i = 1, 6 do + basetextures[i] = "nc_player_sky_box" .. i .. ".png" +end + +local skyboxes = {} +for dark = 0, 255 do + local color = {r = 0x1d, g = 0x21, b = 0x36} + for k, v in pairs(color) do + color[k] = math_floor(0.5 + v * (255 - dark) / 255) + end + skyboxes[dark] = { + base_color = color, + type = "skybox", + textures = {}, + clouds = false, + _darken = dark > 0 and "^[colorize:#000000:" .. dark or "", + } + for k, v in pairs(basetextures) do + skyboxes[dark].textures[k] = v .. skyboxes[dark]._darken + end +end + +local function esc(t) return string_gsub(string_gsub(t, "%^", "\\^"), ":", "\\:") end + +local spawn +nodecore.interval(1, function() + spawn = minetest.setting_get_pos("static_spawnpoint") + or {x = 0, y = 0, z = 0} + end) + +local posscale = 128 / math_log(32768) +nodecore.register_playerstep({ + label = "skybox/sunlight", + action = function(player, data) + local depth = math_floor(player:get_pos().y + 0.5) + + local rawdll = nodecore.get_depth_light(depth, 1) + local dark = 255 - math_ceil(255 * rawdll) + data.sky = {} + for k, v in pairs(skyboxes[dark]) do + data.sky[k] = v + end + local oldtxr = data.sky.textures + data.sky.textures = {} + for k, v in pairs(oldtxr) do + data.sky.textures[k] = v + end + local top = basetextures[1] + top = "[combine:256x256:0,0=" .. esc("(" .. top .. ")^[resize:256x256") + + local pos = vector.subtract(player:get_pos(), spawn) + pos.y = 0 + local dist = vector.length(pos) + local log = math_log(dist + 1) * posscale + pos = vector.multiply(pos, log / dist) + local px = math_ceil(pos.z) + local py = math_ceil(-pos.x) + local opac = (px * px + py * py) / 8 - 200 + if opac > 0 then + if opac > 255 then opac = 255 end + top = top .. ":" .. (123 + px) .. "," .. (123 + py) + .. "=" .. esc("nc_player_sky_star.png^[resize:11x11" + .. "^[opacity:" .. math_ceil(opac)) + data.sky.textures[1] = top .. data.sky._darken + end + + data.daynight = nodecore.get_depth_light(depth) + end + }) + +nodecore.register_on_joinplayer("sky setup", function(player) + for k in pairs({set_sun = true, set_moon = true, set_stars = true}) do + if player[k] then + player[k](player, {visible = false, sunrise_visible = false}) + end + end + end) diff --git a/mods/nc_player_sky/skybox.lua b/mods/nc_player_sky/skybox.lua deleted file mode 100644 index 36bc9195..00000000 --- a/mods/nc_player_sky/skybox.lua +++ /dev/null @@ -1,85 +0,0 @@ --- LUALOCALS < --------------------------------------------------------- -local math, minetest, nodecore, pairs, string, vector - = math, minetest, nodecore, pairs, string, vector -local math_ceil, math_floor, math_log, string_gsub - = math.ceil, math.floor, math.log, string.gsub --- LUALOCALS > --------------------------------------------------------- - -local basetextures = {} -for i = 1, 6 do - basetextures[i] = "nc_player_sky_box" .. i .. ".png" -end - -local skyboxes = {} -for dark = 0, 255 do - local color = {r = 0x1d, g = 0x21, b = 0x36} - for k, v in pairs(color) do - color[k] = math_floor(0.5 + v * (255 - dark) / 255) - end - skyboxes[dark] = { - base_color = color, - type = "skybox", - textures = {}, - clouds = false, - _darken = dark > 0 and "^[colorize:#000000:" .. dark or "", - } - for k, v in pairs(basetextures) do - skyboxes[dark].textures[k] = v .. skyboxes[dark]._darken - end -end - -local function esc(t) return string_gsub(string_gsub(t, "%^", "\\^"), ":", "\\:") end - -local spawn -nodecore.interval(1, function() - spawn = minetest.setting_get_pos("static_spawnpoint") - or {x = 0, y = 0, z = 0} - end) - -local posscale = 128 / math_log(32768) -nodecore.register_playerstep({ - label = "skybox/sunlight", - action = function(player, data) - local depth = math_floor(player:get_pos().y + 0.5) - - local rawdll = nodecore.get_depth_light(depth, 1) - local dark = 255 - math_ceil(255 * rawdll) - data.sky = {} - for k, v in pairs(skyboxes[dark]) do - data.sky[k] = v - end - local oldtxr = data.sky.textures - data.sky.textures = {} - for k, v in pairs(oldtxr) do - data.sky.textures[k] = v - end - local top = basetextures[1] - top = "[combine:256x256:0,0=" .. esc("(" .. top .. ")^[resize:256x256") - - local pos = vector.subtract(player:get_pos(), spawn) - pos.y = 0 - local dist = vector.length(pos) - local log = math_log(dist + 1) * posscale - pos = vector.multiply(pos, log / dist) - local px = math_ceil(pos.z) - local py = math_ceil(-pos.x) - local opac = (px * px + py * py) / 8 - 200 - if opac > 0 then - if opac > 255 then opac = 255 end - top = top .. ":" .. (123 + px) .. "," .. (123 + py) - .. "=" .. esc("nc_player_sky_star.png^[resize:11x11" - .. "^[opacity:" .. math_ceil(opac)) - data.sky.textures[1] = top .. data.sky._darken - end - - data.daynight = nodecore.get_depth_light(depth) - end - }) - -nodecore.register_on_joinplayer("sky setup", function(player) - for k in pairs({set_sun = true, set_moon = true, set_stars = true}) do - if player[k] then - player[k](player, {visible = false, sunrise_visible = false}) - end - end - end) diff --git a/mods/nc_player_sky/timeofday.lua b/mods/nc_player_sky/timeofday.lua deleted file mode 100644 index 28e9398d..00000000 --- a/mods/nc_player_sky/timeofday.lua +++ /dev/null @@ -1,37 +0,0 @@ --- LUALOCALS < --------------------------------------------------------- -local math, minetest, nodecore, string, tonumber - = math, minetest, nodecore, string, tonumber -local math_abs, string_format - = math.abs, string.format --- LUALOCALS > --------------------------------------------------------- - -local fixedtime = 0.2 - -local warncount = 0 -local nextwarn = 0 -local function warn(curtime) - warncount = warncount + 1 - if nextwarn > 0 then return end - nodecore.log("warning", string_format( - "had to manually adjust time of day (e.g. %1.4f -> %1.4f)" - .. " %d time(s), which creates extra network traffic for all clients" - .. "; make sure time_speed = 0 (currently %d)", - curtime, fixedtime, warncount, minetest.settings:get("time_speed") or 72)) - nextwarn = 300 - warncount = 0 -end - -local timer = 0 -minetest.register_globalstep(function(dtime) - nextwarn = nextwarn - dtime - timer = timer - dtime - if timer > 0 then return end - timer = (tonumber(minetest.settings:get("time_send_interval")) or 5) - 0.25 - dtime - local curtime = minetest.get_timeofday() - if math_abs(curtime - fixedtime) > 0.001 then - warn(curtime) - minetest.set_timeofday(fixedtime) - end - end) - -minetest.unregister_chatcommand("time")