Пример #1
0
        public void AddChunk(IChunkColumn chunk, ChunkCoordinates position, bool doUpdates = false)
        {
            var c = Chunks.AddOrUpdate(position, coordinates =>
            {
                return(chunk);
            }, (vector3, chunk1) =>
            {
                if (!ReferenceEquals(chunk1, chunk))
                {
                    chunk1.Dispose();
                }

                Log.Warn($"Replaced/Updated chunk at {position}");
                return(chunk);
            });

            if (doUpdates)
            {
                ScheduleChunkUpdate(position, ScheduleType.Full);

                ScheduleChunkUpdate(new ChunkCoordinates(position.X + 1, position.Z), ScheduleType.Border);
                ScheduleChunkUpdate(new ChunkCoordinates(position.X - 1, position.Z), ScheduleType.Border);
                ScheduleChunkUpdate(new ChunkCoordinates(position.X, position.Z + 1), ScheduleType.Border);
                ScheduleChunkUpdate(new ChunkCoordinates(position.X, position.Z - 1), ScheduleType.Border);
            }

            //InitiateChunk(c, position);
        }
Пример #2
0
        /// <inheritdoc />
        public void AddChunk(ChunkColumn chunk, ChunkCoordinates position, bool doUpdates = false)
        {
            if (CancellationToken.IsCancellationRequested)
            {
                return;
            }
            //chunk.CalculateHeight();
            if (chunk.IsNew)
            {
                SkyLightCalculator.RecalcSkyLight(chunk, World);
                BlockLightCalculations.Recalculate(chunk);
            }

            foreach (var blockEntity in chunk.GetBlockEntities)
            {
                var coordinates = new BlockCoordinates(blockEntity.X, blockEntity.Y, blockEntity.Z);
                //World.SetBlockEntity(coordinates.X, coordinates.Y, coordinates.Z, blockEntity);
                World.EntityManager.AddBlockEntity(coordinates, blockEntity);
            }

            Chunks.AddOrUpdate(
                position, coordinates => chunk, (coordinates, column) =>
            {
                if (!ReferenceEquals(column, chunk))
                {
                    column.Dispose();
                }

                return(chunk);
            });

            ScheduleChunkUpdate(position, ScheduleType.Full);
            //UpdateQueue.Enqueue(position);
        }
Пример #3
0
        /// <inheritdoc />
        public void AddChunk(ChunkColumn chunk, ChunkCoordinates position, bool doUpdates = false)
        {
            //chunk.CalculateHeight();

            Chunks.AddOrUpdate(
                position, coordinates => chunk, (coordinates, column) =>
            {
                if (!ReferenceEquals(column, chunk))
                {
                    column.Dispose();
                }

                return(chunk);
            });

            if (chunk.IsNew)
            {
                var chunkpos = new BlockCoordinates(position.X << 4, 0, position.Z << 4);

                foreach (var ls in chunk.GetLightSources())
                {
                    BlockLightCalculations.Enqueue(chunkpos + ls);
                }

                //SkyLightCalculations s = new SkyLightCalculations();

                //SkyLightCalculator.Calculate(chunk, position);
            }

            foreach (var blockEntity in chunk.GetBlockEntities)
            {
                var coordinates = new BlockCoordinates(blockEntity.X, blockEntity.Y, blockEntity.Z);
                //World.SetBlockEntity(coordinates.X, coordinates.Y, coordinates.Z, blockEntity);
                World.EntityManager.AddBlockEntity(coordinates, blockEntity);
            }

            ScheduleChunkUpdate(position, ScheduleType.Full);
            //UpdateQueue.Enqueue(position);
        }