protected void DoSkyLight(ChunkData chunk, int x, int ystart, int z) { var tileX = chunk.X * 16 + x; var tileZ = chunk.Y * 16 + z; var height = chunk.GetHeight(x, z); // From where should we start calculating int newHeight = Math.Max(height, ystart); // We need to cast light through transparent blocks while (newHeight > 0 && Block.LightAbsorbs[chunk.GetBlock(x, newHeight - 1, z)] == 0) newHeight--; // Nothing changed, we don't need to calculate if (newHeight == height) return; chunk.SetHeight(x, z, newHeight); /* The new height is lower than the last, that means all the tiles * above are fully lit */ if (newHeight < height) { for (int y = newHeight; y < height; y++) { chunk.SkyLight.SetValue(x, y, z, 15); } } else if (newHeight > height) { ScheduleUpdate(LightType.Sky, new Box(tileX, height, tileZ, tileX, newHeight, tileZ)); for (int y = height; y < newHeight; y++) { chunk.SkyLight.SetValue(x, y, z, 0); } } }
public void RecalculateLighting(ChunkData chunk) { for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { chunk.SetHeight(x, z, 0); DoSkyLight(chunk, x, 127, z); } } }