コード例 #1
0
        protected void DigBlock(ChunkColumnStorage chunk, Biome biome, int x, int y, int z, int chunkX, int chunkZ, bool foundTop, BlockState state, BlockState up)
        {
            BlockState top    = biome._topBlock;
            BlockState filler = biome._fillerBlock;

            if (CanReplaceBlock(state, up) ||
                state == top ||
                state == filler)
            {
                // y<10放置岩浆
                if (y < 10)
                {
                    // 设置为岩浆
                    chunk[x, y, z] = BlockStates.Lava();
                }
                else
                {
                    // 设置为空气
                    chunk[x, y, z] = BlockStates.Air();

                    if (up.Id == (uint)BlockId.Sand)
                    {
                        // 如果上面的方块是沙子则替换为沙石
                        chunk[x, y + 1, z] = BlockStates.Sandstone();
                    }

                    if (foundTop && chunk[x, y - 1, z] == filler)
                    {
                        // 如果挖开了顶层方块则把下面的方块设置为biome顶层方块
                        chunk[x, y - 1, z] = top;
                    }
                }
            }
        }
コード例 #2
0
        public bool CanCactiGrow(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Biome biome, Random random, BlockWorldPos pos, int height)
        {
            bool result = true;

            // 检查所有方块可替换
            for (int y = pos.Y; y <= pos.Y + 1 + height; ++y)
            {
                int xzSize = 1;

                // 检查这个平面所有方块可替换
                for (int x = pos.X - xzSize; x <= pos.X + xzSize && result; ++x)
                {
                    for (int z = pos.Z - xzSize; z <= pos.Z + xzSize && result; ++z)
                    {
                        if (y >= 0 && y < 256)
                        {
                            BlockChunkPos chunkPos = new BlockWorldPos(x, y, z).ToBlockChunkPos();
                            BlockState    state    = chunk[chunkPos.X, chunkPos.Y, chunkPos.Z];
                            if (!state.IsAir())
                            {
                                result = false;
                            }
                        }
                        else
                        {
                            result = false;
                        }
                    }
                }
            }

            return(result);
        }
コード例 #3
0
        // 添加其他东西
        public override void Decorate(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Random rand, BlockWorldPos pos)
        {
            GenCacti(world, grainFactory, chunk, rand, pos);

            // TODO 生成仙人掌和枯木
            base.Decorate(world, grainFactory, chunk, rand, pos);
        }
コード例 #4
0
ファイル: BiomeHill.cs プロジェクト: qumeta/MineCase
        public void GenTrees(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Random random, BlockWorldPos pos)
        {
            int treesPerChunk = _treesPerChunk;

            if (random.NextDouble() < _extraTreeChance)
            {
                ++treesPerChunk;
            }

            for (int num = 0; num < treesPerChunk; ++num)
            {
                int x = random.Next(12) + 2;
                int z = random.Next(12) + 2;

                TreeGenerator treeGenerator = new TreeGenerator(5, false, GetRandomTree(random));

                // 获得地表面高度
                int h = 0;
                for (int y = 255; y >= 0; --y)
                {
                    if (!chunk[x, y, z].IsAir())
                    {
                        h = y + 1;
                        break;
                    }
                }

                treeGenerator.Generate(world, grainFactory, chunk, this, random, new BlockWorldPos(pos.X + x, h, pos.Z + z));
            }
        }
コード例 #5
0
 protected virtual void TrySetBlock(ChunkColumnStorage chunk, ChunkWorldPos chunkWorldPos, BlockWorldPos pos, BlockState state)
 {
     if (pos.ToChunkWorldPos() == chunkWorldPos)
     {
         BlockChunkPos blockChunkPos = pos.ToBlockChunkPos();
         chunk[blockChunkPos.X, blockChunkPos.Y, blockChunkPos.Z] = state;
     }
 }
コード例 #6
0
        public void PopulateChunk(IWorld world, ChunkColumnStorage chunk, int x, int z, GeneratorSettings settings)
        {
            int   blockX     = x * 16;
            int   blockZ     = z * 16;
            Biome chunkBiome = Biome.GetBiome(chunk.Biomes[7 * 16 + 7], settings);

            chunkBiome.Decorate(world, GrainFactory, chunk, _random, new BlockWorldPos {
                X = blockX, Y = 0, Z = blockZ
            });
        }
コード例 #7
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);
        }
コード例 #8
0
 public bool CanFlowerGrow(PlantsType type, ChunkColumnStorage chunk, BlockChunkPos pos)
 {
     if (chunk[pos.X, pos.Y - 1, pos.Z] == BlockStates.GrassBlock() ||
         chunk[pos.X, pos.Y - 1, pos.Z] == BlockStates.Dirt())
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #9
0
ファイル: BiomeSwamp.cs プロジェクト: ray-cast/MineCase
        // 添加其他东西
        public override void Decorate(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Random rand, BlockWorldPos pos)
        {
            float grassColor = (_grassColorNoise.Noise((pos.X + 8) / 200.0F, 0.0F, (pos.Z + 8) / 200.0F) - 0.5F) * 2;

            if (grassColor < -0.8F)
            {
                _flowersPerChunk = 15;
                _grassPerChunk   = 5 * 7;
                GenDoubleFlowers(world, grainFactory, chunk, rand, pos);
            }
            else
            {
                _flowersPerChunk = 4;
                _grassPerChunk   = 10 * 7;
            }

            GenGrass(world, grainFactory, chunk, rand, pos);
            GenFlowers(world, grainFactory, chunk, rand, pos);
            GenDoubleGrass(world, grainFactory, chunk, rand, pos);

            int treesPerChunk = _treesPerChunk;

            if (rand.NextDouble() < _extraTreeChance)
            {
                ++treesPerChunk;
            }

            for (int num = 0; num < treesPerChunk; ++num)
            {
                int x = rand.Next(10) + 3;
                int z = rand.Next(10) + 3;

                TreeGenerator treeGenerator = new TreeGenerator(5, true, GetRandomTree(rand));

                // 获得地表面高度
                int h = 0;
                for (int y = 255; y >= 0; --y)
                {
                    if (!chunk[x, y, z].IsAir())
                    {
                        h = y + 1;
                        break;
                    }
                }

                treeGenerator.Generate(world, grainFactory, chunk, this, rand, new BlockWorldPos(pos.X + x, h, pos.Z + z));
            }

            base.Decorate(world, grainFactory, chunk, rand, pos);
        }
コード例 #10
0
ファイル: GrassGenerator.cs プロジェクト: ray-cast/MineCase
        public override void Generate(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Biome biome, Random random, BlockWorldPos pos)
        {
            BlockChunkPos chunkPos = pos.ToBlockChunkPos();
            int           x        = chunkPos.X;
            int           y        = chunkPos.Y;
            int           z        = chunkPos.Z;

            // TODO use block accessor
            if (chunk[x, y, z].IsAir() &&
                chunk[x, y - 1, z] == BlockStates.GrassBlock())
            {
                chunk[x, y, z] = BlockStates.Grass(GrassType.TallGrass);
            }
        }
コード例 #11
0
ファイル: Biome.cs プロジェクト: ray-cast/MineCase
        // 后期添加一些方块,Biome基类主要生成矿物
        public virtual void Decorate(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Random rand, BlockWorldPos pos)
        {
            GenerateOre(_dirtGen, world, grainFactory, chunk, rand, pos, _genSettings.DirtCount, _genSettings.DirtMaxHeight, _genSettings.DirtMinHeight);
            GenerateOre(_gravelOreGen, world, grainFactory, chunk, rand, pos, _genSettings.GravelCount, _genSettings.GravelMaxHeight, _genSettings.GravelMinHeight);
            GenerateOre(_graniteGen, world, grainFactory, chunk, rand, pos, _genSettings.GraniteCount, _genSettings.GraniteMaxHeight, _genSettings.GraniteMinHeight);
            GenerateOre(_dioriteGen, world, grainFactory, chunk, rand, pos, _genSettings.DioriteCount, _genSettings.DioriteMaxHeight, _genSettings.DioriteMinHeight);
            GenerateOre(_andesiteGen, world, grainFactory, chunk, rand, pos, _genSettings.AndesiteCount, _genSettings.AndesiteMaxHeight, _genSettings.AndesiteMinHeight);

            GenerateOre(_coalGen, world, grainFactory, chunk, rand, pos, _genSettings.CoalCount, _genSettings.CoalMaxHeight, _genSettings.CoalMinHeight);
            GenerateOre(_ironGen, world, grainFactory, chunk, rand, pos, _genSettings.IronCount, _genSettings.IronMaxHeight, _genSettings.IronMinHeight);
            GenerateOre(_goldGen, world, grainFactory, chunk, rand, pos, _genSettings.GoldCount, _genSettings.GoldMaxHeight, _genSettings.GoldMinHeight);
            GenerateOre(_redstoneGen, world, grainFactory, chunk, rand, pos, _genSettings.RedstoneCount, _genSettings.RedstoneMaxHeight, _genSettings.RedstoneMinHeight);
            GenerateOre(_diamondGen, world, grainFactory, chunk, rand, pos, _genSettings.DiamondCount, _genSettings.DiamondMaxHeight, _genSettings.DiamondMinHeight);
            GenerateOre(_lapisGen, world, grainFactory, chunk, rand, pos, _genSettings.LapisCount, _genSettings.LapisCenterHeight + _genSettings.LapisSpread, _genSettings.LapisCenterHeight - _genSettings.LapisSpread);
        }
コード例 #12
0
ファイル: BiomeSwamp.cs プロジェクト: ray-cast/MineCase
        // 添加生物群系特有的生物
        public override void SpawnMob(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Random rand, BlockWorldPos pos)
        {
            ChunkWorldPos chunkPos = pos.ToChunkWorldPos();
            int           seed     = chunkPos.Z * 16384 + chunkPos.X;
            Random        r        = new Random(seed);

            foreach (MobType eachType in _passiveMobList)
            {
                if (r.Next(32) == 0)
                {
                    PassiveMobSpawner spawner = new PassiveMobSpawner(eachType, 10);
                    spawner.Spawn(world, grainFactory, chunk, rand, new BlockWorldPos(pos.X, pos.Y, pos.Z));
                }
            }
        }
コード例 #13
0
ファイル: Biome.cs プロジェクト: hong1990/MineCase
        // 添加生物群系特有的怪物
        public virtual void SpawnMonster(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Random rand, BlockWorldPos pos)
        {
            ChunkWorldPos chunkPos = pos.ToChunkWorldPos();
            int           seed     = chunkPos.Z * 16384 + chunkPos.X;
            Random        r        = new Random(seed);

            foreach (MobType eachType in _monsterList)
            {
                if (r.Next(64) == 0)
                {
                    MonsterSpawner spawner = new MonsterSpawner(eachType, 3);
                    spawner.Spawn(world, grainFactory, chunk, rand, new BlockWorldPos(pos.X, pos.Y, pos.Z));
                }
            }
        }
コード例 #14
0
        private void ReplaceBiomeBlocks(GeneratorSettings settings, int x, int z, ChunkColumnStorage chunk, Biome[,] biomesIn)
        {
            _surfaceNoise.Noise(
                _surfaceMap,
                new Vector3(x * 16 + 0.1F, 0, z * 16 + 0.1F),
                new Vector3(0.0625F, 1.0F, 0.0625F));

            for (int x1 = 0; x1 < 16; ++x1)
            {
                for (int z1 = 0; z1 < 16; ++z1)
                {
                    Biome biome = biomesIn[z1, x1];
                    biome.GenerateBiomeTerrain(settings.SeaLevel, _random, chunk, x, z, x1, z1, (_surfaceMap[x1, 0, z1] - 0.5) * 2);
                }
            }
        }
コード例 #15
0
ファイル: MonsterSpawner.cs プロジェクト: hong1990/MineCase
        public bool CanMobStand(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Random random, BlockChunkPos pos)
        {
            // TODO 以后结合boundbox判断
            BlockChunkPos downPos = new BlockChunkPos(pos.X, pos.Y - 1, pos.Z);

            if (chunk[pos.X, pos.Y - 1, pos.Z].IsLightOpacity() == 0)
            {
                if (chunk[pos.X, pos.Y, pos.Z] == BlockStates.Air() &&
                    chunk[pos.X, pos.Y + 1, pos.Z] == BlockStates.Air())
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #16
0
ファイル: TreeGenerator.cs プロジェクト: ray-cast/MineCase
        public bool CanTreeGrow(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Biome biome, Random random, BlockWorldPos pos, int height)
        {
            bool result = true;

            // 检查所有方块可替换
            for (int y = pos.Y; y <= pos.Y + 1 + height; ++y)
            {
                int xzSize = 1;

                // 底端
                if (y == pos.Y)
                {
                    xzSize = 0;
                }

                // 顶端
                if (y >= pos.Y + height - 1)
                {
                    xzSize = 2;
                }

                // 检查这个平面所有方块可替换
                for (int x = pos.X - xzSize; x <= pos.X + xzSize && result; ++x)
                {
                    for (int z = pos.Z - xzSize; z <= pos.Z + xzSize && result; ++z)
                    {
                        if (y >= 0 && y < 256)
                        {
                            BlockChunkPos chunkPos = pos.ToBlockChunkPos();
                            BlockState    state    = chunk[chunkPos.X, chunkPos.Y, chunkPos.Z];
                            if (!state.IsAir() &&
                                state.IsSameId(BlockStates.Leaves()) &&
                                state.IsSameId(BlockStates.Leaves2()))
                            {
                                result = false;
                            }
                        }
                        else
                        {
                            result = false;
                        }
                    }
                }
            }

            return(result);
        }
コード例 #17
0
 private void GenerateSkylightMap(ChunkColumnStorage chunk)
 {
     for (int i = 0; i < ChunkConstants.SectionsPerChunk; ++i)
     {
         var skyLight = chunk.Sections[i].SkyLight;
         for (int y = 0; y < ChunkConstants.BlockEdgeWidthInSection; y++)
         {
             for (int z = 0; z < ChunkConstants.BlockEdgeWidthInSection; z++)
             {
                 for (int x = 0; x < ChunkConstants.BlockEdgeWidthInSection; x++)
                 {
                     skyLight[x, y, z] = 0xF;
                 }
             }
         }
     }
 }
コード例 #18
0
        public override void Generate(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Biome biome, Random random, BlockWorldPos pos)
        {
            int num = random.Next(_flowersMaxNum);

            for (int i = 0; i < num; ++i)
            {
                BlockWorldPos blockpos = BlockWorldPos.Add(pos, random.Next(8), random.Next(4), random.Next(8));
                BlockChunkPos chunkpos = blockpos.ToBlockChunkPos();
                if (chunk[chunkpos.X, chunkpos.Y, chunkpos.Z].IsAir() &&
                    blockpos.Y < 254 &&
                    CanFlowerGrow(_flowerType, chunk, chunkpos))
                {
                    chunk[chunkpos.X, chunkpos.Y, chunkpos.Z]     = BlockStates.LargeFlowers(LargeFlowerType.Sunflower);
                    chunk[chunkpos.X, chunkpos.Y + 1, chunkpos.Z] = BlockStates.LargeFlowers(LargeFlowerType.TopHalfFlag);
                }
            }
        }
コード例 #19
0
        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());
        }
コード例 #20
0
ファイル: BiomeSwamp.cs プロジェクト: ray-cast/MineCase
        private void GenDoubleGrass(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Random random, BlockWorldPos pos)
        {
            DoubleGrassGenerator generator = new DoubleGrassGenerator(PlantsType.DoubleTallgrass);

            for (int grassNum = 0; grassNum < 2; ++grassNum)
            {
                int x = random.Next(16);
                int z = random.Next(16);
                for (int y = 255; y >= 1; --y)
                {
                    if (!chunk[x, y, z].IsAir())
                    {
                        generator.Generate(world, grainFactory, chunk, this, random, new BlockWorldPos(pos.X + x, y + 1, pos.Z + z));
                        break;
                    }
                }
            }
        }
コード例 #21
0
        public override void GenerateBiomeTerrain(int seaLevel, Random rand, ChunkColumnStorage chunk, int chunk_x, int chunk_z, int x_in_chunk, int z_in_chunk, double noiseVal)
        {
            _topBlock    = BlockStates.GrassBlock();
            _fillerBlock = BlockStates.Dirt();

            if ((noiseVal < -1.0D || noiseVal > 2.0D) && _type == BiomeHillType.Mutated)
            {
                _topBlock    = BlockStates.Gravel();
                _fillerBlock = BlockStates.Gravel();
            }
            else if (noiseVal > 0.0D && _type != BiomeHillType.ExtraTrees)
            {
                _topBlock    = BlockStates.Stone();
                _fillerBlock = BlockStates.Stone();
            }

            base.GenerateBiomeTerrain(seaLevel, rand, chunk, chunk_x, chunk_z, x_in_chunk, z_in_chunk, noiseVal);
        }
コード例 #22
0
ファイル: MonsterSpawner.cs プロジェクト: hong1990/MineCase
        public async void Spawn(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Random random, BlockWorldPos pos)
        {
            int num = random.Next(_groupMaxNum);

            for (int n = 0; n < num; ++n)
            {
                int x = random.Next(16);
                int z = random.Next(16);

                int height;
                for (height = 255; height >= 0; height--)
                {
                    if (chunk[x, height, z] != BlockStates.Air())
                    {
                        break;
                    }
                }

                BlockWorldPos standPos = new BlockWorldPos(pos.X + x, height + 1, pos.Z + z);
                if (CanMobStand(world, grainFactory, chunk, random, standPos.ToBlockChunkPos()))
                {
                    // 添加一个生物

                    /*
                     * var eid = await world.NewEntityId();
                     * var entity = grainFactory.GetGrain<IPassiveMob>(world.MakeEntityKey(eid));
                     * await world.AttachEntity(entity);
                     *
                     * await entity.Spawn(Guid.NewGuid(), new Vector3(pos.X + x + 0.5F, height + 1, pos.Z + z + 0.5F), _mobType);
                     * await entity.OnCreated();
                     */

                    IMob entity = grainFactory.GetGrain <IMob>(Guid.NewGuid());
                    await entity.Tell(new SpawnMob
                    {
                        World    = world,
                        EntityId = await world.NewEntityId(),
                        Position = new EntityWorldPos(pos.X + x + 0.5F, height + 1, pos.Z + z + 0.5F),
                        MobType  = _mobType,
                    });
                }
            }
        }
コード例 #23
0
ファイル: BiomeSwamp.cs プロジェクト: ray-cast/MineCase
        private void GenFlowers(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Random random, BlockWorldPos pos)
        {
            int flowersMaxNum          = random.Next(_flowersPerChunk);
            FlowersGenerator generator = new FlowersGenerator();

            for (int flowersNum = 0; flowersNum < flowersMaxNum; ++flowersNum)
            {
                int x = random.Next(16);
                int z = random.Next(16);
                for (int y = 255; y >= 1; --y)
                {
                    if (!chunk[x, y, z].IsAir())
                    {
                        generator.Generate(world, grainFactory, chunk, this, random, new BlockWorldPos(pos.X + x, y + 1, pos.Z + z));
                        break;
                    }
                }
            }
        }
コード例 #24
0
        public override void Generate(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Biome biome, Random random, BlockWorldPos pos)
        {
            int           height   = random.Next(3) + _minCactiHeight;
            BlockChunkPos chunkPos = pos.ToBlockChunkPos();

            // 不超出世界边界
            if (pos.Y >= 1 && pos.Y + height + 1 <= 256)
            {
                if (CanCactiGrow(world, grainFactory, chunk, biome, random, pos, height))
                {
                    BlockState state = chunk[chunkPos.X, chunkPos.Y - 1, chunkPos.Z];
                    if (CanSustainCacti(state))
                    {
                        for (int y = 0; y < height; ++y)
                        {
                            chunk[chunkPos.X, chunkPos.Y + y, chunkPos.Z] = BlockStates.Cactus(CactusType.Interval15);
                        }
                    }
                }
            }
        }
コード例 #25
0
        private void GenCacti(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Random random, BlockWorldPos pos)
        {
            int cactiMaxNum = random.Next(_cactiPerChunk);

            if (random.Next(64) == 0)
            {
                CactiGenerator generator = new CactiGenerator();
                for (int cactiNum = 0; cactiNum < cactiMaxNum; ++cactiNum)
                {
                    int x = random.Next(14) + 1;
                    int z = random.Next(14) + 1;
                    for (int y = 255; y >= 1; --y)
                    {
                        if (!chunk[x, y, z].IsAir())
                        {
                            generator.Generate(world, grainFactory, chunk, this, random, new BlockWorldPos(pos.X + x, y + 1, pos.Z + z));
                            break;
                        }
                    }
                }
            }
        }
コード例 #26
0
        private void GenerateSkylightMap(ChunkColumnStorage chunk)
        {
            int skyLightValue = 15;

            for (int z = 0; z < ChunkConstants.BlockEdgeWidthInSection; z++)
            {
                for (int x = 0; x < ChunkConstants.BlockEdgeWidthInSection; x++)
                {
                    skyLightValue = 15;
                    for (int y = ChunkConstants.ChunkHeight - 1; y >= 0; y--)
                    {
                        int sectionY      = y / ChunkConstants.BlockEdgeWidthInSection;
                        int sectionOffset = y % ChunkConstants.BlockEdgeWidthInSection;
                        var skyLight      = chunk.Sections[sectionY].SkyLight;
                        skyLight[x, sectionOffset, z] = 0;
                    }

                    for (int y = ChunkConstants.ChunkHeight - 1; y >= 0; y--)
                    {
                        int sectionY      = y / ChunkConstants.BlockEdgeWidthInSection;
                        int sectionOffset = y % ChunkConstants.BlockEdgeWidthInSection;
                        var skyLight      = chunk.Sections[sectionY].SkyLight;
                        skyLight[x, sectionOffset, z] = (byte)(skyLightValue & 0xF);
                        int lightOpacity = Block.Block.FromBlockState(chunk[x, y, z]).LightOpacity;
                        if (lightOpacity == 0 && skyLightValue != 15)
                        {
                            lightOpacity = 1;
                        }

                        skyLightValue -= lightOpacity;

                        if (skyLightValue <= 0)
                        {
                            break;
                        }
                    }
                }
            }
        }
コード例 #27
0
        public void Generate(StructureGenerationInfo info, int chunkX, int chunkZ, ChunkColumnStorage chunk, Biome biome)
        {
            int range = _range;

            _info = info;
            _rand = new Random(info.Seed);
            int rand1 = _rand.Next();
            int rand2 = _rand.Next();

            // 遍历周围(range*2+1)*(range*2+1)的区块,默认range=8
            for (int x = chunkX - range; x <= chunkX + range; ++x)
            {
                for (int z = chunkZ - range; z <= chunkZ + range; ++z)
                {
                    int randX = x * rand1;
                    int randZ = z * rand2;
                    _rand = new Random(randX ^ randZ ^ info.Seed);

                    // 调用子类方法
                    RecursiveGenerate(info, x, z, chunkX, chunkZ, chunk, biome);
                }
            }
        }
コード例 #28
0
        public override void Generate(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Biome biome, Random random, BlockWorldPos pos)
        {
            BlockChunkPos chunkPos = pos.ToBlockChunkPos();
            int           x        = chunkPos.X;
            int           y        = chunkPos.Y;
            int           z        = chunkPos.Z;

            // TODO use block accessor
            if (chunk[x, y, z].IsAir() &&
                chunk[x, y - 1, z] == BlockStates.GrassBlock())
            {
                var flowerType = biome.GetRandomFlower(random);
                switch (flowerType)
                {
                case PlantsType.RedFlower:
                    chunk[x, y, z] = BlockStates.Poppy();
                    break;

                case PlantsType.YellowFlower:
                    chunk[x, y, z] = BlockStates.Dandelion();
                    break;
                }
            }
        }
コード例 #29
0
ファイル: Taiga2Generator.cs プロジェクト: ray-cast/MineCase
        public override void Generate(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Biome biome, Random random, BlockWorldPos pos)
        {
            int  height = random.Next(4) + 6;
            int  j      = 1 + random.Next(2);
            int  k      = height - j;
            int  l      = 2 + random.Next(2);
            bool flag   = true;

            if (pos.Y >= 1 && pos.Y + height + 1 <= 255)
            {
                for (int y = pos.Y; y <= pos.Y + 1 + height && flag; ++y)
                {
                    int xzWidth;

                    if (y - pos.Y < j)
                    {
                        xzWidth = 0;
                    }
                    else
                    {
                        xzWidth = l;
                    }

                    for (int x = pos.X - xzWidth; x <= pos.X + xzWidth && flag; ++x)
                    {
                        for (int z = pos.Z - xzWidth; z <= pos.Z + xzWidth && flag; ++z)
                        {
                            if (y >= 0 && y < 256)
                            {
                                BlockChunkPos chunkPos = new BlockWorldPos(x, y, z).ToBlockChunkPos();
                                BlockState    state    = chunk[chunkPos.X, chunkPos.Y, chunkPos.Z];

                                if (!(state.IsAir() ||
                                      state.IsLeaves()))
                                {
                                    flag = false;
                                }
                            }
                            else
                            {
                                flag = false;
                            }
                        }
                    }
                }

                if (!flag)
                {
                    // return false;
                }
                else
                {
                    BlockChunkPos down  = new BlockWorldPos(pos.X, pos.Y - 1, pos.Z).ToBlockChunkPos();
                    BlockState    state = chunk[down.X, down.Y, down.Z];

                    if (CanSustainTree(PlantsType.Spruce, state) && pos.Y < 256 - height - 1)
                    {
                        int xzWidth = random.Next(2);
                        int j3      = 1;
                        int k3      = 0;

                        for (int l3 = 0; l3 <= k; ++l3)
                        {
                            int y = pos.Y + height - l3;

                            for (int x = pos.X - xzWidth; x <= pos.X + xzWidth; ++x)
                            {
                                int deltaX = x - pos.X;

                                for (int z = pos.Z - xzWidth; z <= pos.Z + xzWidth; ++z)
                                {
                                    int deltaZ = z - pos.Z;

                                    if (Math.Abs(deltaX) != xzWidth || Math.Abs(deltaZ) != xzWidth || xzWidth <= 0)
                                    {
                                        BlockChunkPos blockpos = new BlockWorldPos(x, y, z).ToBlockChunkPos();
                                        state = chunk[blockpos.X, blockpos.Y, blockpos.Z];

                                        if (state.IsAir() ||
                                            state.IsLeaves() ||
                                            state.IsSameId(BlockStates.Vines()))
                                        {
                                            chunk[blockpos.X, blockpos.Y, blockpos.Z] = _leaves;
                                        }
                                    }
                                }
                            }

                            if (xzWidth >= j3)
                            {
                                xzWidth = k3;
                                k3      = 1;
                                ++j3;

                                if (j3 > l)
                                {
                                    j3 = l;
                                }
                            }
                            else
                            {
                                ++xzWidth;
                            }
                        }

                        int heightLeft = random.Next(3);

                        for (int y = 0; y < height - heightLeft; ++y)
                        {
                            BlockChunkPos upN = new BlockWorldPos(pos.X, pos.Y + y, pos.Z).ToBlockChunkPos();
                            state = chunk[upN.X, upN.Y, upN.Z];

                            if (state.IsAir() || state.IsSameId(BlockStates.Leaves()) || state.IsSameId(BlockStates.Leaves2()))
                            {
                                chunk[upN.X, upN.Y, upN.Z] = _wood;
                            }
                        }

                        // return true;
                    }
                    else
                    {
                        // return false;
                    }
                }
            }
            else
            {
                // return false;
            }
        }
コード例 #30
0
 protected abstract void RecursiveGenerate(StructureGenerationInfo info, int chunkX, int chunkZ, int centerChunkX, int centerChunkZ, ChunkColumnStorage chunk, Biome biome);