Exemple #1
0
        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);
                }
            }
        }