Esempio n. 1
0
        public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
        {
            for (int attempts = 0; attempts < 8; attempts++)
            {
                var noise = new Perlin();
                noise.Seed = world.Seed - (chunk.Coordinates.X + chunk.Coordinates.Z);
                var offsetNoise = new ClampNoise(noise);
                offsetNoise.MaxValue = 3;
                var x = 0;
                var z = 0;
                var offset = 0.0;
                offset += offsetNoise.Value2D(x, z);
                int finalX = (int)Math.Floor(x + offset);
                int finalZ = (int)Math.Floor(z + offset);
                var y = (int)(10 + offset);

                var blockX = MathHelper.ChunkToBlockX(finalX, chunk.Coordinates.X);
                var blockZ = MathHelper.ChunkToBlockZ(finalZ, chunk.Coordinates.Z);
                var spawnValue = offsetNoise.Value2D(blockX, blockZ);
                if (spawnValue > 1.95 && spawnValue < 2.09)
                {
                    var generated = new Dungeon().GenerateAt(world, chunk, new Coordinates3D(blockX, y, blockZ));
                    if (generated)
                        break;
                }
            }
        }
Esempio n. 2
0
 public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
 {
     var noise = new Perlin();
     noise.Seed = world.Seed;
     var chanceNoise = new ClampNoise(noise);
     chanceNoise.MaxValue = 2;
     for (int x = 0; x < 16; x++)
     {
         for (int z = 0; z < 16; z++)
         {
             var biome = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
             var blockX = MathHelper.ChunkToBlockX(x, chunk.Coordinates.X);
             var blockZ = MathHelper.ChunkToBlockZ(z, chunk.Coordinates.Z);
             var height = chunk.HeightMap[x * Chunk.Width + z];
             if (biome.Plants.Contains(PlantSpecies.Cactus) && chanceNoise.Value2D(blockX, blockZ) > 1.7)
             {
                 var blockLocation = new Coordinates3D(x, height, z);
                 var cactiPosition = blockLocation + Coordinates3D.Up;
                 if (chunk.GetBlockID(blockLocation).Equals(SandBlock.BlockID))
                 {
                     var HeightChance = chanceNoise.Value2D(blockX, blockZ);
                     var CactusHeight = (HeightChance < 1.4) ? 2 : 3;
                     Decoration.GenerateColumn(chunk, cactiPosition, CactusHeight, CactusBlock.BlockID);
                 }
             }
         }
     }
 }
Esempio n. 3
0
 public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
 {
     var noise = new Perlin();
     noise.Seed = world.Seed;
     var chanceNoise = new ClampNoise(noise);
     chanceNoise.MaxValue = 2;
     for (int x = 0; x < 16; x++)
     {
         for (int z = 0; z < 16; z++)
         {
             var biome = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
             var blockX = MathHelper.ChunkToBlockX(x, chunk.Coordinates.X);
             var blockZ = MathHelper.ChunkToBlockZ(z, chunk.Coordinates.Z);
             var height = chunk.HeightMap[x * Chunk.Width + z];
             if (noise.Value2D(blockX, blockZ) > 0)
             {
                 var blockLocation = new Coordinates3D(x, height, z);
                 var plantPosition = blockLocation + Coordinates3D.Up;
                 if (chunk.GetBlockID(blockLocation) == biome.SurfaceBlock && plantPosition.Y < Chunk.Height)
                 {
                     var chance = chanceNoise.Value2D(blockX, blockZ);
                     if (chance < 1)
                     {
                         var bushNoise = chanceNoise.Value2D(blockX * 0.7, blockZ * 0.7);
                         var grassNoise = chanceNoise.Value2D(blockX * 0.3, blockZ * 0.3);
                         if (biome.Plants.Contains(PlantSpecies.Deadbush) && bushNoise > 1 && chunk.GetBlockID(blockLocation) == SandBlock.BlockID)
                         {
                             GenerateDeadBush(chunk, plantPosition);
                             continue;
                         }
                         
                         if (biome.Plants.Contains(PlantSpecies.TallGrass) && grassNoise > 0.3 && grassNoise < 0.95)
                         {
                             byte meta = (grassNoise > 0.3 && grassNoise < 0.45 && biome.Plants.Contains(PlantSpecies.Fern)) ? (byte)0x2 : (byte)0x1;
                             GenerateTallGrass(chunk, plantPosition, meta);
                             continue;
                         }
                     }
                     else
                     {
                         var flowerTypeNoise = chanceNoise.Value2D(blockX * 1.2, blockZ * 1.2);
                         if (biome.Plants.Contains(PlantSpecies.Rose) && flowerTypeNoise > 0.8 && flowerTypeNoise < 1.5)
                         {
                             GenerateRose(chunk, plantPosition);
                         }
                         else if (biome.Plants.Contains(PlantSpecies.Dandelion) && flowerTypeNoise <= 0.8)
                         {
                             GenerateDandelion(chunk, plantPosition);
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 4
0
        public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
        {
            Noise = new Perlin();
            Noise.Seed = world.Seed;
            ChanceNoise = new ClampNoise(Noise);
            ChanceNoise.MaxValue = 2;
            Coordinates2D? lastTree = null;
            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    var biome = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
                    var blockX = MathHelper.ChunkToBlockX(x, chunk.Coordinates.X);
                    var blockZ = MathHelper.ChunkToBlockZ(z, chunk.Coordinates.Z);
                    var height = chunk.HeightMap[x * Chunk.Width + z];

                    if (lastTree != null && lastTree.Value.DistanceTo(new Coordinates2D(x, z)) < biome.TreeDensity)
                        continue;

                    if (Noise.Value2D(blockX, blockZ) > 0.3)
                    {
                        var location = new Coordinates3D(x, height, z);
                        var id = chunk.GetBlockID(location);
                        var provider = world.BlockRepository.GetBlockProvider(id);
                        if (id == DirtBlock.BlockID || id == GrassBlock.BlockID || id == SnowfallBlock.BlockID
                            || (id != StationaryWaterBlock.BlockID && id != WaterBlock.BlockID
                                && id != LavaBlock.BlockID && id != StationaryLavaBlock.BlockID
                                && provider.BoundingBox == null))
                        {
                            if (provider.BoundingBox == null)
                                location.Y--;
                            var oakNoise = ChanceNoise.Value2D(blockX * 0.6, blockZ * 0.6);
                            var birchNoise = ChanceNoise.Value2D(blockX * 0.2, blockZ * 0.2);
                            var spruceNoise = ChanceNoise.Value2D(blockX * 0.35, blockZ * 0.35);

                            var baseCoordinates = location + Coordinates3D.Up;
                            if (biome.Trees.Contains(TreeSpecies.Oak) && oakNoise > 1.01 && oakNoise < 1.25)
                            {
                                var oak = new OakTree().GenerateAt(world, chunk, baseCoordinates);
                                if (oak)
                                {
                                    lastTree = new Coordinates2D(x, z);
                                    continue;
                                }
                            }
                            if (biome.Trees.Contains(TreeSpecies.Birch) && birchNoise > 0.3 && birchNoise < 0.95)
                            {
                                var birch = new BirchTree().GenerateAt(world, chunk, baseCoordinates);
                                if (birch)
                                {
                                    lastTree = new Coordinates2D(x, z);
                                    continue;
                                }
                            }
                            if (biome.Trees.Contains(TreeSpecies.Spruce) && spruceNoise < 0.75)
                            {
                                var random = new Random(world.Seed);
                                var type = random.Next(1, 2);
                                var generated = false;
                                if (type.Equals(1))
                                    generated = new PineTree().GenerateAt(world, chunk, baseCoordinates);
                                else
                                    generated = new ConiferTree().GenerateAt(world, chunk, baseCoordinates);

                                if (generated)
                                {
                                    lastTree = new Coordinates2D(x, z);
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
        }