Exemple #1
0
        public override void Create(int[] blocks, int[] metadata, int x, int y, int z)
        {
            var block = blocks[OverworldGenerator.GetIndex(x, y - 1, z)];

            if (block != 2 && block != 3)
            {
                return;
            }

            BaseSize = 3 + Rnd.Next(2);
            if (Roots > 0f)
            {
                for (int k = 0; k < 3; k++)
                {
                    GenerateBranch(blocks, metadata, x, y + Roots, z, (120 * k) - 40 + Rnd.Next(80), 1.6f + (float)Rnd.NextDouble() * 0.1f, Roots * 1.7f, 1f, 17, 3);
                }
            }

            for (int i = y + Roots; i < y + BaseSize; i++)
            {
                blocks[OverworldGenerator.GetIndex(x, i, z)]   = 17;
                metadata[OverworldGenerator.GetIndex(x, i, z)] = 3;
                //	chunk.SetBlock(x, i, z, 17);
                //	chunk.SetMetadata(x, i, z, 3);
            }

            float horDir, verDir;
            int   eX, eY, eZ;

            for (int j = 0; j < Branches; j++)
            {
                horDir = (120 * j) - 60 + Rnd.Next(120);
                verDir = VerticalStart + (float)Rnd.NextDouble() * VerticalRand;

                eX = x + (int)(Math.Cos(horDir * Math.PI / 180D) * verDir * BranchLength);
                eZ = z + (int)(Math.Sin(horDir * Math.PI / 180D) * verDir * BranchLength);
                eY = y + BaseSize + (int)((1f - verDir) * BranchLength);

                if (CanGenerateBranch(x, y + BaseSize, z, horDir, verDir, BranchLength, 1f, 4f, 1.5f) && CanGenerateLeaves(eX, eY, eZ, 4f, 1.5f))
                {
                    GenerateBranch(blocks, metadata, x, y + BaseSize, z, horDir, verDir, BranchLength, 1f, 17, 3);

                    for (int m = 0; m < 1; m++)
                    {
                        GenerateLeaves(blocks, metadata, eX, eY, eZ, 4f, 1.5f, 18, 3, 17, 3);
                    }
                }
            }

            /*var location = new Vector3(x, y, z);
             * if (!ValidLocation(location, 2)) return;
             *
             * int height = Math.Max(4, Rnd.Next(MaxHeight));
             *
             * GenerateColumn(chunk, location, height, 17, 3);
             * Vector3 leafLocation = location + new Vector3(0, height, 0);
             * GenerateVanillaLeaves(chunk, leafLocation, 2, 18, 3);
             */
            //	base.Create(chunk, x, y, z);
        }
        protected void GenerateBranch(int[] blocks, int[] metadata, float x, float y, float z, double horDir, float verDir, float length, float speed, byte blockId, byte meta)
        {
            if (verDir < 0f)
            {
                verDir = -verDir;
            }

            float c    = 0f;
            float velY = 1f - verDir;

            if (verDir > 1f)
            {
                verDir = 1f - (verDir - 1f);
            }

            float velX = (float)Math.Cos(horDir * Math.PI / 180D) * verDir;
            float velZ = (float)Math.Sin(horDir * Math.PI / 180D) * verDir;

            while (c < length)
            {
                blocks[OverworldGenerator.GetIndex((int)x, (int)y, (int)z)]   = blockId;              //);
                metadata[OverworldGenerator.GetIndex((int)x, (int)y, (int)z)] = meta;
                //world.SetMetadata((int)x, (int)y, (int)z, meta);

                x += velX;
                y += velY;
                z += velZ;

                c += speed;
            }
        }
Exemple #3
0
    public async void TransitionsAsync()
    {
        OverworldGenerator og       = new OverworldGenerator();
        OverworldTerrain   noiseGen = new OverworldTerrain(true);
        await Task.Run(() =>
        {
            var map = new NoiseMap();
            PlaneNoiseMapBuilder builder =
                new PlaneNoiseMapBuilder()
            {
                DestNoiseMap = map, SourceModule = noiseGen.transitions
            };

            var image = new Image();
            var transitionsRenderer = new ImageRenderer()
            {
                SourceNoiseMap = map, DestinationImage = image
            };
            transitionsRenderer.BuildGrayscaleGradient();
            builder.SetBounds(-400, 400, -300, 300);
            builder.SetDestSize(800, 600);
            builder.Build();
            transitionsRenderer.Render();

            var bmp = transitionsRenderer.DestinationImage.ToGdiBitmap();
            bmp.Save("_transitions.bmp");

            Assert.Equal(0, 0);
        });
    }
        protected void GenerateLeaves(int[] blocks, int[] metadata, int x, int y, int z, float size, float width, byte leafBlockId, byte leafMeta, byte woodId, byte woodMeta)
        {
            float dist;
            int   i, j, k, s = (int)(size - 1f), w = (int)((size - 1f) * width);

            for (i = -w; i <= w; i++)
            {
                for (j = -s; j <= s; j++)
                {
                    for (k = -w; k <= w; k++)
                    {
                        dist = Math.Abs((float)i / width) + (float)Math.Abs(j) + Math.Abs((float)k / width);
                        if (dist <= size - 0.5f || (dist <= size && Rnd.NextDouble() < 0.5))
                        {
                            if (dist < 0.6f)
                            {
                                blocks[OverworldGenerator.GetIndex(x + i, y + j, z + k)]   = woodId;
                                metadata[OverworldGenerator.GetIndex(x + i, y + j, z + k)] = woodMeta;
                                //world.SetBlock(x + i, y + j, z + k, woodId);
                                //world.SetMetadata(x + i, y + j, z + k, woodMeta);
                            }
                            if (blocks[OverworldGenerator.GetIndex(x + i, y + j, z + k)] == 0)
                            {
                                blocks[OverworldGenerator.GetIndex(x + i, y + j, z + k)]   = leafBlockId;
                                metadata[OverworldGenerator.GetIndex(x + i, y + j, z + k)] = leafMeta;

                                //world.SetBlock(x + i, y + j, z + k, leafBlockId);
                                //world.SetMetadata(x + i, y + j, z + k, leafMeta);
                            }
                        }
                    }
                }
            }
        }
        public override void Create(int[] blocks, int[] metadata, int x, int y, int z)
        {
            var block = blocks[OverworldGenerator.GetIndex(x, y - 1, z)];

            if (block != 2 && block != 3)
            {
                return;
            }

            var location = new Vector3(x, y, z);

            if (!ValidLocation(location, _leafRadius))
            {
                return;
            }

            var height = Rnd.Next(7, 8);

            GenerateColumn(blocks, metadata, location, height, 17, 1);
            for (var Y = 1; Y < height; Y++)
            {
                if (Y % 2 == 0)
                {
                    GenerateVanillaCircle(blocks, metadata, location + new Vector3(0, Y + 1, 0), _leafRadius - 1, 18, 1);
                    continue;
                }
                GenerateVanillaCircle(blocks, metadata, location + new Vector3(0, Y + 1, 0), _leafRadius, 18, 1);
            }

            GenerateTopper(blocks, metadata, location + new Vector3(0, height, 0), 0x1);
        }
        protected void GenerateCircle(int[] blocks, int[] metadata, Vector3 location, int radius, byte id, byte meta)
        {
            for (var I = -radius; I <= radius; I = (I + 1))
            {
                for (var j = -radius; j <= radius; j = (j + 1))
                {
                    var max = (int)Math.Sqrt((I * I) + (j * j));
                    if (max <= radius)
                    {
                        var X = location.X + I;
                        var Z = location.Z + j;

                        if (X < 0 || X >= 16 || Z < 0 || Z >= 256)
                        {
                            continue;
                        }

                        var x = (int)X;
                        var y = (int)location.Y;
                        var z = (int)Z;
                        if (blocks[OverworldGenerator.GetIndex(x, y, z)].Equals(0))
                        {
                            blocks[OverworldGenerator.GetIndex(x, y, z)]   = id;
                            metadata[OverworldGenerator.GetIndex(x, y, z)] = meta;
                            //chunk.SetBlock(x, y, z, id);
                            //chunk.SetMetadata(x, y, z, meta);
                        }
                    }
                }
            }
        }
        public override void Create(int[] blocks, int[] metadata, int x, int y, int z)
        {
            if (x < 6 || x > 10 || z < 6 || z > 10)
            {
                return;
            }

            var block = blocks[OverworldGenerator.GetIndex(x, y - 1, z)];

            if (block != 2 && block != 3)
            {
                return;
            }

            BaseSize = 9 + Rnd.Next(5);

            if (Roots > 0f)
            {
                for (int k = 0; k < 3; k++)
                {
                    GenerateBranch(blocks, metadata, x, y + Roots, z, (120 * k) - 40 + Rnd.Next(80), 1.6f + (float)Rnd.NextDouble() * 0.1f, Roots * 1.7f, 1f,
                                   17, 3);              //17 = Wood, 3 = Jungle Type
                }
            }

            for (int i = y + Roots; i < y + BaseSize; i++)
            {
                blocks[OverworldGenerator.GetIndex(x, i, z)]   = 17;
                metadata[OverworldGenerator.GetIndex(x, i, z)] = 3;
                //chunk.SetBlock(x, i, z, 17);
                //chunk.SetMetadata(x, i, z, 3);
            }

            float horDir, verDir;
            int   eX, eY, eZ;

            for (int j = 0; j < Branches; j++)
            {
                horDir = (120 * j) - 60 + Rnd.Next(120);
                verDir = VerticalStart + (float)Rnd.NextDouble() * VerticalRand;

                eX = x + (int)(Math.Cos(horDir * Math.PI / 180D) * verDir * BranchLength);
                eZ = z + (int)(Math.Sin(horDir * Math.PI / 180D) * verDir * BranchLength);
                eY = y + BaseSize + (int)((1f - verDir) * BranchLength);

                if (CanGenerateBranch(x, y + BaseSize, z, horDir, verDir, BranchLength, 1f, 4f, 1.5f) && CanGenerateLeaves(eX, eY, eZ, 4f, 1.5f))
                {
                    GenerateBranch(blocks, metadata, x, y + BaseSize, z, horDir, verDir, BranchLength, 1f,
                                   17, 3);              //17 = Wood, 3 = Jungle Type

                    for (int m = 0; m < 1; m++)
                    {
                        GenerateLeaves(blocks, metadata, eX, eY, eZ, 4f, 1.5f,
                                       18, 3,                  //18 = Leaves, 3 = Jungle Type
                                       17, 3);                 //17 = Wood, 3 = Jungle Type
                    }
                }
            }
        }
Exemple #8
0
        public override void Create(int[] blocks, int[] metadata, int x, int y, int z)
        {
            var block = blocks[OverworldGenerator.GetIndex(x, y - 1, z)];

            if (block != 2 && block != 3)
            {
                return;
            }

            base.Create(blocks, metadata, x, y, z);
        }
 public static void GenerateColumn(int[] blocks, int[] metadata, Vector3 location, int height, byte id, byte meta)
 {
     for (var o = 0; o < height; o++)
     {
         var x = (int)location.X;
         var y = (int)location.Y + o;
         var z = (int)location.Z;
         blocks[OverworldGenerator.GetIndex(x, y, z)]   = id;
         metadata[OverworldGenerator.GetIndex(x, y, z)] = meta;
         //chunk.SetBlock(x, y, z, id);
         //chunk.SetMetadata(x, y, z, meta);
     }
 }
Exemple #10
0
        public override void Decorate(int chunkX, int chunkZ, int[] blocks, int[] metadata, BiomeBase biome, float[] thresholdMap, int x, int y, int z, bool surface, bool isBelowMaxHeight)
        {
            if (y > OverworldGenerator.WaterLevel && y > 32)
            {
                return;
            }

            //var density = thresholdMap[x + 16*(y + 256*z)];

            /*var bid = column.GetBlock(x, y, z);
             * if (bid == 0 /* || density < 0) //If this block is supposed to be air.
             * {
             *  if (surface && biome.Temperature <= 0f)
             *  {
             *      column.SetBlock(x, y, z, 79);
             *  }
             *  else
             *  {
             *      column.SetBlock(x, y, z, 8);
             *  }
             * }
             * else if (surface)
             * {
             *  column.SetBlock(x,y,z, 12);
             * }*/

            //	if (y >= SurvivalWorldProvider.WaterLevel) return;

            var block = blocks[OverworldGenerator.GetIndex(x, y, z)];

            if (surface)
            {
                blocks[OverworldGenerator.GetIndex(x, y, z)] = 12;
                //column.SetBlock(x, y, z, 12); //Sand
            }
            else if (y <= OverworldGenerator.WaterLevel && block == 0)
            {
                if (biome.Temperature <= 0f && y == OverworldGenerator.WaterLevel)
                {
                    blocks[OverworldGenerator.GetIndex(x, y, z)] = 79;
                    // column.SetBlock(x, y, z, 79); //Ice
                }
                else
                {
                    blocks[OverworldGenerator.GetIndex(x, y, z)] = 8;
                    //column.SetBlock(x, y, z, 8); //Water
                }
            }
        }
Exemple #11
0
 // Use this for initialization
 void Start()
 {
     if (instance != null)
     {
         Destroy(gameObject);
         Destroy(this);
         return;
     }
     else
     {
         instance = this;
     }
     progress = 0f;
     LoadingProgressBar.StartSecondaryLoadPhase();
     StartCoroutine(Generate());
 }
        protected void GenerateVanillaCircle(int[] blocks, int[] metadata, Vector3 location, int radius, byte id, byte meta,
                                             double corner = 0)
        {
            for (var I = -radius; I <= radius; I = (I + 1))
            {
                for (var j = -radius; j <= radius; j = (j + 1))
                {
                    var 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;
                            }
                        }
                        var x = location.X + I;
                        var z = location.Z + j;
                        if (x < 0 || z > 16)
                        {
                            continue;
                        }
                        if (z < 0 || z > 16)
                        {
                            continue;
                        }

                        var idx = OverworldGenerator.GetIndex((int)x, (int)location.Y, (int)z);

                        if (blocks[idx] == 0)
                        {
                            blocks[idx]   = id;
                            metadata[idx] = meta;
                            //chunk.SetBlock((int)x, (int)location.Y, (int)z, id);
                            //chunk.SetMetadata((int)x, (int)location.Y, (int)z, meta);
                        }
                    }
                }
            }
        }
Exemple #13
0
        private void CreateWorld()
        {
            //Make a new overworld generator
            OverworldGenerator overworldGen = new OverworldGenerator();

            //Generate the basic overworld
            m_World = new WorldInstance(overworldGen.GenerateWorldSpace(WORLD_SIZE), WorldType.Overworld, "Everse");

            //Set the date and time for 1/1/1555, 12:00pm
            m_World.SetDateTime(new DateTime(1555, 1, 1, 12, 0, 0));

            //Do the spawn point
            SpawnPointPlacer spawnPlacer = new SpawnPointPlacer();
            Vector2Int       spawnPoint  = spawnPlacer.PlaceSpawnPoint(m_World);

            while ((spawnPoint.x == -1 && spawnPoint.y == -1))
            {
                spawnPoint = spawnPlacer.PlaceSpawnPoint(m_World);
            }
            m_World.SpawnPoint = spawnPoint;

            //Set up the player
            m_Player.Move(m_World.SpawnPoint);
            m_Player.MyWorld = m_World;
            m_World.AddEntity(m_Player);

            //Begin the first floor of the Naga Pits
            List <string> dungeonTypes = new List <string>();

            dungeonTypes.Add("Naga");
            dungeonTypes.Add("Dungeon Slime");

            WorldInstance dungeon = DungeonGenerator.GenerateDungeon("Naga Pits", WORLD_SIZE, 3, dungeonTypes.ToArray());

            Vector2Int transitionPoint = spawnPlacer.PlaceTransitionPoint(m_World);

            m_World.AddArea(transitionPoint, dungeon);
            Done = true;

            m_Player.AddItem(new ItemInstance(ItemHandler.GetSpecificItem("Lantern"), new Vector2Int(-1, -1), true));
            m_World.Tick();
        }
        protected void GenerateTopper(int[] blocks, int[] metadata, Vector3 location, byte type = 0x0)
        {
            var sectionRadius = 1;

            GenerateCircle(blocks, metadata, location, sectionRadius, 18, 1);
            var top = location + new Vector3(0, 1, 0);
            var x   = (int)location.X;
            var y   = (int)location.Y + 1;
            var z   = (int)location.Z;

            blocks[OverworldGenerator.GetIndex(x, y, z)]   = 18;
            metadata[OverworldGenerator.GetIndex(x, y, z)] = 1;

            //chunk.SetBlock(x, y, z, 18);
            //chunk.SetMetadata(x, y, z, 1);
            if (type == 0x1 && y < 256)
            {
                GenerateVanillaCircle(blocks, metadata, new Vector3(x, y, z), sectionRadius, 18, 1);
            }
        }
Exemple #15
0
        private bool CheckSafe(int[] blocks, int[] metadata, int x, int y, int z)
        {
            if (blocks[OverworldGenerator.GetIndex(x - 1, y, z)] != 0)
            {
                return(false);
            }
            if (blocks[OverworldGenerator.GetIndex(x + 1, y, z)] != 0)
            {
                return(false);
            }
            if (blocks[OverworldGenerator.GetIndex(x, y, z - 1)] != 0)
            {
                return(false);
            }
            if (blocks[OverworldGenerator.GetIndex(x, y, z + 1)] != 0)
            {
                return(false);
            }

            return(true);
        }
Exemple #16
0
        public override void Create(int[] blocks, int[] metadata, int x, int y, int z)
        {
            if (blocks[OverworldGenerator.GetIndex(x, y - 1, z)] != 12)
            {
                return;                                                                     //Not sand, do not generate.
            }
            var growth = Rnd.Next(0x1, 0x15);

            for (int modifiedY = y; modifiedY < y + _height; modifiedY++)
            {
                if (!CheckSafe(blocks, metadata, x, modifiedY, z))
                {
                    break;
                }

                blocks[OverworldGenerator.GetIndex(x, modifiedY, z)]   = 81;
                metadata[OverworldGenerator.GetIndex(x, modifiedY, z)] = (byte)growth;
                //chunk.SetBlock(x, modifiedY, z, 81); //Cactus block
                //chunk.SetMetadata(x, modifiedY, z, (byte)growth);
            }
        }
 private bool IsValidSugarCaneLocation(int[] blocks, int x, int y, int z)
 {
     if (y - 1 <= 0)
     {
         return(false);
     }
     if (x - 1 >= 0 && x + 1 < 16)
     {
         if (z - 1 >= 0 && z + 1 < 16)
         {
             if (blocks[OverworldGenerator.GetIndex(x + 1, y, z)] == 8 ||
                 blocks[OverworldGenerator.GetIndex(x - 1, y, z)] == 8 ||
                 blocks[OverworldGenerator.GetIndex(x, y, z + 1)] == 8 ||
                 blocks[OverworldGenerator.GetIndex(x, y, z - 1)] == 8)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemple #18
0
        public override void Create(int[] blocks, int[] metadata, int x, int y, int z)
        {
            var block = blocks[OverworldGenerator.GetIndex(x, y - 1, z)];

            if (block != 2 && block != 3)
            {
                return;
            }

            var location = new Vector3(x, y, z);

            if (!ValidLocation(location, LeafRadius))
            {
                return;
            }

            int height = Rnd.Next(4, MaxHeight);

            GenerateColumn(blocks, metadata, location, height, 17, 2);
            Vector3 leafLocation = location + new Vector3(0, height, 0);

            GenerateVanillaLeaves(blocks, metadata, leafLocation, LeafRadius, 18, 2);
        }
Exemple #19
0
    public async void TerrainBlendAsync()
    {
        OverworldGenerator og       = new OverworldGenerator();
        OverworldTerrain   noiseGen = new OverworldTerrain(true);
        await Task.Run(() =>
        {
            var noise = new SharpNoise.Modules.ScaleBias()
            {
                Scale   = 4,
                Source0 = noiseGen.selectiveBlend
            };

            var map = new NoiseMap();
            PlaneNoiseMapBuilder builder =
                new PlaneNoiseMapBuilder()
            {
                DestNoiseMap = map, SourceModule = noise
            };

            var image = new Image();
            var transitionsRenderer = new ImageRenderer()
            {
                SourceNoiseMap = map, DestinationImage = image
            };
            transitionsRenderer.BuildTerrainGradient();
            builder.SetBounds(-400, 400, -300, 300);
            builder.SetDestSize(800, 600);
            builder.Build();
            transitionsRenderer.Render();

            var bmp = transitionsRenderer.DestinationImage.ToGdiBitmap();
            bmp.Save("_blendedterrain.bmp");

            Assert.Equal(0, 0);
        });
    }
Exemple #20
0
        private void CreateWorld()
        {
            //Make a new overworld generator
            OverworldGenerator overworldGen = new OverworldGenerator(this.m_WorldInfoHandler);

            //Generate the basic overworld
            this.m_World = new WorldInstance(
                overworldGen.GenerateWorldSpace(WORLD_SIZE, "plains"),
                new string[] { "overworld", "exterior" },
                "Everse",
                GlobalConstants.GameManager.EntityHandler,
                GlobalConstants.GameManager.Roller);

            //Set the date and time for 1/1/1555, 12:00pm
            this.m_World.SetDateTime(new JoyDateTime(1555, 1, 1, 12));

            //Do the spawn point
            SpawnPointPlacer spawnPlacer = new SpawnPointPlacer(GlobalConstants.GameManager.Roller);
            Vector2Int       spawnPoint  = spawnPlacer.PlaceSpawnPoint(this.m_World);

            while ((spawnPoint.x == -1 && spawnPoint.y == -1))
            {
                spawnPoint = spawnPlacer.PlaceSpawnPoint(this.m_World);
            }

            this.m_World.SpawnPoint = spawnPoint;

            //Set up the player
            //m_Player.Move(m_World.SpawnPoint);
            //m_World.AddEntity(m_Player);

            //Begin the first floor of the Naga Pits
            WorldInfo worldInfo = this.m_WorldInfoHandler.GetRandom("interior");

            DungeonGenerator dungeonGenerator = new DungeonGenerator();
            WorldInstance    dungeon          = dungeonGenerator.GenerateDungeon(
                worldInfo,
                WORLD_SIZE,
                3,
                GlobalConstants.GameManager,
                GlobalConstants.GameManager.Roller);

            Vector2Int transitionPoint = spawnPlacer.PlaceTransitionPoint(this.m_World);

            this.m_World.AddArea(transitionPoint, dungeon);
            this.Done = true;

            this.m_ActiveWorld = dungeon;
            this.m_Player.Move(dungeon.SpawnPoint);
            dungeon.AddEntity(this.m_Player);

            GlobalConstants.GameManager.EntityHandler.Add(this.m_Player);

            IItemInstance lightSource = GlobalConstants.GameManager.ItemFactory.CreateRandomItemOfType(
                new string[] { "light source" },
                true);

            IItemInstance bag = GlobalConstants.GameManager.ItemFactory.CreateRandomItemOfType(
                new[] { "container" },
                true);

            IJoyAction addItemAction = this.m_Player.FetchAction("additemaction");

            addItemAction.Execute(
                new IJoyObject[] { this.m_Player, lightSource },
                new[] { "pickup" },
                new Dictionary <string, object>
            {
                { "newOwner", true }
            });

            addItemAction.Execute(
                new IJoyObject[] { this.m_Player, bag },
                new[] { "pickup" },
                new Dictionary <string, object>
            {
                { "newOwner", true }
            });

            for (int i = 0; i < 4; i++)
            {
                IItemInstance newItem = GlobalConstants.GameManager.ItemFactory.CreateRandomWeightedItem(
                    true,
                    false);
                addItemAction.Execute(
                    new IJoyObject[]
                {
                    this.m_Player,
                    newItem
                },
                    new[] { "pickup" },
                    new Dictionary <string, object>
                {
                    { "newOwner", true }
                });
            }

            this.m_World.Tick();

            GlobalConstants.GameManager.WorldHandler.Add(this.m_World);

            WorldSerialiser worldSerialiser = new WorldSerialiser(GlobalConstants.GameManager.ObjectIconHandler);

            worldSerialiser.Serialise(this.m_World);

            this.Done = true;
        }
        public override void Decorate(int chunkX, int chunkZ, int[] blocks, int[] metadata, BiomeBase biome, float[] thresholdMap, int x, int y, int z, bool surface,
                                      bool isBelowMaxHeight)
        {
            try
            {
                var currentTemperature = biome.Temperature;
                if (y > 64)
                {
                    int distanceToSeaLevel = y - 64;
                    currentTemperature = biome.Temperature - (0.00166667f * distanceToSeaLevel);
                }

                int rx = chunkX * 16 + x;
                int rz = chunkZ * 16 + z;

                bool generated = false;
                if (surface && y >= OverworldGenerator.WaterLevel)
                {
                    var noise = Simplex.Noise(rx, rz, Math.Min(biome.Downfall * 0.32f, 0.03f), 0.5, true);
                    if (x >= 3 && x <= 13 && z >= 3 && z <= 13)
                    {
                        Structure tree = null;
                        if (biome.Downfall <= 0f && biome.Temperature >= 2f)
                        {
                            if (GetRandom(32) == 16)
                            {
                                var randValue = GetRandom(18);
                                if (randValue >= 0 && randValue <= 2)                                 //3 tall cactus
                                {
                                    tree = new CactusStructure(3);
                                }
                                else if (randValue > 2 && randValue <= 5)                                 // 2 tall cactus
                                {
                                    tree = new CactusStructure(2);
                                }
                                else if (randValue > 5 && randValue <= 11)                                 // 1 tall cactus
                                {
                                    tree = new CactusStructure(1);
                                }
                            }
                        }

                        if (tree == null && biome.Downfall >= 0 && (noise > (0.5f + (y / 512f))))
                        {
                            if (currentTemperature >= 1f && biome.Downfall >= 0.4f)
                            {
                                if (GetRandom(8) == 4)
                                {
                                    tree = new LargeJungleTree();
                                }
                                else
                                {
                                    tree = new SmallJungleTree();
                                }
                            }

                            /*	else if (currentTemperature >= 0.7F && biome.Downfall >= 0.2f)
                             *      {
                             *              tree = new OakTree(true);
                             *      }*/
                            else if (currentTemperature >= 0.7F && biome.Downfall < 0.2f)
                            {
                                tree = new AcaciaTree();
                            }
                            else if (currentTemperature > 0.25f && biome.Downfall > 0f)
                            {
                                if (biome.Name.Contains("Birch") || GetRandom(16) == 8)
                                {
                                    tree = new BirchTree();
                                }
                                else
                                {
                                    tree = new OakTree();
                                }
                            }
                            else if (currentTemperature <= 0.25f && biome.Downfall > 0f)
                            {
                                tree = new PineTree();
                            }
                        }

                        if (tree != null)
                        {
                            if (y + 1 < 254)
                            {
                                tree.Create(blocks, metadata, x, y + 1, z);
                            }
                            generated = true;
                        }
                    }

                    if (!generated)
                    {
                        if (noise > 0.5)                         //Threshold 1
                        {
                            /*if (currentTemperature > 0.3f && currentTemperature < 1.5f && biome.Downfall >= 0.85f)
                             * {
                             *      column.SetBlock(x, y + 1, z, 18); //Leaves
                             *      column.SetMetadata(x, y + 1, z, 3); //Jungle Leaves
                             * }
                             * else*/
                            if (currentTemperature > 0.3f && currentTemperature < 1.5f && biome.Downfall > 0)
                            {
                                var blockBeneath = blocks[OverworldGenerator.GetIndex(x, y, z)];                                // column.GetBlock(x, y, z);

                                var sugarPosibility = GetRandom(18);
                                if (/*sugarPosibility <= 11*/ noise > 0.75f &&
                                    (blockBeneath == 3 || blockBeneath == 2 || blockBeneath == 12) &&
                                    IsValidSugarCaneLocation(blocks, x, y, z))
                                {
                                    int height = 1;
                                    if (sugarPosibility <= 2)
                                    {
                                        height = 3;
                                    }
                                    else if (sugarPosibility <= 5)
                                    {
                                        height = 2;
                                    }

                                    //var growth = Rnd.Next(0x1, 0x15);
                                    for (int mY = y + 1; mY < y + 1 + height; mY++)
                                    {
                                        //column.SetBlock(x, mY, z, 83); //SugarCane
                                        blocks[OverworldGenerator.GetIndex(x, mY, z)] = 83;

                                        if (mY == y + 1 + height)
                                        {
                                            metadata[OverworldGenerator.GetIndex(x, mY, z)] = (byte)Rnd.Next(0, 15);
                                            //column.SetMetadata(x, mY, z, (byte) Rnd.Next(0, 15));
                                        }
                                        else
                                        {
                                            metadata[OverworldGenerator.GetIndex(x, mY, z)] = (byte)0;
                                            //column.SetMetadata(x, mY, z, 0);
                                        }
                                    }
                                }
                                else if (noise > 0.8 && blockBeneath == 3 || blockBeneath == 2)                                 //If above 0.8, we generate flowers :)
                                {
                                    if (Simplex.Noise(rx, rz, 0.5f, 0.5f, true) > 0.5)
                                    {
                                        blocks[OverworldGenerator.GetIndex(x, y + 1, z)]   = 38;
                                        metadata[OverworldGenerator.GetIndex(x, y + 1, z)] = (byte)GetRandom(8);
                                        //column.SetBlock(x, y + 1, z, 38); //Poppy
                                        //column.SetMetadata(x, y + 1, z, (byte) GetRandom(8));
                                    }
                                    else
                                    {
                                        blocks[OverworldGenerator.GetIndex(x, y + 1, z)] = 37;
                                        //	column.SetBlock(x, y + 1, z, 37); //Dandelion
                                    }
                                }
                                else if (blockBeneath == 3 || blockBeneath == 2)
                                {
                                    blocks[OverworldGenerator.GetIndex(x, y + 1, z)]   = 31;
                                    metadata[OverworldGenerator.GetIndex(x, y + 1, z)] = (byte)1;
                                    //column.SetBlock(x, y + 1, z, 31); //Grass
                                    //column.SetMetadata(x, y + 1, z, 1);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
            }
        }