Exemple #1
0
        private void GenerateChunk(MapGenerationInfo info, ChunkColumnStorage chunk, int x, int z, GeneratorSettings settings)
        {
            // 生物群系生成
            // 获取生物群系
            int[,] biomeIds = _genlayer.GetInts(x * 16 - 8, z * 16 - 8, 32, 32);

            for (int i = 0; i < 10; ++i)
            {
                for (int j = 0; j < 10; ++j)
                {
                    _biomesForGeneration[j, i] = Biome.GetBiome(biomeIds[(int)(0.861111F * j * 4), (int)(0.861111F * i * 4)], settings);
                }
            }

            // 基本地形生成
            GenerateBasicTerrain(chunk, x, z, settings);

            // 获取生物群系
            biomeIds = _genlayer.GetInts(x * 16, z * 16, 16, 16);

            for (int i = 0; i < 16; ++i)
            {
                for (int j = 0; j < 16; ++j)
                {
                    _biomesForGeneration[j, i] = Biome.GetBiome(biomeIds[j, i], settings);
                }
            }

            // 设置生物群系
            for (int height = 0; height < 64; ++height)
            {
                for (int i = 0; i < 4; ++i)
                {
                    for (int j = 0; j < 4; ++j)
                    {
                        chunk.Biomes[(height * 4 + i) * 4 + j] = (int)_biomesForGeneration[j * 4, i * 4].GetBiomeId();
                    }
                }
            }

            // 添加生物群系特有方块
            ReplaceBiomeBlocks(settings, x, z, chunk, _biomesForGeneration);

            // Todo genrate structure
            // 生成洞穴
            if (settings.UseCaves)
            {
                CavesGenerator generator = new CavesGenerator(info);
                generator.Generate(info, x, z, chunk, _biomesForGeneration[8, 8]);
            }

            // 计算skylight
            GenerateSkylightMap(chunk);
        }
        public async Task <ChunkColumnCompactStorage> Generate(IWorld world, int x, int z, GeneratorSettings settings)
        {
            var chunkColumn = new ChunkColumnStorage();

            for (int i = 0; i < chunkColumn.Sections.Length; ++i)
            {
                chunkColumn.Sections[i] = new ChunkSectionStorage(true);
            }

            var info = new MapGenerationInfo
            {
                Seed = await world.GetSeed()
            };

            GenerateChunk(info, chunkColumn, x, z, settings);
            PopulateChunk(world, chunkColumn, x, z, settings);
            return(chunkColumn.Compact());
        }
Exemple #3
0
        protected override void RecursiveGenerate(MapGenerationInfo info, int chunkX, int chunkZ, int centerChunkX, int centerChunkZ, ChunkColumnStorage chunk, Biome biome)
        {
            // 之前根据chunkXZ设置种子了
            int seedPointCount = _rand.Next(15);

            // 仅1/7概率生成洞穴
            if (_rand.Next(7) != 0)
            {
                seedPointCount = 0;
            }

            for (int i = 0; i < seedPointCount; ++i)
            {
                // 在chunk内x=0-16,y=8~127,z=0-16随机选种子点
                double seedPointX     = (double)(chunkX * 16 + _rand.Next(16));
                double seedPointY     = (double)_rand.Next(120) + 8;
                double seedPointZ     = (double)(chunkZ * 16 + _rand.Next(16));
                int    directionCount = 1;

                // 四分之一概率挖一个默认的洞
                if (_rand.Next(4) == 0)
                {
                    // 使用默认参数挖出一个洞
                    AddTunnel(_rand.Next(), centerChunkX, centerChunkZ, chunk, biome, seedPointX, seedPointY, seedPointZ);
                    directionCount += _rand.Next(4);
                }

                // 向几个方向挖洞
                for (int j = 0; j < directionCount; ++j)
                {
                    float yawAngle   = (float)_rand.NextDouble() * (float)Math.PI * 2.0F;
                    float pitchAngle = ((float)_rand.NextDouble() - 0.5F) * 2.0F / 8.0F;
                    float rangeScale = (float)_rand.NextDouble() * 2.0F + (float)_rand.NextDouble();

                    if (_rand.Next(10) == 0)
                    {
                        // 扩大到1~3倍
                        rangeScale *= (float)_rand.NextDouble() * 3.0F + 1.0F;
                    }

                    AddTunnel(_rand.Next(), centerChunkX, centerChunkZ, chunk, biome, seedPointX, seedPointY, seedPointZ, rangeScale, yawAngle, pitchAngle, 0, 0, 1.0D);
                }
            }
        }
Exemple #4
0
 public CavesGenerator(MapGenerationInfo info, int range = 8)
     : base(info, range)
 {
 }