Esempio n. 1
0
        private void CreateEntraces(IChunk chunk, Coordinates3D location, Random random)
        {
            var entrances = 0;
            var above     = location + Coordinates3D.Up;

            for (var X = location.X; X < location.X + Size.X; X++)
            {
                if (entrances >= MaxEntrances)
                {
                    break;
                }
                for (var Z = location.Z; Z < location.Z + Size.Z; Z++)
                {
                    if (entrances >= MaxEntrances)
                    {
                        break;
                    }
                    if (random.Next(0, 3) == 0 && IsCuboidWall(new Coordinates2D(X, Z), location, Size) &&
                        !IsCuboidCorner(new Coordinates2D(X, Z), location, Size))
                    {
                        var blockLocation = new Coordinates3D(X, above.Y, Z);
                        if (blockLocation.X < 0 || blockLocation.X >= Chunk.Width ||
                            blockLocation.Z < 0 || blockLocation.Z >= Chunk.Depth ||
                            blockLocation.Y < 0 || blockLocation.Y >= Chunk.Height)
                        {
                            continue;
                        }
                        chunk.SetBlockID(blockLocation, AirBlock.BlockId);
                        chunk.SetBlockID(blockLocation + Coordinates3D.Up, AirBlock.BlockId);
                        entrances++;
                    }
                }
            }
        }
Esempio n. 2
0
        private void CreateEntraces(IChunk chunk, Coordinates3D location, Random random)
        {
            int entrances = 0;
            var above     = location + Coordinates3D.Up;

            for (int X = location.X; X < location.X + Size.X; X++)
            {
                if (entrances >= MaxEntrances)
                {
                    break;
                }
                for (int Z = location.Z; Z < location.Z + Size.Z; Z++)
                {
                    if (entrances >= MaxEntrances)
                    {
                        break;
                    }
                    if (random.Next(0, 3) == 0 && IsCuboidWall(new Coordinates2D(X, Z), location, Size) &&
                        !IsCuboidCorner(new Coordinates2D(X, Z), location, Size))
                    {
                        var blockLocation = new Coordinates3D(X, above.Y, Z);
                        chunk.SetBlockID(blockLocation, AirBlock.BlockID);
                        chunk.SetBlockID(blockLocation + Coordinates3D.Up, AirBlock.BlockID);
                        entrances++;
                    }
                }
            }
        }
Esempio n. 3
0
        public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
        {
            for (var x = 0; x < Chunk.Width; x++)
            {
                for (var z = 0; z < Chunk.Depth; z++)
                {
                    var biome  = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
                    var height = chunk.HeightMap[x * Chunk.Width + z];
                    for (var y = height; y <= WaterLevel; y++)
                    {
                        var blockLocation = new Coordinates3D(x, y, z);
                        int blockId       = chunk.GetBlockID(blockLocation);
                        if (blockId.Equals(AirBlock.BlockId))
                        {
                            chunk.SetBlockID(blockLocation, biome.WaterBlock);
                            var below = blockLocation + Coordinates3D.Down;
                            if (!chunk.GetBlockID(below).Equals(AirBlock.BlockId) &&
                                !chunk.GetBlockID(below).Equals(biome.WaterBlock))
                            {
                                if (!biome.WaterBlock.Equals(LavaBlock.BlockId) &&
                                    !biome.WaterBlock.Equals(StationaryLavaBlock.BlockId))
                                {
                                    var random = new Random(world.Seed);
                                    if (random.Next(100) < 40)
                                    {
                                        chunk.SetBlockID(below, ClayBlock.BlockId);
                                    }
                                    else
                                    {
                                        chunk.SetBlockID(below, SandBlock.BlockId);
                                    }
                                }
                            }
                        }
                    }

                    for (var y = 4; y < height / 8; y++)
                    {
                        var blockLocation = new Coordinates3D(x, y, z);
                        int blockId       = chunk.GetBlockID(blockLocation);
                        if (blockId.Equals(AirBlock.BlockId))
                        {
                            chunk.SetBlockID(blockLocation, LavaBlock.BlockId);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public override bool GenerateAt(IWorld world, IChunk chunk, Coordinates3D location)
        {
            if (!ValidLocation(location))
            {
                return(false);
            }

            var random = new Random(world.Seed);

            //Generate room
            GenerateCuboid(chunk, location, Size, CobblestoneBlock.BlockID, 0x0, 0x2);

            //Randomly add mossy cobblestone to floor
            MossFloor(chunk, location, random);

            //Place Spawner
            chunk.SetBlockID(new Coordinates3D((int)(location.X + ((Size.X + 1) / 2)), (int)((location + Coordinates3D.Up).Y), (int)(location.Z + ((Size.Z + 1) / 2))), MonsterSpawnerBlock.BlockID);

            //Create entrances
            CreateEntraces(chunk, location, random);

            //Place Chests
            PlaceChests(chunk, location, random);

            return(true);
        }
Esempio n. 5
0
        protected static void GenerateSphere(IChunk chunk, Coordinates3D location, int radius, byte block,
                                             byte meta = 0x0)
        {
            for (var i = -radius; i <= radius; i = i + 1)
            {
                for (var j = -radius; j <= radius; j = j + 1)
                {
                    for (var k = -radius; k <= radius; k = k + 1)
                    {
                        var max = (int)Math.Sqrt(i * i + j * j + k * k);
                        if (max <= radius)
                        {
                            var x = location.X + i;
                            var y = location.Y + k;
                            var z = location.Z + j;

                            if (x < 0 || x >= Chunk.Width || z < 0 || z >= Chunk.Depth || y < 0 || y >= Chunk.Height)
                            {
                                continue;
                            }

                            var currentBlock = new Coordinates3D(x, y, z);
                            if (chunk.GetBlockID(currentBlock).Equals(0))
                            {
                                chunk.SetBlockID(currentBlock, block);
                                chunk.SetMetadata(currentBlock, meta);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        private void PlaceChests(IChunk chunk, Coordinates3D location, Random random)
        {
            var above  = location + Coordinates3D.Up;
            var chests = random.Next(0, 2);

            for (int i = 0; i < chests; i++)
            {
                for (int attempts = 0; attempts < 10; attempts++)
                {
                    var x = random.Next(location.X, location.X + (int)Size.X);
                    var z = random.Next(location.Z, location.Z + (int)Size.Z);
                    if (!IsCuboidWall(new Coordinates2D(x, z), location, Size) && !IsCuboidCorner(new Coordinates2D(x, z), location, Size))
                    {
                        if (NeighboursBlock(chunk, new Coordinates3D(x, above.Y, z), CobblestoneBlock.BlockID))
                        {
                            if (x < 0 || x >= Chunk.Width ||
                                z < 0 || z >= Chunk.Depth ||
                                above.Y < 0 || above.Y >= Chunk.Height)
                            {
                                continue;
                            }
                            chunk.SetBlockID(new Coordinates3D(x, above.Y, z), ChestBlock.BlockID);
                            break;
                        }
                    }
                }
            }
        }
Esempio n. 7
0
 protected void GenerateVanillaCircle(IChunk chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0, double corner = 0)
 {
     for (int i = -radius; i <= radius; i = (i + 1))
     {
         for (int j = -radius; j <= radius; j = (j + 1))
         {
             int max = (int)Math.Sqrt((i * i) + (j * j));
             if (max <= radius)
             {
                 if (i.Equals(-radius) && j.Equals(-radius) ||
                     i.Equals(-radius) && j.Equals(radius) ||
                     i.Equals(radius) && j.Equals(-radius) ||
                     i.Equals(radius) && j.Equals(radius))
                 {
                     if (corner + radius * 0.2 < 0.4 || corner + radius * 0.2 > 0.7 || corner.Equals(0))
                     {
                         continue;
                     }
                 }
                 int x            = location.X + i;
                 int z            = location.Z + j;
                 var currentBlock = new Coordinates3D(x, location.Y, z);
                 if (chunk.GetBlockID(currentBlock).Equals(0))
                 {
                     chunk.SetBlockID(currentBlock, block);
                     chunk.SetMetadata(currentBlock, meta);
                 }
             }
         }
     }
 }
Esempio n. 8
0
        protected static void GenerateSphere(IChunk chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0)
        {
            for (int i = -radius; i <= radius; i = (i + 1))
            {
                for (int j = -radius; j <= radius; j = (j + 1))
                {
                    for (int k = -radius; k <= radius; k = (k + 1))
                    {
                        int max = (int)Math.Sqrt((i * i) + (j * j) + (k * k));
                        if (max <= radius)
                        {
                            int x = location.X + i;
                            int y = location.Y + k;
                            int z = location.Z + j;

                            if (x < 0 || x >= Chunk.Width || z < 0 || z >= Chunk.Depth || y < 0 || y >= Chunk.Height)
                            {
                                continue;
                            }

                            var currentBlock = new Coordinates3D(x, y, z);
                            if (chunk.GetBlockID(currentBlock).Equals(0))
                            {
                                chunk.SetBlockID(currentBlock, block);
                                chunk.SetMetadata(currentBlock, meta);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 9
0
 public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
 {
     for (var x = 0; x < 16; x++)
     {
         for (var z = 0; z < 16; z++)
         {
             var biome = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
             if (biome.Temperature < 0.15)
             {
                 var height = chunk.HeightMap[x * Chunk.Width + z];
                 for (var y = height; y < Chunk.Height; y++)
                 {
                     var location = new Coordinates3D(x, y, z);
                     if (chunk.GetBlockID(location).Equals(StationaryWaterBlock.BlockId) ||
                         chunk.GetBlockID(location).Equals(WaterBlock.BlockId))
                     {
                         chunk.SetBlockID(location, IceBlock.BlockId);
                     }
                     else
                     {
                         var    below     = chunk.GetBlockID(location);
                         byte[] whitelist =
                         {
                             DirtBlock.BlockId,
                             GrassBlock.BlockId,
                             IceBlock.BlockId,
                             LeavesBlock.BlockId
                         };
                         if (y == height && whitelist.Any(w => w == below))
                         {
                             if (chunk.GetBlockID(location).Equals(IceBlock.BlockId) &&
                                 CoverIce(chunk, biomes, location))
                             {
                                 chunk.SetBlockID(location + Coordinates3D.Up, SnowfallBlock.BlockId);
                             }
                             else if (!chunk.GetBlockID(location).Equals(SnowfallBlock.BlockId) &&
                                      !chunk.GetBlockID(location).Equals(AirBlock.BlockId))
                             {
                                 chunk.SetBlockID(location + Coordinates3D.Up, SnowfallBlock.BlockId);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 10
0
 public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
 {
     for (int x = 0; x < Chunk.Width; x++)
     {
         for (int z = 0; z < Chunk.Depth; z++)
         {
             var biome = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
             var height = chunk.HeightMap[x * Chunk.Width + z];
             for (int y = height; y <= WaterLevel; y++)
             {
                 var blockLocation = new Coordinates3D(x, y, z);
                 int blockId = chunk.GetBlockID(blockLocation);
                 if (blockId.Equals(AirBlock.BlockID))
                 {
                     chunk.SetBlockID(blockLocation, biome.WaterBlock);
                     var below = blockLocation + Coordinates3D.Down;
                     if (!chunk.GetBlockID(below).Equals(AirBlock.BlockID) && !chunk.GetBlockID(below).Equals(biome.WaterBlock))
                     {
                         if (!biome.WaterBlock.Equals(LavaBlock.BlockID) && !biome.WaterBlock.Equals(StationaryLavaBlock.BlockID))
                         {
                             var random = new Random(world.Seed);
                             if (random.Next(100) < 40)
                             {
                                 chunk.SetBlockID(below, ClayBlock.BlockID);
                             }
                             else
                             {
                                 chunk.SetBlockID(below, SandBlock.BlockID);
                             }
                         }
                     }
                 }
             }
             for (int y = 4; y < height / 8; y++)
             {
                 var blockLocation = new Coordinates3D(x, y, z);
                 int blockId = chunk.GetBlockID(blockLocation);
                 if (blockId.Equals(AirBlock.BlockID))
                 {
                     chunk.SetBlockID(blockLocation, LavaBlock.BlockID);
                 }
             }
         }
     }
 }
Esempio n. 11
0
 /*
  * Generates the top of the pine/conifer trees.
  * Type:
  * 0x0 - two level topper
  * 0x1 - three level topper
  */
 protected void GenerateTopper(IChunk chunk, Coordinates3D location, byte type = 0x0)
 {
     const int sectionRadius = 1;
     GenerateCircle(chunk, location, sectionRadius, LeavesBlock.BlockID, 0x1);
     var top = location + Coordinates3D.Up;
     chunk.SetBlockID(top, LeavesBlock.BlockID);
     chunk.SetMetadata(top, 0x1);
     if (type == 0x1 && (top + Coordinates3D.Up).Y < Chunk.Height)
         GenerateVanillaCircle(chunk, top + Coordinates3D.Up, sectionRadius, LeavesBlock.BlockID, 0x1); 
 }
Esempio n. 12
0
 private void MossFloor(IChunk chunk, Coordinates3D location, Random random)
 {
     for (int x = location.X; x < location.X + Size.X; x++)
     {
         for (int z = location.Z; z < location.Z + Size.Z; z++)
         {
             if (random.Next(0, 3) == 0)
                 chunk.SetBlockID(new Coordinates3D(x, location.Y, z), MossStoneBlock.BlockID);
         }
     }
 }
Esempio n. 13
0
 public static void GenerateColumn(IChunk chunk, Coordinates3D location, int height, byte block, byte meta = 0x0)
 {
     for (int offset = 0; offset < height; offset++)
     {
         var blockLocation = location + new Coordinates3D(0, offset, 0);
         if (blockLocation.Y >= Chunk.Height)
             return;
         chunk.SetBlockID(blockLocation, block);
         chunk.SetMetadata(blockLocation, meta);
     }
 }
Esempio n. 14
0
 public static void GenerateColumn(IChunk chunk, Coordinates3D location, int height, byte block, byte meta = 0x0)
 {
     for (int offset = 0; offset < height; offset++)
     {
         var blockLocation = location + new Coordinates3D(0, offset, 0);
         if (blockLocation.Y >= Chunk.Height)
         {
             return;
         }
         chunk.SetBlockID(blockLocation, block);
         chunk.SetMetadata(blockLocation, meta);
     }
 }
Esempio n. 15
0
 private void MossFloor(IChunk chunk, Coordinates3D location, Random random)
 {
     for (int x = location.X; x < location.X + Size.X; x++)
     {
         for (int z = location.Z; z < location.Z + Size.Z; z++)
         {
             if (random.Next(0, 3) == 0)
             {
                 chunk.SetBlockID(new Coordinates3D(x, location.Y, z), MossStoneBlock.BlockID);
             }
         }
     }
 }
Esempio n. 16
0
 public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
 {
     for (int x = 0; x < 16; x++)
     {
         for (int z = 0; z < 16; z++)
         {
             var biome = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
             if (biome.Temperature < 0.15)
             {
                 var height = chunk.HeightMap[x * Chunk.Width + z];
                 for (int y = height; y < Chunk.Height; y++)
                 {
                     var location = new Coordinates3D(x, y, z);
                     if (chunk.GetBlockID(location).Equals(StationaryWaterBlock.BlockID) || chunk.GetBlockID(location).Equals(WaterBlock.BlockID))
                         chunk.SetBlockID(location, IceBlock.BlockID);
                     else
                     {
                         var below = chunk.GetBlockID(location);
                         byte[] whitelist =
                         {
                             DirtBlock.BlockID,
                             GrassBlock.BlockID,
                             IceBlock.BlockID,
                             LeavesBlock.BlockID
                         };
                         if (y == height && whitelist.Any(w => w == below))
                         {
                             if (chunk.GetBlockID(location).Equals(IceBlock.BlockID) && CoverIce(chunk, biomes, location))
                                 chunk.SetBlockID((location + Coordinates3D.Up), SnowfallBlock.BlockID);
                             else if (!chunk.GetBlockID(location).Equals(SnowfallBlock.BlockID) && !chunk.GetBlockID(location).Equals(AirBlock.BlockID))
                                 chunk.SetBlockID((location + Coordinates3D.Up), SnowfallBlock.BlockID);
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 17
0
        /*
         * Generates the top of the pine/conifer trees.
         * Type:
         * 0x0 - two level topper
         * 0x1 - three level topper
         */
        protected void GenerateTopper(IChunk chunk, Coordinates3D location, byte type = 0x0)
        {
            const int sectionRadius = 1;

            GenerateCircle(chunk, location, sectionRadius, LeavesBlock.BlockId, 0x1);
            var top = location + Coordinates3D.Up;

            chunk.SetBlockID(top, LeavesBlock.BlockId);
            chunk.SetMetadata(top, 0x1);
            if (type == 0x1 && (top + Coordinates3D.Up).Y < Chunk.Height)
            {
                GenerateVanillaCircle(chunk, top + Coordinates3D.Up, sectionRadius, LeavesBlock.BlockId, 0x1);
            }
        }
Esempio n. 18
0
 private void CreateEntraces(IChunk chunk, Coordinates3D location, Random random)
 {
     int entrances = 0;
     var above = location + Coordinates3D.Up;
     for (int X = location.X; X < location.X + Size.X; X++)
     {
         if (entrances >= MaxEntrances)
             break;
         for (int Z = location.Z; Z < location.Z + Size.Z; Z++)
         {
             if (entrances >= MaxEntrances)
                 break;
             if (random.Next(0, 3) == 0 && IsCuboidWall(new Coordinates2D(X, Z), location, Size)
                 && !IsCuboidCorner(new Coordinates2D(X, Z), location, Size))
             {
                 var blockLocation = new Coordinates3D(X, above.Y, Z);
                 chunk.SetBlockID(blockLocation, AirBlock.BlockID);
                 chunk.SetBlockID(blockLocation + Coordinates3D.Up, AirBlock.BlockID);
                 entrances++;
             }
         }
     }
 }
Esempio n. 19
0
 private void MossFloor(IChunk chunk, Coordinates3D location, Random random)
 {
     for (int x = location.X; x < location.X + Size.X; x++)
     {
         for (int z = location.Z; z < location.Z + Size.Z; z++)
         {
             if (x < 0 || x >= Chunk.Width ||
                 z < 0 || z >= Chunk.Depth ||
                 location.Y < 0 || location.Y >= Chunk.Height)
             {
                 continue;
             }
             if (random.Next(0, 3) == 0)
             {
                 chunk.SetBlockID(new Coordinates3D(x, location.Y, z), MossStoneBlock.BlockID);
             }
         }
     }
 }
Esempio n. 20
0
        /*
         * Cuboid Modes
         * 0x0 - Solid cuboid of the specified block
         * 0x1 - Hollow cuboid of the specified block
         * 0x2 - Outlines the area of the cuboid using the specified block
         */
        public static void GenerateCuboid(IChunk chunk, Coordinates3D location, Vector3 size, byte block,
                                          byte meta = 0x0, byte mode = 0x0)
        {
            //If mode is 0x2 offset the size by 2 and change mode to 0x1
            if (mode.Equals(0x2))
            {
                size += new Vector3(2, 2, 2);
                mode  = 0x1;
            }

            for (var w = location.X; w < location.X + size.X; w++)
            {
                for (var l = location.Z; l < location.Z + size.Z; l++)
                {
                    for (var h = location.Y; h < location.Y + size.Y; h++)
                    {
                        if (w < 0 || w >= Chunk.Width || l < 0 || l >= Chunk.Depth || h < 0 || h >= Chunk.Height)
                        {
                            continue;
                        }
                        var BlockLocation = new Coordinates3D(w, h, l);
                        if (!h.Equals(location.Y) && !h.Equals(location.Y + (int)size.Y - 1) &&
                            !IsCuboidWall(new Coordinates2D(w, l), location, size) &&
                            !IsCuboidCorner(new Coordinates2D(w, l), location, size))
                        {
                            continue;
                        }

                        chunk.SetBlockID(BlockLocation, block);
                        if (meta != 0x0)
                        {
                            chunk.SetMetadata(BlockLocation, meta);
                        }
                    }
                }
            }
        }
Esempio n. 21
0
        public override bool GenerateAt(IWorld world, IChunk chunk, Coordinates3D location)
        {
            if (!ValidLocation(location))
                return false;

            var random = new Random(world.Seed);

            //Generate room
            GenerateCuboid(chunk, location, Size, CobblestoneBlock.BlockID, 0x0, 0x2);

            //Randomly add mossy cobblestone to floor
            MossFloor(chunk, location, random);

            //Place Spawner
            chunk.SetBlockID(new Coordinates3D((int)(location.X + ((Size.X + 1) / 2)), (int)((location + Coordinates3D.Up).Y), (int)(location.Z + ((Size.Z + 1) / 2))), MonsterSpawnerBlock.BlockID);
            
            //Create entrances
            CreateEntraces(chunk, location, random);

            //Place Chests
            PlaceChests(chunk, location, random);

            return true;
        }
Esempio n. 22
0
 void GenerateDandelion(IChunk chunk, Coordinates3D location)
 {
     chunk.SetBlockID(location, DandelionBlock.BlockID);
 }
Esempio n. 23
0
 void GenerateRose(IChunk chunk, Coordinates3D location)
 {
     chunk.SetBlockID(location, RoseBlock.BlockID);
 }
Esempio n. 24
0
 private void PlaceChests(IChunk chunk, Coordinates3D location, Random random)
 {
     var above = location + Coordinates3D.Up;
     var chests = random.Next(0, 2);
     for (int i = 0; i < chests; i++)
     {
         for (int attempts = 0; attempts < 10; attempts++)
         {
             var x = random.Next(location.X, location.X + (int)Size.X);
             var z = random.Next(location.Z, location.Z + (int)Size.Z);
             if (!IsCuboidWall(new Coordinates2D(x, z), location, Size) && !IsCuboidCorner(new Coordinates2D(x, z), location, Size))
             {
                 if (NeighboursBlock(chunk, new Coordinates3D(x, above.Y, z), CobblestoneBlock.BlockID))
                 {
                     chunk.SetBlockID(new Coordinates3D(x, above.Y, z), ChestBlock.BlockID);
                     break;
                 }
             }
         }
     }
 }
Esempio n. 25
0
 protected void GenerateVanillaCircle(IChunk chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0, double corner = 0)
 {
     for (int i = -radius; i <= radius; i = (i + 1))
     {
         for (int j = -radius; j <= radius; j = (j + 1))
         {
             int max = (int)Math.Sqrt((i * i) + (j * j));
             if (max <= radius)
             {
                 if (i.Equals(-radius) && j.Equals(-radius)
                     || i.Equals(-radius) && j.Equals(radius)
                     || i.Equals(radius) && j.Equals(-radius)
                     || i.Equals(radius) && j.Equals(radius))
                 {
                     if (corner + radius * 0.2 < 0.4 || corner + radius * 0.2 > 0.7 || corner.Equals(0))
                         continue;
                 }
                 int x = location.X + i;
                 int z = location.Z + j;
                 var currentBlock = new Coordinates3D(x, location.Y, z);
                 if (chunk.GetBlockID(currentBlock).Equals(0))
                 {
                     chunk.SetBlockID(currentBlock, block);
                     chunk.SetMetadata(currentBlock, meta);
                 }
             }
         }
     }
 }
Esempio n. 26
0
        protected static void GenerateSphere(IChunk chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0)
        {
            for (int i = -radius; i <= radius; i = (i + 1))
            {
                for (int j = -radius; j <= radius; j = (j + 1))
                {
                    for (int k = -radius; k <= radius; k = (k + 1))
                    {
                        int max = (int)Math.Sqrt((i * i) + (j * j) + (k * k));
                        if (max <= radius)
                        {
                            int x = location.X + i;
                            int y = location.Y + k;
                            int z = location.Z + j;

                            if (x < 0 || x >= Chunk.Width || z < 0 || z >= Chunk.Depth || y < 0 || y >= Chunk.Height)
                                continue;

                            var currentBlock = new Coordinates3D(x, y, z);
                            if (chunk.GetBlockID(currentBlock).Equals(0))
                            {
                                chunk.SetBlockID(currentBlock, block);
                                chunk.SetMetadata(currentBlock, meta);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 27
0
        /*
         * Cuboid Modes
         * 0x0 - Solid cuboid of the specified block
         * 0x1 - Hollow cuboid of the specified block
         * 0x2 - Outlines the area of the cuboid using the specified block
         */
        public static void GenerateCuboid(IChunk chunk, Coordinates3D location, Vector3 size, byte block, byte meta = 0x0, byte mode = 0x0)
        {
            //If mode is 0x2 offset the size by 2 and change mode to 0x1
            if (mode.Equals(0x2))
            {
                size += new Vector3(2, 2, 2);
                mode = 0x1;
            }

            for (int w = location.X; w < location.X + size.X; w++)
            {
                for (int l = location.Z; l < location.Z + size.Z; l++)
                {
                    for (int h = location.Y; h < location.Y + size.Y; h++)
                    {

                        if (w < 0 || w >= Chunk.Width || l < 0 || l >= Chunk.Depth || h < 0 || h >= Chunk.Height)
                            continue;
                        Coordinates3D BlockLocation = new Coordinates3D(w, h, l);
                        if (!h.Equals(location.Y) && !h.Equals(location.Y + (int)size.Y - 1)
                            && !IsCuboidWall(new Coordinates2D(w, l), location, size)
                            && !IsCuboidCorner(new Coordinates2D(w, l), location, size))
                            continue;

                        chunk.SetBlockID(BlockLocation, block);
                        if (meta != 0x0)
                            chunk.SetMetadata(BlockLocation, meta);
                    }
                }
            }
        }
Esempio n. 28
0
        public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
        {
            var perlin = new Perlin(world.Seed);

            perlin.Lacunarity = 1;
            perlin.Amplitude  = 7;
            perlin.Frequency  = 0.015;
            var chanceNoise     = new ClampNoise(perlin);
            var noise           = new ScaledNoise(perlin);
            var random          = new Random(world.Seed);
            var lowWeightOffset = new int[2] {
                2, 3
            };
            var highWeightOffset = new int[2] {
                2, 2
            };

            foreach (var data in Ores)
            {
                var       midpoint      = (data.MaxY + data.MinY) / 2;
                var       weightOffsets = data.MaxY > 30 ? highWeightOffset : lowWeightOffset;
                const int weightPasses  = 4;
                for (var i = 0; i < data.Veins; i++)
                {
                    double weight = 0;
                    for (var j = 0; j < weightPasses; j++)
                    {
                        weight += random.NextDouble();
                    }
                    weight /= data.Rarity;
                    weight  = weightOffsets[0] - Math.Abs(weight - weightOffsets[1]);
                    double x = random.Next(0, Chunk.Width);
                    double z = random.Next(0, Chunk.Depth);
                    var    y = weight * midpoint;

                    double randomOffsetX = (float)random.NextDouble() - 1;
                    double randomOffsetY = (float)random.NextDouble() - 1;
                    double randomOffsetZ = (float)random.NextDouble() - 1;

                    var abundance = random.Next(0, data.Abundance);
                    for (var k = 0; k < abundance; k++)
                    {
                        x += randomOffsetX;
                        y += randomOffsetY;
                        z += randomOffsetZ;
                        if (x >= 0 && z >= 0 && y >= data.MinY && x < Chunk.Width && y < data.MaxY && z < Chunk.Depth)
                        {
                            var biome = biomes.GetBiome(chunk.Biomes[(int)(x * Chunk.Width + z)]);
                            if (biome.Ores.Contains(data.Type) && chunk
                                .GetBlockID(new Coordinates3D((int)x, (int)y, (int)z))
                                .Equals(StoneBlock.BlockId))
                            {
                                chunk.SetBlockID(new Coordinates3D((int)x, (int)y, (int)z), data.Id);
                            }
                        }

                        var blockX = MathHelper.ChunkToBlockX((int)x, chunk.Coordinates.X);
                        var blockZ = MathHelper.ChunkToBlockZ((int)z, chunk.Coordinates.Z);

                        double offsetX = 0;
                        double offsetY = 0;
                        double offsetZ = 0;
                        var    offset  = random.Next(0, 3);
                        var    offset2 = random.NextDouble();

                        if (offset.Equals(0) && offset2 < 0.4)
                        {
                            offsetX += 1;
                        }
                        else if (offset.Equals(1) && offset2 >= 0.4 && offset2 < 0.65)
                        {
                            offsetY += 1;
                        }
                        else
                        {
                            offsetZ += 1;
                        }

                        var newX = (int)(x + offsetX);
                        var newY = (int)(y + offsetY);
                        var newZ = (int)(z + offsetZ);
                        if (newX >= 0 && newZ >= 0 && newY >= data.MinY && newX < Chunk.Width && newY < data.MaxY &&
                            newZ < Chunk.Depth)
                        {
                            var Biome       = biomes.GetBiome(chunk.Biomes[newX * Chunk.Width + newZ]);
                            var coordinates = new Coordinates3D(newX, newY, newZ);
                            if (Biome.Ores.Contains(data.Type) &&
                                chunk.GetBlockID(coordinates).Equals(StoneBlock.BlockId))
                            {
                                chunk.SetBlockID(coordinates, data.Id);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 29
0
 void GenerateDeadBush(IChunk chunk, Coordinates3D location)
 {
     chunk.SetBlockID(location, DeadBushBlock.BlockID);
 }
Esempio n. 30
0
 void GenerateTallGrass(IChunk chunk, Coordinates3D location, byte meta)
 {
     chunk.SetBlockID(location, TallGrassBlock.BlockID);
     chunk.SetMetadata(location, meta);
 }
Esempio n. 31
0
 void GenerateDandelion(IChunk chunk, Coordinates3D location)
 {
     chunk.SetBlockID(location, DandelionBlock.BlockID);
 }
Esempio n. 32
0
 void GenerateRose(IChunk chunk, Coordinates3D location)
 {
     chunk.SetBlockID(location, RoseBlock.BlockID);
 }
Esempio n. 33
0
 void GenerateTallGrass(IChunk chunk, Coordinates3D location, byte meta)
 {
     chunk.SetBlockID(location, TallGrassBlock.BlockID);
     chunk.SetMetadata(location, meta);
 }
Esempio n. 34
0
 void GenerateDeadBush(IChunk chunk, Coordinates3D location)
 {
     chunk.SetBlockID(location, DeadBushBlock.BlockID);
 }
Esempio n. 35
0
        public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
        {
            //Test Seed: 291887241
            var perlin = new Perlin();
            perlin.Lacunarity = 1;
            perlin.Amplitude = 7;
            perlin.Frequency = 0.015;
            perlin.Seed = world.Seed;
            var chanceNoise = new ClampNoise(perlin);
            var noise = new ScaledNoise(perlin);
            var random = new Random(world.Seed);
            var lowWeightOffset = new int[2] { 2, 3 };
            var highWeightOffset = new int[2] { 2, 2 };
            foreach (var data in Ores)
            {
                var midpoint = (data.MaxY + data.MinY) / 2;
                var weightOffsets = (data.MaxY > 30) ? highWeightOffset : lowWeightOffset;
                const int weightPasses = 4;
                for (int i = 0; i < data.Veins; i++)
                {
                    double weight = 0;
                    for (int j = 0; j < weightPasses; j++)
                    {
                        weight += random.NextDouble();
                    }
                    weight /= data.Rarity;
                    weight = weightOffsets[0] - Math.Abs(weight - weightOffsets[1]);
                    double x = random.Next(0, Chunk.Width);
                    double z = random.Next(0, Chunk.Depth);
                    double y = weight * midpoint;

                    double randomOffsetX = (float)random.NextDouble() - 1;
                    double randomOffsetY = (float)random.NextDouble() - 1;
                    double randomOffsetZ = (float)random.NextDouble() - 1;

                    int abundance = random.Next(0, data.Abundance);
                    for (int k = 0; k < abundance; k++)
                    {
                        x += randomOffsetX;
                        y += randomOffsetY;
                        z += randomOffsetZ;
                        if (x >= 0 && z >= 0 && y >= data.MinY && x < Chunk.Width && y < data.MaxY && z < Chunk.Depth)
                        {
                            var biome = biomes.GetBiome(chunk.Biomes[(int)(x * Chunk.Width + z)]);
                            if (biome.Ores.Contains(data.Type) && chunk.GetBlockID(new Coordinates3D((int)x, (int)y, (int)z)).Equals(StoneBlock.BlockID))
                                chunk.SetBlockID(new Coordinates3D((int)x, (int)y, (int)z), data.ID);
                        }
                        var blockX = MathHelper.ChunkToBlockX((int)(x), chunk.Coordinates.X);
                        var blockZ = MathHelper.ChunkToBlockZ((int)(z), chunk.Coordinates.Z);

                        double offsetX = 0;
                        double offsetY = 0;
                        double offsetZ = 0;
                        int offset = random.Next(0, 3);
                        double offset2 = random.NextDouble();

                        if (offset.Equals(0) && offset2 < 0.4)
                            offsetX += 1;
                        else if (offset.Equals(1) && offset2 >= 0.4 && offset2 < 0.65)
                            offsetY += 1;
                        else
                            offsetZ += 1;

                        var newX = (int)(x + offsetX);
                        var newY = (int)(y + offsetY);
                        var newZ = (int)(z + offsetZ);
                        if (newX >= 0 && newZ >= 0 && newY >= data.MinY && newX < Chunk.Width && newY < data.MaxY && newZ < Chunk.Depth)
                        {
                            IBiomeProvider Biome = biomes.GetBiome(chunk.Biomes[newX * Chunk.Width + newZ]);
                            var coordinates = new Coordinates3D((int)newX, (int)newY, (int)newZ);
                            if (Biome.Ores.Contains(data.Type) && chunk.GetBlockID(coordinates).Equals(StoneBlock.BlockID))
                            {
                                chunk.SetBlockID(coordinates, data.ID);
                            }
                        }
                    }
                }
            }
        }