If you look at some of the previous posts you will see this code or a variant of it in use. It may be useful to some. It is very much a hack and i hope to revisit it perhaps in c++ or java.
public static void SpreadChunkLight(Chunk chunk)
{
int x, y, z; byte l;
using (new Timer("Spread Light"))
{
while (chunk.lightSources.Count > 0)
{
LightUnit lu = chunk.lightSources.Dequeue();
x = lu.pos.X; y = lu.pos.Y; z = lu.pos.Z;
l = lu.val;
if (IsolatedSunlight(lu.pos.X, lu.pos.Y, lu.pos.Z)) { continue; }
Spread(x - 1, y, z, l, chunk);
Spread(x + 1, y, z, l, chunk);
Spread(x, y + 1, z, l, chunk);
Spread(x, y - 1, z, l, chunk);
Spread(x, y, z + 1, l, chunk);
Spread(x, y, z - 1, l, chunk);
}
}
chunk.State = ChunkState.SpreadLight; chunk.working = false;
chunk.StateCheck();
}
static void Spread(int x, int y, int z, byte l, Chunk pchunk)
{
if (l <2) { return; }
if (World.IsOpaque(x, y, z)) { return; }
Chunk chunk = World.GetChunkFromHit(x, y, z);
if (chunk == null) { return; }
byte blocklight = GetBlockLightIndex(x, y, z);
if (blocklight > (byte)(l - 2)) { return; }
if (World.loadedChunks >= World.totalChunks)
{
if (chunk.X != pchunk.X || chunk.Y != pchunk.Y || chunk.Z != pchunk.Z)
{
// Debug.Log("light into chunk");
// if (!Pool.toCheckState.Contains(chunk) && chunk.State == ChunkState.Render) { chunk.working = false; chunk.State = ChunkState.SpreadLight; Pool.toCheckState.Enqueue(chunk); }
}
}
lightspreadcount++;
l = (byte)(l - 1);
CoreLighting.SetBlockLight(x, y, z, l);
Spread(x - 1, y, z, l, pchunk);
Spread(x + 1, y, z, l, pchunk);
Spread(x, y + 1, z, l, pchunk);
Spread(x, y - 1, z, l, pchunk);
Spread(x, y, z + 1, l, pchunk);
Spread(x, y, z - 1, l, pchunk);
}