Пример #1
0
        public virtual bool LoadChunk(ChunkPos chunkPos)
        {
            byte[] data = ChunkData.GetChunkData(chunkPos);
            if (data == null)
            {
                return(false);
            }

            short[,,] blockData = new short[Chunk.ChunkSize, Chunk.ChunkHeight, Chunk.ChunkSize];
            Buffer.BlockCopy(data, 0, blockData, 0, data.Length);

            Chunk chunk = null;

            lock (Chunks)
            {
                chunk = PutChunk(chunkPos, blockData);
            }

            if (chunk != null)
            {
                var air = BlockRegistry.GetBlock <BlockAir>();

                Enumerable.Range(0, Chunk.ChunkHeight).AsParallel().ForAll(y =>
                {
                    for (int x = 0; x < Chunk.ChunkSize; x++)
                    {
                        for (int z = 0; z < Chunk.ChunkSize; z++)
                        {
                            var localPos = new BlockPos(x, y, z);

                            var state = chunk.GetBlockState(localPos);

                            if (state.Block == air)
                            {
                                continue;
                            }

                            var worldPos = new BlockPos(chunkPos.ToVec() + localPos.ToVec());

                            if (state.Block.CreateTileEntity(this, worldPos) is TileEntity te)
                            {
                                chunk.AddTileEntity(localPos, te);
                            }
                        }
                    }
                });
            }

            return(true);
        }