Exemplo n.º 1
0
        private void Spread(ConcurrentQueue <LightingItem> queue, ChunkColumn chunk, BlockFace face, int x, int y, int z, int lightLevel)
        {
            if (lightLevel <= 0)
            {
                return;
            }

            var chunkCoordinates = new ChunkCoordinates(x >> 4, z >> 4);

            if (chunkCoordinates.X != chunk.X || chunkCoordinates.Z != chunk.Z)
            {
                Enqueue(face, x, y, z, lightLevel);
                return;
            }

            //if (!ChunkManager.TryGetChunk(chunkCoordinates, out var chunk))
            //{
            //	Enqueue(face, x, y, z, lightLevel);
            //	return;
            //}

            //var self = World.GetBlockState(x, y, z).Block;
            var self = chunk.GetBlockState(x & 0xf, y & 0xff, z & 0xf).Block;

            if (self.BlockMaterial.BlocksLight)
            {
                return;
            }

            lightLevel -= self.LightOpacity;

            if (lightLevel < 0)
            {
                lightLevel = 0;
            }

            if (lightLevel < chunk.GetSkylight(x & 0xf, y & 0xff, z & 0xf))
            {
                return;
            }

            chunk.SetSkyLight(x & 0xf, y & 0xff, z & 0xf, (byte)lightLevel);

            if (lightLevel <= 0)
            {
                return;
            }

            //lightLevel--;

            if (face != BlockFace.East)
            {
                Enqueue(queue, BlockFace.West, x - 1, y, z, lightLevel);
            }

            if (face != BlockFace.West)
            {
                Enqueue(queue, BlockFace.East, x + 1, y, z, lightLevel);
            }

            if (face != BlockFace.South)
            {
                Enqueue(queue,
                        BlockFace.North, x, y, z - 1, lightLevel);
            }

            if (face != BlockFace.North)
            {
                Enqueue(queue, BlockFace.South, x, y, z + 1, lightLevel);
            }

            if (face != BlockFace.Up && y > 0)
            {
                Enqueue(queue, BlockFace.Down, x, y - 1, z, lightLevel);
            }

            if (face != BlockFace.Down && y < 256)
            {
                Enqueue(queue, BlockFace.Up, x, y + 1, z, lightLevel);
            }
        }