light restore PoC

master
BuckarooBanzay 2020-06-05 18:40:50 +02:00
parent 9a9e4e3d0c
commit 895e4a3983
2 changed files with 47 additions and 0 deletions

View File

@ -22,5 +22,6 @@ dofile(MP.."/mapgen.lua")
dofile(MP.."/skybox.lua")
dofile(MP.."/vacuum.lua")
dofile(MP.."/marble.lua")
--dofile(MP.."/light_restore.lua")
print("[OK] Planet: mars (start: " .. planet_mars.y_start .. ", height:" .. planet_mars.y_height .. ")")

46
light_restore.lua Normal file
View File

@ -0,0 +1,46 @@
-- proof of concept light restore
-- XXX: unstable, unfinished, things may explode
local c_air = minetest.get_content_id("air")
local c_airlight = minetest.get_content_id("planet_mars:airlight")
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer < 2 then
return
end
timer = 0
print("light recalc")
for _, player in ipairs(minetest.get_connected_players()) do
-- TODO: check if player is in mars and in a cave (perlin noise)
local pos = player:get_pos()
local distance = 8
local pos1 = vector.subtract(pos, distance)
local pos2 = vector.add(pos, distance)
local manip = minetest.get_voxel_manip()
local minp, maxp = manip:read_from_map(pos1, pos2)
local area = VoxelArea:new({MinEdge=minp, MaxEdge=maxp})
local data = manip:get_data()
for z=minp.z,maxp.z do
for y=minp.y,maxp.y do
for x=minp.x,maxp.x do
local index = area:index(x,y,z)
if data[index] == c_air then
data[index] = c_airlight
end
end --x
end --y
end --z
manip:set_data(data)
manip:write_to_map()
end
end)