use param1 light update to light-up caves
parent
d345cfe3d2
commit
c7d5bcd6be
|
@ -1,48 +1,43 @@
|
|||
|
||||
local c_air = minetest.get_content_id("air")
|
||||
local c_airlight = minetest.get_content_id("planet_mars:airlight")
|
||||
|
||||
minetest.register_chatcommand("mars_lightup", {
|
||||
description = "restores the airlights on mars around the player position",
|
||||
func = function(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
local pos = player:get_pos()
|
||||
description = "restores the airlights on mars around the player position",
|
||||
func = function(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
local pos = player:get_pos()
|
||||
|
||||
if not planet_mars.is_pos_on_mars(pos) then
|
||||
-- TODO: only light up in mars _caves_
|
||||
return false, "You are not on mars!"
|
||||
end
|
||||
|
||||
local start = minetest.get_us_time()
|
||||
local radius = 16
|
||||
local range = {x=radius, y=radius, z=radius}
|
||||
-- column shape to let light propagate
|
||||
local range = {x=radius, y=radius*5, z=radius}
|
||||
|
||||
local pos1 = vector.subtract(pos, range)
|
||||
local pos2 = vector.add(pos, range)
|
||||
local pos1 = vector.subtract(pos, range)
|
||||
local pos2 = vector.add(pos, range)
|
||||
|
||||
local manip = minetest.get_voxel_manip()
|
||||
local e1, e2 = manip:read_from_map(pos1, pos2)
|
||||
local area = VoxelArea:new({MinEdge=e1, MaxEdge=e2})
|
||||
local data = manip:get_data()
|
||||
local count = 0
|
||||
local manip = minetest.get_voxel_manip()
|
||||
local e1, e2 = manip:read_from_map(pos1, pos2)
|
||||
local area = VoxelArea:new({MinEdge=e1, MaxEdge=e2})
|
||||
local data = manip:get_light_data()
|
||||
|
||||
for z=pos1.z, pos2.z do
|
||||
for y=pos1.y, pos2.y do
|
||||
for x=pos1.x, pos2.x do
|
||||
for z=pos1.z, pos2.z do
|
||||
for y=pos1.y, pos2.y do
|
||||
for x=pos1.x, pos2.x do
|
||||
local index = area:index(x, y, z)
|
||||
data[index] = 14 -- MAX_LIGHT
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local index = area:index(x, y, z)
|
||||
-- check for air and randomize
|
||||
if data[index] == c_air and math.random(5) == 1 then
|
||||
data[index] = c_airlight
|
||||
count = count + 1
|
||||
end
|
||||
manip:set_light_data(data)
|
||||
manip:write_to_map()
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
local diff = minetest.get_us_time() - start
|
||||
local millis = math.floor(diff / 1000)
|
||||
|
||||
manip:set_data(data)
|
||||
manip:write_to_map()
|
||||
|
||||
return true, "Replaced " .. count .. " air nodes with airlights " ..
|
||||
"in a " .. radius .. " node radius"
|
||||
end
|
||||
return true, "light-up completed in " .. millis .. " milliseconds"
|
||||
end
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue