Ejemplo n.º 1
0
Archivo: World.cs Proyecto: gaeqs/CMine
        public Chunk CreateChunk(Vector3i position)
        {
            var regionPosition = position >> 2;

            var region = GetChunkRegion(regionPosition);

            if (region == null)
            {
                region = new ChunkRegion(this, regionPosition);
                region.LoadIfDeleted();
                _chunkRegions[regionPosition] = region;
            }
            else
            {
                region.LoadIfDeleted();
            }

            var chunk = region.GetChunkFromChunkPosition(position);

            if (chunk != null)
            {
                return(chunk);
            }

            var chunkPositionInRegion = position - (regionPosition << 2);

            if (region.TryLoadSavedChunk(chunkPositionInRegion, out chunk))
            {
                _unloadedChunkGenerationManager.OnChunkLoad(chunk);
                return(chunk);
            }

            chunk = new Chunk(region, position)
            {
                Natural = true
            };
            region.SetChunk(chunk, chunkPositionInRegion);
            _worldGenerator.GenerateChunkData(chunk);
            _unloadedChunkGenerationManager.FlushToAllChunks();

            return(chunk);
        }
Ejemplo n.º 2
0
Archivo: World.cs Proyecto: gaeqs/CMine
        public Block SetBlock(BlockSnapshot snapshot, Vector3i position, Func <Block, bool> canBeReplaced)
        {
            var regionPosition = position >> 6;
            var chunkPosition  = position >> 4;

            var region = GetChunkRegion(regionPosition);

            if (region == null)
            {
                region = new ChunkRegion(this, regionPosition);
                region.LoadIfDeleted();
                _chunkRegions[regionPosition] = region;
            }

            var chunk = region.GetChunkFromChunkPosition(chunkPosition);

            if (chunk != null)
            {
                return(chunk.SetBlockFromWorldPosition(snapshot, position, canBeReplaced));
            }
            _unloadedChunkGenerationManager.AddBlock(position, snapshot, true);
            return(null);
        }