public void GenerateWorld(GenerationProgress progress = null)
        {
            Stopwatch stopwatch = new Stopwatch();
            float     num       = 0f;

            foreach (GenPass pass in _passes)
            {
                num += pass.Weight;
            }
            if (progress == null)
            {
                progress = new GenerationProgress();
            }
            progress.TotalWeight = num;
            string text = "";

            Main.MenuUI.SetState(new UIWorldLoad(progress));
            Main.menuMode = 888;
            foreach (GenPass pass2 in _passes)
            {
                stopwatch.Start();
                progress.Start(pass2.Weight);
                pass2.Apply(progress);
                progress.End();
                string text2 = text;
                text = text2 + "Pass - " + pass2.Name + " : " + stopwatch.Elapsed.TotalMilliseconds + ",\n";
                stopwatch.Reset();
            }
        }
Ejemplo n.º 2
0
 public void GenerateWorld(GenerationProgress progress = null)
 {
     Stopwatch stopwatch = new Stopwatch();
     float weight = 0f;
     foreach (GenPass _pass in this._passes)
     {
         weight = weight + _pass.Weight;
     }
     if (progress == null)
     {
         progress = new GenerationProgress();
     }
     progress.TotalWeight = weight;
     string str = "";
     Main.menuMode = 888;
     foreach (GenPass genPass in this._passes)
     {
         stopwatch.Start();
         progress.Start(genPass.Weight);
         genPass.Apply(progress);
         progress.End();
         string str1 = str;
         string[] name = new string[] { str1, "Pass - ", genPass.Name, " : ", null, null };
         name[4] = stopwatch.Elapsed.TotalMilliseconds.ToString();
         name[5] = ",\n";
         str = string.Concat(name);
         stopwatch.Reset();
     }
 }
Ejemplo n.º 3
0
        public void GenerateWorld(GenerationProgress progress = null)
        {
            Stopwatch stopwatch = new Stopwatch();
            float     num       = 0.0f;

            foreach (GenPass pass in this._passes)
            {
                num += pass.Weight;
            }
            if (progress == null)
            {
                progress = new GenerationProgress();
            }
            progress.TotalWeight = num;
            Main.menuMode        = 888;
            Main.MenuUI.SetState((UIState) new UIWorldLoad(progress));
            foreach (GenPass pass in this._passes)
            {
                WorldGen._genRand = new UnifiedRandom(this._seed);
                Main.rand         = new UnifiedRandom(this._seed);
                stopwatch.Start();
                progress.Start(pass.Weight);
                pass.Apply(progress);
                progress.End();
                stopwatch.Reset();
            }
        }
Ejemplo n.º 4
0
        public void GenerateWorld(GenerationProgress progress = null)
        {
            Stopwatch stopwatch = new Stopwatch();
            float     num       = 0.0f;

            foreach (GenPass genPass in this._passes)
            {
                num += genPass.Weight;
            }
            if (progress == null)
            {
                progress = new GenerationProgress();
            }
            progress.TotalWeight = num;
            string str = "";

            Main.MenuUI.SetState((UIState) new UIWorldLoad(progress));
            Main.menuMode = 888;
            foreach (GenPass genPass in this._passes)
            {
                stopwatch.Start();
                progress.Start(genPass.Weight);
                genPass.Apply(progress);
                progress.End();
                str = str + "Pass - " + genPass.Name + " : " + stopwatch.Elapsed.TotalMilliseconds.ToString() + ",\n";
                stopwatch.Reset();
            }
        }
		public void GenerateWorld(GenerationProgress progress = null)
		{
			Stopwatch stopwatch = new Stopwatch();
			float num = 0f;
			foreach (GenPass current in this._passes)
			{
				num += current.Weight;
			}
			if (progress == null)
			{
				progress = new GenerationProgress();
			}
			progress.TotalWeight = num;
			string text = "";
			Main.MenuUI.SetState(new UIWorldLoad(progress));
			Main.menuMode = 888;
			foreach (GenPass current2 in this._passes)
			{
				stopwatch.Start();
				progress.Start(current2.Weight);
				current2.Apply(progress);
				progress.End();
				string text2 = text;
				text = string.Concat(new string[]
				{
					text2,
					"Pass - ",
					current2.Name,
					" : ",
					stopwatch.Elapsed.TotalMilliseconds.ToString(),
					",\n"
				});
				stopwatch.Reset();
			}
		}
Ejemplo n.º 6
0
        public void GenerateWorld(GenerationProgress progress = null)
        {
            Stopwatch stopwatch = new Stopwatch();
            float     weight    = 0f;

            foreach (GenPass _pass in this._passes)
            {
                weight = weight + _pass.Weight;
            }
            if (progress == null)
            {
                progress = new GenerationProgress();
            }
            progress.TotalWeight = weight;
            string str = "";

            Main.menuMode = 888;
            foreach (GenPass genPass in this._passes)
            {
                stopwatch.Start();
                progress.Start(genPass.Weight);
                genPass.Apply(progress);
                progress.End();
                string   str1 = str;
                string[] name = new string[] { str1, "Pass - ", genPass.Name, " : ", null, null };
                name[4] = stopwatch.Elapsed.TotalMilliseconds.ToString();
                name[5] = ",\n";
                str     = string.Concat(name);
                stopwatch.Reset();
            }
        }
Ejemplo n.º 7
0
 public override void Apply(GenerationProgress progress)
 {
     int num = this._count;
     while (num > 0)
     {
         if (this._perUnit(GenBase._random.Next(1, GenBase._worldWidth), GenBase._random.Next(1, GenBase._worldHeight), new object[0]))
             --num;
     }
 }
Ejemplo n.º 8
0
            public override void Apply(GenerationProgress progress)
            {
                int num = this._count;

                while (num > 0)
                {
                    if (this._perUnit(GenBase._random.Next(1, GenBase._worldWidth), GenBase._random.Next(1, GenBase._worldHeight), new object[0]))
                    {
                        --num;
                    }
                }
            }
Ejemplo n.º 9
0
 public override void Apply(GenerationProgress progress)
 {
     for (int index1 = 0; index1 < GenBase._worldWidth; ++index1)
     {
         for (int index2 = 0; index2 < GenBase._worldHeight; ++index2)
         {
             if (GenBase._tiles[index1, index2] == null)
                 GenBase._tiles[index1, index2] = new Tile();
             else
                 GenBase._tiles[index1, index2].ClearEverything();
         }
     }
 }
Ejemplo n.º 10
0
 public UIWorldLoad(GenerationProgress progress)
 {
     _progressBar.Top.Pixels = 370f;
     _progressBar.HAlign = 0.5f;
     _progressBar.VAlign = 0.0f;
     _progressBar.Recalculate();
     _progressMessage.CopyStyle(_progressBar);
     _progressMessage.Top.Pixels -= 70f;
     _progressMessage.Recalculate();
     _progress = progress;
     Append(_progressBar);
     Append(_progressMessage);
 }
		public UIWorldLoad(GenerationProgress progress)
		{
			this._progressBar.Top.Pixels = 370f;
			this._progressBar.HAlign = 0.5f;
			this._progressBar.VAlign = 0f;
			this._progressBar.Recalculate();
			this._progressMessage.CopyStyle(this._progressBar);
			UIHeader expr_78_cp_0 = this._progressMessage;
			expr_78_cp_0.Top.Pixels = expr_78_cp_0.Top.Pixels - 70f;
			this._progressMessage.Recalculate();
			this._progress = progress;
			base.Append(this._progressBar);
			base.Append(this._progressMessage);
		}
			public override void Apply(GenerationProgress progress)
			{
				for (int i = 0; i < GenBase._worldWidth; i++)
				{
					for (int j = 0; j < GenBase._worldHeight; j++)
					{
						if (GenBase._tiles[i, j] == null)
						{
							GenBase._tiles[i, j] = new Tile();
						}
						else
						{
							GenBase._tiles[i, j].ClearEverything();
						}
					}
				}
			}
Ejemplo n.º 13
0
 public override void Apply(GenerationProgress progress)
 {
     for (int i = 0; i < GenBase._worldWidth; i++)
     {
         for (int j = 0; j < GenBase._worldHeight; j++)
         {
             if (GenBase._tiles[i, j] != null)
             {
                 GenBase._tiles[i, j].ClearEverything();
             }
             else
             {
                 GenBase._tiles[i, j] = new Tile();
             }
         }
     }
 }
Ejemplo n.º 14
0
 public override void Apply(GenerationProgress progress)
 {
     for (int index1 = 0; index1 < GenBase._worldWidth; ++index1)
     {
         for (int index2 = 0; index2 < GenBase._worldHeight; ++index2)
         {
             if (GenBase._tiles[index1, index2] == null)
             {
                 GenBase._tiles[index1, index2] = new Tile();
             }
             else
             {
                 GenBase._tiles[index1, index2].ClearEverything();
             }
         }
     }
 }
Ejemplo n.º 15
0
 public void GenerateWorld(GenerationProgress progress = null)
 {
     Stopwatch stopwatch = new Stopwatch();
     float num = 0.0f;
     foreach (GenPass genPass in this._passes)
         num += genPass.Weight;
     if (progress == null)
         progress = new GenerationProgress();
     progress.TotalWeight = num;
     string str = "";
     Main.MenuUI.SetState((UIState)new UIWorldLoad(progress));
     Main.menuMode = 888;
     foreach (GenPass genPass in this._passes)
     {
         stopwatch.Start();
         progress.Start(genPass.Weight);
         genPass.Apply(progress);
         progress.End();
         str = str + "Pass - " + genPass.Name + " : " + stopwatch.Elapsed.TotalMilliseconds.ToString() + ",\n";
         stopwatch.Reset();
     }
 }
Ejemplo n.º 16
0
        public void DedServ()
        {
            ServerApi.Hooks.InvokeGameInitialize();
            string str;
            Main.rand = new Random();
            Console.Title = string.Concat("Terraria Server ", Main.versionNumber2);
            Main.dedServ = true;
            Main.showSplash = false;
            if (Main.autoGen)
            {
                Main.ActiveWorldFileData = new WorldFileData();
                Main.ActiveWorldFileData.Path = Main.WorldPathClassic;
            }
            this.Initialize();
            Lang.setLang(false);
            for (int i = 0; i < 540; i++)
            {
                NPC nPC = new NPC();
                nPC.SetDefaults(i, -1f);
                Main.npcName[i] = nPC.name;
            }

            if (Console.IsInputRedirected == true && string.IsNullOrEmpty(Main.WorldPathClassic) == true && !Main.autoGen)
            {
                throw new Exception("When running in the background, the world must be specified with -world <path>");
            }

            while (string.IsNullOrEmpty(Main.worldPathName))
            {
                bool flag = true;
                while (flag)
                {
                    Main.LoadWorlds();
                    Console.WriteLine(string.Concat("Terraria Server ", Main.versionNumber2));
                    Console.WriteLine("");
                    for (int j = 0; j < Main.WorldList.Count; j++)
                    {
                        object[] name = new object[]
                        {
                            j + 1,
                            '\t',
                            '\t', Main.WorldList[j].Name
                        };
                        Console.WriteLine("{0,-4}{1,-22}{2}, {3}, {4,-6}{5}",
                            j + 1,
                            Main.WorldList[j].Name,
                            Main.WorldList[j].IsHardMode ? "hard" : "norm",
                            Main.WorldList[j].HasCrimson ? "crim" : "corr",
                            Main.WorldList[j].IsExpertMode ? "exp" : "norm",
                            String.Format("Last used: {0}",
                                File.GetLastWriteTime(Main.WorldList[j].Path).ToString("g")));
                    }
                    Console.WriteLine();
                    Console.WriteLine("n           \tNew World");
                    Console.WriteLine("d   <number>\tDelete World");
                    Console.WriteLine("");
                    Console.Write("Choose World: ");
                    string str2 = Console.ReadLine() ?? "";
                    try
                    {
                        Console.Clear();
                    }
                    catch (Exception ex)
                    {
            #if DEBUG
                        Console.WriteLine(ex);
                        System.Diagnostics.Debugger.Break();

            #endif
                    }
                    if (str2.Length >= 2 && str2.Substring(0, 2).ToLower() == "d ")
                    {
                        try
                        {
                            int num = Convert.ToInt32(str2.Substring(2)) - 1;
                            if (num < Main.WorldList.Count)
                            {
                                Console.WriteLine(string.Concat("Terraria Server ", Main.versionNumber2));
                                Console.WriteLine("");
                                Console.WriteLine(string.Concat("Really delete ", Main.WorldList[num].Name, "?"));
                                Console.Write("(y/n): ");
                                if (Console.ReadLine().ToLower() == "y")
                                {
                                    Main.EraseWorld(num);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
            #if DEBUG
                            Console.WriteLine(ex);
                            System.Diagnostics.Debugger.Break();

            #endif
                        }
                        try
                        {
                            Console.Clear();
                        }
                        catch (Exception ex)
                        {
            #if DEBUG
                            Console.WriteLine(ex);
                            System.Diagnostics.Debugger.Break();

            #endif
                        }
                    }
                    else if (str2 == "n" || str2 == "N")
                    {
                        bool flag1 = true;
                        while (flag1)
                        {
                            Console.WriteLine(string.Concat("Terraria Server ", Main.versionNumber2));
                            Console.WriteLine("");
                            Console.WriteLine(string.Concat("1", '\t', "Small"));
                            Console.WriteLine(string.Concat("2", '\t', "Medium"));
                            Console.WriteLine(string.Concat("3", '\t', "Large"));
                            Console.WriteLine("");
                            Console.Write("Choose size: ");
                            str = Console.ReadLine();
                            try
                            {
                                int num1 = Convert.ToInt32(str);
                                if (num1 == 1)
                                {
                                    Main.maxTilesX = 4200;
                                    Main.maxTilesY = 1200;
                                    flag1 = false;
                                }
                                else if (num1 == 2)
                                {
                                    Main.maxTilesX = 6400;
                                    Main.maxTilesY = 1800;
                                    flag1 = false;
                                }
                                else if (num1 == 3)
                                {
                                    Main.maxTilesX = 8400;
                                    Main.maxTilesY = 2400;
                                    flag1 = false;
                                }
                            }
                            catch (Exception ex)
                            {
            #if DEBUG
                                Console.WriteLine(ex);
                                System.Diagnostics.Debugger.Break();

            #endif
                            }
                            try
                            {
                                Console.Clear();
                            }
                            catch (Exception ex)
                            {
            #if DEBUG
                                Console.WriteLine(ex);
                                System.Diagnostics.Debugger.Break();

            #endif
                            }
                        }
                        flag1 = true;
                        while (flag1)
                        {
                            Console.WriteLine(string.Concat("Terraria Server ", Main.versionNumber2));
                            Console.WriteLine("");
                            Console.WriteLine(string.Concat("1", '\t', "Normal"));
                            Console.WriteLine(string.Concat("2", '\t', "Expert"));
                            Console.WriteLine("");
                            Console.Write("Choose difficulty: ");
                            str = Console.ReadLine();
                            try
                            {
                                int num2 = Convert.ToInt32(str);
                                if (num2 == 1)
                                {
                                    Main.expertMode = false;
                                    flag1 = false;
                                }
                                else if (num2 == 2)
                                {
                                    Main.expertMode = true;
                                    flag1 = false;
                                }
                            }
                            catch (Exception ex)
                            {
            #if DEBUG
                                Console.WriteLine(ex);
                                System.Diagnostics.Debugger.Break();

            #endif
                            }
                            try
                            {
                                Console.Clear();
                            }
                            catch (Exception ex)
                            {
            #if DEBUG
                                Console.WriteLine(ex);
                                System.Diagnostics.Debugger.Break();

            #endif
                            }
                        }
                        flag1 = true;
                        while (flag1)
                        {
                            Console.WriteLine(string.Concat("Terraria Server ", Main.versionNumber2));
                            Console.WriteLine("");
                            Console.Write("Enter world name: ");
                            Main.newWorldName = Console.ReadLine();
                            if (Main.newWorldName != "" && Main.newWorldName != " " && Main.newWorldName != null)
                            {
                                if (Main.newWorldName.Length > 20)
                                {
                                    Main.newWorldName = Main.newWorldName.Substring(0, 20);
                                }
                                flag1 = false;
                            }
                            try
                            {
                                Console.Clear();
                            }
                            catch (Exception ex)
                            {
            #if DEBUG
                                Console.WriteLine(ex);
                                System.Diagnostics.Debugger.Break();

            #endif
                            }
                        }
                        Main.worldName = Main.newWorldName;
                        Main.ActiveWorldFileData = WorldFile.CreateMetadata(Main.worldName, Main.expertMode);
                        Main.menuMode = 10;
                        Main.serverGenLock = true;
                        GenerationProgress generationProgress = new GenerationProgress();
                        WorldGen.CreateNewWorld(generationProgress);
                        flag1 = false;
                        while (Main.menuMode == 10)
                        {
                            if (Main.oldStatusText == Main.statusText)
                            {
                                continue;
                            }
                            Main.oldStatusText = Main.statusText;
                            Console.WriteLine(Main.statusText);
                        }
                        try
                        {
                            Console.Clear();
                        }
                        catch (Exception ex)
                        {
            #if DEBUG
                            Console.WriteLine(ex);
                            System.Diagnostics.Debugger.Break();

            #endif
                        }

                        int oldProgress = 0;
                        int oldValue = 0;

                        while (Main.serverGenLock)
                        {

                            if ((int)(generationProgress.TotalProgress * 100) != oldProgress || (int)(generationProgress.Value * 100) != oldValue)
                            {
                                Main.statusText = string.Format(string.Concat("{0:0%} - ", generationProgress.Message, " - {1:0%}"), generationProgress.TotalProgress, generationProgress.Value);
                                Main.oldStatusText = Main.statusText;
                                oldProgress = (int)(generationProgress.TotalProgress * 100);
                                oldValue = (int)(generationProgress.Value * 100);
                                Console.WriteLine(Main.statusText);
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            int num3 = Convert.ToInt32(str2);
                            num3--;
                            if (num3 >= 0 && num3 < Main.WorldList.Count)
                            {
                                bool flag2 = true;
                                while (flag2)
                                {
                                    Console.WriteLine(string.Concat("Terraria Server ", Main.versionNumber2));
                                    Console.WriteLine("");
                                    Console.Write("Max players (press enter for {0}): ", Main.maxNetPlayers);
                                    string str3 = Console.ReadLine();
                                    try
                                    {
                                        if (str3 == "")
                                        {
                                            str3 = Main.maxNetPlayers.ToString();
                                        }
                                        int num4 = Convert.ToInt32(str3);
                                        if (num4 <= 255 && num4 >= 1)
                                        {
                                            Main.maxNetPlayers = num4;
                                            flag2 = false;
                                        }
                                        flag2 = false;
                                    }
                                    catch (Exception ex)
                                    {
            #if DEBUG
                                        Console.WriteLine(ex);
                                        System.Diagnostics.Debugger.Break();

            #endif
                                    }
                                    try
                                    {
                                        Console.Clear();
                                    }
                                    catch (Exception ex)
                                    {
            #if DEBUG
                                        Console.WriteLine(ex);
                                        System.Diagnostics.Debugger.Break();

            #endif
                                    }
                                }
                                flag2 = true;
                                while (flag2)
                                {
                                    if (Netplay.ListenPort != 7777) //If the port has been changed by the API do not allow it to be changed.
                                    {
                                        flag2 = false;
                                        break;
                                    }
                                    Console.WriteLine(string.Concat("Terraria Server ", Main.versionNumber2));
                                    Console.WriteLine("");
                                    Console.Write("Server port (press enter for 7777): ");
                                    string str4 = Console.ReadLine();
                                    try
                                    {
                                        if (str4 == "")
                                        {
                                            str4 = "7777";
                                        }
                                        int num5 = Convert.ToInt32(str4);
                                        if (num5 <= 65535)
                                        {
                                            Netplay.ListenPort = num5;
                                            flag2 = false;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
            #if DEBUG
                                        Console.WriteLine(ex);
                                        System.Diagnostics.Debugger.Break();

            #endif
                                    }
                                    try
                                    {
                                        Console.Clear();
                                    }
                                    catch (Exception ex)
                                    {
            #if DEBUG
                                        Console.WriteLine(ex);
                                        System.Diagnostics.Debugger.Break();

            #endif
                                    }
                                }
                                Main.ActiveWorldFileData = Main.WorldList[num3];
                                flag = false;
                                try
                                {
                                    Console.Clear();
                                }
                                catch (Exception ex)
                                {
            #if DEBUG
                                    Console.WriteLine(ex);
                                    System.Diagnostics.Debugger.Break();

            #endif
                                }
                            }
                        }
                        catch (Exception ex)
                        {
            #if DEBUG
                            Console.WriteLine(ex);
                            System.Diagnostics.Debugger.Break();

            #endif
                        }
                    }
                }
            }
            try
            {
                Console.Clear();
            }
            catch (Exception ex)
            {
            #if DEBUG
                Console.WriteLine(ex);
                System.Diagnostics.Debugger.Break();

            #endif
            }
            WorldGen.serverLoadWorld();
            Console.WriteLine(string.Concat("Terraria Server ", Main.versionNumber));
            Console.WriteLine("");
            while (!Netplay.IsServerRunning)
            {
                if (Main.oldStatusText == Main.statusText)
                {
                    continue;
                }
                Main.oldStatusText = Main.statusText;
                Console.WriteLine(Main.statusText);
            }
            try
            {
                Console.Clear();
            }
            catch (Exception ex)
            {
            #if DEBUG
                Console.WriteLine(ex);
                System.Diagnostics.Debugger.Break();

            #endif
            }
            Console.WriteLine(string.Concat("Terraria Server ", Main.versionNumber));
            Console.WriteLine("");
            Console.WriteLine(string.Concat("Listening on port ", Netplay.ListenPort));
            Console.WriteLine("Type 'help' for a list of commands.");
            Console.WriteLine("");
            Console.Title = string.Concat("Terraria Server: ", Main.worldName);

            Stopwatch stopwatch = new Stopwatch();
            if (!Main.autoShutdown)
            {
                Main.startDedInput();
            }
            ServerApi.Hooks.InvokeGamePostInitialize();
            stopwatch.Start();
            double num6 = 16.6666666666667;
            double num7 = 0;
            int num8 = 0;
            while (!Netplay.disconnect)
            {
                double elapsedMilliseconds = (double)stopwatch.ElapsedMilliseconds;
                if (elapsedMilliseconds + num7 >= num6)
                {
                    num8++;
                    num7 = num7 + (elapsedMilliseconds - num6);
                    stopwatch.Reset();
                    stopwatch.Start();
                    if (Main.oldStatusText != Main.statusText)
                    {
                        Main.oldStatusText = Main.statusText;
                        Console.WriteLine(Main.statusText);
                    }
                    if (Netplay.anyClients || ServerApi.ForceUpdate)
                    {
                        ServerApi.Hooks.InvokeGameUpdate();
                        this.Update();
                        ServerApi.Hooks.InvokeGamePostUpdate();
                    }
                    double elapsedMilliseconds1 = (double)stopwatch.ElapsedMilliseconds + num7;
                    if (elapsedMilliseconds1 < num6)
                    {
                        int num9 = (int)(num6 - elapsedMilliseconds1) - 1;
                        if (num9 > 1)
                        {
                            Thread.Sleep(num9 - 1);
                            if (!Netplay.anyClients)
                            {
                                num7 = 0;
                                Thread.Sleep(10);
                            }
                        }
                    }
                }
                Thread.Sleep(0);
            }
        }
		public abstract void Apply(GenerationProgress progress);
Ejemplo n.º 18
0
 public static void CreateNewWorld(GenerationProgress progress = null)
 {
     ThreadPool.QueueUserWorkItem(new WaitCallback(WorldGen.worldGenCallBack), progress);
 }
Ejemplo n.º 19
0
 public static void generateWorld(int seed = -1, GenerationProgress customProgressObject = null)
 {
     WorldGen._generator = new WorldGenerator();
     if (seed > 0)
     {
         WorldGen.genRand = new Random(seed);
     }
     else
     {
         WorldGen.genRand = new Random((int)DateTime.Now.Ticks);
     }
     MicroBiome.ResetAll();
     StructureMap structures = new StructureMap();
     double worldSurface = 0.0;
     WorldGen.worldSurfaceLow = 0.0;
     double worldSurfaceHigh = 0.0;
     double rockLayer = 0.0;
     double rockLayerLow = 0.0;
     double rockLayerHigh = 0.0;
     int copper = 7;
     int iron = 6;
     int silver = 9;
     int gold = 8;
     int dungeonSide = 0;
     ushort jungleHut = (ushort)WorldGen.genRand.Next(5);
     int howFar = 0;
     int[] PyrX = null;
     int[] PyrY = null;
     int numPyr = 0;
     int[] snowMinX = new int[Main.maxTilesY];
     int[] snowMaxX = new int[Main.maxTilesY];
     int snowTop = 0;
     int snowBottom = 0;
     float dub2 = 0f;
     int skyLakes = 1;
     if (Main.maxTilesX > 8000)
     {
         skyLakes++;
     }
     if (Main.maxTilesX > 6000)
     {
         skyLakes++;
     }
     for (int i = 0; i < WorldGen.hellChestItem.Length; i++)
     {
         bool flag = true;
         while (flag)
         {
             flag = false;
             WorldGen.hellChestItem[i] = WorldGen.genRand.Next(WorldGen.hellChestItem.Length);
             for (int j = 0; j < i; j++)
             {
                 if (WorldGen.hellChestItem[j] == WorldGen.hellChestItem[i])
                 {
                     flag = true;
                 }
             }
         }
     }
     WorldGen.AddGenerationPass("Reset", delegate (GenerationProgress progress)
     {
         WorldGen.noTileActions = true;
         progress.Message = "";
         WorldGen.SetupStatueList();
         WorldGen.RandomizeWeather();
         Main.cloudAlpha = 0f;
         Main.maxRaining = 0f;
         WorldFile.tempMaxRain = 0f;
         Main.raining = false;
         WorldGen.heartCount = 0;
         Main.CheckXMas();
         Main.checkHalloween();
         WorldGen.gen = true;
         WorldGen.ResetGenerator();
         WorldGen.numLarva = 0;
         int num = 86400;
         Main.slimeRainTime = (double)(-(double)WorldGen.genRand.Next(num * 2, num * 3));
         Main.cloudBGActive = (float)(-(float)WorldGen.genRand.Next(8640, 86400));
         WorldGen.CopperTierOre = 7;
         WorldGen.IronTierOre = 6;
         WorldGen.SilverTierOre = 9;
         WorldGen.GoldTierOre = 8;
         WorldGen.copperBar = 20;
         WorldGen.ironBar = 22;
         WorldGen.silverBar = 21;
         WorldGen.goldBar = 19;
         if (WorldGen.genRand.Next(2) == 0)
         {
             copper = 166;
             WorldGen.copperBar = 703;
             WorldGen.CopperTierOre = 166;
         }
         if (WorldGen.genRand.Next(2) == 0)
         {
             iron = 167;
             WorldGen.ironBar = 704;
             WorldGen.IronTierOre = 167;
         }
         if (WorldGen.genRand.Next(2) == 0)
         {
             silver = 168;
             WorldGen.silverBar = 705;
             WorldGen.SilverTierOre = 168;
         }
         if (WorldGen.genRand.Next(2) == 0)
         {
             gold = 169;
             WorldGen.goldBar = 706;
             WorldGen.GoldTierOre = 169;
         }
         WorldGen.crimson = (WorldGen.genRand.Next(2) == 0);
         if (jungleHut == 0)
         {
             jungleHut = 119;
         }
         else if (jungleHut == 1)
         {
             jungleHut = 120;
         }
         else if (jungleHut == 2)
         {
             jungleHut = 158;
         }
         else if (jungleHut == 3)
         {
             jungleHut = 175;
         }
         else if (jungleHut == 4)
         {
             jungleHut = 45;
         }
         Main.worldID = WorldGen.genRand.Next(2147483647);
         WorldGen.RandomizeTreeStyle();
         WorldGen.RandomizeCaveBackgrounds();
         WorldGen.RandomizeBackgrounds();
         WorldGen.RandomizeMoonState();
         dungeonSide = ((WorldGen.genRand.Next(2) == 0) ? -1 : 1);
     });
     WorldGen.AddGenerationPass("Terrain", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[0];
         int num = 0;
         int num2 = 0;
         worldSurface = (double)Main.maxTilesY * 0.3;
         worldSurface *= (double)WorldGen.genRand.Next(90, 110) * 0.005;
         rockLayer = worldSurface + (double)Main.maxTilesY * 0.2;
         rockLayer *= (double)WorldGen.genRand.Next(90, 110) * 0.01;
         WorldGen.worldSurfaceLow = worldSurface;
         worldSurfaceHigh = worldSurface;
         rockLayerLow = rockLayer;
         rockLayerHigh = rockLayer;
         for (int k = 0; k < Main.maxTilesX; k++)
         {
             float value = (float)k / (float)Main.maxTilesX;
             progress.Set(value);
             if (worldSurface < WorldGen.worldSurfaceLow)
             {
                 WorldGen.worldSurfaceLow = worldSurface;
             }
             if (worldSurface > worldSurfaceHigh)
             {
                 worldSurfaceHigh = worldSurface;
             }
             if (rockLayer < rockLayerLow)
             {
                 rockLayerLow = rockLayer;
             }
             if (rockLayer > rockLayerHigh)
             {
                 rockLayerHigh = rockLayer;
             }
             if (num2 <= 0)
             {
                 num = WorldGen.genRand.Next(0, 5);
                 num2 = WorldGen.genRand.Next(5, 40);
                 if (num == 0)
                 {
                     num2 *= (int)((double)WorldGen.genRand.Next(5, 30) * 0.2);
                 }
             }
             num2--;
             if ((double)k > (double)Main.maxTilesX * 0.43 && (double)k < (double)Main.maxTilesX * 0.57 && num >= 3)
             {
                 num = WorldGen.genRand.Next(3);
             }
             if ((double)k > (double)Main.maxTilesX * 0.47 && (double)k < (double)Main.maxTilesX * 0.53)
             {
                 num = 0;
             }
             if (num == 0)
             {
                 while (WorldGen.genRand.Next(0, 7) == 0)
                 {
                     worldSurface += (double)WorldGen.genRand.Next(-1, 2);
                 }
             }
             else if (num == 1)
             {
                 while (WorldGen.genRand.Next(0, 4) == 0)
                 {
                     worldSurface -= 1.0;
                 }
                 while (WorldGen.genRand.Next(0, 10) == 0)
                 {
                     worldSurface += 1.0;
                 }
             }
             else if (num == 2)
             {
                 while (WorldGen.genRand.Next(0, 4) == 0)
                 {
                     worldSurface += 1.0;
                 }
                 while (WorldGen.genRand.Next(0, 10) == 0)
                 {
                     worldSurface -= 1.0;
                 }
             }
             else if (num == 3)
             {
                 while (WorldGen.genRand.Next(0, 2) == 0)
                 {
                     worldSurface -= 1.0;
                 }
                 while (WorldGen.genRand.Next(0, 6) == 0)
                 {
                     worldSurface += 1.0;
                 }
             }
             else if (num == 4)
             {
                 while (WorldGen.genRand.Next(0, 2) == 0)
                 {
                     worldSurface += 1.0;
                 }
                 while (WorldGen.genRand.Next(0, 5) == 0)
                 {
                     worldSurface -= 1.0;
                 }
             }
             if (worldSurface < (double)Main.maxTilesY * 0.17)
             {
                 worldSurface = (double)Main.maxTilesY * 0.17;
                 num2 = 0;
             }
             else if (worldSurface > (double)Main.maxTilesY * 0.3)
             {
                 worldSurface = (double)Main.maxTilesY * 0.3;
                 num2 = 0;
             }
             if ((k < 275 || k > Main.maxTilesX - 275) && worldSurface > (double)Main.maxTilesY * 0.25)
             {
                 worldSurface = (double)Main.maxTilesY * 0.25;
                 num2 = 1;
             }
             while (WorldGen.genRand.Next(0, 3) == 0)
             {
                 rockLayer += (double)WorldGen.genRand.Next(-2, 3);
             }
             if (rockLayer < worldSurface + (double)Main.maxTilesY * 0.05)
             {
                 rockLayer += 1.0;
             }
             if (rockLayer > worldSurface + (double)Main.maxTilesY * 0.35)
             {
                 rockLayer -= 1.0;
             }
             int num3 = 0;
             while ((double)num3 < worldSurface)
             {
                 Main.tile[k, num3].active(false);
                 Main.tile[k, num3].frameX = -1;
                 Main.tile[k, num3].frameY = -1;
                 num3++;
             }
             for (int l = (int)worldSurface; l < Main.maxTilesY; l++)
             {
                 if ((double)l < rockLayer)
                 {
                     Main.tile[k, l].active(true);
                     Main.tile[k, l].type = 0;
                     Main.tile[k, l].frameX = -1;
                     Main.tile[k, l].frameY = -1;
                 }
                 else
                 {
                     Main.tile[k, l].active(true);
                     Main.tile[k, l].type = 1;
                     Main.tile[k, l].frameX = -1;
                     Main.tile[k, l].frameY = -1;
                 }
             }
         }
         Main.worldSurface = worldSurfaceHigh + 25.0;
         Main.rockLayer = rockLayerHigh;
         double num4 = (double)((int)((Main.rockLayer - Main.worldSurface) / 6.0) * 6);
         Main.rockLayer = Main.worldSurface + num4;
         WorldGen.waterLine = (int)(Main.rockLayer + (double)Main.maxTilesY) / 2;
         WorldGen.waterLine += WorldGen.genRand.Next(-100, 20);
         WorldGen.lavaLine = WorldGen.waterLine + WorldGen.genRand.Next(50, 80);
     });
     WorldGen.AddGenerationPass("Tunnels", delegate (GenerationProgress progress)
     {
         for (int k = 0; k < (int)((double)Main.maxTilesX * 0.0015); k++)
         {
             int[] array = new int[10];
             int[] array2 = new int[10];
             int num = WorldGen.genRand.Next(450, Main.maxTilesX - 450);
             int num2 = 0;
             for (int l = 0; l < 10; l++)
             {
                 while (!Main.tile[num, num2].active())
                 {
                     num2++;
                 }
                 array[l] = num;
                 array2[l] = num2 - WorldGen.genRand.Next(11, 16);
                 num += WorldGen.genRand.Next(5, 11);
             }
             for (int m = 0; m < 10; m++)
             {
                 WorldGen.TileRunner(array[m], array2[m], (double)WorldGen.genRand.Next(5, 8), WorldGen.genRand.Next(6, 9), 0, true, -2f, -0.3f, false, true);
                 WorldGen.TileRunner(array[m], array2[m], (double)WorldGen.genRand.Next(5, 8), WorldGen.genRand.Next(6, 9), 0, true, 2f, -0.3f, false, true);
             }
         }
     });
     WorldGen.AddGenerationPass("Sand", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[1];
         int num = WorldGen.genRand.Next((int)((double)Main.maxTilesX * 0.0008), (int)((double)Main.maxTilesX * 0.0025));
         num += 2;
         PyrX = new int[num];
         PyrY = new int[num];
         for (int k = 0; k < num; k++)
         {
             int num2 = WorldGen.genRand.Next(Main.maxTilesX);
             while ((float)num2 > (float)Main.maxTilesX * 0.4f && (float)num2 < (float)Main.maxTilesX * 0.6f)
             {
                 num2 = WorldGen.genRand.Next(Main.maxTilesX);
             }
             int num3 = WorldGen.genRand.Next(35, 90);
             if (k == 1)
             {
                 float num4 = (float)(Main.maxTilesX / 4200);
                 num3 += (int)((float)WorldGen.genRand.Next(20, 40) * num4);
             }
             if (WorldGen.genRand.Next(3) == 0)
             {
                 num3 *= 2;
             }
             if (k == 1)
             {
                 num3 *= 2;
             }
             int num5 = num2 - num3;
             num3 = WorldGen.genRand.Next(35, 90);
             if (WorldGen.genRand.Next(3) == 0)
             {
                 num3 *= 2;
             }
             if (k == 1)
             {
                 num3 *= 2;
             }
             int num6 = num2 + num3;
             if (num5 < 0)
             {
                 num5 = 0;
             }
             if (num6 > Main.maxTilesX)
             {
                 num6 = Main.maxTilesX;
             }
             if (k == 0)
             {
                 num5 = 0;
                 num6 = WorldGen.genRand.Next(260, 300);
                 if (dungeonSide == 1)
                 {
                     num6 += 40;
                 }
             }
             else if (k == 2)
             {
                 num5 = Main.maxTilesX - WorldGen.genRand.Next(260, 300);
                 num6 = Main.maxTilesX;
                 if (dungeonSide == -1)
                 {
                     num5 -= 40;
                 }
             }
             int num7 = WorldGen.genRand.Next(50, 100);
             for (int l = num5; l < num6; l++)
             {
                 if (WorldGen.genRand.Next(2) == 0)
                 {
                     num7 += WorldGen.genRand.Next(-1, 2);
                     if (num7 < 50)
                     {
                         num7 = 50;
                     }
                     if (num7 > 100)
                     {
                         num7 = 100;
                     }
                 }
                 int num8 = 0;
                 while ((double)num8 < Main.worldSurface)
                 {
                     if (Main.tile[l, num8].active())
                     {
                         if (l == (num5 + num6) / 2 && WorldGen.genRand.Next(6) == 0)
                         {
                             PyrX[numPyr] = l;
                             PyrY[numPyr] = num8;
                             numPyr++;
                         }
                         int num9 = num7;
                         if (l - num5 < num9)
                         {
                             num9 = l - num5;
                         }
                         if (num6 - l < num9)
                         {
                             num9 = num6 - l;
                         }
                         num9 += WorldGen.genRand.Next(5);
                         for (int m = num8; m < num8 + num9; m++)
                         {
                             if (l > num5 + WorldGen.genRand.Next(5) && l < num6 - WorldGen.genRand.Next(5))
                             {
                                 Main.tile[l, m].type = 53;
                             }
                         }
                         break;
                     }
                     num8++;
                 }
             }
         }
         for (int n = 0; n < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 8E-06); n++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)Main.worldSurface, (int)Main.rockLayer), (double)WorldGen.genRand.Next(15, 70), WorldGen.genRand.Next(20, 130), 53, false, 0f, 0f, false, true);
         }
     });
     WorldGen.AddGenerationPass("Mount Caves", delegate (GenerationProgress progress)
     {
         WorldGen.numMCaves = 0;
         progress.Message = Lang.gen[2];
         for (int k = 0; k < (int)((double)Main.maxTilesX * 0.0008); k++)
         {
             int num = 0;
             bool flag2 = false;
             bool flag3 = false;
             int num2 = WorldGen.genRand.Next((int)((double)Main.maxTilesX * 0.25), (int)((double)Main.maxTilesX * 0.75));
             while (!flag3)
             {
                 flag3 = true;
                 while (num2 > Main.maxTilesX / 2 - 100 && num2 < Main.maxTilesX / 2 + 100)
                 {
                     num2 = WorldGen.genRand.Next((int)((double)Main.maxTilesX * 0.25), (int)((double)Main.maxTilesX * 0.75));
                 }
                 for (int l = 0; l < WorldGen.numMCaves; l++)
                 {
                     if (num2 > WorldGen.mCaveX[l] - 50 && num2 < WorldGen.mCaveX[l] + 50)
                     {
                         num++;
                         flag3 = false;
                         break;
                     }
                 }
                 if (num >= 200)
                 {
                     flag2 = true;
                     break;
                 }
             }
             if (!flag2)
             {
                 int num3 = 0;
                 while ((double)num3 < Main.worldSurface)
                 {
                     if (Main.tile[num2, num3].active())
                     {
                         for (int m = num2 - 50; m < num2 + 50; m++)
                         {
                             for (int n = num3 - 25; n < num3 + 25; n++)
                             {
                                 if (Main.tile[m, n].active() && (Main.tile[m, n].type == 53 || Main.tile[m, n].type == 151 || Main.tile[m, n].type == 274))
                                 {
                                     flag2 = true;
                                 }
                             }
                         }
                         if (!flag2)
                         {
                             WorldGen.Mountinater(num2, num3);
                             WorldGen.mCaveX[WorldGen.numMCaves] = num2;
                             WorldGen.mCaveY[WorldGen.numMCaves] = num3;
                             WorldGen.numMCaves++;
                             break;
                         }
                     }
                     num3++;
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Dirt Wall Backgrounds", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[3];
         for (int k = 1; k < Main.maxTilesX - 1; k++)
         {
             byte wall = 2;
             float value = (float)k / (float)Main.maxTilesX;
             progress.Set(value);
             bool flag2 = false;
             howFar += WorldGen.genRand.Next(-1, 2);
             if (howFar < 0)
             {
                 howFar = 0;
             }
             if (howFar > 10)
             {
                 howFar = 10;
             }
             int num = 0;
             while ((double)num < Main.worldSurface + 10.0 && (double)num <= Main.worldSurface + (double)howFar)
             {
                 if (Main.tile[k, num].active())
                 {
                     if (Main.tile[k, num].type == 147)
                     {
                         wall = 40;
                     }
                     else
                     {
                         wall = 2;
                     }
                 }
                 if (flag2 && Main.tile[k, num].wall != 64)
                 {
                     Main.tile[k, num].wall = wall;
                 }
                 if (Main.tile[k, num].active() && Main.tile[k - 1, num].active() && Main.tile[k + 1, num].active() && Main.tile[k, num + 1].active() && Main.tile[k - 1, num + 1].active() && Main.tile[k + 1, num + 1].active())
                 {
                     flag2 = true;
                 }
                 num++;
             }
         }
     });
     WorldGen.AddGenerationPass("Rocks In Dirt", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[4];
         for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.00015); k++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next(0, (int)WorldGen.worldSurfaceLow + 1), (double)WorldGen.genRand.Next(4, 15), WorldGen.genRand.Next(5, 40), 1, false, 0f, 0f, false, true);
         }
         for (int l = 0; l < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.0002); l++)
         {
             int num = WorldGen.genRand.Next(0, Main.maxTilesX);
             int num2 = WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, (int)worldSurfaceHigh + 1);
             if (!Main.tile[num, num2 - 10].active())
             {
                 num2 = WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, (int)worldSurfaceHigh + 1);
             }
             WorldGen.TileRunner(num, num2, (double)WorldGen.genRand.Next(4, 10), WorldGen.genRand.Next(5, 30), 1, false, 0f, 0f, false, true);
         }
         for (int m = 0; m < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.0045); m++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)worldSurfaceHigh, (int)rockLayerHigh + 1), (double)WorldGen.genRand.Next(2, 7), WorldGen.genRand.Next(2, 23), 1, false, 0f, 0f, false, true);
         }
     });
     WorldGen.AddGenerationPass("Dirt In Rocks", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[5];
         for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.005); k++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)rockLayerLow, Main.maxTilesY), (double)WorldGen.genRand.Next(2, 6), WorldGen.genRand.Next(2, 40), 0, false, 0f, 0f, false, true);
         }
     });
     WorldGen.AddGenerationPass("Clay", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[6];
         for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 2E-05); k++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next(0, (int)WorldGen.worldSurfaceLow), (double)WorldGen.genRand.Next(4, 14), WorldGen.genRand.Next(10, 50), 40, false, 0f, 0f, false, true);
         }
         for (int l = 0; l < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 5E-05); l++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, (int)worldSurfaceHigh + 1), (double)WorldGen.genRand.Next(8, 14), WorldGen.genRand.Next(15, 45), 40, false, 0f, 0f, false, true);
         }
         for (int m = 0; m < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 2E-05); m++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)worldSurfaceHigh, (int)rockLayerHigh + 1), (double)WorldGen.genRand.Next(8, 15), WorldGen.genRand.Next(5, 50), 40, false, 0f, 0f, false, true);
         }
         for (int n = 5; n < Main.maxTilesX - 5; n++)
         {
             int num = 1;
             while ((double)num < Main.worldSurface - 1.0)
             {
                 if (Main.tile[n, num].active())
                 {
                     for (int num2 = num; num2 < num + 5; num2++)
                     {
                         if (Main.tile[n, num2].type == 40)
                         {
                             Main.tile[n, num2].type = 0;
                         }
                     }
                     break;
                 }
                 num++;
             }
         }
     });
     int i2;
     WorldGen.AddGenerationPass("Small Holes", delegate (GenerationProgress progress)
     {
         i2 = 0;
         progress.Message = Lang.gen[7];
         for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.0015); k++)
         {
             float value = (float)((double)k / ((double)(Main.maxTilesX * Main.maxTilesY) * 0.0015));
             progress.Set(value);
             int type = -1;
             if (WorldGen.genRand.Next(5) == 0)
             {
                 type = -2;
             }
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)worldSurfaceHigh, Main.maxTilesY), (double)WorldGen.genRand.Next(2, 5), WorldGen.genRand.Next(2, 20), type, false, 0f, 0f, false, true);
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)worldSurfaceHigh, Main.maxTilesY), (double)WorldGen.genRand.Next(8, 15), WorldGen.genRand.Next(7, 30), type, false, 0f, 0f, false, true);
         }
     });
     WorldGen.AddGenerationPass("Dirt Layer Caves", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[8];
         for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 3E-05); k++)
         {
             float value = (float)((double)k / ((double)(Main.maxTilesX * Main.maxTilesY) * 3E-05));
             progress.Set(value);
             if (rockLayerHigh <= (double)Main.maxTilesY)
             {
                 int type = -1;
                 if (WorldGen.genRand.Next(6) == 0)
                 {
                     type = -2;
                 }
                 WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, (int)rockLayerHigh + 1), (double)WorldGen.genRand.Next(5, 15), WorldGen.genRand.Next(30, 200), type, false, 0f, 0f, false, true);
             }
         }
     });
     WorldGen.AddGenerationPass("Rock Layer Caves", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[9];
         for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.00013); k++)
         {
             float value = (float)((double)k / ((double)(Main.maxTilesX * Main.maxTilesY) * 0.00013));
             progress.Set(value);
             if (rockLayerHigh <= (double)Main.maxTilesY)
             {
                 int type = -1;
                 if (WorldGen.genRand.Next(10) == 0)
                 {
                     type = -2;
                 }
                 WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)rockLayerHigh, Main.maxTilesY), (double)WorldGen.genRand.Next(6, 20), WorldGen.genRand.Next(50, 300), type, false, 0f, 0f, false, true);
             }
         }
     });
     WorldGen.AddGenerationPass("Surface Caves", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[10];
         for (int k = 0; k < (int)((double)Main.maxTilesX * 0.002); k++)
         {
             i2 = WorldGen.genRand.Next(0, Main.maxTilesX);
             while ((double)i2 > (double)Main.maxTilesX * 0.45 && (double)i2 < (double)Main.maxTilesX * 0.55)
             {
                 i2 = WorldGen.genRand.Next(0, Main.maxTilesX);
             }
             int num = 0;
             while ((double)num < worldSurfaceHigh)
             {
                 if (Main.tile[i2, num].active())
                 {
                     WorldGen.TileRunner(i2, num, (double)WorldGen.genRand.Next(3, 6), WorldGen.genRand.Next(5, 50), -1, false, (float)WorldGen.genRand.Next(-10, 11) * 0.1f, 1f, false, true);
                     break;
                 }
                 num++;
             }
         }
         for (int l = 0; l < (int)((double)Main.maxTilesX * 0.0007); l++)
         {
             i2 = WorldGen.genRand.Next(0, Main.maxTilesX);
             while ((double)i2 > (double)Main.maxTilesX * 0.43 && (double)i2 < (double)Main.maxTilesX * 0.58)
             {
                 i2 = WorldGen.genRand.Next(0, Main.maxTilesX);
             }
             int num2 = 0;
             while ((double)num2 < worldSurfaceHigh)
             {
                 if (Main.tile[i2, num2].active())
                 {
                     WorldGen.TileRunner(i2, num2, (double)WorldGen.genRand.Next(10, 15), WorldGen.genRand.Next(50, 130), -1, false, (float)WorldGen.genRand.Next(-10, 11) * 0.1f, 2f, false, true);
                     break;
                 }
                 num2++;
             }
         }
         for (int m = 0; m < (int)((double)Main.maxTilesX * 0.0003); m++)
         {
             i2 = WorldGen.genRand.Next(0, Main.maxTilesX);
             while ((double)i2 > (double)Main.maxTilesX * 0.4 && (double)i2 < (double)Main.maxTilesX * 0.6)
             {
                 i2 = WorldGen.genRand.Next(0, Main.maxTilesX);
             }
             int num3 = 0;
             while ((double)num3 < worldSurfaceHigh)
             {
                 if (Main.tile[i2, num3].active())
                 {
                     WorldGen.TileRunner(i2, num3, (double)WorldGen.genRand.Next(12, 25), WorldGen.genRand.Next(150, 500), -1, false, (float)WorldGen.genRand.Next(-10, 11) * 0.1f, 4f, false, true);
                     WorldGen.TileRunner(i2, num3, (double)WorldGen.genRand.Next(8, 17), WorldGen.genRand.Next(60, 200), -1, false, (float)WorldGen.genRand.Next(-10, 11) * 0.1f, 2f, false, true);
                     WorldGen.TileRunner(i2, num3, (double)WorldGen.genRand.Next(5, 13), WorldGen.genRand.Next(40, 170), -1, false, (float)WorldGen.genRand.Next(-10, 11) * 0.1f, 2f, false, true);
                     break;
                 }
                 num3++;
             }
         }
         for (int n = 0; n < (int)((double)Main.maxTilesX * 0.0004); n++)
         {
             i2 = WorldGen.genRand.Next(0, Main.maxTilesX);
             while ((double)i2 > (double)Main.maxTilesX * 0.4 && (double)i2 < (double)Main.maxTilesX * 0.6)
             {
                 i2 = WorldGen.genRand.Next(0, Main.maxTilesX);
             }
             int num4 = 0;
             while ((double)num4 < worldSurfaceHigh)
             {
                 if (Main.tile[i2, num4].active())
                 {
                     WorldGen.TileRunner(i2, num4, (double)WorldGen.genRand.Next(7, 12), WorldGen.genRand.Next(150, 250), -1, false, 0f, 1f, true, true);
                     break;
                 }
                 num4++;
             }
         }
         float num5 = (float)(Main.maxTilesX / 4200);
         int num6 = 0;
         while ((float)num6 < 5f * num5)
         {
             try
             {
                 WorldGen.Caverer(WorldGen.genRand.Next(100, Main.maxTilesX - 100), WorldGen.genRand.Next((int)Main.rockLayer, Main.maxTilesY - 400));
             }
             catch
             {
             }
             num6++;
         }
     });
     WorldGen.AddGenerationPass("Slush Check", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[56];
         snowTop = (int)Main.worldSurface;
         int num = WorldGen.genRand.Next(Main.maxTilesX);
         if (dungeonSide == 1)
         {
             while ((float)num < (float)Main.maxTilesX * 0.55f || (float)num > (float)Main.maxTilesX * 0.7f)
             {
                 num = WorldGen.genRand.Next(Main.maxTilesX);
             }
         }
         else
         {
             while ((float)num < (float)Main.maxTilesX * 0.3f || (float)num > (float)Main.maxTilesX * 0.45f)
             {
                 num = WorldGen.genRand.Next(Main.maxTilesX);
             }
         }
         int num2 = WorldGen.genRand.Next(50, 90);
         float num3 = (float)(Main.maxTilesX / 4200);
         num2 += (int)((float)WorldGen.genRand.Next(20, 40) * num3);
         num2 += (int)((float)WorldGen.genRand.Next(20, 40) * num3);
         int num4 = num - num2;
         num2 = WorldGen.genRand.Next(50, 90);
         num2 += (int)((float)WorldGen.genRand.Next(20, 40) * num3);
         num2 += (int)((float)WorldGen.genRand.Next(20, 40) * num3);
         int num5 = num + num2;
         if (num4 < 0)
         {
             num4 = 0;
         }
         if (num5 > Main.maxTilesX)
         {
             num5 = Main.maxTilesX;
         }
         int num6 = 10;
         for (int k = 0; k <= WorldGen.lavaLine - 140; k++)
         {
             num4 += WorldGen.genRand.Next(-4, 4);
             num5 += WorldGen.genRand.Next(-3, 5);
             snowMinX[k] = num4;
             snowMaxX[k] = num5;
             for (int l = num4; l < num5; l++)
             {
                 if (k < WorldGen.lavaLine - 140)
                 {
                     if (Main.tile[l, k].wall == 2)
                     {
                         Main.tile[l, k].wall = 40;
                     }
                     int type = (int)Main.tile[l, k].type;
                     if (type == 0 || type == 2 || type == 23 || type == 40 || type == 53)
                     {
                         Main.tile[l, k].type = 147;
                     }
                     else if (type == 1)
                     {
                         Main.tile[l, k].type = 161;
                     }
                 }
                 else
                 {
                     num6 += WorldGen.genRand.Next(-3, 4);
                     if (WorldGen.genRand.Next(3) == 0)
                     {
                         num6 += WorldGen.genRand.Next(-4, 5);
                         if (WorldGen.genRand.Next(3) == 0)
                         {
                             num6 += WorldGen.genRand.Next(-6, 7);
                         }
                     }
                     if (num6 < 0)
                     {
                         num6 = WorldGen.genRand.Next(3);
                     }
                     else if (num6 > 50)
                     {
                         num6 = 50 - WorldGen.genRand.Next(3);
                     }
                     for (int m = k; m < k + num6; m++)
                     {
                         if (Main.tile[l, m].wall == 2)
                         {
                             Main.tile[l, m].wall = 40;
                         }
                         int type2 = (int)Main.tile[l, m].type;
                         if (type2 == 0 || type2 == 2 || type2 == 23 || type2 == 40 || type2 == 53)
                         {
                             Main.tile[l, m].type = 147;
                         }
                         else if (type2 == 1)
                         {
                             Main.tile[l, m].type = 161;
                         }
                     }
                 }
             }
             if (snowBottom < k)
             {
                 snowBottom = k;
             }
         }
     });
     WorldGen.AddGenerationPass("Grass", delegate (GenerationProgress progress)
     {
         for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.002); k++)
         {
             int num = WorldGen.genRand.Next(1, Main.maxTilesX - 1);
             int num2 = WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, (int)worldSurfaceHigh);
             if (num2 >= Main.maxTilesY)
             {
                 num2 = Main.maxTilesY - 2;
             }
             if (Main.tile[num - 1, num2].active() && Main.tile[num - 1, num2].type == 0 && Main.tile[num + 1, num2].active() && Main.tile[num + 1, num2].type == 0 && Main.tile[num, num2 - 1].active() && Main.tile[num, num2 - 1].type == 0 && Main.tile[num, num2 + 1].active() && Main.tile[num, num2 + 1].type == 0)
             {
                 Main.tile[num, num2].active(true);
                 Main.tile[num, num2].type = 2;
             }
             num = WorldGen.genRand.Next(1, Main.maxTilesX - 1);
             num2 = WorldGen.genRand.Next(0, (int)WorldGen.worldSurfaceLow);
             if (num2 >= Main.maxTilesY)
             {
                 num2 = Main.maxTilesY - 2;
             }
             if (Main.tile[num - 1, num2].active() && Main.tile[num - 1, num2].type == 0 && Main.tile[num + 1, num2].active() && Main.tile[num + 1, num2].type == 0 && Main.tile[num, num2 - 1].active() && Main.tile[num, num2 - 1].type == 0 && Main.tile[num, num2 + 1].active() && Main.tile[num, num2 + 1].type == 0)
             {
                 Main.tile[num, num2].active(true);
                 Main.tile[num, num2].type = 2;
             }
         }
     });
     WorldGen.AddGenerationPass("Jungle", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[11];
         float num = (float)(Main.maxTilesX / 4200);
         num *= 1.5f;
         float num2 = (float)WorldGen.genRand.Next(15, 30) * 0.01f;
         int num3;
         if (dungeonSide == -1)
         {
             num2 = 1f - num2;
             num3 = (int)((float)Main.maxTilesX * num2);
         }
         else
         {
             num3 = (int)((float)Main.maxTilesX * num2);
         }
         int num4 = (int)((double)Main.maxTilesY + Main.rockLayer) / 2;
         num3 += WorldGen.genRand.Next((int)(-100f * num), (int)(101f * num));
         num4 += WorldGen.genRand.Next((int)(-100f * num), (int)(101f * num));
         int num5 = num3;
         int num6 = num4;
         WorldGen.TileRunner(num3, num4, (double)WorldGen.genRand.Next((int)(250f * num), (int)(500f * num)), WorldGen.genRand.Next(50, 150), 59, false, (float)(dungeonSide * 3), 0f, false, true);
         int num7 = 0;
         while ((float)num7 < 6f * num)
         {
             WorldGen.TileRunner(num3 + WorldGen.genRand.Next(-(int)(125f * num), (int)(125f * num)), num4 + WorldGen.genRand.Next(-(int)(125f * num), (int)(125f * num)), (double)WorldGen.genRand.Next(3, 7), WorldGen.genRand.Next(3, 8), WorldGen.genRand.Next(63, 65), false, 0f, 0f, false, true);
             num7++;
         }
         WorldGen.mudWall = true;
         progress.Set(0.15f);
         num3 += WorldGen.genRand.Next((int)(-250f * num), (int)(251f * num));
         num4 += WorldGen.genRand.Next((int)(-150f * num), (int)(151f * num));
         int num8 = num3;
         int num9 = num4;
         int num10 = num3;
         int num11 = num4;
         WorldGen.TileRunner(num3, num4, (double)WorldGen.genRand.Next((int)(250f * num), (int)(500f * num)), WorldGen.genRand.Next(50, 150), 59, false, 0f, 0f, false, true);
         WorldGen.mudWall = false;
         int num12 = 0;
         while ((float)num12 < 6f * num)
         {
             WorldGen.TileRunner(num3 + WorldGen.genRand.Next(-(int)(125f * num), (int)(125f * num)), num4 + WorldGen.genRand.Next(-(int)(125f * num), (int)(125f * num)), (double)WorldGen.genRand.Next(3, 7), WorldGen.genRand.Next(3, 8), WorldGen.genRand.Next(65, 67), false, 0f, 0f, false, true);
             num12++;
         }
         WorldGen.mudWall = true;
         progress.Set(0.3f);
         num3 += WorldGen.genRand.Next((int)(-400f * num), (int)(401f * num));
         num4 += WorldGen.genRand.Next((int)(-150f * num), (int)(151f * num));
         int num13 = num3;
         int num14 = num4;
         WorldGen.TileRunner(num3, num4, (double)WorldGen.genRand.Next((int)(250f * num), (int)(500f * num)), WorldGen.genRand.Next(50, 150), 59, false, (float)(dungeonSide * -3), 0f, false, true);
         WorldGen.mudWall = false;
         int num15 = 0;
         while ((float)num15 < 6f * num)
         {
             WorldGen.TileRunner(num3 + WorldGen.genRand.Next(-(int)(125f * num), (int)(125f * num)), num4 + WorldGen.genRand.Next(-(int)(125f * num), (int)(125f * num)), (double)WorldGen.genRand.Next(3, 7), WorldGen.genRand.Next(3, 8), WorldGen.genRand.Next(67, 69), false, 0f, 0f, false, true);
             num15++;
         }
         WorldGen.mudWall = true;
         progress.Set(0.45f);
         num3 = (num5 + num8 + num13) / 3;
         num4 = (num6 + num9 + num14) / 3;
         WorldGen.TileRunner(num3, num4, (double)WorldGen.genRand.Next((int)(400f * num), (int)(600f * num)), 10000, 59, false, 0f, -20f, true, true);
         WorldGen.JungleRunner(num3, num4);
         progress.Set(0.6f);
         WorldGen.mudWall = false;
         for (int k = 0; k < Main.maxTilesX / 4; k++)
         {
             num3 = WorldGen.genRand.Next(20, Main.maxTilesX - 20);
             num4 = WorldGen.genRand.Next((int)worldSurface + 10, Main.maxTilesY - 200);
             while (Main.tile[num3, num4].wall != 64 && Main.tile[num3, num4].wall != 15)
             {
                 num3 = WorldGen.genRand.Next(20, Main.maxTilesX - 20);
                 num4 = WorldGen.genRand.Next((int)worldSurface + 10, Main.maxTilesY - 200);
             }
             WorldGen.MudWallRunner(num3, num4);
         }
         num3 = num10;
         num4 = num11;
         int num16 = 0;
         while ((float)num16 <= 20f * num)
         {
             progress.Set((60f + (float)num16 / num) * 0.01f);
             num3 += WorldGen.genRand.Next((int)(-5f * num), (int)(6f * num));
             num4 += WorldGen.genRand.Next((int)(-5f * num), (int)(6f * num));
             WorldGen.TileRunner(num3, num4, (double)WorldGen.genRand.Next(40, 100), WorldGen.genRand.Next(300, 500), 59, false, 0f, 0f, false, true);
             num16++;
         }
         int num17 = 0;
         while ((float)num17 <= 10f * num)
         {
             progress.Set((80f + (float)num17 / num * 2f) * 0.01f);
             num3 = num10 + WorldGen.genRand.Next((int)(-600f * num), (int)(600f * num));
             num4 = num11 + WorldGen.genRand.Next((int)(-200f * num), (int)(200f * num));
             while (num3 < 1 || num3 >= Main.maxTilesX - 1 || num4 < 1 || num4 >= Main.maxTilesY - 1 || Main.tile[num3, num4].type != 59)
             {
                 num3 = num10 + WorldGen.genRand.Next((int)(-600f * num), (int)(600f * num));
                 num4 = num11 + WorldGen.genRand.Next((int)(-200f * num), (int)(200f * num));
             }
             int num18 = 0;
             while ((float)num18 < 8f * num)
             {
                 num3 += WorldGen.genRand.Next(-30, 31);
                 num4 += WorldGen.genRand.Next(-30, 31);
                 int type = -1;
                 if (WorldGen.genRand.Next(7) == 0)
                 {
                     type = -2;
                 }
                 WorldGen.TileRunner(num3, num4, (double)WorldGen.genRand.Next(10, 20), WorldGen.genRand.Next(30, 70), type, false, 0f, 0f, false, true);
                 num18++;
             }
             num17++;
         }
         int num19 = 0;
         while ((float)num19 <= 300f * num)
         {
             num3 = num10 + WorldGen.genRand.Next((int)(-600f * num), (int)(600f * num));
             num4 = num11 + WorldGen.genRand.Next((int)(-200f * num), (int)(200f * num));
             while (num3 < 1 || num3 >= Main.maxTilesX - 1 || num4 < 1 || num4 >= Main.maxTilesY - 1 || Main.tile[num3, num4].type != 59)
             {
                 num3 = num10 + WorldGen.genRand.Next((int)(-600f * num), (int)(600f * num));
                 num4 = num11 + WorldGen.genRand.Next((int)(-200f * num), (int)(200f * num));
             }
             WorldGen.TileRunner(num3, num4, (double)WorldGen.genRand.Next(4, 10), WorldGen.genRand.Next(5, 30), 1, false, 0f, 0f, false, true);
             if (WorldGen.genRand.Next(4) == 0)
             {
                 int type2 = WorldGen.genRand.Next(63, 69);
                 WorldGen.TileRunner(num3 + WorldGen.genRand.Next(-1, 2), num4 + WorldGen.genRand.Next(-1, 2), (double)WorldGen.genRand.Next(3, 7), WorldGen.genRand.Next(4, 8), type2, false, 0f, 0f, false, true);
             }
             num19++;
         }
     });
     WorldGen.AddGenerationPass("Marble", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[80];
         float num = (float)(Main.maxTilesX * Main.maxTilesY) / 5040000f;
         int num2 = (int)((float)WorldGen.genRand.Next(10, 15) * num);
         float num3 = (float)(Main.maxTilesX - 160) / (float)num2;
         int k = 0;
         while (k < num2)
         {
             float num4 = (float)k / (float)num2;
             progress.Set(num4);
             Point origin = WorldGen.RandomRectanglePoint((int)(num4 * (float)(Main.maxTilesX - 160)) + 80, (int)rockLayer + 20, (int)num3, Main.maxTilesY - ((int)rockLayer + 40) - 200);
             if (Biomes<MarbleBiome>.Place(origin, structures))
             {
                 k++;
             }
         }
     });
     WorldGen.AddGenerationPass("Granite", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[81];
         float num = (float)Main.maxTilesX / 4200f;
         int num2 = (int)((float)WorldGen.genRand.Next(8, 14) * num);
         float num3 = (float)(Main.maxTilesX - 200) / (float)num2;
         int k = 0;
         while (k < num2)
         {
             float num4 = (float)k / (float)num2;
             progress.Set(num4);
             Point origin = WorldGen.RandomRectanglePoint((int)(num4 * (float)(Main.maxTilesX - 200)) + 100, (int)rockLayer + 20, (int)num3, Main.maxTilesY - ((int)rockLayer + 40) - 200);
             if (Biomes<GraniteBiome>.Place(origin, structures))
             {
                 k++;
             }
         }
     });
     WorldGen.AddGenerationPass("Mud Caves To Grass", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[77];
         for (int k = 0; k < Main.maxTilesX; k++)
         {
             for (int l = 0; l < Main.maxTilesY; l++)
             {
                 if (Main.tile[k, l].active())
                 {
                     WorldGen.grassSpread = 0;
                     WorldGen.SpreadGrass(k, l, 59, 60, true, 0);
                 }
                 progress.Set(0.2f * ((float)(k * Main.maxTilesY + l) / (float)(Main.maxTilesX * Main.maxTilesY)));
             }
         }
         for (int m = 10; m < Main.maxTilesX - 10; m++)
         {
             for (int n = 10; n < Main.maxTilesY - 10; n++)
             {
                 if (Main.tile[m, n].active())
                 {
                     int num = WorldGen.tileCounter(m, n);
                     if (num < WorldGen.tileCounterMax)
                     {
                         WorldGen.tileCounterKill();
                     }
                 }
                 float num2 = (float)((m - 10) * (Main.maxTilesY - 20) + (n - 10)) / (float)((Main.maxTilesX - 20) * (Main.maxTilesY - 20));
                 progress.Set(0.2f + num2 * 0.8f);
             }
         }
     });
     WorldGen.AddGenerationPass("Full Desert", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[78];
         int num = dungeonSide;
         int num2 = Main.maxTilesX / 2;
         int num3 = WorldGen.genRand.Next(num2) / 8;
         num3 += num2 / 8;
         int x = num2 + num3 * -num;
         int num4 = 0;
         while (!Biomes<DesertBiome>.Place(new Point(x, (int)worldSurface), structures))
         {
             num3 = WorldGen.genRand.Next(num2) / 2;
             num3 += num2 / 8;
             x = num2 + num3 * -num;
             if (++num4 > 1000)
             {
                 num *= -1;
                 num4 = 0;
             }
         }
     });
     WorldGen.AddGenerationPass("Floating Islands", delegate (GenerationProgress progress)
     {
         WorldGen.numIslandHouses = 0;
         WorldGen.houseCount = 0;
         progress.Message = Lang.gen[12];
         for (int k = 0; k < (int)((double)Main.maxTilesX * 0.0008) + skyLakes; k++)
         {
             int num = 1000;
             int num2 = WorldGen.genRand.Next((int)((double)Main.maxTilesX * 0.1), (int)((double)Main.maxTilesX * 0.9));
             while (--num > 0)
             {
                 bool flag2 = true;
                 while (num2 > Main.maxTilesX / 2 - 80 && num2 < Main.maxTilesX / 2 + 80)
                 {
                     num2 = WorldGen.genRand.Next((int)((double)Main.maxTilesX * 0.1), (int)((double)Main.maxTilesX * 0.9));
                 }
                 for (int l = 0; l < WorldGen.numIslandHouses; l++)
                 {
                     if (num2 > WorldGen.fihX[l] - 180 && num2 < WorldGen.fihX[l] + 180)
                     {
                         flag2 = false;
                         break;
                     }
                 }
                 if (flag2)
                 {
                     flag2 = false;
                     int num3 = 0;
                     int num4 = 200;
                     while ((double)num4 < Main.worldSurface)
                     {
                         if (Main.tile[num2, num4].active())
                         {
                             num3 = num4;
                             flag2 = true;
                             break;
                         }
                         num4++;
                     }
                     if (flag2)
                     {
                         int num5 = WorldGen.genRand.Next(90, num3 - 100);
                         num5 = Math.Min(num5, (int)WorldGen.worldSurfaceLow - 50);
                         if (k < skyLakes)
                         {
                             WorldGen.skyLake[WorldGen.numIslandHouses] = true;
                             WorldGen.CloudLake(num2, num5);
                         }
                         else
                         {
                             WorldGen.CloudIsland(num2, num5);
                         }
                         WorldGen.fihX[WorldGen.numIslandHouses] = num2;
                         WorldGen.fihY[WorldGen.numIslandHouses] = num5;
                         WorldGen.numIslandHouses++;
                     }
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Mushroom Patches", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[13];
         for (int k = 0; k < Main.maxTilesX / 500; k++)
         {
             int num = 0;
             bool flag2 = true;
             while (flag2)
             {
                 int num2 = WorldGen.genRand.Next((int)((double)Main.maxTilesX * 0.3), (int)((double)Main.maxTilesX * 0.7));
                 int num3 = WorldGen.genRand.Next((int)Main.rockLayer, Main.maxTilesY - 350);
                 flag2 = false;
                 int num4 = 60;
                 for (int l = num2 - num4; l < num2 + num4; l += 3)
                 {
                     for (int m = num3 - num4; m < num3 + num4; m += 3)
                     {
                         if (Main.tile[l, m].type == 147 || Main.tile[l, m].type == 161 || Main.tile[l, m].type == 162)
                         {
                             flag2 = true;
                             break;
                         }
                         if (WorldGen.UndergroundDesertLocation.Contains(new Point(l, m)))
                         {
                             flag2 = true;
                             break;
                         }
                     }
                 }
                 if (!flag2)
                 {
                     WorldGen.ShroomPatch(num2, num3);
                 }
                 num++;
                 if (num > 100)
                 {
                     break;
                 }
             }
         }
         for (int n = 0; n < Main.maxTilesX; n++)
         {
             for (int num5 = (int)Main.worldSurface; num5 < Main.maxTilesY; num5++)
             {
                 if (Main.tile[n, num5].active())
                 {
                     WorldGen.grassSpread = 0;
                     WorldGen.SpreadGrass(n, num5, 59, 70, false, 0);
                     if (Main.tile[n, num5].type == 70 && WorldGen.genRand.Next(20) == 0)
                     {
                         int num6;
                         if (WorldGen.genRand.Next(5) == 0)
                         {
                             num6 = 2;
                         }
                         else
                         {
                             num6 = 1;
                         }
                         int num7 = WorldGen.genRand.Next(2, 6);
                         int num8 = num5 - num7;
                         bool flag3 = true;
                         for (int num9 = n - num6; num9 <= n + num6; num9++)
                         {
                             if (Main.tile[num9, num8].active())
                             {
                                 flag3 = false;
                             }
                             if (Main.tileBrick[(int)Main.tile[num9, num8 - 1].type])
                             {
                                 flag3 = false;
                             }
                             if (Main.tileBrick[(int)Main.tile[num9, num8 + 1].type])
                             {
                                 flag3 = false;
                             }
                         }
                         if (Main.tile[n - num6 - 1, num8].type == 190)
                         {
                             flag3 = false;
                         }
                         if (Main.tile[n + num6 + 1, num8].type == 190)
                         {
                             flag3 = false;
                         }
                         for (int num10 = num8; num10 < num5; num10++)
                         {
                             if (Main.tile[n, num10].active())
                             {
                                 flag3 = false;
                             }
                             if (Main.tileBrick[(int)Main.tile[n - 1, num10].type])
                             {
                                 flag3 = false;
                             }
                             if (Main.tileBrick[(int)Main.tile[n + 1, num10].type])
                             {
                                 flag3 = false;
                             }
                         }
                         if (flag3)
                         {
                             for (int num11 = n - num6; num11 <= n + num6; num11++)
                             {
                                 WorldGen.PlaceTile(num11, num8, 190, true, true, -1, 0);
                             }
                             for (int num12 = num8; num12 < num5; num12++)
                             {
                                 WorldGen.PlaceTile(n, num12, 190, true, true, -1, 0);
                             }
                         }
                     }
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Mud To Dirt", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[14];
         for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.001); k++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)rockLayerLow, Main.maxTilesY), (double)WorldGen.genRand.Next(2, 6), WorldGen.genRand.Next(2, 40), 59, false, 0f, 0f, false, true);
         }
     });
     WorldGen.AddGenerationPass("Silt", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[15];
         for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.0001); k++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)rockLayerHigh, Main.maxTilesY), (double)WorldGen.genRand.Next(5, 12), WorldGen.genRand.Next(15, 50), 123, false, 0f, 0f, false, true);
         }
         for (int l = 0; l < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.0005); l++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)rockLayerHigh, Main.maxTilesY), (double)WorldGen.genRand.Next(2, 5), WorldGen.genRand.Next(2, 5), 123, false, 0f, 0f, false, true);
         }
     });
     WorldGen.AddGenerationPass("Shinies", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[16];
         for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); k++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, (int)worldSurfaceHigh), (double)WorldGen.genRand.Next(3, 6), WorldGen.genRand.Next(2, 6), copper, false, 0f, 0f, false, true);
         }
         for (int l = 0; l < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 8E-05); l++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)worldSurfaceHigh, (int)rockLayerHigh), (double)WorldGen.genRand.Next(3, 7), WorldGen.genRand.Next(3, 7), copper, false, 0f, 0f, false, true);
         }
         for (int m = 0; m < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.0002); m++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)rockLayerLow, Main.maxTilesY), (double)WorldGen.genRand.Next(4, 9), WorldGen.genRand.Next(4, 8), copper, false, 0f, 0f, false, true);
         }
         for (int n = 0; n < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 3E-05); n++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, (int)worldSurfaceHigh), (double)WorldGen.genRand.Next(3, 7), WorldGen.genRand.Next(2, 5), iron, false, 0f, 0f, false, true);
         }
         for (int num = 0; num < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 8E-05); num++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)worldSurfaceHigh, (int)rockLayerHigh), (double)WorldGen.genRand.Next(3, 6), WorldGen.genRand.Next(3, 6), iron, false, 0f, 0f, false, true);
         }
         for (int num2 = 0; num2 < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.0002); num2++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)rockLayerLow, Main.maxTilesY), (double)WorldGen.genRand.Next(4, 9), WorldGen.genRand.Next(4, 8), iron, false, 0f, 0f, false, true);
         }
         for (int num3 = 0; num3 < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 2.6E-05); num3++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)worldSurfaceHigh, (int)rockLayerHigh), (double)WorldGen.genRand.Next(3, 6), WorldGen.genRand.Next(3, 6), silver, false, 0f, 0f, false, true);
         }
         for (int num4 = 0; num4 < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.00015); num4++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)rockLayerLow, Main.maxTilesY), (double)WorldGen.genRand.Next(4, 9), WorldGen.genRand.Next(4, 8), silver, false, 0f, 0f, false, true);
         }
         for (int num5 = 0; num5 < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.00017); num5++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next(0, (int)WorldGen.worldSurfaceLow), (double)WorldGen.genRand.Next(4, 9), WorldGen.genRand.Next(4, 8), silver, false, 0f, 0f, false, true);
         }
         for (int num6 = 0; num6 < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.00012); num6++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)rockLayerLow, Main.maxTilesY), (double)WorldGen.genRand.Next(4, 8), WorldGen.genRand.Next(4, 8), gold, false, 0f, 0f, false, true);
         }
         for (int num7 = 0; num7 < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.00012); num7++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next(0, (int)WorldGen.worldSurfaceLow - 20), (double)WorldGen.genRand.Next(4, 8), WorldGen.genRand.Next(4, 8), gold, false, 0f, 0f, false, true);
         }
         if (WorldGen.crimson)
         {
             for (int num8 = 0; num8 < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 2E-05); num8++)
             {
                 WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)rockLayerLow, Main.maxTilesY), (double)WorldGen.genRand.Next(2, 4), WorldGen.genRand.Next(3, 6), 204, false, 0f, 0f, false, true);
             }
             return;
         }
         for (int num9 = 0; num9 < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 2E-05); num9++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)rockLayerLow, Main.maxTilesY), (double)WorldGen.genRand.Next(2, 4), WorldGen.genRand.Next(3, 6), 22, false, 0f, 0f, false, true);
         }
     });
     WorldGen.AddGenerationPass("Webs", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[17];
         for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.0006); k++)
         {
             int num = WorldGen.genRand.Next(20, Main.maxTilesX - 20);
             int num2 = WorldGen.genRand.Next((int)worldSurfaceHigh, Main.maxTilesY - 20);
             if (k < WorldGen.numMCaves)
             {
                 num = WorldGen.mCaveX[k];
                 num2 = WorldGen.mCaveY[k];
             }
             if (!Main.tile[num, num2].active())
             {
                 if ((double)num2 <= Main.worldSurface)
                 {
                     if (Main.tile[num, num2].wall <= 0)
                     {
                         goto IL_140;
                     }
                 }
                 while (!Main.tile[num, num2].active() && num2 > (int)WorldGen.worldSurfaceLow)
                 {
                     num2--;
                 }
                 num2++;
                 int num3 = 1;
                 if (WorldGen.genRand.Next(2) == 0)
                 {
                     num3 = -1;
                 }
                 while (!Main.tile[num, num2].active() && num > 10 && num < Main.maxTilesX - 10)
                 {
                     num += num3;
                 }
                 num -= num3;
                 if ((double)num2 > Main.worldSurface || Main.tile[num, num2].wall > 0)
                 {
                     WorldGen.TileRunner(num, num2, (double)WorldGen.genRand.Next(4, 11), WorldGen.genRand.Next(2, 4), 51, true, (float)num3, -1f, false, false);
                 }
             }
             IL_140:;
         }
     });
     WorldGen.AddGenerationPass("Underworld", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[18];
         progress.Set(0f);
         int num = Main.maxTilesY - WorldGen.genRand.Next(150, 190);
         for (int k = 0; k < Main.maxTilesX; k++)
         {
             num += WorldGen.genRand.Next(-3, 4);
             if (num < Main.maxTilesY - 190)
             {
                 num = Main.maxTilesY - 190;
             }
             if (num > Main.maxTilesY - 160)
             {
                 num = Main.maxTilesY - 160;
             }
             for (int l = num - 20 - WorldGen.genRand.Next(3); l < Main.maxTilesY; l++)
             {
                 if (l >= num)
                 {
                     Main.tile[k, l].active(false);
                     Main.tile[k, l].lava(false);
                     Main.tile[k, l].liquid = 0;
                 }
                 else
                 {
                     Main.tile[k, l].type = 57;
                 }
             }
         }
         int num2 = Main.maxTilesY - WorldGen.genRand.Next(40, 70);
         for (int m = 10; m < Main.maxTilesX - 10; m++)
         {
             num2 += WorldGen.genRand.Next(-10, 11);
             if (num2 > Main.maxTilesY - 60)
             {
                 num2 = Main.maxTilesY - 60;
             }
             if (num2 < Main.maxTilesY - 100)
             {
                 num2 = Main.maxTilesY - 120;
             }
             for (int n = num2; n < Main.maxTilesY - 10; n++)
             {
                 if (!Main.tile[m, n].active())
                 {
                     Main.tile[m, n].lava(true);
                     Main.tile[m, n].liquid = 255;
                 }
             }
         }
         for (int num3 = 0; num3 < Main.maxTilesX; num3++)
         {
             if (WorldGen.genRand.Next(50) == 0)
             {
                 int num4 = Main.maxTilesY - 65;
                 while (!Main.tile[num3, num4].active() && num4 > Main.maxTilesY - 135)
                 {
                     num4--;
                 }
                 WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), num4 + WorldGen.genRand.Next(20, 50), (double)WorldGen.genRand.Next(15, 20), 1000, 57, true, 0f, (float)WorldGen.genRand.Next(1, 3), true, true);
             }
         }
         Liquid.QuickWater(-2, -1, -1);
         for (int num5 = 0; num5 < Main.maxTilesX; num5++)
         {
             float num6 = (float)num5 / (float)(Main.maxTilesX - 1);
             progress.Set(num6 / 2f + 0.5f);
             if (WorldGen.genRand.Next(13) == 0)
             {
                 int num7 = Main.maxTilesY - 65;
                 while ((Main.tile[num5, num7].liquid > 0 || Main.tile[num5, num7].active()) && num7 > Main.maxTilesY - 140)
                 {
                     num7--;
                 }
                 WorldGen.TileRunner(num5, num7 - WorldGen.genRand.Next(2, 5), (double)WorldGen.genRand.Next(5, 30), 1000, 57, true, 0f, (float)WorldGen.genRand.Next(1, 3), true, true);
                 float num8 = (float)WorldGen.genRand.Next(1, 3);
                 if (WorldGen.genRand.Next(3) == 0)
                 {
                     num8 *= 0.5f;
                 }
                 if (WorldGen.genRand.Next(2) == 0)
                 {
                     WorldGen.TileRunner(num5, num7 - WorldGen.genRand.Next(2, 5), (double)((int)((float)WorldGen.genRand.Next(5, 15) * num8)), (int)((float)WorldGen.genRand.Next(10, 15) * num8), 57, true, 1f, 0.3f, false, true);
                 }
                 if (WorldGen.genRand.Next(2) == 0)
                 {
                     num8 = (float)WorldGen.genRand.Next(1, 3);
                     WorldGen.TileRunner(num5, num7 - WorldGen.genRand.Next(2, 5), (double)((int)((float)WorldGen.genRand.Next(5, 15) * num8)), (int)((float)WorldGen.genRand.Next(10, 15) * num8), 57, true, -1f, 0.3f, false, true);
                 }
                 WorldGen.TileRunner(num5 + WorldGen.genRand.Next(-10, 10), num7 + WorldGen.genRand.Next(-10, 10), (double)WorldGen.genRand.Next(5, 15), WorldGen.genRand.Next(5, 10), -2, false, (float)WorldGen.genRand.Next(-1, 3), (float)WorldGen.genRand.Next(-1, 3), false, true);
                 if (WorldGen.genRand.Next(3) == 0)
                 {
                     WorldGen.TileRunner(num5 + WorldGen.genRand.Next(-10, 10), num7 + WorldGen.genRand.Next(-10, 10), (double)WorldGen.genRand.Next(10, 30), WorldGen.genRand.Next(10, 20), -2, false, (float)WorldGen.genRand.Next(-1, 3), (float)WorldGen.genRand.Next(-1, 3), false, true);
                 }
                 if (WorldGen.genRand.Next(5) == 0)
                 {
                     WorldGen.TileRunner(num5 + WorldGen.genRand.Next(-15, 15), num7 + WorldGen.genRand.Next(-15, 10), (double)WorldGen.genRand.Next(15, 30), WorldGen.genRand.Next(5, 20), -2, false, (float)WorldGen.genRand.Next(-1, 3), (float)WorldGen.genRand.Next(-1, 3), false, true);
                 }
             }
         }
         for (int num9 = 0; num9 < Main.maxTilesX; num9++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(20, Main.maxTilesX - 20), WorldGen.genRand.Next(Main.maxTilesY - 180, Main.maxTilesY - 10), (double)WorldGen.genRand.Next(2, 7), WorldGen.genRand.Next(2, 7), -2, false, 0f, 0f, false, true);
         }
         for (int num10 = 0; num10 < Main.maxTilesX; num10++)
         {
             if (!Main.tile[num10, Main.maxTilesY - 145].active())
             {
                 Main.tile[num10, Main.maxTilesY - 145].liquid = 255;
                 Main.tile[num10, Main.maxTilesY - 145].lava(true);
             }
             if (!Main.tile[num10, Main.maxTilesY - 144].active())
             {
                 Main.tile[num10, Main.maxTilesY - 144].liquid = 255;
                 Main.tile[num10, Main.maxTilesY - 144].lava(true);
             }
         }
         for (int num11 = 0; num11 < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.0008); num11++)
         {
             WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next(Main.maxTilesY - 140, Main.maxTilesY), (double)WorldGen.genRand.Next(2, 7), WorldGen.genRand.Next(3, 7), 58, false, 0f, 0f, false, true);
         }
         WorldGen.AddHellHouses();
     });
     WorldGen.AddGenerationPass("Lakes", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[19];
         int num = WorldGen.genRand.Next(2, (int)((double)Main.maxTilesX * 0.005));
         for (int k = 0; k < num; k++)
         {
             float value = (float)k / (float)num;
             progress.Set(value);
             int num2 = WorldGen.genRand.Next(300, Main.maxTilesX - 300);
             while (num2 > Main.maxTilesX / 2 - 100 && num2 < Main.maxTilesX / 2 + 100)
             {
                 num2 = WorldGen.genRand.Next(300, Main.maxTilesX - 300);
             }
             int num3 = (int)WorldGen.worldSurfaceLow - 20;
             while (!Main.tile[num2, num3].active())
             {
                 num3++;
             }
             WorldGen.Lakinater(num2, num3);
         }
     });
     WorldGen.AddGenerationPass("Dungeon", delegate (GenerationProgress progress)
     {
         int x;
         if (dungeonSide == -1)
         {
             x = WorldGen.genRand.Next((int)((double)Main.maxTilesX * 0.05), (int)((double)Main.maxTilesX * 0.2));
             dungeonSide = -1;
         }
         else
         {
             x = WorldGen.genRand.Next((int)((double)Main.maxTilesX * 0.8), (int)((double)Main.maxTilesX * 0.95));
             dungeonSide = 1;
         }
         int y = (int)((Main.worldSurface + Main.rockLayer) / 2.0) + WorldGen.genRand.Next(-200, 200);
         WorldGen.MakeDungeon(x, y);
     });
     WorldGen.AddGenerationPass("Corruption", delegate (GenerationProgress progress)
     {
         if (WorldGen.crimson)
         {
             progress.Message = Lang.gen[72];
             int num = 0;
             while ((double)num < (double)Main.maxTilesX * 0.00045)
             {
                 float value = (float)((double)num / ((double)Main.maxTilesX * 0.00045));
                 progress.Set(value);
                 bool flag2 = false;
                 int num2 = 0;
                 int num3 = 0;
                 int num4 = 0;
                 while (!flag2)
                 {
                     int num5 = 0;
                     flag2 = true;
                     int num6 = Main.maxTilesX / 2;
                     int num7 = 200;
                     if (dungeonSide < 0)
                     {
                         num2 = WorldGen.genRand.Next(600, Main.maxTilesX - 320);
                     }
                     else
                     {
                         num2 = WorldGen.genRand.Next(320, Main.maxTilesX - 600);
                     }
                     num3 = num2 - WorldGen.genRand.Next(200) - 100;
                     num4 = num2 + WorldGen.genRand.Next(200) + 100;
                     if (num3 < 285)
                     {
                         num3 = 285;
                     }
                     if (num4 > Main.maxTilesX - 285)
                     {
                         num4 = Main.maxTilesX - 285;
                     }
                     if (dungeonSide < 0 && num3 < 400)
                     {
                         num3 = 400;
                     }
                     else if (dungeonSide > 0 && num3 > Main.maxTilesX - 400)
                     {
                         num3 = Main.maxTilesX - 400;
                     }
                     if (num2 > num6 - num7 && num2 < num6 + num7)
                     {
                         flag2 = false;
                     }
                     if (num3 > num6 - num7 && num3 < num6 + num7)
                     {
                         flag2 = false;
                     }
                     if (num4 > num6 - num7 && num4 < num6 + num7)
                     {
                         flag2 = false;
                     }
                     if (num2 > WorldGen.UndergroundDesertLocation.X && num2 < WorldGen.UndergroundDesertLocation.X + WorldGen.UndergroundDesertLocation.Width)
                     {
                         flag2 = false;
                     }
                     if (num3 > WorldGen.UndergroundDesertLocation.X && num3 < WorldGen.UndergroundDesertLocation.X + WorldGen.UndergroundDesertLocation.Width)
                     {
                         flag2 = false;
                     }
                     if (num4 > WorldGen.UndergroundDesertLocation.X && num4 < WorldGen.UndergroundDesertLocation.X + WorldGen.UndergroundDesertLocation.Width)
                     {
                         flag2 = false;
                     }
                     for (int k = num3; k < num4; k++)
                     {
                         for (int l = 0; l < (int)Main.worldSurface; l += 5)
                         {
                             if (Main.tile[k, l].active() && Main.tileDungeon[(int)Main.tile[k, l].type])
                             {
                                 flag2 = false;
                                 break;
                             }
                             if (!flag2)
                             {
                                 break;
                             }
                         }
                     }
                     if (num5 < 200 && WorldGen.JungleX > num3 && WorldGen.JungleX < num4)
                     {
                         num5++;
                         flag2 = false;
                     }
                 }
                 WorldGen.CrimStart(num2, (int)WorldGen.worldSurfaceLow - 10);
                 for (int m = num3; m < num4; m++)
                 {
                     int num8 = (int)WorldGen.worldSurfaceLow;
                     while ((double)num8 < Main.worldSurface - 1.0)
                     {
                         if (Main.tile[m, num8].active())
                         {
                             int num9 = num8 + WorldGen.genRand.Next(10, 14);
                             for (int n = num8; n < num9; n++)
                             {
                                 if ((Main.tile[m, n].type == 59 || Main.tile[m, n].type == 60) && m >= num3 + WorldGen.genRand.Next(5) && m < num4 - WorldGen.genRand.Next(5))
                                 {
                                     Main.tile[m, n].type = 0;
                                 }
                             }
                             break;
                         }
                         num8++;
                     }
                 }
                 double num10 = Main.worldSurface + 40.0;
                 for (int num11 = num3; num11 < num4; num11++)
                 {
                     num10 += (double)WorldGen.genRand.Next(-2, 3);
                     if (num10 < Main.worldSurface + 30.0)
                     {
                         num10 = Main.worldSurface + 30.0;
                     }
                     if (num10 > Main.worldSurface + 50.0)
                     {
                         num10 = Main.worldSurface + 50.0;
                     }
                     i2 = num11;
                     bool flag3 = false;
                     int num12 = (int)WorldGen.worldSurfaceLow;
                     while ((double)num12 < num10)
                     {
                         if (Main.tile[i2, num12].active())
                         {
                             if (Main.tile[i2, num12].type == 53 && i2 >= num3 + WorldGen.genRand.Next(5) && i2 <= num4 - WorldGen.genRand.Next(5))
                             {
                                 Main.tile[i2, num12].type = 234;
                             }
                             if (Main.tile[i2, num12].type == 0 && (double)num12 < Main.worldSurface - 1.0 && !flag3)
                             {
                                 WorldGen.grassSpread = 0;
                                 WorldGen.SpreadGrass(i2, num12, 0, 199, true, 0);
                             }
                             flag3 = true;
                             if (Main.tile[i2, num12].wall == 216)
                             {
                                 Main.tile[i2, num12].wall = 218;
                             }
                             else if (Main.tile[i2, num12].wall == 187)
                             {
                                 Main.tile[i2, num12].wall = 221;
                             }
                             if (Main.tile[i2, num12].type == 1)
                             {
                                 if (i2 >= num3 + WorldGen.genRand.Next(5) && i2 <= num4 - WorldGen.genRand.Next(5))
                                 {
                                     Main.tile[i2, num12].type = 203;
                                 }
                             }
                             else if (Main.tile[i2, num12].type == 2)
                             {
                                 Main.tile[i2, num12].type = 199;
                             }
                             else if (Main.tile[i2, num12].type == 161)
                             {
                                 Main.tile[i2, num12].type = 200;
                             }
                             else if (Main.tile[i2, num12].type == 396)
                             {
                                 Main.tile[i2, num12].type = 401;
                             }
                             else if (Main.tile[i2, num12].type == 397)
                             {
                                 Main.tile[i2, num12].type = 399;
                             }
                         }
                         num12++;
                     }
                 }
                 int num13 = WorldGen.genRand.Next(10, 15);
                 for (int num14 = 0; num14 < num13; num14++)
                 {
                     int num15 = 0;
                     bool flag4 = false;
                     int num16 = 0;
                     while (!flag4)
                     {
                         num15++;
                         int num17 = WorldGen.genRand.Next(num3 - num16, num4 + num16);
                         int num18 = WorldGen.genRand.Next((int)(Main.worldSurface - (double)(num16 / 2)), (int)(Main.worldSurface + 100.0 + (double)num16));
                         if (num15 > 100)
                         {
                             num16++;
                             num15 = 0;
                         }
                         if (!Main.tile[num17, num18].active())
                         {
                             while (!Main.tile[num17, num18].active())
                             {
                                 num18++;
                             }
                             num18--;
                         }
                         else
                         {
                             while (Main.tile[num17, num18].active() && (double)num18 > Main.worldSurface)
                             {
                                 num18--;
                             }
                         }
                         if (num16 > 10 || (Main.tile[num17, num18 + 1].active() && Main.tile[num17, num18 + 1].type == 203))
                         {
                             WorldGen.Place3x2(num17, num18, 26, 1);
                             if (Main.tile[num17, num18].type == 26)
                             {
                                 flag4 = true;
                             }
                         }
                         if (num16 > 100)
                         {
                             flag4 = true;
                         }
                     }
                 }
                 num++;
             }
             return;
         }
         progress.Message = Lang.gen[20];
         int num19 = 0;
         while ((double)num19 < (double)Main.maxTilesX * 0.00045)
         {
             float value2 = (float)((double)num19 / ((double)Main.maxTilesX * 0.00045));
             progress.Set(value2);
             bool flag5 = false;
             int num20 = 0;
             int num21 = 0;
             int num22 = 0;
             while (!flag5)
             {
                 int num23 = 0;
                 flag5 = true;
                 int num24 = Main.maxTilesX / 2;
                 int num25 = 200;
                 num20 = WorldGen.genRand.Next(320, Main.maxTilesX - 320);
                 num21 = num20 - WorldGen.genRand.Next(200) - 100;
                 num22 = num20 + WorldGen.genRand.Next(200) + 100;
                 if (num21 < 285)
                 {
                     num21 = 285;
                 }
                 if (num22 > Main.maxTilesX - 285)
                 {
                     num22 = Main.maxTilesX - 285;
                 }
                 if (num20 > num24 - num25 && num20 < num24 + num25)
                 {
                     flag5 = false;
                 }
                 if (num21 > num24 - num25 && num21 < num24 + num25)
                 {
                     flag5 = false;
                 }
                 if (num22 > num24 - num25 && num22 < num24 + num25)
                 {
                     flag5 = false;
                 }
                 if (num20 > WorldGen.UndergroundDesertLocation.X && num20 < WorldGen.UndergroundDesertLocation.X + WorldGen.UndergroundDesertLocation.Width)
                 {
                     flag5 = false;
                 }
                 if (num21 > WorldGen.UndergroundDesertLocation.X && num21 < WorldGen.UndergroundDesertLocation.X + WorldGen.UndergroundDesertLocation.Width)
                 {
                     flag5 = false;
                 }
                 if (num22 > WorldGen.UndergroundDesertLocation.X && num22 < WorldGen.UndergroundDesertLocation.X + WorldGen.UndergroundDesertLocation.Width)
                 {
                     flag5 = false;
                 }
                 for (int num26 = num21; num26 < num22; num26++)
                 {
                     for (int num27 = 0; num27 < (int)Main.worldSurface; num27 += 5)
                     {
                         if (Main.tile[num26, num27].active() && Main.tileDungeon[(int)Main.tile[num26, num27].type])
                         {
                             flag5 = false;
                             break;
                         }
                         if (!flag5)
                         {
                             break;
                         }
                     }
                 }
                 if (num23 < 200 && WorldGen.JungleX > num21 && WorldGen.JungleX < num22)
                 {
                     num23++;
                     flag5 = false;
                 }
             }
             int num28 = 0;
             for (int num29 = num21; num29 < num22; num29++)
             {
                 if (num28 > 0)
                 {
                     num28--;
                 }
                 if (num29 == num20 || num28 == 0)
                 {
                     int num30 = (int)WorldGen.worldSurfaceLow;
                     while ((double)num30 < Main.worldSurface - 1.0)
                     {
                         if (Main.tile[num29, num30].active() || Main.tile[num29, num30].wall > 0)
                         {
                             if (num29 == num20)
                             {
                                 num28 = 20;
                                 WorldGen.ChasmRunner(num29, num30, WorldGen.genRand.Next(150) + 150, true);
                                 break;
                             }
                             if (WorldGen.genRand.Next(35) == 0 && num28 == 0)
                             {
                                 num28 = 30;
                                 bool makeOrb = true;
                                 WorldGen.ChasmRunner(num29, num30, WorldGen.genRand.Next(50) + 50, makeOrb);
                                 break;
                             }
                             break;
                         }
                         else
                         {
                             num30++;
                         }
                     }
                 }
                 int num31 = (int)WorldGen.worldSurfaceLow;
                 while ((double)num31 < Main.worldSurface - 1.0)
                 {
                     if (Main.tile[num29, num31].active())
                     {
                         int num32 = num31 + WorldGen.genRand.Next(10, 14);
                         for (int num33 = num31; num33 < num32; num33++)
                         {
                             if ((Main.tile[num29, num33].type == 59 || Main.tile[num29, num33].type == 60) && num29 >= num21 + WorldGen.genRand.Next(5) && num29 < num22 - WorldGen.genRand.Next(5))
                             {
                                 Main.tile[num29, num33].type = 0;
                             }
                         }
                         break;
                     }
                     num31++;
                 }
             }
             double num34 = Main.worldSurface + 40.0;
             for (int num35 = num21; num35 < num22; num35++)
             {
                 num34 += (double)WorldGen.genRand.Next(-2, 3);
                 if (num34 < Main.worldSurface + 30.0)
                 {
                     num34 = Main.worldSurface + 30.0;
                 }
                 if (num34 > Main.worldSurface + 50.0)
                 {
                     num34 = Main.worldSurface + 50.0;
                 }
                 i2 = num35;
                 bool flag6 = false;
                 int num36 = (int)WorldGen.worldSurfaceLow;
                 while ((double)num36 < num34)
                 {
                     if (Main.tile[i2, num36].active())
                     {
                         if (Main.tile[i2, num36].type == 53 && i2 >= num21 + WorldGen.genRand.Next(5) && i2 <= num22 - WorldGen.genRand.Next(5))
                         {
                             Main.tile[i2, num36].type = 112;
                         }
                         if (Main.tile[i2, num36].type == 0 && (double)num36 < Main.worldSurface - 1.0 && !flag6)
                         {
                             WorldGen.grassSpread = 0;
                             WorldGen.SpreadGrass(i2, num36, 0, 23, true, 0);
                         }
                         flag6 = true;
                         if (Main.tile[i2, num36].type == 1 && i2 >= num21 + WorldGen.genRand.Next(5) && i2 <= num22 - WorldGen.genRand.Next(5))
                         {
                             Main.tile[i2, num36].type = 25;
                         }
                         if (Main.tile[i2, num36].wall == 216)
                         {
                             Main.tile[i2, num36].wall = 217;
                         }
                         else if (Main.tile[i2, num36].wall == 187)
                         {
                             Main.tile[i2, num36].wall = 220;
                         }
                         if (Main.tile[i2, num36].type == 2)
                         {
                             Main.tile[i2, num36].type = 23;
                         }
                         if (Main.tile[i2, num36].type == 161)
                         {
                             Main.tile[i2, num36].type = 163;
                         }
                         else if (Main.tile[i2, num36].type == 396)
                         {
                             Main.tile[i2, num36].type = 400;
                         }
                         else if (Main.tile[i2, num36].type == 397)
                         {
                             Main.tile[i2, num36].type = 398;
                         }
                     }
                     num36++;
                 }
             }
             for (int num37 = num21; num37 < num22; num37++)
             {
                 for (int num38 = 0; num38 < Main.maxTilesY - 50; num38++)
                 {
                     if (Main.tile[num37, num38].active() && Main.tile[num37, num38].type == 31)
                     {
                         int num39 = num37 - 13;
                         int num40 = num37 + 13;
                         int num41 = num38 - 13;
                         int num42 = num38 + 13;
                         for (int num43 = num39; num43 < num40; num43++)
                         {
                             if (num43 > 10 && num43 < Main.maxTilesX - 10)
                             {
                                 for (int num44 = num41; num44 < num42; num44++)
                                 {
                                     if (Math.Abs(num43 - num37) + Math.Abs(num44 - num38) < 9 + WorldGen.genRand.Next(11) && WorldGen.genRand.Next(3) != 0 && Main.tile[num43, num44].type != 31)
                                     {
                                         Main.tile[num43, num44].active(true);
                                         Main.tile[num43, num44].type = 25;
                                         if (Math.Abs(num43 - num37) <= 1 && Math.Abs(num44 - num38) <= 1)
                                         {
                                             Main.tile[num43, num44].active(false);
                                         }
                                     }
                                     if (Main.tile[num43, num44].type != 31 && Math.Abs(num43 - num37) <= 2 + WorldGen.genRand.Next(3) && Math.Abs(num44 - num38) <= 2 + WorldGen.genRand.Next(3))
                                     {
                                         Main.tile[num43, num44].active(false);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             num19++;
         }
     });
     WorldGen.AddGenerationPass("Slush", delegate (GenerationProgress progress)
     {
         for (int k = snowTop; k < snowBottom; k++)
         {
             for (int l = snowMinX[k]; l < snowMaxX[k]; l++)
             {
                 int type = (int)Main.tile[l, k].type;
                 if (type == 123)
                 {
                     Main.tile[l, k].type = 224;
                 }
                 else if (type == 59)
                 {
                     bool flag2 = true;
                     int num = 3;
                     for (int m = l - num; m <= l + num; m++)
                     {
                         for (int n = k - num; n <= k + num; n++)
                         {
                             if (Main.tile[m, n].type == 60 || Main.tile[m, n].type == 70 || Main.tile[m, n].type == 71 || Main.tile[m, n].type == 72)
                             {
                                 flag2 = false;
                                 break;
                             }
                         }
                     }
                     if (flag2)
                     {
                         Main.tile[l, k].type = 224;
                     }
                 }
                 else if (type == 1)
                 {
                     Main.tile[l, k].type = 161;
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Mud Caves To Grass", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[21];
         for (int k = 0; k < WorldGen.numMCaves; k++)
         {
             int i3 = WorldGen.mCaveX[k];
             int j2 = WorldGen.mCaveY[k];
             WorldGen.CaveOpenater(i3, j2);
             WorldGen.Cavinator(i3, j2, WorldGen.genRand.Next(40, 50));
         }
     });
     WorldGen.AddGenerationPass("Beaches", delegate (GenerationProgress progress)
     {
         int num = 0;
         int num2 = 0;
         int num3 = 20;
         int num4 = Main.maxTilesX - 20;
         progress.Message = Lang.gen[22];
         for (int k = 0; k < 2; k++)
         {
             if (k == 0)
             {
                 int num5 = 0;
                 int num6 = WorldGen.genRand.Next(125, 200) + 50;
                 if (dungeonSide == 1)
                 {
                     num6 = 275;
                 }
                 int num7 = 0;
                 float num8 = 1f;
                 int num9 = 0;
                 while (!Main.tile[num6 - 1, num9].active())
                 {
                     num9++;
                 }
                 num = num9;
                 num9 += WorldGen.genRand.Next(1, 5);
                 for (int l = num6 - 1; l >= num5; l--)
                 {
                     num7++;
                     if (num7 < 3)
                     {
                         num8 += (float)WorldGen.genRand.Next(10, 20) * 0.2f;
                     }
                     else if (num7 < 6)
                     {
                         num8 += (float)WorldGen.genRand.Next(10, 20) * 0.15f;
                     }
                     else if (num7 < 9)
                     {
                         num8 += (float)WorldGen.genRand.Next(10, 20) * 0.1f;
                     }
                     else if (num7 < 15)
                     {
                         num8 += (float)WorldGen.genRand.Next(10, 20) * 0.07f;
                     }
                     else if (num7 < 50)
                     {
                         num8 += (float)WorldGen.genRand.Next(10, 20) * 0.05f;
                     }
                     else if (num7 < 75)
                     {
                         num8 += (float)WorldGen.genRand.Next(10, 20) * 0.04f;
                     }
                     else if (num7 < 100)
                     {
                         num8 += (float)WorldGen.genRand.Next(10, 20) * 0.03f;
                     }
                     else if (num7 < 125)
                     {
                         num8 += (float)WorldGen.genRand.Next(10, 20) * 0.02f;
                     }
                     else if (num7 < 150)
                     {
                         num8 += (float)WorldGen.genRand.Next(10, 20) * 0.01f;
                     }
                     else if (num7 < 175)
                     {
                         num8 += (float)WorldGen.genRand.Next(10, 20) * 0.005f;
                     }
                     else if (num7 < 200)
                     {
                         num8 += (float)WorldGen.genRand.Next(10, 20) * 0.001f;
                     }
                     else if (num7 < 230)
                     {
                         num8 += (float)WorldGen.genRand.Next(10, 20) * 0.01f;
                     }
                     else if (num7 < 235)
                     {
                         num8 += (float)WorldGen.genRand.Next(10, 20) * 0.05f;
                     }
                     else if (num7 < 240)
                     {
                         num8 += (float)WorldGen.genRand.Next(10, 20) * 0.1f;
                     }
                     else if (num7 < 245)
                     {
                         num8 += (float)WorldGen.genRand.Next(10, 20) * 0.05f;
                     }
                     else if (num7 < 255)
                     {
                         num8 += (float)WorldGen.genRand.Next(10, 20) * 0.01f;
                     }
                     if (num7 == 235)
                     {
                         num4 = l;
                     }
                     if (num7 == 235)
                     {
                         num3 = l;
                     }
                     int num10 = WorldGen.genRand.Next(15, 20);
                     int num11 = 0;
                     while ((float)num11 < (float)num9 + num8 + (float)num10)
                     {
                         if ((float)num11 < (float)num9 + num8 * 0.75f - 3f)
                         {
                             Main.tile[l, num11].active(false);
                             if (num11 > num9)
                             {
                                 Main.tile[l, num11].liquid = 255;
                             }
                             else if (num11 == num9)
                             {
                                 Main.tile[l, num11].liquid = 127;
                             }
                         }
                         else if (num11 > num9)
                         {
                             Main.tile[l, num11].type = 53;
                             Main.tile[l, num11].active(true);
                         }
                         Main.tile[l, num11].wall = 0;
                         num11++;
                     }
                 }
             }
             else
             {
                 int num5 = Main.maxTilesX - WorldGen.genRand.Next(125, 200) - 50;
                 int num6 = Main.maxTilesX;
                 if (dungeonSide == -1)
                 {
                     num5 = Main.maxTilesX - 275;
                 }
                 float num12 = 1f;
                 int num13 = 0;
                 int num14 = 0;
                 while (!Main.tile[num5, num14].active())
                 {
                     num14++;
                 }
                 num2 = num14;
                 num14 += WorldGen.genRand.Next(1, 5);
                 for (int m = num5; m < num6; m++)
                 {
                     num13++;
                     if (num13 < 3)
                     {
                         num12 += (float)WorldGen.genRand.Next(10, 20) * 0.2f;
                     }
                     else if (num13 < 6)
                     {
                         num12 += (float)WorldGen.genRand.Next(10, 20) * 0.15f;
                     }
                     else if (num13 < 9)
                     {
                         num12 += (float)WorldGen.genRand.Next(10, 20) * 0.1f;
                     }
                     else if (num13 < 15)
                     {
                         num12 += (float)WorldGen.genRand.Next(10, 20) * 0.07f;
                     }
                     else if (num13 < 50)
                     {
                         num12 += (float)WorldGen.genRand.Next(10, 20) * 0.05f;
                     }
                     else if (num13 < 75)
                     {
                         num12 += (float)WorldGen.genRand.Next(10, 20) * 0.04f;
                     }
                     else if (num13 < 100)
                     {
                         num12 += (float)WorldGen.genRand.Next(10, 20) * 0.03f;
                     }
                     else if (num13 < 125)
                     {
                         num12 += (float)WorldGen.genRand.Next(10, 20) * 0.02f;
                     }
                     else if (num13 < 150)
                     {
                         num12 += (float)WorldGen.genRand.Next(10, 20) * 0.01f;
                     }
                     else if (num13 < 175)
                     {
                         num12 += (float)WorldGen.genRand.Next(10, 20) * 0.005f;
                     }
                     else if (num13 < 200)
                     {
                         num12 += (float)WorldGen.genRand.Next(10, 20) * 0.001f;
                     }
                     else if (num13 < 230)
                     {
                         num12 += (float)WorldGen.genRand.Next(10, 20) * 0.01f;
                     }
                     else if (num13 < 235)
                     {
                         num12 += (float)WorldGen.genRand.Next(10, 20) * 0.05f;
                     }
                     else if (num13 < 240)
                     {
                         num12 += (float)WorldGen.genRand.Next(10, 20) * 0.1f;
                     }
                     else if (num13 < 245)
                     {
                         num12 += (float)WorldGen.genRand.Next(10, 20) * 0.05f;
                     }
                     else if (num13 < 255)
                     {
                         num12 += (float)WorldGen.genRand.Next(10, 20) * 0.01f;
                     }
                     if (num13 == 235)
                     {
                         num4 = m;
                     }
                     int num15 = WorldGen.genRand.Next(15, 20);
                     int num16 = 0;
                     while ((float)num16 < (float)num14 + num12 + (float)num15)
                     {
                         if ((float)num16 < (float)num14 + num12 * 0.75f - 3f && (double)num16 < Main.worldSurface - 2.0)
                         {
                             Main.tile[m, num16].active(false);
                             if (num16 > num14)
                             {
                                 Main.tile[m, num16].liquid = 255;
                             }
                             else if (num16 == num14)
                             {
                                 Main.tile[m, num16].liquid = 127;
                             }
                         }
                         else if (num16 > num14)
                         {
                             Main.tile[m, num16].type = 53;
                             Main.tile[m, num16].active(true);
                         }
                         Main.tile[m, num16].wall = 0;
                         num16++;
                     }
                 }
             }
         }
         while (!Main.tile[num3, num].active())
         {
             num++;
         }
         num++;
         while (!Main.tile[num4, num2].active())
         {
             num2++;
         }
         num2++;
     });
     WorldGen.AddGenerationPass("Gems", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[23];
         for (int k = 63; k <= 68; k++)
         {
             float num = 0f;
             if (k == 67)
             {
                 num = (float)Main.maxTilesX * 0.5f;
             }
             else if (k == 66)
             {
                 num = (float)Main.maxTilesX * 0.45f;
             }
             else if (k == 63)
             {
                 num = (float)Main.maxTilesX * 0.3f;
             }
             else if (k == 65)
             {
                 num = (float)Main.maxTilesX * 0.25f;
             }
             else if (k == 64)
             {
                 num = (float)Main.maxTilesX * 0.1f;
             }
             else if (k == 68)
             {
                 num = (float)Main.maxTilesX * 0.05f;
             }
             num *= 0.2f;
             int num2 = 0;
             while ((float)num2 < num)
             {
                 int num3 = WorldGen.genRand.Next(0, Main.maxTilesX);
                 int num4 = WorldGen.genRand.Next((int)Main.worldSurface, Main.maxTilesY);
                 while (Main.tile[num3, num4].type != 1)
                 {
                     num3 = WorldGen.genRand.Next(0, Main.maxTilesX);
                     num4 = WorldGen.genRand.Next((int)Main.worldSurface, Main.maxTilesY);
                 }
                 WorldGen.TileRunner(num3, num4, (double)WorldGen.genRand.Next(2, 6), WorldGen.genRand.Next(3, 7), k, false, 0f, 0f, false, true);
                 num2++;
             }
         }
         for (int l = 0; l < 2; l++)
         {
             int num5 = 1;
             int num6 = 5;
             int num7 = Main.maxTilesX - 5;
             if (l == 1)
             {
                 num5 = -1;
                 num6 = Main.maxTilesX - 5;
                 num7 = 5;
             }
             for (int num8 = num6; num8 != num7; num8 += num5)
             {
                 for (int m = 10; m < Main.maxTilesY - 10; m++)
                 {
                     if (Main.tile[num8, m].active() && Main.tile[num8, m + 1].active() && Main.tileSand[(int)Main.tile[num8, m].type] && Main.tileSand[(int)Main.tile[num8, m + 1].type])
                     {
                         ushort type = Main.tile[num8, m].type;
                         int num9 = num8 + num5;
                         int num10 = m + 1;
                         if (!Main.tile[num9, m].active() && !Main.tile[num9, m + 1].active())
                         {
                             while (!Main.tile[num9, num10].active())
                             {
                                 num10++;
                             }
                             num10--;
                             Main.tile[num8, m].active(false);
                             Main.tile[num9, num10].active(true);
                             Main.tile[num9, num10].type = type;
                         }
                     }
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Gravitating Sand", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[24];
         for (int k = 0; k < Main.maxTilesX; k++)
         {
             float value = (float)k / (float)(Main.maxTilesX - 1);
             progress.Set(value);
             bool flag2 = false;
             int num = 0;
             for (int l = Main.maxTilesY - 1; l > 0; l--)
             {
                 if (WorldGen.SolidOrSlopedTile(k, l))
                 {
                     ushort type = Main.tile[k, l].type;
                     if (flag2 && l < (int)Main.worldSurface && l != num - 1 && TileID.Sets.Falling[(int)type])
                     {
                         for (int m = l; m < num; m++)
                         {
                             Main.tile[k, m].type = type;
                             Main.tile[k, m].active(true);
                         }
                     }
                     flag2 = true;
                     num = l;
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Clean Up Dirt", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[25];
         for (int k = 3; k < Main.maxTilesX - 3; k++)
         {
             float num = (float)k / (float)Main.maxTilesX;
             progress.Set(0.5f * num);
             bool flag2 = true;
             int num2 = 0;
             while ((double)num2 < Main.worldSurface)
             {
                 if (flag2)
                 {
                     if (Main.tile[k, num2].wall == 2 || Main.tile[k, num2].wall == 40 || Main.tile[k, num2].wall == 64)
                     {
                         Main.tile[k, num2].wall = 0;
                     }
                     if (Main.tile[k, num2].type != 53 && Main.tile[k, num2].type != 112 && Main.tile[k, num2].type != 234)
                     {
                         if (Main.tile[k - 1, num2].wall == 2 || Main.tile[k - 1, num2].wall == 40 || Main.tile[k - 1, num2].wall == 40)
                         {
                             Main.tile[k - 1, num2].wall = 0;
                         }
                         if ((Main.tile[k - 2, num2].wall == 2 || Main.tile[k - 2, num2].wall == 40 || Main.tile[k - 2, num2].wall == 40) && WorldGen.genRand.Next(2) == 0)
                         {
                             Main.tile[k - 2, num2].wall = 0;
                         }
                         if ((Main.tile[k - 3, num2].wall == 2 || Main.tile[k - 3, num2].wall == 40 || Main.tile[k - 3, num2].wall == 40) && WorldGen.genRand.Next(2) == 0)
                         {
                             Main.tile[k - 3, num2].wall = 0;
                         }
                         if (Main.tile[k + 1, num2].wall == 2 || Main.tile[k + 1, num2].wall == 40 || Main.tile[k + 1, num2].wall == 40)
                         {
                             Main.tile[k + 1, num2].wall = 0;
                         }
                         if ((Main.tile[k + 2, num2].wall == 2 || Main.tile[k + 2, num2].wall == 40 || Main.tile[k + 2, num2].wall == 40) && WorldGen.genRand.Next(2) == 0)
                         {
                             Main.tile[k + 2, num2].wall = 0;
                         }
                         if ((Main.tile[k + 3, num2].wall == 2 || Main.tile[k + 3, num2].wall == 40 || Main.tile[k + 3, num2].wall == 40) && WorldGen.genRand.Next(2) == 0)
                         {
                             Main.tile[k + 3, num2].wall = 0;
                         }
                         if (Main.tile[k, num2].active())
                         {
                             flag2 = false;
                         }
                     }
                 }
                 else if (Main.tile[k, num2].wall == 0 && Main.tile[k, num2 + 1].wall == 0 && Main.tile[k, num2 + 2].wall == 0 && Main.tile[k, num2 + 3].wall == 0 && Main.tile[k, num2 + 4].wall == 0 && Main.tile[k - 1, num2].wall == 0 && Main.tile[k + 1, num2].wall == 0 && Main.tile[k - 2, num2].wall == 0 && Main.tile[k + 2, num2].wall == 0 && !Main.tile[k, num2].active() && !Main.tile[k, num2 + 1].active() && !Main.tile[k, num2 + 2].active() && !Main.tile[k, num2 + 3].active())
                 {
                     flag2 = true;
                 }
                 num2++;
             }
         }
         for (int l = Main.maxTilesX - 5; l >= 5; l--)
         {
             float num3 = (float)l / (float)Main.maxTilesX;
             progress.Set(1f - 0.5f * num3);
             bool flag3 = true;
             int num4 = 0;
             while ((double)num4 < Main.worldSurface)
             {
                 if (flag3)
                 {
                     if (Main.tile[l, num4].wall == 2 || Main.tile[l, num4].wall == 40 || Main.tile[l, num4].wall == 64)
                     {
                         Main.tile[l, num4].wall = 0;
                     }
                     if (Main.tile[l, num4].type != 53)
                     {
                         if (Main.tile[l - 1, num4].wall == 2 || Main.tile[l - 1, num4].wall == 40 || Main.tile[l - 1, num4].wall == 40)
                         {
                             Main.tile[l - 1, num4].wall = 0;
                         }
                         if ((Main.tile[l - 2, num4].wall == 2 || Main.tile[l - 2, num4].wall == 40 || Main.tile[l - 2, num4].wall == 40) && WorldGen.genRand.Next(2) == 0)
                         {
                             Main.tile[l - 2, num4].wall = 0;
                         }
                         if ((Main.tile[l - 3, num4].wall == 2 || Main.tile[l - 3, num4].wall == 40 || Main.tile[l - 3, num4].wall == 40) && WorldGen.genRand.Next(2) == 0)
                         {
                             Main.tile[l - 3, num4].wall = 0;
                         }
                         if (Main.tile[l + 1, num4].wall == 2 || Main.tile[l + 1, num4].wall == 40 || Main.tile[l + 1, num4].wall == 40)
                         {
                             Main.tile[l + 1, num4].wall = 0;
                         }
                         if ((Main.tile[l + 2, num4].wall == 2 || Main.tile[l + 2, num4].wall == 40 || Main.tile[l + 2, num4].wall == 40) && WorldGen.genRand.Next(2) == 0)
                         {
                             Main.tile[l + 2, num4].wall = 0;
                         }
                         if ((Main.tile[l + 3, num4].wall == 2 || Main.tile[l + 3, num4].wall == 40 || Main.tile[l + 3, num4].wall == 40) && WorldGen.genRand.Next(2) == 0)
                         {
                             Main.tile[l + 3, num4].wall = 0;
                         }
                         if (Main.tile[l, num4].active())
                         {
                             flag3 = false;
                         }
                     }
                 }
                 else if (Main.tile[l, num4].wall == 0 && Main.tile[l, num4 + 1].wall == 0 && Main.tile[l, num4 + 2].wall == 0 && Main.tile[l, num4 + 3].wall == 0 && Main.tile[l, num4 + 4].wall == 0 && Main.tile[l - 1, num4].wall == 0 && Main.tile[l + 1, num4].wall == 0 && Main.tile[l - 2, num4].wall == 0 && Main.tile[l + 2, num4].wall == 0 && !Main.tile[l, num4].active() && !Main.tile[l, num4 + 1].active() && !Main.tile[l, num4 + 2].active() && !Main.tile[l, num4 + 3].active())
                 {
                     flag3 = true;
                 }
                 num4++;
             }
         }
     });
     WorldGen.AddGenerationPass("Pyramids", delegate (GenerationProgress progress)
     {
         for (int k = 0; k < numPyr; k++)
         {
             int num = PyrX[k];
             int num2 = PyrY[k];
             if (num > 300 && num < Main.maxTilesX - 300 && (dungeonSide >= 0 || (double)num >= (double)WorldGen.dungeonX + (double)Main.maxTilesX * 0.15))
             {
                 if (dungeonSide <= 0 || (double)num <= (double)WorldGen.dungeonX - (double)Main.maxTilesX * 0.15)
                 {
                     while (!Main.tile[num, num2].active() && (double)num2 < Main.worldSurface)
                     {
                         num2++;
                     }
                     if ((double)num2 < Main.worldSurface && Main.tile[num, num2].type == 53)
                     {
                         int num3 = Main.maxTilesX;
                         for (int l = 0; l < k; l++)
                         {
                             int num4 = Math.Abs(num - PyrX[l]);
                             if (num4 < num3)
                             {
                                 num3 = num4;
                             }
                         }
                         if (num3 >= 250)
                         {
                             num2--;
                             WorldGen.Pyramid(num, num2);
                         }
                     }
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Dirt Rock Wall Runner", delegate (GenerationProgress progress)
     {
         for (int k = 0; k < Main.maxTilesX; k++)
         {
             int num = WorldGen.genRand.Next(10, Main.maxTilesX - 10);
             int num2 = WorldGen.genRand.Next(10, (int)Main.worldSurface);
             if (Main.tile[num, num2].wall == 2)
             {
                 WorldGen.DirtyRockRunner(num, num2);
             }
         }
     });
     WorldGen.AddGenerationPass("Living Trees", delegate (GenerationProgress progress)
     {
         float num = (float)(Main.maxTilesX / 4200);
         int num2 = WorldGen.genRand.Next(0, (int)(3f * num));
         for (int k = 0; k < num2; k++)
         {
             bool flag2 = false;
             int num3 = 0;
             while (!flag2)
             {
                 num3++;
                 if (num3 > 1000)
                 {
                     flag2 = true;
                 }
                 int num4 = WorldGen.genRand.Next(300, Main.maxTilesX - 300);
                 if (num4 <= Main.maxTilesX / 2 - 100 || num4 >= Main.maxTilesX / 2 + 100)
                 {
                     int num5 = 0;
                     while (!Main.tile[num4, num5].active() && (double)num5 < Main.worldSurface)
                     {
                         num5++;
                     }
                     if (Main.tile[num4, num5].type == 0)
                     {
                         num5--;
                         if (num5 > 150)
                         {
                             bool flag3 = true;
                             for (int l = num4 - 50; l < num4 + 50; l++)
                             {
                                 for (int m = num5 - 50; m < num5 + 50; m++)
                                 {
                                     if (Main.tile[l, m].active())
                                     {
                                         int type = (int)Main.tile[l, m].type;
                                         if (type == 41 || type == 43 || type == 44 || type == 189 || type == 196)
                                         {
                                             flag3 = false;
                                         }
                                     }
                                 }
                             }
                             if (flag3)
                             {
                                 flag2 = WorldGen.GrowLivingTree(num4, num5);
                             }
                         }
                     }
                 }
             }
         }
         Main.tileSolid[192] = false;
     });
     WorldGen.AddGenerationPass("Wood Tree Walls", delegate (GenerationProgress progress)
     {
         for (int k = 25; k < Main.maxTilesX - 25; k++)
         {
             int num = 25;
             while ((double)num < Main.worldSurface)
             {
                 if (Main.tile[k, num].type == 191 || Main.tile[k, num - 1].type == 191 || Main.tile[k - 1, num].type == 191 || Main.tile[k + 1, num].type == 191 || Main.tile[k, num + 1].type == 191)
                 {
                     bool flag2 = true;
                     for (int l = k - 1; l <= k + 1; l++)
                     {
                         for (int m = num - 1; m <= num + 1; m++)
                         {
                             if (l != k && m != num && Main.tile[l, m].type != 191 && Main.tile[l, m].wall != 78)
                             {
                                 flag2 = false;
                             }
                         }
                     }
                     if (flag2)
                     {
                         Main.tile[k, num].wall = 78;
                     }
                 }
                 num++;
             }
         }
     });
     WorldGen.AddGenerationPass("Alters", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[26];
         for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 2E-05); k++)
         {
             float value = (float)((double)k / ((double)(Main.maxTilesX * Main.maxTilesY) * 2E-05));
             progress.Set(value);
             bool flag2 = false;
             int num = 0;
             while (!flag2)
             {
                 int num2 = WorldGen.genRand.Next(1, Main.maxTilesX);
                 int num3 = (int)(worldSurfaceHigh + 20.0);
                 int style = 0;
                 if (WorldGen.crimson)
                 {
                     style = 1;
                 }
                 WorldGen.Place3x2(num2, num3, 26, style);
                 if (Main.tile[num2, num3].type == 26)
                 {
                     flag2 = true;
                 }
                 else
                 {
                     num++;
                     if (num >= 10000)
                     {
                         flag2 = true;
                     }
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Wet Jungle", delegate (GenerationProgress progress)
     {
         for (int k = 0; k < Main.maxTilesX; k++)
         {
             i2 = k;
             int num = (int)WorldGen.worldSurfaceLow;
             while ((double)num < Main.worldSurface - 1.0)
             {
                 if (Main.tile[i2, num].active())
                 {
                     if (Main.tile[i2, num].type == 60)
                     {
                         Main.tile[i2, num - 1].liquid = 255;
                         Main.tile[i2, num - 2].liquid = 255;
                         break;
                     }
                     break;
                 }
                 else
                 {
                     num++;
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Remove Water From Sand", delegate (GenerationProgress progress)
     {
         for (int k = 400; k < Main.maxTilesX - 400; k++)
         {
             i2 = k;
             int num = (int)WorldGen.worldSurfaceLow;
             while ((double)num < Main.worldSurface - 1.0)
             {
                 if (Main.tile[i2, num].active())
                 {
                     ushort type = Main.tile[i2, num].type;
                     if (type == 53 || type == 396 || type == 397 || type == 404 || type == 407)
                     {
                         int num2 = num;
                         while ((double)num2 > WorldGen.worldSurfaceLow)
                         {
                             num2--;
                             Main.tile[i2, num2].liquid = 0;
                         }
                         break;
                     }
                     break;
                 }
                 else
                 {
                     num++;
                 }
             }
         }
         Main.tileSolid[192] = true;
     });
     WorldGen.AddGenerationPass("Jungle Temple", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[70];
         bool flag2 = true;
         while (flag2)
         {
             int num = WorldGen.genRand.Next((int)Main.rockLayer, Main.maxTilesY - 500);
             int num2;
             if (dungeonSide < 0)
             {
                 num2 = WorldGen.genRand.Next((int)((double)Main.maxTilesX * 0.6), (int)((double)Main.maxTilesX * 0.85));
             }
             else
             {
                 num2 = WorldGen.genRand.Next((int)((double)Main.maxTilesX * 0.15), (int)((double)Main.maxTilesX * 0.4));
             }
             if (Main.tile[num2, num].active() && Main.tile[num2, num].type == 60)
             {
                 flag2 = false;
                 WorldGen.makeTemple(num2, num);
             }
         }
     });
     WorldGen.AddGenerationPass("Hives", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[71];
         float num = (float)(Main.maxTilesX / 4200);
         float num2 = (float)(1 + WorldGen.genRand.Next((int)(5f * num), (int)(8f * num)));
         int num3 = 10000;
         while (num2 > 0f && num3 > 0)
         {
             num3--;
             Point origin = WorldGen.RandomWorldPoint((int)(Main.worldSurface + Main.rockLayer) >> 1, 20, 300, 20);
             if (Biomes<HiveBiome>.Place(origin, structures))
             {
                 num2 -= 1f;
                 int num4 = WorldGen.genRand.Next(5);
                 int num5 = 0;
                 int num6 = 10000;
                 while (num5 < num4 && num6 > 0)
                 {
                     float num7 = WorldGen.genRand.NextFloat() * 60f + 30f;
                     float num8 = WorldGen.genRand.NextFloat() * 6.28318548f;
                     int num9 = (int)(Math.Cos((double)num8) * (double)num7) + origin.X;
                     int y = (int)(Math.Sin((double)num8) * (double)num7) + origin.Y;
                     num6--;
                     if (num9 > 50 && num9 < Main.maxTilesX - 50 && Biomes<HoneyPatchBiome>.Place(num9, y, structures))
                     {
                         num5++;
                     }
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Jungle Chests", delegate (GenerationProgress progress)
     {
         int num = WorldGen.genRand.Next(40, Main.maxTilesX - 40);
         int num2 = WorldGen.genRand.Next((int)(Main.worldSurface + Main.rockLayer) / 2, Main.maxTilesY - 400);
         float num3 = (float)WorldGen.genRand.Next(7, 12);
         num3 *= (float)(Main.maxTilesX / 4200);
         int num4 = 0;
         while ((float)num4 < num3)
         {
             bool flag2 = true;
             while (flag2)
             {
                 num = WorldGen.genRand.Next(40, Main.maxTilesX / 2 - 40);
                 if (dungeonSide < 0)
                 {
                     num += Main.maxTilesX / 2;
                 }
                 num2 = WorldGen.genRand.Next((int)(Main.worldSurface + Main.rockLayer) / 2, Main.maxTilesY - 400);
                 if (Main.tile[num, num2].type == 60)
                 {
                     int num5 = 30;
                     flag2 = false;
                     for (int k = num - num5; k < num + num5; k += 3)
                     {
                         for (int l = num2 - num5; l < num2 + num5; l += 3)
                         {
                             if (Main.tile[k, l].active() && (Main.tile[k, l].type == 225 || Main.tile[k, l].type == 229 || Main.tile[k, l].type == 226 || Main.tile[k, l].type == 119 || Main.tile[k, l].type == 120))
                             {
                                 flag2 = false;
                             }
                             if (Main.tile[k, l].wall == 86 || Main.tile[k, l].wall == 87)
                             {
                                 flag2 = false;
                             }
                         }
                     }
                 }
                 if (!flag2)
                 {
                     int m = WorldGen.genRand.Next(2, 4);
                     int num6 = WorldGen.genRand.Next(2, 4);
                     int num7 = 0;
                     if (jungleHut == 119)
                     {
                         num7 = 23;
                     }
                     else if (jungleHut == 120)
                     {
                         num7 = 24;
                     }
                     else if (jungleHut == 158)
                     {
                         num7 = 42;
                     }
                     else if (jungleHut == 175)
                     {
                         num7 = 45;
                     }
                     else if (jungleHut == 45)
                     {
                         num7 = 10;
                     }
                     for (int n = num - m - 1; n <= num + m + 1; n++)
                     {
                         for (int num8 = num2 - num6 - 1; num8 <= num2 + num6 + 1; num8++)
                         {
                             Main.tile[n, num8].active(true);
                             Main.tile[n, num8].type = jungleHut;
                             Main.tile[n, num8].liquid = 0;
                             Main.tile[n, num8].lava(false);
                         }
                     }
                     for (int num9 = num - m; num9 <= num + m; num9++)
                     {
                         for (int num10 = num2 - num6; num10 <= num2 + num6; num10++)
                         {
                             Main.tile[num9, num10].active(false);
                             Main.tile[num9, num10].wall = (byte)num7;
                         }
                     }
                     bool flag3 = false;
                     int num11 = 0;
                     while (!flag3 && num11 < 100)
                     {
                         num11++;
                         int num12 = WorldGen.genRand.Next(num - m, num + m + 1);
                         int num13 = WorldGen.genRand.Next(num2 - num6, num2 + num6 - 2);
                         WorldGen.PlaceTile(num12, num13, 4, true, false, -1, 3);
                         if (Main.tile[num12, num13].type == 4)
                         {
                             flag3 = true;
                         }
                     }
                     for (int num14 = num - m - 1; num14 <= num + m + 1; num14++)
                     {
                         for (int num15 = num2 + num6 - 2; num15 <= num2 + num6; num15++)
                         {
                             Main.tile[num14, num15].active(false);
                         }
                     }
                     for (int num16 = num - m - 1; num16 <= num + m + 1; num16++)
                     {
                         for (int num17 = num2 + num6 - 2; num17 <= num2 + num6 - 1; num17++)
                         {
                             Main.tile[num16, num17].active(false);
                         }
                     }
                     for (int num18 = num - m - 1; num18 <= num + m + 1; num18++)
                     {
                         int num19 = 4;
                         int num20 = num2 + num6 + 2;
                         while (!Main.tile[num18, num20].active() && num20 < Main.maxTilesY && num19 > 0)
                         {
                             Main.tile[num18, num20].active(true);
                             Main.tile[num18, num20].type = 59;
                             num20++;
                             num19--;
                         }
                     }
                     m -= WorldGen.genRand.Next(1, 3);
                     int num21 = num2 - num6 - 2;
                     while (m > -1)
                     {
                         for (int num22 = num - m - 1; num22 <= num + m + 1; num22++)
                         {
                             Main.tile[num22, num21].active(true);
                             Main.tile[num22, num21].type = jungleHut;
                         }
                         m -= WorldGen.genRand.Next(1, 3);
                         num21--;
                     }
                     WorldGen.JChestX[WorldGen.numJChests] = num;
                     WorldGen.JChestY[WorldGen.numJChests] = num2;
                     WorldGen.numJChests++;
                 }
             }
             num4++;
         }
         Main.tileSolid[137] = false;
     });
     WorldGen.AddGenerationPass("Smooth World", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[60];
         for (int k = 20; k < Main.maxTilesX - 20; k++)
         {
             float value = (float)k / (float)Main.maxTilesX;
             progress.Set(value);
             for (int l = 20; l < Main.maxTilesY - 20; l++)
             {
                 if (Main.tile[k, l].type != 48 && Main.tile[k, l].type != 137 && Main.tile[k, l].type != 232 && Main.tile[k, l].type != 191 && Main.tile[k, l].type != 151 && Main.tile[k, l].type != 274)
                 {
                     if (!Main.tile[k, l - 1].active())
                     {
                         if (WorldGen.SolidTile(k, l) && TileID.Sets.CanBeClearedDuringGeneration[(int)Main.tile[k, l].type])
                         {
                             if (!Main.tile[k - 1, l].halfBrick() && !Main.tile[k + 1, l].halfBrick() && Main.tile[k - 1, l].slope() == 0 && Main.tile[k + 1, l].slope() == 0)
                             {
                                 if (WorldGen.SolidTile(k, l + 1))
                                 {
                                     if (!WorldGen.SolidTile(k - 1, l) && !Main.tile[k - 1, l + 1].halfBrick() && WorldGen.SolidTile(k - 1, l + 1) && WorldGen.SolidTile(k + 1, l) && !Main.tile[k + 1, l - 1].active())
                                     {
                                         if (WorldGen.genRand.Next(2) == 0)
                                         {
                                             WorldGen.SlopeTile(k, l, 2);
                                         }
                                         else
                                         {
                                             WorldGen.PoundTile(k, l);
                                         }
                                     }
                                     else if (!WorldGen.SolidTile(k + 1, l) && !Main.tile[k + 1, l + 1].halfBrick() && WorldGen.SolidTile(k + 1, l + 1) && WorldGen.SolidTile(k - 1, l) && !Main.tile[k - 1, l - 1].active())
                                     {
                                         if (WorldGen.genRand.Next(2) == 0)
                                         {
                                             WorldGen.SlopeTile(k, l, 1);
                                         }
                                         else
                                         {
                                             WorldGen.PoundTile(k, l);
                                         }
                                     }
                                     else if (WorldGen.SolidTile(k + 1, l + 1) && WorldGen.SolidTile(k - 1, l + 1) && !Main.tile[k + 1, l].active() && !Main.tile[k - 1, l].active())
                                     {
                                         WorldGen.PoundTile(k, l);
                                     }
                                     if (WorldGen.SolidTile(k, l))
                                     {
                                         if (WorldGen.SolidTile(k - 1, l) && WorldGen.SolidTile(k + 1, l + 2) && !Main.tile[k + 1, l].active() && !Main.tile[k + 1, l + 1].active() && !Main.tile[k - 1, l - 1].active())
                                         {
                                             WorldGen.KillTile(k, l, false, false, false);
                                         }
                                         else if (WorldGen.SolidTile(k + 1, l) && WorldGen.SolidTile(k - 1, l + 2) && !Main.tile[k - 1, l].active() && !Main.tile[k - 1, l + 1].active() && !Main.tile[k + 1, l - 1].active())
                                         {
                                             WorldGen.KillTile(k, l, false, false, false);
                                         }
                                         else if (!Main.tile[k - 1, l + 1].active() && !Main.tile[k - 1, l].active() && WorldGen.SolidTile(k + 1, l) && WorldGen.SolidTile(k, l + 2))
                                         {
                                             if (WorldGen.genRand.Next(5) == 0)
                                             {
                                                 WorldGen.KillTile(k, l, false, false, false);
                                             }
                                             else if (WorldGen.genRand.Next(5) == 0)
                                             {
                                                 WorldGen.PoundTile(k, l);
                                             }
                                             else
                                             {
                                                 WorldGen.SlopeTile(k, l, 2);
                                             }
                                         }
                                         else if (!Main.tile[k + 1, l + 1].active() && !Main.tile[k + 1, l].active() && WorldGen.SolidTile(k - 1, l) && WorldGen.SolidTile(k, l + 2))
                                         {
                                             if (WorldGen.genRand.Next(5) == 0)
                                             {
                                                 WorldGen.KillTile(k, l, false, false, false);
                                             }
                                             else if (WorldGen.genRand.Next(5) == 0)
                                             {
                                                 WorldGen.PoundTile(k, l);
                                             }
                                             else
                                             {
                                                 WorldGen.SlopeTile(k, l, 1);
                                             }
                                         }
                                     }
                                 }
                                 if (WorldGen.SolidTile(k, l) && !Main.tile[k - 1, l].active() && !Main.tile[k + 1, l].active())
                                 {
                                     WorldGen.KillTile(k, l, false, false, false);
                                 }
                             }
                         }
                         else if (!Main.tile[k, l].active() && Main.tile[k, l + 1].type != 151 && Main.tile[k, l + 1].type != 274)
                         {
                             if (Main.tile[k + 1, l].type != 190 && Main.tile[k + 1, l].type != 48 && Main.tile[k + 1, l].type != 232 && WorldGen.SolidTile(k - 1, l + 1) && WorldGen.SolidTile(k + 1, l) && !Main.tile[k - 1, l].active() && !Main.tile[k + 1, l - 1].active())
                             {
                                 WorldGen.PlaceTile(k, l, (int)Main.tile[k, l + 1].type, false, false, -1, 0);
                                 if (WorldGen.genRand.Next(2) == 0)
                                 {
                                     WorldGen.SlopeTile(k, l, 2);
                                 }
                                 else
                                 {
                                     WorldGen.PoundTile(k, l);
                                 }
                             }
                             if (Main.tile[k - 1, l].type != 190 && Main.tile[k - 1, l].type != 48 && Main.tile[k - 1, l].type != 232 && WorldGen.SolidTile(k + 1, l + 1) && WorldGen.SolidTile(k - 1, l) && !Main.tile[k + 1, l].active() && !Main.tile[k - 1, l - 1].active())
                             {
                                 WorldGen.PlaceTile(k, l, (int)Main.tile[k, l + 1].type, false, false, -1, 0);
                                 if (WorldGen.genRand.Next(2) == 0)
                                 {
                                     WorldGen.SlopeTile(k, l, 1);
                                 }
                                 else
                                 {
                                     WorldGen.PoundTile(k, l);
                                 }
                             }
                         }
                     }
                     else if (!Main.tile[k, l + 1].active() && WorldGen.genRand.Next(2) == 0 && WorldGen.SolidTile(k, l) && !Main.tile[k - 1, l].halfBrick() && !Main.tile[k + 1, l].halfBrick() && Main.tile[k - 1, l].slope() == 0 && Main.tile[k + 1, l].slope() == 0 && WorldGen.SolidTile(k, l - 1))
                     {
                         if (WorldGen.SolidTile(k - 1, l) && !WorldGen.SolidTile(k + 1, l) && WorldGen.SolidTile(k - 1, l - 1))
                         {
                             WorldGen.SlopeTile(k, l, 3);
                         }
                         else if (WorldGen.SolidTile(k + 1, l) && !WorldGen.SolidTile(k - 1, l) && WorldGen.SolidTile(k + 1, l - 1))
                         {
                             WorldGen.SlopeTile(k, l, 4);
                         }
                     }
                 }
             }
         }
         for (int m = 20; m < Main.maxTilesX - 20; m++)
         {
             for (int n = 20; n < Main.maxTilesY - 20; n++)
             {
                 if (WorldGen.genRand.Next(2) == 0 && !Main.tile[m, n - 1].active() && Main.tile[m, n].type != 137 && Main.tile[m, n].type != 48 && Main.tile[m, n].type != 232 && Main.tile[m, n].type != 191 && Main.tile[m, n].type != 151 && Main.tile[m, n].type != 274 && Main.tile[m, n].type != 75 && Main.tile[m, n].type != 76 && WorldGen.SolidTile(m, n) && Main.tile[m - 1, n].type != 137 && Main.tile[m + 1, n].type != 137)
                 {
                     if (WorldGen.SolidTile(m, n + 1) && WorldGen.SolidTile(m + 1, n) && !Main.tile[m - 1, n].active())
                     {
                         WorldGen.SlopeTile(m, n, 2);
                     }
                     if (WorldGen.SolidTile(m, n + 1) && WorldGen.SolidTile(m - 1, n) && !Main.tile[m + 1, n].active())
                     {
                         WorldGen.SlopeTile(m, n, 1);
                     }
                 }
                 if (Main.tile[m, n].slope() == 1 && !WorldGen.SolidTile(m - 1, n))
                 {
                     WorldGen.SlopeTile(m, n, 0);
                     WorldGen.PoundTile(m, n);
                 }
                 if (Main.tile[m, n].slope() == 2 && !WorldGen.SolidTile(m + 1, n))
                 {
                     WorldGen.SlopeTile(m, n, 0);
                     WorldGen.PoundTile(m, n);
                 }
             }
         }
         Main.tileSolid[137] = true;
         Main.tileSolid[190] = false;
         Main.tileSolid[192] = false;
     });
     WorldGen.AddGenerationPass("Settle Liquids", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[27];
         Liquid.QuickWater(3, -1, -1);
         WorldGen.WaterCheck();
         int k = 0;
         Liquid.quickSettle = true;
         while (k < 10)
         {
             int num = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer;
             k++;
             float num2 = 0f;
             while (Liquid.numLiquid > 0)
             {
                 float num3 = (float)(num - (Liquid.numLiquid + LiquidBuffer.numLiquidBuffer)) / (float)num;
                 if (Liquid.numLiquid + LiquidBuffer.numLiquidBuffer > num)
                 {
                     num = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer;
                 }
                 if (num3 > num2)
                 {
                     num2 = num3;
                 }
                 else
                 {
                     num3 = num2;
                 }
                 if (k == 1)
                 {
                     progress.Set(num3 / 3f + 0.33f);
                 }
                 int num4 = 10;
                 if (k > num4)
                 {
                 }
                 Liquid.UpdateLiquid();
             }
             WorldGen.WaterCheck();
             progress.Set((float)k * 0.1f / 3f + 0.66f);
         }
         Liquid.quickSettle = false;
         Main.tileSolid[190] = true;
     });
     WorldGen.AddGenerationPass("Waterfalls", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[69];
         for (int k = 20; k < Main.maxTilesX - 20; k++)
         {
             float num = (float)k / (float)Main.maxTilesX;
             progress.Set(num * 0.5f);
             for (int l = 20; l < Main.maxTilesY - 20; l++)
             {
                 if (WorldGen.SolidTile(k, l) && !Main.tile[k - 1, l].active() && WorldGen.SolidTile(k, l + 1) && !Main.tile[k + 1, l].active() && (Main.tile[k - 1, l].liquid > 0 || Main.tile[k + 1, l].liquid > 0))
                 {
                     bool flag2 = true;
                     int num2 = WorldGen.genRand.Next(8, 20);
                     int num3 = WorldGen.genRand.Next(8, 20);
                     num2 = l - num2;
                     num3 += l;
                     for (int m = num2; m <= num3; m++)
                     {
                         if (Main.tile[k, m].halfBrick())
                         {
                             flag2 = false;
                         }
                     }
                     if ((Main.tile[k, l].type == 75 || Main.tile[k, l].type == 76) && WorldGen.genRand.Next(10) != 0)
                     {
                         flag2 = false;
                     }
                     if (flag2)
                     {
                         WorldGen.PoundTile(k, l);
                     }
                 }
             }
         }
         for (int n = 20; n < Main.maxTilesX - 20; n++)
         {
             float num4 = (float)n / (float)Main.maxTilesX;
             progress.Set(num4 * 0.5f + 0.5f);
             for (int num5 = 20; num5 < Main.maxTilesY - 20; num5++)
             {
                 if (Main.tile[n, num5].type != 48 && Main.tile[n, num5].type != 232 && WorldGen.SolidTile(n, num5) && WorldGen.SolidTile(n, num5 + 1))
                 {
                     if (!WorldGen.SolidTile(n + 1, num5) && Main.tile[n - 1, num5].halfBrick() && Main.tile[n - 2, num5].liquid > 0)
                     {
                         WorldGen.PoundTile(n, num5);
                     }
                     if (!WorldGen.SolidTile(n - 1, num5) && Main.tile[n + 1, num5].halfBrick() && Main.tile[n + 2, num5].liquid > 0)
                     {
                         WorldGen.PoundTile(n, num5);
                     }
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Ice", delegate (GenerationProgress progress)
     {
         for (int k = 10; k < Main.maxTilesX - 10; k++)
         {
             for (int l = (int)Main.worldSurface; l < Main.maxTilesY - 100; l++)
             {
                 if (Main.tile[k, l].liquid > 0 && !Main.tile[k, l].lava())
                 {
                     WorldGen.MakeWateryIceThing(k, l);
                 }
             }
         }
         Main.tileSolid[226] = false;
         Main.tileSolid[162] = false;
     });
     WorldGen.AddGenerationPass("Wall Variety", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[79];
         float num = (float)(Main.maxTilesX * Main.maxTilesY) / 5040000f;
         int k = (int)(300f * num);
         int num2 = k;
         ShapeData shapeData = new ShapeData();
         while (k > 0)
         {
             progress.Set(1f - (float)k / (float)num2);
             Point point = WorldGen.RandomWorldPoint((int)worldSurface, 2, 190, 2);
             Tile tile = Main.tile[point.X, point.Y];
             Tile tile2 = Main.tile[point.X, point.Y - 1];
             byte b = 0;
             if (tile.type == 59 || tile.type == 60)
             {
                 b = (byte)(204 + WorldGen.genRand.Next(4));
             }
             else if (tile.type == 1 && tile2.wall == 0)
             {
                 if ((double)point.Y < rockLayer)
                 {
                     b = (byte)(196 + WorldGen.genRand.Next(4));
                 }
                 else if (point.Y < WorldGen.lavaLine)
                 {
                     b = (byte)(212 + WorldGen.genRand.Next(4));
                 }
                 else
                 {
                     b = (byte)(208 + WorldGen.genRand.Next(4));
                 }
             }
             if (tile.active() && b != 0 && !tile2.active())
             {
                 bool foundInvalidTile = false;
                 bool flag2 = WorldUtils.Gen(new Point(point.X, point.Y - 1), new ShapeFloodFill(1000), Actions.Chain(new GenAction[]
                 {
                     new Modifiers.IsNotSolid(),
                     new Actions.Blank().Output(shapeData),
                     new Actions.ContinueWrapper(Actions.Chain(new GenAction[]
                     {
                         new Modifiers.IsTouching(true, new ushort[]
                         {
                             60,
                             147,
                             161,
                             396,
                             397
                         }),
                         new Actions.Custom(delegate(int x, int y, object[] args)
                         {
                             foundInvalidTile = true;
                             return true;
                         })
                     }))
                 }));
                 if (shapeData.Count > 50 && flag2 && !foundInvalidTile)
                 {
                     WorldUtils.Gen(new Point(point.X, point.Y), new ModShapes.OuterOutline(shapeData, true, true), new Actions.PlaceWall(b, true));
                     k--;
                 }
                 shapeData.Clear();
             }
         }
     });
     WorldGen.AddGenerationPass("Traps", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[34];
         for (int k = 0; k < (int)((double)Main.maxTilesX * 0.05); k++)
         {
             float value = (float)((double)k / ((double)Main.maxTilesX * 0.05));
             progress.Set(value);
             for (int l = 0; l < 1000; l++)
             {
                 int num = WorldGen.genRand.Next(200, Main.maxTilesX - 200);
                 int num2 = WorldGen.genRand.Next((int)Main.worldSurface, Main.maxTilesY - 300);
                 if (Main.tile[num, num2].wall == 0 && WorldGen.placeTrap(num, num2, -1))
                 {
                     break;
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Life Crystals", delegate (GenerationProgress progress)
     {
         dub2 = (float)(Main.maxTilesX / 4200);
         progress.Message = Lang.gen[28];
         for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 2E-05); k++)
         {
             float value = (float)((double)k / ((double)(Main.maxTilesX * Main.maxTilesY) * 2E-05));
             progress.Set(value);
             bool flag2 = false;
             int num = 0;
             while (!flag2)
             {
                 if (WorldGen.AddLifeCrystal(WorldGen.genRand.Next(40, Main.maxTilesX - 40), WorldGen.genRand.Next((int)(worldSurfaceHigh + 20.0), Main.maxTilesY - 300)))
                 {
                     flag2 = true;
                 }
                 else
                 {
                     num++;
                     if (num >= 10000)
                     {
                         flag2 = true;
                     }
                 }
             }
         }
         Main.tileSolid[225] = false;
     });
     WorldGen.AddGenerationPass("Statues", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[29];
         int num = 0;
         int num2 = (int)((float)(WorldGen.statueList.Length * 2) * dub2);
         for (int k = 0; k < num2; k++)
         {
             if (num >= WorldGen.statueList.Length)
             {
                 num = 0;
             }
             int x = (int)WorldGen.statueList[num].X;
             int y = (int)WorldGen.statueList[num].Y;
             float value = (float)(k / num2);
             progress.Set(value);
             bool flag2 = false;
             int num3 = 0;
             while (!flag2)
             {
                 int num4 = WorldGen.genRand.Next(20, Main.maxTilesX - 20);
                 int num5 = WorldGen.genRand.Next((int)(worldSurfaceHigh + 20.0), Main.maxTilesY - 300);
                 while (!Main.tile[num4, num5].active())
                 {
                     num5++;
                 }
                 num5--;
                 WorldGen.PlaceTile(num4, num5, x, true, true, -1, y);
                 if (Main.tile[num4, num5].active() && (int)Main.tile[num4, num5].type == x)
                 {
                     flag2 = true;
                     if (WorldGen.StatuesWithTraps.Contains(num))
                     {
                         WorldGen.PlaceStatueTrap(num4, num5);
                     }
                     num++;
                 }
                 else
                 {
                     num3++;
                     if (num3 >= 10000)
                     {
                         flag2 = true;
                     }
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Buried Chests", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[30];
         Main.tileSolid[226] = true;
         Main.tileSolid[162] = true;
         Main.tileSolid[225] = true;
         for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 1.6E-05); k++)
         {
             float value = (float)((double)k / ((double)(Main.maxTilesX * Main.maxTilesY) * 1.6E-05));
             progress.Set(value);
             bool flag2 = false;
             int num = 0;
             while (!flag2)
             {
                 float num2 = (float)WorldGen.genRand.Next((int)(5f * dub2), (int)(8f * dub2 + 1f));
                 int num3 = WorldGen.genRand.Next(20, Main.maxTilesX - 20);
                 int num4 = WorldGen.genRand.Next((int)(worldSurfaceHigh + 20.0), Main.maxTilesY - 230);
                 if ((float)k <= num2)
                 {
                     num4 = WorldGen.genRand.Next(Main.maxTilesY - 200, Main.maxTilesY - 50);
                 }
                 int num5 = 0;
                 while (Main.wallDungeon[(int)Main.tile[num3, num4].wall])
                 {
                     num5++;
                     num3 = WorldGen.genRand.Next(1, Main.maxTilesX);
                     num4 = WorldGen.genRand.Next((int)(worldSurfaceHigh + 20.0), Main.maxTilesY - 230);
                     if (num5 < 1000 && (float)k <= num2)
                     {
                         num4 = WorldGen.genRand.Next(Main.maxTilesY - 200, Main.maxTilesY - 50);
                     }
                 }
                 if ((float)k > num2)
                 {
                     for (int l = 10; l > 0; l--)
                     {
                         int x = WorldGen.genRand.Next(80, Main.maxTilesX - 80);
                         int y = WorldGen.genRand.Next((int)(worldSurfaceHigh + 20.0), Main.maxTilesY - 230);
                         if (Biomes<CaveHouseBiome>.Place(x, y, structures))
                         {
                             flag2 = true;
                             break;
                         }
                     }
                 }
                 else if (WorldGen.AddBuriedChest(num3, num4, 0, false, -1))
                 {
                     flag2 = true;
                 }
                 num++;
                 if (num >= 1000)
                 {
                     flag2 = true;
                 }
             }
         }
         int num6 = (int)(2f * (float)(Main.maxTilesX * Main.maxTilesY) / 5040000f);
         int num7 = 1000;
         while (num7 >= 0 && num6 >= 0)
         {
             if (Biomes<CaveHouseBiome>.Place(WorldGen.RandomRectanglePoint(WorldGen.UndergroundDesertLocation), structures))
             {
                 num6--;
             }
             num7--;
         }
         Main.tileSolid[226] = false;
         Main.tileSolid[162] = false;
         Main.tileSolid[225] = false;
     });
     WorldGen.AddGenerationPass("Surface Chests", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[31];
         for (int k = 0; k < (int)((double)Main.maxTilesX * 0.005); k++)
         {
             float value = (float)((double)k / ((double)Main.maxTilesX * 0.005));
             progress.Set(value);
             bool flag2 = false;
             int num = 0;
             while (!flag2)
             {
                 int num2 = WorldGen.genRand.Next(300, Main.maxTilesX - 300);
                 int num3 = WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, (int)Main.worldSurface);
                 bool flag3 = false;
                 if (Main.tile[num2, num3].wall == 2 && !Main.tile[num2, num3].active())
                 {
                     flag3 = true;
                 }
                 if (flag3 && WorldGen.AddBuriedChest(num2, num3, 0, true, -1))
                 {
                     flag2 = true;
                 }
                 else
                 {
                     num++;
                     if (num >= 2000)
                     {
                         flag2 = true;
                     }
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Jungle Chests Placement", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[32];
         for (int k = 0; k < WorldGen.numJChests; k++)
         {
             float value = (float)(k / WorldGen.numJChests);
             progress.Set(value);
             int nextJungleChestItem = WorldGen.GetNextJungleChestItem();
             if (!WorldGen.AddBuriedChest(WorldGen.JChestX[k] + WorldGen.genRand.Next(2), WorldGen.JChestY[k], nextJungleChestItem, false, 10))
             {
                 for (int l = WorldGen.JChestX[k] - 1; l <= WorldGen.JChestX[k] + 1; l++)
                 {
                     for (int m = WorldGen.JChestY[k]; m <= WorldGen.JChestY[k] + 2; m++)
                     {
                         WorldGen.KillTile(l, m, false, false, false);
                     }
                 }
                 for (int n = WorldGen.JChestX[k] - 1; n <= WorldGen.JChestX[k] + 1; n++)
                 {
                     for (int num = WorldGen.JChestY[k]; num <= WorldGen.JChestY[k] + 3; num++)
                     {
                         if (num < Main.maxTilesY)
                         {
                             Main.tile[n, num].slope(0);
                             Main.tile[n, num].halfBrick(false);
                         }
                     }
                 }
                 WorldGen.AddBuriedChest(WorldGen.JChestX[k], WorldGen.JChestY[k], nextJungleChestItem, false, 10);
             }
         }
     });
     WorldGen.AddGenerationPass("Water Chests", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[33];
         int num = 0;
         int num2 = 0;
         while ((float)num2 < 9f * dub2)
         {
             float value = (float)num2 / (9f * dub2);
             progress.Set(value);
             num++;
             int contain;
             if (WorldGen.genRand.Next(15) == 0)
             {
                 contain = 863;
             }
             else if (num == 1)
             {
                 contain = 186;
             }
             else if (num == 2)
             {
                 contain = 277;
             }
             else
             {
                 contain = 187;
                 num = 0;
             }
             bool flag2 = false;
             while (!flag2)
             {
                 int num3 = WorldGen.genRand.Next(1, Main.maxTilesX);
                 int num4 = WorldGen.genRand.Next(1, Main.maxTilesY - 200);
                 while (Main.tile[num3, num4].liquid < 200 || Main.tile[num3, num4].lava())
                 {
                     num3 = WorldGen.genRand.Next(1, Main.maxTilesX);
                     num4 = WorldGen.genRand.Next(1, Main.maxTilesY - 200);
                 }
                 flag2 = WorldGen.AddBuriedChest(num3, num4, contain, false, 17);
             }
             flag2 = false;
             while (!flag2)
             {
                 int num5 = WorldGen.genRand.Next(1, Main.maxTilesX);
                 int num6 = WorldGen.genRand.Next((int)Main.worldSurface, Main.maxTilesY - 200);
                 while (Main.tile[num5, num6].liquid < 200 || Main.tile[num5, num6].lava())
                 {
                     num5 = WorldGen.genRand.Next(1, Main.maxTilesX);
                     num6 = WorldGen.genRand.Next(1, Main.maxTilesY - 200);
                 }
                 flag2 = WorldGen.AddBuriedChest(num5, num6, contain, false, 17);
             }
             num2++;
         }
     });
     WorldGen.AddGenerationPass("Spider Caves", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[64];
         WorldGen.maxTileCount = 3500;
         for (int k = 0; k < (int)((double)Main.maxTilesX * 0.005); k++)
         {
             float value = (float)((double)k / ((double)Main.maxTilesX * 0.005));
             progress.Set(value);
             int num = 0;
             int x = WorldGen.genRand.Next(200, Main.maxTilesX - 200);
             int y = WorldGen.genRand.Next((int)(Main.worldSurface + Main.rockLayer) / 2, Main.maxTilesY - 230);
             int num2 = WorldGen.countTiles(x, y, false, true);
             while ((num2 >= 3500 || num2 < 500) && num < 500)
             {
                 num++;
                 x = WorldGen.genRand.Next(200, Main.maxTilesX - 200);
                 y = WorldGen.genRand.Next((int)Main.rockLayer + 30, Main.maxTilesY - 230);
                 num2 = WorldGen.countTiles(x, y, false, true);
             }
             if (num < 500)
             {
                 WorldGen.Spread.Spider(x, y);
             }
         }
         Main.tileSolid[162] = true;
     });
     WorldGen.AddGenerationPass("Gem Caves", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[64];
         WorldGen.maxTileCount = 300;
         for (int k = 0; k < (int)((double)Main.maxTilesX * 0.003); k++)
         {
             float value = (float)((double)k / ((double)Main.maxTilesX * 0.003));
             progress.Set(value);
             int num = 0;
             int x = WorldGen.genRand.Next(200, Main.maxTilesX - 200);
             int y = WorldGen.genRand.Next((int)Main.rockLayer + 30, Main.maxTilesY - 230);
             int num2 = WorldGen.countTiles(x, y, false, false);
             while ((num2 >= 300 || num2 < 50 || WorldGen.lavaCount > 0 || WorldGen.iceCount > 0 || WorldGen.rockCount == 0) && num < 1000)
             {
                 num++;
                 x = WorldGen.genRand.Next(200, Main.maxTilesX - 200);
                 y = WorldGen.genRand.Next((int)Main.rockLayer + 30, Main.maxTilesY - 230);
                 num2 = WorldGen.countTiles(x, y, false, false);
             }
             if (num < 1000)
             {
                 WorldGen.gemCave(x, y);
             }
         }
     });
     WorldGen.AddGenerationPass("Moss", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[61];
         WorldGen.randMoss();
         WorldGen.maxTileCount = 2500;
         for (int k = 0; k < (int)((double)Main.maxTilesX * 0.01); k++)
         {
             float value = (float)((double)k / ((double)Main.maxTilesX * 0.01));
             progress.Set(value);
             int num = 0;
             int x = WorldGen.genRand.Next(200, Main.maxTilesX - 200);
             int y = WorldGen.genRand.Next((int)(Main.worldSurface + Main.rockLayer) / 2, WorldGen.waterLine);
             int num2 = WorldGen.countTiles(x, y, false, false);
             while ((num2 >= 2500 || num2 < 10 || WorldGen.lavaCount > 0 || WorldGen.iceCount > 0 || WorldGen.rockCount == 0) && num < 1000)
             {
                 num++;
                 x = WorldGen.genRand.Next(200, Main.maxTilesX - 200);
                 y = WorldGen.genRand.Next((int)Main.rockLayer + 30, Main.maxTilesY - 230);
                 num2 = WorldGen.countTiles(x, y, false, false);
             }
             if (num < 1000)
             {
                 WorldGen.setMoss(x, y);
                 WorldGen.Spread.Moss(x, y);
             }
         }
         for (int l = 0; l < Main.maxTilesX; l++)
         {
             int num3 = WorldGen.genRand.Next(50, Main.maxTilesX - 50);
             int num4 = WorldGen.genRand.Next((int)(Main.worldSurface + Main.rockLayer) / 2, WorldGen.lavaLine);
             if (Main.tile[num3, num4].type == 1)
             {
                 WorldGen.setMoss(num3, num4);
                 Main.tile[num3, num4].type = (ushort)WorldGen.mossTile;
             }
         }
         float num5 = (float)Main.maxTilesX * 0.05f;
         while (num5 > 0f)
         {
             int num6 = WorldGen.genRand.Next(50, Main.maxTilesX - 50);
             int num7 = WorldGen.genRand.Next((int)(Main.worldSurface + Main.rockLayer) / 2, WorldGen.lavaLine);
             if (Main.tile[num6, num7].type == 1 && (!Main.tile[num6 - 1, num7].active() || !Main.tile[num6 + 1, num7].active() || !Main.tile[num6, num7 - 1].active() || !Main.tile[num6, num7 + 1].active()))
             {
                 WorldGen.setMoss(num6, num7);
                 Main.tile[num6, num7].type = (ushort)WorldGen.mossTile;
                 num5 -= 1f;
             }
         }
         num5 = (float)Main.maxTilesX * 0.065f;
         while (num5 > 0f)
         {
             int num8 = WorldGen.genRand.Next(50, Main.maxTilesX - 50);
             int num9 = WorldGen.genRand.Next(WorldGen.waterLine, Main.maxTilesY - 200);
             if (Main.tile[num8, num9].type == 1 && (!Main.tile[num8 - 1, num9].active() || !Main.tile[num8 + 1, num9].active() || !Main.tile[num8, num9 - 1].active() || !Main.tile[num8, num9 + 1].active()))
             {
                 int num10 = 25;
                 int num11 = 0;
                 for (int m = num8 - num10; m < num8 + num10; m++)
                 {
                     for (int n = num9 - num10; n < num9 + num10; n++)
                     {
                         if (Main.tile[m, n].liquid > 0 && Main.tile[m, n].lava())
                         {
                             num11++;
                         }
                     }
                 }
                 if (num11 > 20)
                 {
                     Main.tile[num8, num9].type = 381;
                     num5 -= 1f;
                 }
                 else
                 {
                     num5 -= 0.002f;
                 }
             }
         }
         for (int num12 = 0; num12 < Main.maxTilesX; num12++)
         {
             for (int num13 = 0; num13 < Main.maxTilesY; num13++)
             {
                 if (Main.tile[num12, num13].active() && Main.tileMoss[(int)Main.tile[num12, num13].type])
                 {
                     for (int num14 = 0; num14 < 4; num14++)
                     {
                         int num15 = num12;
                         int num16 = num13;
                         if (num14 == 0)
                         {
                             num15--;
                         }
                         if (num14 == 1)
                         {
                             num15++;
                         }
                         if (num14 == 2)
                         {
                             num16--;
                         }
                         if (num14 == 3)
                         {
                             num16++;
                         }
                         try
                         {
                             WorldGen.grassSpread = 0;
                             WorldGen.SpreadGrass(num15, num16, 1, (int)Main.tile[num12, num13].type, true, 0);
                         }
                         catch
                         {
                             WorldGen.grassSpread = 0;
                             WorldGen.SpreadGrass(num15, num16, 1, (int)Main.tile[num12, num13].type, false, 0);
                         }
                     }
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Temple", delegate (GenerationProgress progress)
     {
         Main.tileSolid[162] = false;
         Main.tileSolid[226] = true;
         WorldGen.templePart2();
         Main.tileSolid[232] = false;
     });
     WorldGen.AddGenerationPass("Ice Walls", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[63];
         WorldGen.maxTileCount = 1500;
         for (int k = 0; k < (int)((double)Main.maxTilesX * 0.04); k++)
         {
             float num = (float)((double)k / ((double)Main.maxTilesX * 0.04));
             progress.Set(num * 0.66f);
             int num2 = 0;
             int x = WorldGen.genRand.Next(200, Main.maxTilesX - 200);
             int y = WorldGen.genRand.Next((int)(Main.worldSurface + Main.rockLayer) / 2, Main.maxTilesY - 220);
             int num3 = WorldGen.countTiles(x, y, false, true);
             while ((num3 >= 1500 || num3 < 10) && num2 < 500)
             {
                 num2++;
                 x = WorldGen.genRand.Next(200, Main.maxTilesX - 200);
                 y = WorldGen.genRand.Next((int)(Main.worldSurface + Main.rockLayer) / 2, Main.maxTilesY - 220);
                 num3 = WorldGen.countTiles(x, y, false, true);
             }
             if (num2 < 500)
             {
                 int num4 = WorldGen.genRand.Next(2);
                 if (WorldGen.iceCount > 0)
                 {
                     if (num4 == 0)
                     {
                         num4 = 40;
                     }
                     else if (num4 == 1)
                     {
                         num4 = 71;
                     }
                 }
                 else if (WorldGen.lavaCount > 0)
                 {
                     num4 = 79;
                 }
                 else
                 {
                     num4 = WorldGen.genRand.Next(4);
                     if (num4 == 0)
                     {
                         num4 = 59;
                     }
                     else if (num4 == 1)
                     {
                         num4 = 61;
                     }
                     else if (num4 == 2)
                     {
                         num4 = 170;
                     }
                     else if (num4 == 3)
                     {
                         num4 = 171;
                     }
                 }
                 WorldGen.Spread.Wall(x, y, num4);
             }
         }
         WorldGen.maxTileCount = 1500;
         for (int l = 0; l < (int)((double)Main.maxTilesX * 0.02); l++)
         {
             float num5 = (float)((double)l / ((double)Main.maxTilesX * 0.02));
             progress.Set(num5 * 0.34f + 0.66f);
             int num6 = 0;
             int num7 = WorldGen.genRand.Next(200, Main.maxTilesX - 200);
             int num8 = WorldGen.genRand.Next((int)Main.worldSurface, WorldGen.lavaLine);
             int num9 = 0;
             if (Main.tile[num7, num8].wall == 64)
             {
                 num9 = WorldGen.countTiles(num7, num8, true, false);
             }
             while ((num9 >= 1500 || num9 < 10) && num6 < 1000)
             {
                 num6++;
                 num7 = WorldGen.genRand.Next(200, Main.maxTilesX - 200);
                 num8 = WorldGen.genRand.Next((int)Main.worldSurface, WorldGen.lavaLine);
                 if (!Main.wallHouse[(int)Main.tile[num7, num8].wall])
                 {
                     if (Main.tile[num7, num8].wall == 64)
                     {
                         num9 = WorldGen.countTiles(num7, num8, true, false);
                     }
                     else
                     {
                         num9 = 0;
                     }
                 }
             }
             if (num6 < 1000)
             {
                 WorldGen.Spread.Wall2(num7, num8, 15);
             }
         }
     });
     WorldGen.AddGenerationPass("Jungle Trees", delegate (GenerationProgress progress)
     {
         for (int k = 0; k < Main.maxTilesX; k++)
         {
             for (int l = (int)Main.worldSurface - 1; l < Main.maxTilesY - 350; l++)
             {
                 if (WorldGen.genRand.Next(10) == 0)
                 {
                     WorldGen.GrowUndergroundTree(k, l);
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Floating Island Houses", delegate (GenerationProgress progress)
     {
         for (int k = 0; k < WorldGen.numIslandHouses; k++)
         {
             if (!WorldGen.skyLake[k])
             {
                 WorldGen.IslandHouse(WorldGen.fihX[k], WorldGen.fihY[k]);
             }
         }
     });
     WorldGen.AddGenerationPass("Quick Cleanup", delegate (GenerationProgress progress)
     {
         Main.tileSolid[137] = false;
         Main.tileSolid[130] = false;
         for (int k = 20; k < Main.maxTilesX - 20; k++)
         {
             for (int l = 20; l < Main.maxTilesY - 20; l++)
             {
                 if (Main.tile[k, l].type != 19 && TileID.Sets.CanBeClearedDuringGeneration[(int)Main.tile[k, l].type])
                 {
                     if (Main.tile[k, l].topSlope() || Main.tile[k, l].halfBrick())
                     {
                         if (!WorldGen.SolidTile(k, l + 1))
                         {
                             Main.tile[k, l].active(false);
                         }
                         if (Main.tile[k + 1, l].type == 137 || Main.tile[k - 1, l].type == 137)
                         {
                             Main.tile[k, l].active(false);
                         }
                     }
                     else if (Main.tile[k, l].bottomSlope())
                     {
                         if (!WorldGen.SolidTile(k, l - 1))
                         {
                             Main.tile[k, l].active(false);
                         }
                         if (Main.tile[k + 1, l].type == 137 || Main.tile[k - 1, l].type == 137)
                         {
                             Main.tile[k, l].active(false);
                         }
                     }
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Pots", delegate (GenerationProgress progress)
     {
         Main.tileSolid[137] = true;
         Main.tileSolid[130] = true;
         progress.Message = Lang.gen[35];
         for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 0.0008); k++)
         {
             float num = (float)((double)k / ((double)(Main.maxTilesX * Main.maxTilesY) * 0.0008));
             progress.Set(num);
             bool flag2 = false;
             int num2 = 0;
             while (!flag2)
             {
                 int num3 = WorldGen.genRand.Next((int)worldSurfaceHigh, Main.maxTilesY - 10);
                 if ((double)num > 0.93)
                 {
                     num3 = Main.maxTilesY - 150;
                 }
                 else if ((double)num > 0.75)
                 {
                     num3 = (int)WorldGen.worldSurfaceLow;
                 }
                 int num4 = WorldGen.genRand.Next(1, Main.maxTilesX);
                 bool flag3 = false;
                 for (int l = num3; l < Main.maxTilesY; l++)
                 {
                     if (!flag3)
                     {
                         if (Main.tile[num4, l].active() && Main.tileSolid[(int)Main.tile[num4, l].type] && !Main.tile[num4, l - 1].lava())
                         {
                             flag3 = true;
                         }
                     }
                     else
                     {
                         int style = WorldGen.genRand.Next(0, 4);
                         int num5 = 0;
                         if (l < Main.maxTilesY - 5)
                         {
                             num5 = (int)Main.tile[num4, l + 1].type;
                         }
                         if (num5 == 147 || num5 == 161 || num5 == 162)
                         {
                             style = WorldGen.genRand.Next(4, 7);
                         }
                         if (num5 == 60)
                         {
                             style = WorldGen.genRand.Next(7, 10);
                         }
                         if (Main.wallDungeon[(int)Main.tile[num4, l].wall])
                         {
                             style = WorldGen.genRand.Next(10, 13);
                         }
                         if (num5 == 41 || num5 == 43 || num5 == 44)
                         {
                             style = WorldGen.genRand.Next(10, 13);
                         }
                         if (num5 == 22 || num5 == 23 || num5 == 25)
                         {
                             style = WorldGen.genRand.Next(16, 19);
                         }
                         if (num5 == 199 || num5 == 203 || num5 == 204 || num5 == 200)
                         {
                             style = WorldGen.genRand.Next(22, 25);
                         }
                         if (num5 == 367)
                         {
                             style = WorldGen.genRand.Next(31, 34);
                         }
                         if (num5 == 226)
                         {
                             style = WorldGen.genRand.Next(28, 31);
                         }
                         if (l > Main.maxTilesY - 200)
                         {
                             style = WorldGen.genRand.Next(13, 16);
                         }
                         if (WorldGen.PlacePot(num4, l, 28, style))
                         {
                             flag2 = true;
                             break;
                         }
                         num2++;
                         if (num2 >= 10000)
                         {
                             flag2 = true;
                             break;
                         }
                     }
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Hellforge", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[36];
         for (int k = 0; k < Main.maxTilesX / 200; k++)
         {
             float value = (float)(k / (Main.maxTilesX / 200));
             progress.Set(value);
             bool flag2 = false;
             int num = 0;
             while (!flag2)
             {
                 int num2 = WorldGen.genRand.Next(1, Main.maxTilesX);
                 int num3 = WorldGen.genRand.Next(Main.maxTilesY - 250, Main.maxTilesY - 5);
                 try
                 {
                     if (Main.tile[num2, num3].wall != 13)
                     {
                         if (Main.tile[num2, num3].wall != 14)
                         {
                             continue;
                         }
                     }
                     while (!Main.tile[num2, num3].active())
                     {
                         num3++;
                     }
                     num3--;
                     WorldGen.PlaceTile(num2, num3, 77, false, false, -1, 0);
                     if (Main.tile[num2, num3].type == 77)
                     {
                         flag2 = true;
                     }
                     else
                     {
                         num++;
                         if (num >= 10000)
                         {
                             flag2 = true;
                         }
                     }
                 }
                 catch
                 {
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Spreading Grass", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[37];
         for (int k = 0; k < Main.maxTilesX; k++)
         {
             i2 = k;
             bool flag2 = true;
             int num = 0;
             while ((double)num < Main.worldSurface - 1.0)
             {
                 if (Main.tile[i2, num].active())
                 {
                     if (flag2 && Main.tile[i2, num].type == 0)
                     {
                         try
                         {
                             WorldGen.grassSpread = 0;
                             WorldGen.SpreadGrass(i2, num, 0, 2, true, 0);
                         }
                         catch
                         {
                             WorldGen.grassSpread = 0;
                             WorldGen.SpreadGrass(i2, num, 0, 2, false, 0);
                         }
                     }
                     if ((double)num > worldSurfaceHigh)
                     {
                         break;
                     }
                     flag2 = false;
                 }
                 else if (Main.tile[i2, num].wall == 0)
                 {
                     flag2 = true;
                 }
                 num++;
             }
         }
     });
     WorldGen.AddGenerationPass("Piles", delegate (GenerationProgress progress)
     {
         Main.tileSolid[190] = false;
         Main.tileSolid[196] = false;
         Main.tileSolid[189] = false;
         Main.tileSolid[202] = false;
         int num = 0;
         while ((double)num < (double)Main.maxTilesX * 0.06)
         {
             bool flag2 = false;
             while (!flag2)
             {
                 int num2 = WorldGen.genRand.Next(25, Main.maxTilesX - 25);
                 int num3 = WorldGen.genRand.Next((int)Main.worldSurface, Main.maxTilesY - 300);
                 if (!Main.tile[num2, num3].active())
                 {
                     int num4 = 186;
                     while (!Main.tile[num2, num3 + 1].active() && num3 < Main.maxTilesY - 5)
                     {
                         num3++;
                     }
                     int num5 = WorldGen.genRand.Next(22);
                     if (num5 >= 16 && num5 <= 22)
                     {
                         num5 = WorldGen.genRand.Next(22);
                     }
                     if ((Main.tile[num2, num3 + 1].type == 0 || Main.tile[num2, num3 + 1].type == 1 || Main.tileMoss[(int)Main.tile[num2, num3 + 1].type]) && WorldGen.genRand.Next(5) == 0)
                     {
                         num5 = WorldGen.genRand.Next(23, 29);
                         num4 = 187;
                     }
                     if (num3 > Main.maxTilesY - 300 || Main.wallDungeon[(int)Main.tile[num2, num3].wall] || Main.tile[num2, num3 + 1].type == 30 || Main.tile[num2, num3 + 1].type == 19 || Main.tile[num2, num3 + 1].type == 25 || Main.tile[num2, num3 + 1].type == 203)
                     {
                         num5 = WorldGen.genRand.Next(7);
                         num4 = 186;
                     }
                     if (Main.tile[num2, num3 + 1].type == 147 || Main.tile[num2, num3 + 1].type == 161 || Main.tile[num2, num3 + 1].type == 162)
                     {
                         num5 = WorldGen.genRand.Next(26, 32);
                         num4 = 186;
                     }
                     if (Main.tile[num2, num3 + 1].type == 60)
                     {
                         num4 = 187;
                         num5 = WorldGen.genRand.Next(6);
                     }
                     if ((Main.tile[num2, num3 + 1].type == 57 || Main.tile[num2, num3 + 1].type == 58) && WorldGen.genRand.Next(3) < 2)
                     {
                         num4 = 187;
                         num5 = WorldGen.genRand.Next(6, 9);
                     }
                     if (Main.tile[num2, num3 + 1].type == 226)
                     {
                         num4 = 187;
                         num5 = WorldGen.genRand.Next(18, 23);
                     }
                     if (Main.tile[num2, num3 + 1].type == 70)
                     {
                         num5 = WorldGen.genRand.Next(32, 35);
                         num4 = 186;
                     }
                     if (num4 == 186 && num5 >= 7 && num5 <= 15 && WorldGen.genRand.Next(75) == 0)
                     {
                         num4 = 187;
                         num5 = 17;
                     }
                     if (Main.wallDungeon[(int)Main.tile[num2, num3].wall] && WorldGen.genRand.Next(3) != 0)
                     {
                         flag2 = true;
                     }
                     else
                     {
                         WorldGen.PlaceTile(num2, num3, num4, true, false, -1, num5);
                         if (Main.tile[num2, num3].type == 186 || Main.tile[num2, num3].type == 187)
                         {
                             flag2 = true;
                         }
                         if (flag2 && num4 == 186 && num5 <= 7)
                         {
                             int num6 = WorldGen.genRand.Next(1, 5);
                             for (int k = 0; k < num6; k++)
                             {
                                 int num7 = num2 + WorldGen.genRand.Next(-10, 11);
                                 int num8 = num3 - WorldGen.genRand.Next(5);
                                 if (!Main.tile[num7, num8].active())
                                 {
                                     while (!Main.tile[num7, num8 + 1].active() && num8 < Main.maxTilesY - 5)
                                     {
                                         num8++;
                                     }
                                     int x = WorldGen.genRand.Next(12, 36);
                                     WorldGen.PlaceSmallPile(num7, num8, x, 0, 185);
                                 }
                             }
                         }
                     }
                 }
             }
             num++;
         }
         int num9 = 0;
         while ((double)num9 < (double)Main.maxTilesX * 0.01)
         {
             bool flag3 = false;
             while (!flag3)
             {
                 int num10 = WorldGen.genRand.Next(25, Main.maxTilesX - 25);
                 int num11 = WorldGen.genRand.Next(Main.maxTilesY - 300, Main.maxTilesY - 10);
                 if (!Main.tile[num10, num11].active())
                 {
                     int num12 = 186;
                     while (!Main.tile[num10, num11 + 1].active() && num11 < Main.maxTilesY - 5)
                     {
                         num11++;
                     }
                     int num13 = WorldGen.genRand.Next(22);
                     if (num13 >= 16 && num13 <= 22)
                     {
                         num13 = WorldGen.genRand.Next(22);
                     }
                     if (num11 > Main.maxTilesY - 300 || Main.wallDungeon[(int)Main.tile[num10, num11].wall] || Main.tile[num10, num11 + 1].type == 30 || Main.tile[num10, num11 + 1].type == 19)
                     {
                         num13 = WorldGen.genRand.Next(7);
                     }
                     if ((Main.tile[num10, num11 + 1].type == 57 || Main.tile[num10, num11 + 1].type == 58) && WorldGen.genRand.Next(3) < 2)
                     {
                         num12 = 187;
                         num13 = WorldGen.genRand.Next(6, 9);
                     }
                     if (Main.tile[num10, num11 + 1].type == 147 || Main.tile[num10, num11 + 1].type == 161 || Main.tile[num10, num11 + 1].type == 162)
                     {
                         num13 = WorldGen.genRand.Next(26, 32);
                     }
                     WorldGen.PlaceTile(num10, num11, num12, true, false, -1, num13);
                     if (Main.tile[num10, num11].type == 186 || Main.tile[num10, num11].type == 187)
                     {
                         flag3 = true;
                     }
                     if (flag3 && num12 == 186 && num13 <= 7)
                     {
                         int num14 = WorldGen.genRand.Next(1, 5);
                         for (int l = 0; l < num14; l++)
                         {
                             int num15 = num10 + WorldGen.genRand.Next(-10, 11);
                             int num16 = num11 - WorldGen.genRand.Next(5);
                             if (!Main.tile[num15, num16].active())
                             {
                                 while (!Main.tile[num15, num16 + 1].active() && num16 < Main.maxTilesY - 5)
                                 {
                                     num16++;
                                 }
                                 int x2 = WorldGen.genRand.Next(12, 36);
                                 WorldGen.PlaceSmallPile(num15, num16, x2, 0, 185);
                             }
                         }
                     }
                 }
             }
             num9++;
         }
         int num17 = 0;
         while ((double)num17 < (double)Main.maxTilesX * 0.003)
         {
             bool flag4 = false;
             while (!flag4)
             {
                 int num18 = 186;
                 int num19 = WorldGen.genRand.Next(25, Main.maxTilesX - 25);
                 int num20 = WorldGen.genRand.Next(10, (int)Main.worldSurface);
                 if (!Main.tile[num19, num20].active())
                 {
                     while (!Main.tile[num19, num20 + 1].active() && num20 < Main.maxTilesY - 5)
                     {
                         num20++;
                     }
                     int num21 = WorldGen.genRand.Next(7, 13);
                     if (num20 > Main.maxTilesY - 300 || Main.wallDungeon[(int)Main.tile[num19, num20].wall] || Main.tile[num19, num20 + 1].type == 30 || Main.tile[num19, num20 + 1].type == 19 || Main.tile[num19, num20 + 1].type == 53 || Main.tile[num19, num20 + 1].type == 25 || Main.tile[num19, num20 + 1].type == 203)
                     {
                         num21 = -1;
                     }
                     if (Main.tile[num19, num20 + 1].type == 147 || Main.tile[num19, num20 + 1].type == 161 || Main.tile[num19, num20 + 1].type == 162)
                     {
                         num21 = WorldGen.genRand.Next(26, 32);
                     }
                     if (Main.tile[num19, num20 + 1].type == 2 || Main.tile[num19 - 1, num20 + 1].type == 2 || Main.tile[num19 + 1, num20 + 1].type == 2)
                     {
                         num18 = 187;
                         num21 = WorldGen.genRand.Next(14, 17);
                     }
                     if (Main.tile[num19, num20 + 1].type == 151 || Main.tile[num19, num20 + 1].type == 274)
                     {
                         num18 = 186;
                         num21 = WorldGen.genRand.Next(7);
                     }
                     if (num21 >= 0)
                     {
                         WorldGen.PlaceTile(num19, num20, num18, true, false, -1, num21);
                     }
                     if ((int)Main.tile[num19, num20].type == num18)
                     {
                         flag4 = true;
                     }
                 }
             }
             num17++;
         }
         int num22 = 0;
         while ((double)num22 < (double)Main.maxTilesX * 0.0035)
         {
             bool flag5 = false;
             while (!flag5)
             {
                 int num23 = WorldGen.genRand.Next(25, Main.maxTilesX - 25);
                 int num24 = WorldGen.genRand.Next(10, (int)Main.worldSurface);
                 if (!Main.tile[num23, num24].active() && Main.tile[num23, num24].wall > 0)
                 {
                     int num25 = 186;
                     while (!Main.tile[num23, num24 + 1].active() && num24 < Main.maxTilesY - 5)
                     {
                         num24++;
                     }
                     int num26 = WorldGen.genRand.Next(7, 13);
                     if (num24 > Main.maxTilesY - 300 || Main.wallDungeon[(int)Main.tile[num23, num24].wall] || Main.tile[num23, num24 + 1].type == 30 || Main.tile[num23, num24 + 1].type == 19)
                     {
                         num26 = -1;
                     }
                     if (Main.tile[num23, num24 + 1].type == 25)
                     {
                         num26 = WorldGen.genRand.Next(7);
                     }
                     if (Main.tile[num23, num24 + 1].type == 147 || Main.tile[num23, num24 + 1].type == 161 || Main.tile[num23, num24 + 1].type == 162)
                     {
                         num26 = WorldGen.genRand.Next(26, 32);
                     }
                     if (Main.tile[num23, num24 + 1].type == 2 || Main.tile[num23 - 1, num24 + 1].type == 2 || Main.tile[num23 + 1, num24 + 1].type == 2)
                     {
                         num25 = 187;
                         num26 = WorldGen.genRand.Next(14, 17);
                     }
                     if (Main.tile[num23, num24 + 1].type == 151 || Main.tile[num23, num24 + 1].type == 274)
                     {
                         num25 = 186;
                         num26 = WorldGen.genRand.Next(7);
                     }
                     if (num26 >= 0)
                     {
                         WorldGen.PlaceTile(num23, num24, num25, true, false, -1, num26);
                     }
                     if ((int)Main.tile[num23, num24].type == num25)
                     {
                         flag5 = true;
                     }
                     if (flag5 && num26 <= 7)
                     {
                         int num27 = WorldGen.genRand.Next(1, 5);
                         for (int m = 0; m < num27; m++)
                         {
                             int num28 = num23 + WorldGen.genRand.Next(-10, 11);
                             int num29 = num24 - WorldGen.genRand.Next(5);
                             if (!Main.tile[num28, num29].active())
                             {
                                 while (!Main.tile[num28, num29 + 1].active() && num29 < Main.maxTilesY - 5)
                                 {
                                     num29++;
                                 }
                                 int x3 = WorldGen.genRand.Next(12, 36);
                                 WorldGen.PlaceSmallPile(num28, num29, x3, 0, 185);
                             }
                         }
                     }
                 }
             }
             num22++;
         }
         int num30 = 0;
         while ((double)num30 < (double)Main.maxTilesX * 0.6)
         {
             bool flag6 = false;
             while (!flag6)
             {
                 int num31 = WorldGen.genRand.Next(25, Main.maxTilesX - 25);
                 int num32 = WorldGen.genRand.Next((int)Main.worldSurface, Main.maxTilesY - 20);
                 if (Main.tile[num31, num32].wall == 87 && WorldGen.genRand.Next(2) == 0)
                 {
                     num31 = WorldGen.genRand.Next(25, Main.maxTilesX - 25);
                     num32 = WorldGen.genRand.Next((int)Main.worldSurface, Main.maxTilesY - 20);
                 }
                 if (!Main.tile[num31, num32].active())
                 {
                     while (!Main.tile[num31, num32 + 1].active() && num32 < Main.maxTilesY - 5)
                     {
                         num32++;
                     }
                     int num33 = WorldGen.genRand.Next(2);
                     int num34 = WorldGen.genRand.Next(36);
                     if (num34 >= 28 && num34 <= 35)
                     {
                         num34 = WorldGen.genRand.Next(36);
                     }
                     if (num33 == 1)
                     {
                         num34 = WorldGen.genRand.Next(25);
                         if (num34 >= 16 && num34 <= 24)
                         {
                             num34 = WorldGen.genRand.Next(25);
                         }
                     }
                     if (num32 > Main.maxTilesY - 300)
                     {
                         if (num33 == 0)
                         {
                             num34 = WorldGen.genRand.Next(12, 28);
                         }
                         if (num33 == 1)
                         {
                             num34 = WorldGen.genRand.Next(6, 16);
                         }
                     }
                     if (Main.wallDungeon[(int)Main.tile[num31, num32].wall] || Main.tile[num31, num32 + 1].type == 30 || Main.tile[num31, num32 + 1].type == 19 || Main.tile[num31, num32 + 1].type == 25 || Main.tile[num31, num32 + 1].type == 203 || Main.tile[num31, num32].wall == 87)
                     {
                         if (num33 == 0 && num34 < 12)
                         {
                             num34 += 12;
                         }
                         if (num33 == 1 && num34 < 6)
                         {
                             num34 += 6;
                         }
                         if (num33 == 1 && num34 >= 17)
                         {
                             num34 -= 10;
                         }
                     }
                     if (Main.tile[num31, num32 + 1].type == 147 || Main.tile[num31, num32 + 1].type == 161 || Main.tile[num31, num32 + 1].type == 162)
                     {
                         if (num33 == 0 && num34 < 12)
                         {
                             num34 += 36;
                         }
                         if (num33 == 1 && num34 >= 20)
                         {
                             num34 += 6;
                         }
                         if (num33 == 1 && num34 < 6)
                         {
                             num34 += 25;
                         }
                     }
                     if (Main.tile[num31, num32 + 1].type == 151 || Main.tile[num31, num32 + 1].type == 274)
                     {
                         if (num33 == 0)
                         {
                             num34 = WorldGen.genRand.Next(12, 28);
                         }
                         if (num33 == 1)
                         {
                             num34 = WorldGen.genRand.Next(12, 19);
                         }
                     }
                     flag6 = ((Main.wallDungeon[(int)Main.tile[num31, num32].wall] && WorldGen.genRand.Next(3) != 0) || WorldGen.PlaceSmallPile(num31, num32, num34, num33, 185));
                     if (flag6 && num33 == 1 && num34 >= 6 && num34 <= 15)
                     {
                         int num35 = WorldGen.genRand.Next(1, 5);
                         for (int n = 0; n < num35; n++)
                         {
                             int num36 = num31 + WorldGen.genRand.Next(-10, 11);
                             int num37 = num32 - WorldGen.genRand.Next(5);
                             if (!Main.tile[num36, num37].active())
                             {
                                 while (!Main.tile[num36, num37 + 1].active() && num37 < Main.maxTilesY - 5)
                                 {
                                     num37++;
                                 }
                                 int x4 = WorldGen.genRand.Next(12, 36);
                                 WorldGen.PlaceSmallPile(num36, num37, x4, 0, 185);
                             }
                         }
                     }
                 }
             }
             num30++;
         }
         int num38 = 0;
         while ((float)num38 < (float)Main.maxTilesX * 0.02f)
         {
             bool flag7 = false;
             while (!flag7)
             {
                 int num39 = WorldGen.genRand.Next(25, Main.maxTilesX - 25);
                 int num40 = WorldGen.genRand.Next(15, (int)Main.worldSurface);
                 if (!Main.tile[num39, num40].active())
                 {
                     while (!Main.tile[num39, num40 + 1].active() && num40 < Main.maxTilesY - 5)
                     {
                         num40++;
                     }
                     int num41 = WorldGen.genRand.Next(2);
                     int num42 = WorldGen.genRand.Next(11);
                     if (num41 == 1)
                     {
                         num42 = WorldGen.genRand.Next(5);
                     }
                     if (Main.tile[num39, num40 + 1].type == 147 || Main.tile[num39, num40 + 1].type == 161 || Main.tile[num39, num40 + 1].type == 162)
                     {
                         if (num41 == 0 && num42 < 12)
                         {
                             num42 += 36;
                         }
                         if (num41 == 1 && num42 >= 20)
                         {
                             num42 += 6;
                         }
                         if (num41 == 1 && num42 < 6)
                         {
                             num42 += 25;
                         }
                     }
                     if (Main.tile[num39, num40 + 1].type == 2 && num41 == 1)
                     {
                         num42 = WorldGen.genRand.Next(38, 41);
                     }
                     if (Main.tile[num39, num40 + 1].type == 151 || Main.tile[num39, num40 + 1].type == 274)
                     {
                         if (num41 == 0)
                         {
                             num42 = WorldGen.genRand.Next(12, 28);
                         }
                         if (num41 == 1)
                         {
                             num42 = WorldGen.genRand.Next(12, 19);
                         }
                     }
                     if (!Main.wallDungeon[(int)Main.tile[num39, num40].wall] && Main.tile[num39, num40 + 1].type != 30 && Main.tile[num39, num40 + 1].type != 19 && Main.tile[num39, num40 + 1].type != 41 && Main.tile[num39, num40 + 1].type != 43 && Main.tile[num39, num40 + 1].type != 44 && Main.tile[num39, num40 + 1].type != 45 && Main.tile[num39, num40 + 1].type != 46 && Main.tile[num39, num40 + 1].type != 47 && Main.tile[num39, num40 + 1].type != 175 && Main.tile[num39, num40 + 1].type != 176 && Main.tile[num39, num40 + 1].type != 177 && Main.tile[num39, num40 + 1].type != 53 && Main.tile[num39, num40 + 1].type != 25 && Main.tile[num39, num40 + 1].type != 203)
                     {
                         flag7 = WorldGen.PlaceSmallPile(num39, num40, num42, num41, 185);
                     }
                 }
             }
             num38++;
         }
         int num43 = 0;
         while ((float)num43 < (float)Main.maxTilesX * 0.15f)
         {
             bool flag8 = false;
             while (!flag8)
             {
                 int num44 = WorldGen.genRand.Next(25, Main.maxTilesX - 25);
                 int num45 = WorldGen.genRand.Next(15, (int)Main.worldSurface);
                 if (!Main.tile[num44, num45].active())
                 {
                     if (Main.tile[num44, num45].wall != 2)
                     {
                         if (Main.tile[num44, num45].wall != 40)
                         {
                             continue;
                         }
                     }
                     while (!Main.tile[num44, num45 + 1].active() && num45 < Main.maxTilesY - 5)
                     {
                         num45++;
                     }
                     int num46 = WorldGen.genRand.Next(2);
                     int num47 = WorldGen.genRand.Next(11);
                     if (num46 == 1)
                     {
                         num47 = WorldGen.genRand.Next(5);
                     }
                     if (Main.tile[num44, num45 + 1].type == 147 || Main.tile[num44, num45 + 1].type == 161 || Main.tile[num44, num45 + 1].type == 162)
                     {
                         if (num46 == 0 && num47 < 12)
                         {
                             num47 += 36;
                         }
                         if (num46 == 1 && num47 >= 20)
                         {
                             num47 += 6;
                         }
                         if (num46 == 1 && num47 < 6)
                         {
                             num47 += 25;
                         }
                     }
                     if (Main.tile[num44, num45 + 1].type == 2 && num46 == 1)
                     {
                         num47 = WorldGen.genRand.Next(38, 41);
                     }
                     if (Main.tile[num44, num45 + 1].type == 151 || Main.tile[num44, num45 + 1].type == 274)
                     {
                         if (num46 == 0)
                         {
                             num47 = WorldGen.genRand.Next(12, 28);
                         }
                         if (num46 == 1)
                         {
                             num47 = WorldGen.genRand.Next(12, 19);
                         }
                     }
                     if (!Main.wallDungeon[(int)Main.tile[num44, num45].wall] && Main.tile[num44, num45 + 1].type != 30 && Main.tile[num44, num45 + 1].type != 19 && Main.tile[num44, num45 + 1].type != 41 && Main.tile[num44, num45 + 1].type != 43 && Main.tile[num44, num45 + 1].type != 44 && Main.tile[num44, num45 + 1].type != 45 && Main.tile[num44, num45 + 1].type != 46 && Main.tile[num44, num45 + 1].type != 47 && Main.tile[num44, num45 + 1].type != 175 && Main.tile[num44, num45 + 1].type != 176 && Main.tile[num44, num45 + 1].type != 177 && Main.tile[num44, num45 + 1].type != 25 && Main.tile[num44, num45 + 1].type != 203)
                     {
                         flag8 = WorldGen.PlaceSmallPile(num44, num45, num47, num46, 185);
                     }
                 }
             }
             num43++;
         }
         Main.tileSolid[190] = true;
         Main.tileSolid[192] = true;
         Main.tileSolid[196] = true;
         Main.tileSolid[189] = true;
         Main.tileSolid[202] = true;
         Main.tileSolid[225] = true;
     });
     WorldGen.AddGenerationPass("Moss", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[38];
         int num = 8;
         int num2 = 400;
         int num3 = 4;
         int num4 = 275;
         bool flag2;
         int maxValue;
         int num5;
         int num6;
         for (int k = 0; k < 3; k++)
         {
             switch (k)
             {
                 case 0:
                     {
                         num5 = 5;
                         num6 = num4;
                         flag2 = false;
                         maxValue = num3;
                         break;
                     }
                 case 1:
                     {
                         num5 = num2;
                         num6 = Main.maxTilesX - num2;
                         flag2 = true;
                         maxValue = num;
                         break;
                     }
                 case 2:
                     {
                         num5 = Main.maxTilesX - num4;
                         num6 = Main.maxTilesX - 5;
                         flag2 = false;
                         maxValue = num3;
                         break;
                     }
                 default:
                     goto case 0;
             }
             for (int l = num5; l < num6; l++)
             {
                 if (WorldGen.genRand.Next(maxValue) == 0)
                 {
                     int num7 = 0;
                     while ((double)num7 < Main.worldSurface - 1.0)
                     {
                         Tile tile = Main.tile[l, num7];
                         if (tile.active() && tile.type == 53)
                         {
                             Tile tile2 = Main.tile[l, num7 - 1];
                             if (!tile2.active() && tile2.wall == 0)
                             {
                                 if (flag2)
                                 {
                                     WorldGen.PlantCactus(l, num7);
                                     break;
                                 }
                                 if (Main.tile[l, num7 - 2].liquid == 255 && Main.tile[l, num7 - 3].liquid == 255 && Main.tile[l, num7 - 4].liquid == 255)
                                 {
                                     if (WorldGen.genRand.Next(2) == 0)
                                     {
                                         WorldGen.PlaceTile(l, num7 - 1, 81, true, false, -1, 0);
                                         break;
                                     }
                                     WorldGen.PlaceTile(l, num7 - 1, 324, true, false, -1, WorldGen.genRand.Next(2));
                                     break;
                                 }
                                 else if (Main.tile[l, num7 - 2].liquid == 0)
                                 {
                                     WorldGen.PlaceTile(l, num7 - 1, 324, true, false, -1, WorldGen.genRand.Next(2));
                                     break;
                                 }
                             }
                         }
                         num7++;
                     }
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Spawn Point", delegate (GenerationProgress progress)
     {
         int num = 5;
         bool flag2 = true;
         while (flag2)
         {
             int num2 = Main.maxTilesX / 2 + WorldGen.genRand.Next(-num, num + 1);
             for (int k = 0; k < Main.maxTilesY; k++)
             {
                 if (Main.tile[num2, k].active())
                 {
                     Main.spawnTileX = num2;
                     Main.spawnTileY = k;
                     break;
                 }
             }
             flag2 = false;
             num++;
             if ((double)Main.spawnTileY > Main.worldSurface)
             {
                 flag2 = true;
             }
             if (Main.tile[Main.spawnTileX, Main.spawnTileY - 1].liquid > 0)
             {
                 flag2 = true;
             }
         }
         int num3 = 10;
         while ((double)Main.spawnTileY > Main.worldSurface)
         {
             int num4 = WorldGen.genRand.Next(Main.maxTilesX / 2 - num3, Main.maxTilesX / 2 + num3);
             for (int l = 0; l < Main.maxTilesY; l++)
             {
                 if (Main.tile[num4, l].active())
                 {
                     Main.spawnTileX = num4;
                     Main.spawnTileY = l;
                     break;
                 }
             }
             num3++;
         }
     });
     WorldGen.AddGenerationPass("Grass Wall", delegate (GenerationProgress progress)
     {
         WorldGen.maxTileCount = 3500;
         for (int k = 50; k < Main.maxTilesX - 50; k++)
         {
             int num = 0;
             while ((double)num < Main.worldSurface - 10.0)
             {
                 if (WorldGen.genRand.Next(4) == 0)
                 {
                     bool flag2 = false;
                     int num2 = -1;
                     int num3 = -1;
                     if (Main.tile[k, num].active() && Main.tile[k, num].type == 2 && (Main.tile[k, num].wall == 2 || Main.tile[k, num].wall == 63))
                     {
                         for (int l = k - 1; l <= k + 1; l++)
                         {
                             for (int m = num - 1; m <= num + 1; m++)
                             {
                                 if (Main.tile[l, m].wall == 0 && !WorldGen.SolidTile(l, m))
                                 {
                                     flag2 = true;
                                 }
                             }
                         }
                         if (flag2)
                         {
                             for (int n = k - 1; n <= k + 1; n++)
                             {
                                 for (int num4 = num - 1; num4 <= num + 1; num4++)
                                 {
                                     if ((Main.tile[n, num4].wall == 2 || Main.tile[n, num4].wall == 15) && !WorldGen.SolidTile(n, num4))
                                     {
                                         num2 = n;
                                         num3 = num4;
                                     }
                                 }
                             }
                         }
                     }
                     if (flag2 && num2 > -1 && num3 > -1)
                     {
                         int num5 = WorldGen.countDirtTiles(num2, num3);
                         if (num5 < WorldGen.maxTileCount)
                         {
                             try
                             {
                                 WorldGen.Spread.Wall2(num2, num3, 63);
                             }
                             catch
                             {
                             }
                         }
                     }
                 }
                 num++;
             }
         }
         for (int num6 = 5; num6 < Main.maxTilesX - 5; num6++)
         {
             int num7 = 10;
             while ((double)num7 < Main.worldSurface - 1.0)
             {
                 if (Main.tile[num6, num7].wall == 63 && WorldGen.genRand.Next(10) == 0)
                 {
                     Main.tile[num6, num7].wall = 65;
                 }
                 if (Main.tile[num6, num7].active() && Main.tile[num6, num7].type == 0)
                 {
                     bool flag3 = false;
                     for (int num8 = num6 - 1; num8 <= num6 + 1; num8++)
                     {
                         for (int num9 = num7 - 1; num9 <= num7 + 1; num9++)
                         {
                             if (Main.tile[num6, num7].wall == 63 || Main.tile[num6, num7].wall == 65)
                             {
                                 flag3 = true;
                                 break;
                             }
                         }
                     }
                     if (flag3)
                     {
                         WorldGen.SpreadGrass(num6, num7, 0, 2, true, 0);
                     }
                 }
                 num7++;
             }
         }
     });
     WorldGen.AddGenerationPass("Guide", delegate (GenerationProgress progress)
     {
         int num = NPC.NewNPC(Main.spawnTileX * 16, Main.spawnTileY * 16, 22, 0, 0f, 0f, 0f, 0f, 255);
         Main.npc[num].homeTileX = Main.spawnTileX;
         Main.npc[num].homeTileY = Main.spawnTileY;
         Main.npc[num].direction = 1;
         Main.npc[num].homeless = true;
     });
     WorldGen.AddGenerationPass("Sunflowers", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[39];
         int num = 0;
         while ((double)num < (double)Main.maxTilesX * 0.002)
         {
             int arg_22_0 = Main.maxTilesX / 2;
             int num2 = WorldGen.genRand.Next(Main.maxTilesX);
             int num3 = num2 - WorldGen.genRand.Next(10) - 7;
             int num4 = num2 + WorldGen.genRand.Next(10) + 7;
             if (num3 < 0)
             {
                 num3 = 0;
             }
             if (num4 > Main.maxTilesX - 1)
             {
                 num4 = Main.maxTilesX - 1;
             }
             for (int k = num3; k < num4; k++)
             {
                 int num5 = 1;
                 while ((double)num5 < Main.worldSurface - 1.0)
                 {
                     if (Main.tile[k, num5].type == 2 && Main.tile[k, num5].active() && !Main.tile[k, num5 - 1].active())
                     {
                         WorldGen.PlaceTile(k, num5 - 1, 27, true, false, -1, 0);
                     }
                     if (Main.tile[k, num5].active())
                     {
                         break;
                     }
                     num5++;
                 }
             }
             num++;
         }
     });
     WorldGen.AddGenerationPass("Planting Trees", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[40];
         int num = 0;
         while ((double)num < (double)Main.maxTilesX * 0.003)
         {
             int num2 = WorldGen.genRand.Next(50, Main.maxTilesX - 50);
             int num3 = WorldGen.genRand.Next(25, 50);
             for (int k = num2 - num3; k < num2 + num3; k++)
             {
                 int num4 = 20;
                 while ((double)num4 < Main.worldSurface)
                 {
                     WorldGen.GrowEpicTree(k, num4);
                     num4++;
                 }
             }
             num++;
         }
         WorldGen.AddTrees();
     });
     WorldGen.AddGenerationPass("Herbs", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[41];
         int num = 0;
         while ((double)num < (double)Main.maxTilesX * 1.7)
         {
             WorldGen.PlantAlch();
             num++;
         }
     });
     WorldGen.AddGenerationPass("Dye Plants", delegate (GenerationProgress progress)
     {
         for (int k = 0; k < Main.maxTilesX; k++)
         {
             WorldGen.plantDye(WorldGen.genRand.Next(100, Main.maxTilesX - 100), WorldGen.genRand.Next(100, Main.maxTilesY - 200), false);
         }
         for (int l = 0; l < Main.maxTilesX / 8; l++)
         {
             WorldGen.plantDye(WorldGen.genRand.Next(100, Main.maxTilesX - 100), WorldGen.genRand.Next(100, Main.maxTilesY - 200), true);
         }
     });
     WorldGen.AddGenerationPass("Webs And Honey", delegate (GenerationProgress progress)
     {
         for (int k = 100; k < Main.maxTilesX - 100; k++)
         {
             for (int l = (int)Main.worldSurface; l < Main.maxTilesY - 100; l++)
             {
                 if (Main.tile[k, l].wall == 86)
                 {
                     if (Main.tile[k, l].liquid > 0)
                     {
                         Main.tile[k, l].honey(true);
                     }
                     if (WorldGen.genRand.Next(3) == 0)
                     {
                         WorldGen.PlaceTight(k, l, 165, false);
                     }
                 }
                 if (Main.tile[k, l].wall == 62)
                 {
                     Main.tile[k, l].liquid = 0;
                     Main.tile[k, l].lava(false);
                 }
                 if (Main.tile[k, l].wall == 62 && !Main.tile[k, l].active() && WorldGen.genRand.Next(10) != 0)
                 {
                     int num = WorldGen.genRand.Next(2, 5);
                     int num2 = k - num;
                     int num3 = k + num;
                     int num4 = l - num;
                     int num5 = l + num;
                     bool flag2 = false;
                     for (int m = num2; m <= num3; m++)
                     {
                         for (int n = num4; n <= num5; n++)
                         {
                             if (WorldGen.SolidTile(m, n))
                             {
                                 flag2 = true;
                                 break;
                             }
                         }
                     }
                     if (flag2)
                     {
                         WorldGen.PlaceTile(k, l, 51, true, false, -1, 0);
                         WorldGen.TileFrame(k, l, false, false);
                     }
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Weeds", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[42];
         if (Main.halloween)
         {
             for (int k = 40; k < Main.maxTilesX - 40; k++)
             {
                 int num = 50;
                 while ((double)num < Main.worldSurface)
                 {
                     if (Main.tile[k, num].active() && Main.tile[k, num].type == 2 && WorldGen.genRand.Next(15) == 0)
                     {
                         WorldGen.PlacePumpkin(k, num - 1);
                         int num2 = WorldGen.genRand.Next(5);
                         for (int l = 0; l < num2; l++)
                         {
                             WorldGen.GrowPumpkin(k, num - 1, 254);
                         }
                     }
                     num++;
                 }
             }
         }
         WorldGen.AddPlants();
     });
     WorldGen.AddGenerationPass("Mud Caves To Grass", delegate (GenerationProgress progress)
     {
         for (int k = 0; k < Main.maxTilesX; k++)
         {
             for (int l = 0; l < Main.maxTilesY; l++)
             {
                 if (Main.tile[k, l].active())
                 {
                     if (l >= (int)Main.worldSurface && Main.tile[k, l].type == 70 && !Main.tile[k, l - 1].active())
                     {
                         WorldGen.GrowShroom(k, l);
                         if (!Main.tile[k, l - 1].active())
                         {
                             WorldGen.PlaceTile(k, l - 1, 71, true, false, -1, 0);
                         }
                     }
                     if (Main.tile[k, l].type == 60 && !Main.tile[k, l - 1].active())
                     {
                         WorldGen.PlaceTile(k, l - 1, 61, true, false, -1, 0);
                     }
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Jungle Plants", delegate (GenerationProgress progress)
     {
         for (int k = 0; k < Main.maxTilesX * 100; k++)
         {
             int num = WorldGen.genRand.Next(40, Main.maxTilesX / 2 - 40);
             if (dungeonSide < 0)
             {
                 num += Main.maxTilesX / 2;
             }
             int num2 = WorldGen.genRand.Next(Main.maxTilesY - 300);
             while (!Main.tile[num, num2].active() && num2 < Main.maxTilesY - 300)
             {
                 num2++;
             }
             if (Main.tile[num, num2].active() && Main.tile[num, num2].type == 60)
             {
                 num2--;
                 WorldGen.PlaceJunglePlant(num, num2, 233, WorldGen.genRand.Next(8), 0);
                 if (Main.tile[num, num2].type != 233)
                 {
                     WorldGen.PlaceJunglePlant(num, num2, 233, WorldGen.genRand.Next(12), 1);
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Vines", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[43];
         for (int k = 0; k < Main.maxTilesX; k++)
         {
             int num = 0;
             int num2 = 0;
             while ((double)num2 < Main.worldSurface)
             {
                 if (num > 0 && !Main.tile[k, num2].active())
                 {
                     Main.tile[k, num2].active(true);
                     Main.tile[k, num2].type = 52;
                     num--;
                 }
                 else
                 {
                     num = 0;
                 }
                 if (Main.tile[k, num2].active() && !Main.tile[k, num2].bottomSlope() && (Main.tile[k, num2].type == 2 || (Main.tile[k, num2].type == 192 && WorldGen.genRand.Next(4) == 0)) && WorldGen.genRand.Next(5) < 3)
                 {
                     num = WorldGen.genRand.Next(1, 10);
                 }
                 num2++;
             }
             num = 0;
             for (int l = 0; l < Main.maxTilesY; l++)
             {
                 if (num > 0 && !Main.tile[k, l].active())
                 {
                     Main.tile[k, l].active(true);
                     Main.tile[k, l].type = 62;
                     num--;
                 }
                 else
                 {
                     num = 0;
                 }
                 if (Main.tile[k, l].active() && Main.tile[k, l].type == 60 && !Main.tile[k, l].bottomSlope() && WorldGen.genRand.Next(5) < 3)
                 {
                     num = WorldGen.genRand.Next(1, 10);
                 }
             }
             num = 0;
             for (int m = 0; m < Main.maxTilesY; m++)
             {
                 if (num > 0 && !Main.tile[k, m].active())
                 {
                     Main.tile[k, m].active(true);
                     Main.tile[k, m].type = 205;
                     num--;
                 }
                 else
                 {
                     num = 0;
                 }
                 if (Main.tile[k, m].active() && Main.tile[k, m].type == 199 && WorldGen.genRand.Next(5) < 3)
                 {
                     num = WorldGen.genRand.Next(1, 10);
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Flowers", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[44];
         int num = 0;
         while ((double)num < (double)Main.maxTilesX * 0.005)
         {
             int num2 = WorldGen.genRand.Next(20, Main.maxTilesX - 20);
             int num3 = WorldGen.genRand.Next(5, 15);
             int num4 = WorldGen.genRand.Next(15, 30);
             int num5 = 1;
             while ((double)num5 < Main.worldSurface - 1.0)
             {
                 if (Main.tile[num2, num5].active())
                 {
                     for (int k = num2 - num3; k < num2 + num3; k++)
                     {
                         for (int l = num5 - num4; l < num5 + num4; l++)
                         {
                             if (Main.tile[k, l].type == 3 || Main.tile[k, l].type == 24)
                             {
                                 Main.tile[k, l].frameX = (short)(WorldGen.genRand.Next(6, 8) * 18);
                                 if (Main.tile[k, l].type == 3 && WorldGen.genRand.Next(2) == 0)
                                 {
                                     Main.tile[k, l].frameX = (short)(WorldGen.genRand.Next(9, 11) * 18);
                                 }
                             }
                         }
                     }
                     break;
                 }
                 num5++;
             }
             num++;
         }
     });
     WorldGen.AddGenerationPass("Mushrooms", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[45];
         int num = 0;
         while ((double)num < (double)Main.maxTilesX * 0.002)
         {
             int num2 = WorldGen.genRand.Next(20, Main.maxTilesX - 20);
             int num3 = WorldGen.genRand.Next(4, 10);
             int num4 = WorldGen.genRand.Next(15, 30);
             int num5 = 1;
             while ((double)num5 < Main.worldSurface - 1.0)
             {
                 if (Main.tile[num2, num5].active())
                 {
                     for (int k = num2 - num3; k < num2 + num3; k++)
                     {
                         for (int l = num5 - num4; l < num5 + num4; l++)
                         {
                             if (Main.tile[k, l].type == 3 || Main.tile[k, l].type == 24)
                             {
                                 Main.tile[k, l].frameX = 144;
                             }
                             else if (Main.tile[k, l].type == 201)
                             {
                                 Main.tile[k, l].frameX = 270;
                             }
                         }
                     }
                     break;
                 }
                 num5++;
             }
             num++;
         }
     });
     WorldGen.AddGenerationPass("Stalac", delegate (GenerationProgress progress)
     {
         for (int k = 20; k < Main.maxTilesX - 20; k++)
         {
             for (int l = (int)Main.worldSurface; l < Main.maxTilesY - 20; l++)
             {
                 if (!Main.tile[k, l].active() && WorldGen.genRand.Next(5) == 0)
                 {
                     if ((Main.tile[k, l - 1].type == 1 || Main.tile[k, l - 1].type == 147 || Main.tile[k, l - 1].type == 161 || Main.tile[k, l - 1].type == 25 || Main.tile[k, l - 1].type == 203 || Main.tileStone[(int)Main.tile[k, l - 1].type] || Main.tileMoss[(int)Main.tile[k, l - 1].type]) && !Main.tile[k, l].active() && !Main.tile[k, l + 1].active())
                     {
                         Main.tile[k, l - 1].slope(0);
                     }
                     if ((Main.tile[k, l + 1].type == 1 || Main.tile[k, l + 1].type == 147 || Main.tile[k, l + 1].type == 161 || Main.tile[k, l + 1].type == 25 || Main.tile[k, l + 1].type == 203 || Main.tileStone[(int)Main.tile[k, l + 1].type] || Main.tileMoss[(int)Main.tile[k, l + 1].type]) && !Main.tile[k, l].active() && !Main.tile[k, l - 1].active())
                     {
                         Main.tile[k, l + 1].slope(0);
                     }
                     WorldGen.PlaceTight(k, l, 165, false);
                 }
             }
             for (int m = 5; m < (int)Main.worldSurface; m++)
             {
                 if ((Main.tile[k, m - 1].type == 147 || Main.tile[k, m - 1].type == 161) && WorldGen.genRand.Next(5) == 0)
                 {
                     if (!Main.tile[k, m].active() && !Main.tile[k, m + 1].active())
                     {
                         Main.tile[k, m - 1].slope(0);
                     }
                     WorldGen.PlaceTight(k, m, 165, false);
                 }
                 if ((Main.tile[k, m - 1].type == 25 || Main.tile[k, m - 1].type == 203) && WorldGen.genRand.Next(5) == 0)
                 {
                     if (!Main.tile[k, m].active() && !Main.tile[k, m + 1].active())
                     {
                         Main.tile[k, m - 1].slope(0);
                     }
                     WorldGen.PlaceTight(k, m, 165, false);
                 }
                 if ((Main.tile[k, m + 1].type == 25 || Main.tile[k, m + 1].type == 203) && WorldGen.genRand.Next(5) == 0)
                 {
                     if (!Main.tile[k, m].active() && !Main.tile[k, m - 1].active())
                     {
                         Main.tile[k, m + 1].slope(0);
                     }
                     WorldGen.PlaceTight(k, m, 165, false);
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Gems In Ice Biome", delegate (GenerationProgress progress)
     {
         int num = 0;
         while ((double)num < (double)Main.maxTilesX * 0.25)
         {
             int num2 = WorldGen.genRand.Next((int)(Main.worldSurface + Main.rockLayer) / 2, WorldGen.lavaLine);
             int num3 = WorldGen.genRand.Next(snowMinX[num2], snowMaxX[num2]);
             if (Main.tile[num3, num2].active() && (Main.tile[num3, num2].type == 147 || Main.tile[num3, num2].type == 161 || Main.tile[num3, num2].type == 162 || Main.tile[num3, num2].type == 224))
             {
                 int num4 = WorldGen.genRand.Next(1, 4);
                 int num5 = WorldGen.genRand.Next(1, 4);
                 int num6 = WorldGen.genRand.Next(1, 4);
                 int num7 = WorldGen.genRand.Next(1, 4);
                 int num8 = WorldGen.genRand.Next(12);
                 int style;
                 if (num8 < 3)
                 {
                     style = 0;
                 }
                 else if (num8 < 6)
                 {
                     style = 1;
                 }
                 else if (num8 < 8)
                 {
                     style = 2;
                 }
                 else if (num8 < 10)
                 {
                     style = 3;
                 }
                 else if (num8 < 11)
                 {
                     style = 4;
                 }
                 else
                 {
                     style = 5;
                 }
                 for (int k = num3 - num4; k < num3 + num5; k++)
                 {
                     for (int l = num2 - num6; l < num2 + num7; l++)
                     {
                         if (!Main.tile[k, l].active())
                         {
                             WorldGen.PlaceTile(k, l, 178, true, false, -1, style);
                         }
                     }
                 }
             }
             num++;
         }
     });
     WorldGen.AddGenerationPass("Random Gems", delegate (GenerationProgress progress)
     {
         for (int k = 0; k < Main.maxTilesX; k++)
         {
             int num = WorldGen.genRand.Next(20, Main.maxTilesX - 20);
             int num2 = WorldGen.genRand.Next((int)Main.rockLayer, Main.maxTilesY - 300);
             if (!Main.tile[num, num2].active() && !Main.tile[num, num2].lava() && !Main.wallDungeon[(int)Main.tile[num, num2].wall] && Main.tile[num, num2].wall != 27)
             {
                 int num3 = WorldGen.genRand.Next(12);
                 int style;
                 if (num3 < 3)
                 {
                     style = 0;
                 }
                 else if (num3 < 6)
                 {
                     style = 1;
                 }
                 else if (num3 < 8)
                 {
                     style = 2;
                 }
                 else if (num3 < 10)
                 {
                     style = 3;
                 }
                 else if (num3 < 11)
                 {
                     style = 4;
                 }
                 else
                 {
                     style = 5;
                 }
                 WorldGen.PlaceTile(num, num2, 178, true, false, -1, style);
             }
         }
     });
     WorldGen.AddGenerationPass("Moss Grass", delegate (GenerationProgress progress)
     {
         for (int k = 5; k < Main.maxTilesX - 5; k++)
         {
             for (int l = 5; l < Main.maxTilesY - 5; l++)
             {
                 if (Main.tile[k, l].active() && Main.tileMoss[(int)Main.tile[k, l].type])
                 {
                     for (int m = 0; m < 4; m++)
                     {
                         int num = k;
                         int num2 = l;
                         if (m == 0)
                         {
                             num--;
                         }
                         if (m == 1)
                         {
                             num++;
                         }
                         if (m == 2)
                         {
                             num2--;
                         }
                         if (m == 3)
                         {
                             num2++;
                         }
                         if (!Main.tile[num, num2].active())
                         {
                             WorldGen.PlaceTile(num, num2, 184, true, false, -1, 0);
                         }
                     }
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Muds Walls In Jungle", delegate (GenerationProgress progress)
     {
         int num = 0;
         int num2 = 0;
         bool flag2 = false;
         for (int k = 5; k < Main.maxTilesX - 5; k++)
         {
             int num3 = 0;
             while ((double)num3 < Main.worldSurface + 20.0)
             {
                 if (Main.tile[k, num3].active() && Main.tile[k, num3].type == 60)
                 {
                     num = k;
                     flag2 = true;
                     break;
                 }
                 num3++;
             }
             if (flag2)
             {
                 break;
             }
         }
         flag2 = false;
         for (int l = Main.maxTilesX - 5; l > 5; l--)
         {
             int num4 = 0;
             while ((double)num4 < Main.worldSurface + 20.0)
             {
                 if (Main.tile[l, num4].active() && Main.tile[l, num4].type == 60)
                 {
                     num2 = l;
                     flag2 = true;
                     break;
                 }
                 num4++;
             }
             if (flag2)
             {
                 break;
             }
         }
         for (int m = num; m <= num2; m++)
         {
             int num5 = 0;
             while ((double)num5 < Main.worldSurface + 20.0)
             {
                 if (((m >= num + 2 && m <= num2 - 2) || WorldGen.genRand.Next(2) != 0) && ((m >= num + 3 && m <= num2 - 3) || WorldGen.genRand.Next(3) != 0) && (Main.tile[m, num5].wall == 2 || Main.tile[m, num5].wall == 59))
                 {
                     Main.tile[m, num5].wall = 15;
                 }
                 num5++;
             }
         }
     });
     WorldGen.AddGenerationPass("Larva", delegate (GenerationProgress progress)
     {
         for (int k = 0; k < WorldGen.numLarva; k++)
         {
             int num = WorldGen.larvaX[k];
             int num2 = WorldGen.larvaY[k];
             for (int l = num - 1; l <= num + 1; l++)
             {
                 for (int m = num2 - 2; m <= num2 + 1; m++)
                 {
                     if (m != num2 + 1)
                     {
                         Main.tile[l, m].active(false);
                     }
                     else
                     {
                         Main.tile[l, m].active(true);
                         Main.tile[l, m].type = 225;
                         Main.tile[l, m].slope(0);
                         Main.tile[l, m].halfBrick(false);
                     }
                 }
             }
             WorldGen.PlaceTile(num, num2, 231, true, false, -1, 0);
         }
         Main.tileSolid[232] = true;
         Main.tileSolid[162] = true;
     });
     WorldGen.AddGenerationPass("Tile Cleanup", delegate (GenerationProgress progress)
     {
         for (int k = 40; k < Main.maxTilesX - 40; k++)
         {
             for (int l = 40; l < Main.maxTilesY - 40; l++)
             {
                 if (!Main.tile[k, l].active() && Main.tile[k, l].liquid == 0 && WorldGen.genRand.Next(3) != 0 && WorldGen.SolidTile(k, l - 1))
                 {
                     int num = WorldGen.genRand.Next(15, 21);
                     for (int m = l - 2; m >= l - num; m--)
                     {
                         if (Main.tile[k, m].liquid >= 128)
                         {
                             int num2 = 373;
                             if (Main.tile[k, m].lava())
                             {
                                 num2 = 374;
                             }
                             else if (Main.tile[k, m].honey())
                             {
                                 num2 = 375;
                             }
                             int maxValue = l - m;
                             if (WorldGen.genRand.Next(maxValue) <= 1)
                             {
                                 Main.tile[k, l].type = (ushort)num2;
                                 Main.tile[k, l].frameX = 0;
                                 Main.tile[k, l].frameY = 0;
                                 Main.tile[k, l].active(true);
                                 break;
                             }
                         }
                     }
                     if (!Main.tile[k, l].active())
                     {
                         num = WorldGen.genRand.Next(3, 11);
                         for (int n = l + 1; n <= l + num; n++)
                         {
                             if (Main.tile[k, n].liquid >= 200)
                             {
                                 int num3 = 373;
                                 if (Main.tile[k, n].lava())
                                 {
                                     num3 = 374;
                                 }
                                 else if (Main.tile[k, n].honey())
                                 {
                                     num3 = 375;
                                 }
                                 int num4 = n - l;
                                 if (WorldGen.genRand.Next(num4 * 3) <= 1)
                                 {
                                     Main.tile[k, l].type = (ushort)num3;
                                     Main.tile[k, l].frameX = 0;
                                     Main.tile[k, l].frameY = 0;
                                     Main.tile[k, l].active(true);
                                     break;
                                 }
                             }
                         }
                     }
                 }
                 if (Main.tile[k, l].type == 137)
                 {
                     if (Main.tile[k, l].frameY <= 52)
                     {
                         int num5 = -1;
                         if (Main.tile[k, l].frameX >= 18)
                         {
                             num5 = 1;
                         }
                         if (Main.tile[k + num5, l].halfBrick() || Main.tile[k + num5, l].slope() != 0)
                         {
                             Main.tile[k + num5, l].active(false);
                         }
                     }
                 }
                 else if (Main.tile[k, l].type == 162 && Main.tile[k, l + 1].liquid == 0)
                 {
                     Main.tile[k, l].active(false);
                 }
                 if (Main.tile[k, l].wall == 13 || Main.tile[k, l].wall == 14)
                 {
                     Main.tile[k, l].liquid = 0;
                 }
                 if (Main.tile[k, l].type == 31)
                 {
                     int num6 = (int)(Main.tile[k, l].frameX / 18);
                     int num7 = 0;
                     int num8 = k;
                     num7 += num6 / 2;
                     num7 = (WorldGen.crimson ? 1 : 0);
                     num6 %= 2;
                     num8 -= num6;
                     int num9 = (int)(Main.tile[k, l].frameY / 18);
                     int num10 = 0;
                     int num11 = l;
                     num10 += num9 / 2;
                     num9 %= 2;
                     num11 -= num9;
                     for (int num12 = 0; num12 < 2; num12++)
                     {
                         for (int num13 = 0; num13 < 2; num13++)
                         {
                             int num14 = num8 + num12;
                             int num15 = num11 + num13;
                             Main.tile[num14, num15].active(true);
                             Main.tile[num14, num15].slope(0);
                             Main.tile[num14, num15].halfBrick(false);
                             Main.tile[num14, num15].type = 31;
                             Main.tile[num14, num15].frameX = (short)(num12 * 18 + 36 * num7);
                             Main.tile[num14, num15].frameY = (short)(num13 * 18 + 36 * num10);
                         }
                     }
                 }
                 if (Main.tile[k, l].type == 12)
                 {
                     int num16 = (int)(Main.tile[k, l].frameX / 18);
                     int num17 = 0;
                     int num18 = k;
                     num17 += num16 / 2;
                     num16 %= 2;
                     num18 -= num16;
                     int num19 = (int)(Main.tile[k, l].frameY / 18);
                     int num20 = 0;
                     int num21 = l;
                     num20 += num19 / 2;
                     num19 %= 2;
                     num21 -= num19;
                     for (int num22 = 0; num22 < 2; num22++)
                     {
                         for (int num23 = 0; num23 < 2; num23++)
                         {
                             int num24 = num18 + num22;
                             int num25 = num21 + num23;
                             Main.tile[num24, num25].active(true);
                             Main.tile[num24, num25].slope(0);
                             Main.tile[num24, num25].halfBrick(false);
                             Main.tile[num24, num25].type = 12;
                             Main.tile[num24, num25].frameX = (short)(num22 * 18 + 36 * num17);
                             Main.tile[num24, num25].frameY = (short)(num23 * 18 + 36 * num20);
                         }
                         if (!Main.tile[num22, l + 2].active())
                         {
                             Main.tile[num22, l + 2].active(true);
                             if (!Main.tileSolid[(int)Main.tile[num22, l + 2].type] || Main.tileSolidTop[(int)Main.tile[num22, l + 2].type])
                             {
                                 Main.tile[num22, l + 2].type = 0;
                             }
                         }
                         Main.tile[num22, l + 2].slope(0);
                         Main.tile[num22, l + 2].halfBrick(false);
                     }
                 }
                 if (Main.tile[k, l].type == 21)
                 {
                     int num26 = (int)(Main.tile[k, l].frameX / 18);
                     int num27 = 0;
                     int num28 = k;
                     int num29 = l - (int)(Main.tile[k, l].frameY / 18);
                     while (num26 >= 2)
                     {
                         num27++;
                         num26 -= 2;
                     }
                     num28 -= num26;
                     for (int num30 = 0; num30 < 2; num30++)
                     {
                         for (int num31 = 0; num31 < 2; num31++)
                         {
                             int num32 = num28 + num30;
                             int num33 = num29 + num31;
                             Main.tile[num32, num33].active(true);
                             Main.tile[num32, num33].slope(0);
                             Main.tile[num32, num33].halfBrick(false);
                             Main.tile[num32, num33].type = 21;
                             Main.tile[num32, num33].frameX = (short)(num30 * 18 + 36 * num27);
                             Main.tile[num32, num33].frameY = (short)(num31 * 18);
                         }
                         if (!Main.tile[num30, l + 2].active())
                         {
                             Main.tile[num30, l + 2].active(true);
                             if (!Main.tileSolid[(int)Main.tile[num30, l + 2].type] || Main.tileSolidTop[(int)Main.tile[num30, l + 2].type])
                             {
                                 Main.tile[num30, l + 2].type = 0;
                             }
                         }
                         Main.tile[num30, l + 2].slope(0);
                         Main.tile[num30, l + 2].halfBrick(false);
                     }
                 }
                 if (Main.tile[k, l].type == 28)
                 {
                     int num34 = (int)(Main.tile[k, l].frameX / 18);
                     int num35 = 0;
                     int num36 = k;
                     while (num34 >= 2)
                     {
                         num35++;
                         num34 -= 2;
                     }
                     num36 -= num34;
                     int num37 = (int)(Main.tile[k, l].frameY / 18);
                     int num38 = 0;
                     int num39 = l;
                     while (num37 >= 2)
                     {
                         num38++;
                         num37 -= 2;
                     }
                     num39 -= num37;
                     for (int num40 = 0; num40 < 2; num40++)
                     {
                         for (int num41 = 0; num41 < 2; num41++)
                         {
                             int num42 = num36 + num40;
                             int num43 = num39 + num41;
                             Main.tile[num42, num43].active(true);
                             Main.tile[num42, num43].slope(0);
                             Main.tile[num42, num43].halfBrick(false);
                             Main.tile[num42, num43].type = 28;
                             Main.tile[num42, num43].frameX = (short)(num40 * 18 + 36 * num35);
                             Main.tile[num42, num43].frameY = (short)(num41 * 18 + 36 * num38);
                         }
                         if (!Main.tile[num40, l + 2].active())
                         {
                             Main.tile[num40, l + 2].active(true);
                             if (!Main.tileSolid[(int)Main.tile[num40, l + 2].type] || Main.tileSolidTop[(int)Main.tile[num40, l + 2].type])
                             {
                                 Main.tile[num40, l + 2].type = 0;
                             }
                         }
                         Main.tile[num40, l + 2].slope(0);
                         Main.tile[num40, l + 2].halfBrick(false);
                     }
                 }
                 if (Main.tile[k, l].type == 26)
                 {
                     int num44 = (int)(Main.tile[k, l].frameX / 18);
                     int num45 = 0;
                     int num46 = k;
                     int num47 = l - (int)(Main.tile[k, l].frameY / 18);
                     while (num44 >= 3)
                     {
                         num45++;
                         num44 -= 3;
                     }
                     num46 -= num44;
                     for (int num48 = 0; num48 < 3; num48++)
                     {
                         for (int num49 = 0; num49 < 2; num49++)
                         {
                             int num50 = num46 + num48;
                             int num51 = num47 + num49;
                             Main.tile[num50, num51].active(true);
                             Main.tile[num50, num51].slope(0);
                             Main.tile[num50, num51].halfBrick(false);
                             Main.tile[num50, num51].type = 26;
                             Main.tile[num50, num51].frameX = (short)(num48 * 18 + 54 * num45);
                             Main.tile[num50, num51].frameY = (short)(num49 * 18);
                         }
                         if (!Main.tile[num46 + num48, num47 + 2].active() || !Main.tileSolid[(int)Main.tile[num46 + num48, num47 + 2].type] || Main.tileSolidTop[(int)Main.tile[num46 + num48, num47 + 2].type])
                         {
                             Main.tile[num46 + num48, num47 + 2].active(true);
                             if (!Main.tileSolid[(int)Main.tile[num46 + num48, num47 + 2].type] || Main.tileSolidTop[(int)Main.tile[num46 + num48, num47 + 2].type])
                             {
                                 Main.tile[num46 + num48, num47 + 2].type = 0;
                             }
                             if (Main.tile[num46 + num48, num47 + 2].slope() > 0 || Main.tile[num46 + num48, num47 + 2].halfBrick())
                             {
                                 Main.tile[num46 + num48, num47 + 2].halfBrick(false);
                                 Main.tile[num46 + num48, num47 + 2].slope(0);
                             }
                         }
                         Main.tile[num46 + num48, num47 + 2].slope(0);
                         Main.tile[num46 + num48, num47 + 2].halfBrick(false);
                     }
                 }
             }
         }
     });
     WorldGen.AddGenerationPass("Lihzahrd Altars", delegate (GenerationProgress progress)
     {
         int num = WorldGen.lAltarX;
         int num2 = WorldGen.lAltarY;
         for (int k = 0; k <= 2; k++)
         {
             for (int l = 0; l <= 1; l++)
             {
                 int num3 = num + k;
                 int num4 = num2 + l;
                 Main.tile[num3, num4].active(true);
                 Main.tile[num3, num4].type = 237;
                 Main.tile[num3, num4].frameX = (short)(k * 18);
                 Main.tile[num3, num4].frameY = (short)(l * 18);
             }
             Main.tile[k, num2 + 2].active(true);
             Main.tile[k, num2 + 2].slope(0);
             Main.tile[k, num2 + 2].halfBrick(false);
             Main.tile[k, num2 + 2].type = 226;
         }
     });
     WorldGen.AddGenerationPass("Micro Biomes", delegate (GenerationProgress progress)
     {
         progress.Message = Lang.gen[76];
         float num = (float)(Main.maxTilesX * Main.maxTilesY) / 5040000f;
         float num2 = (float)Main.maxTilesX / 4200f;
         int num3 = (int)((float)WorldGen.genRand.Next(3, 6) * num);
         int k = 0;
         while (k < num3)
         {
             if (Biomes<ThinIceBiome>.Place(WorldGen.RandomWorldPoint((int)Main.worldSurface + 20, 50, 200, 50), structures))
             {
                 k++;
             }
         }
         progress.Set(0.1f);
         int num4 = (int)Math.Ceiling((double)num);
         int l = 0;
         while (l < num4)
         {
             Point origin;
             origin.Y = (int)worldSurface + WorldGen.genRand.Next(50, 100);
             if (WorldGen.genRand.Next(2) == 0)
             {
                 origin.X = WorldGen.genRand.Next(50, (int)((float)Main.maxTilesX * 0.3f));
             }
             else
             {
                 origin.X = WorldGen.genRand.Next((int)((float)Main.maxTilesX * 0.7f), Main.maxTilesX - 50);
             }
             if (Biomes<EnchantedSwordBiome>.Place(origin, structures))
             {
                 l++;
             }
         }
         progress.Set(0.2f);
         int num5 = (int)((float)WorldGen.genRand.Next(6, 12) * num);
         int m = 0;
         while (m < num5)
         {
             if (Biomes<CampsiteBiome>.Place(WorldGen.RandomWorldPoint((int)Main.worldSurface, 50, 200, 50), structures))
             {
                 m++;
             }
         }
         int num6 = (int)((float)WorldGen.genRand.Next(14, 30) * num);
         int n = 0;
         while (n < num6)
         {
             if (Biomes<MiningExplosivesBiome>.Place(WorldGen.RandomWorldPoint((int)rockLayer, 50, 200, 50), structures))
             {
                 n++;
             }
         }
         progress.Set(0.3f);
         int num7 = (int)((float)WorldGen.genRand.Next(6, 12) * num2);
         int num8 = 0;
         int num9 = 0;
         while (num8 < num7 && num9 < 20000)
         {
             if (Biomes<MahoganyTreeBiome>.Place(WorldGen.RandomWorldPoint((int)Main.worldSurface + 50, 50, 500, 50), structures))
             {
                 num8++;
             }
             num9++;
         }
         progress.Set(0.4f);
         if (!WorldGen.crimson)
         {
             int num10 = (int)((float)WorldGen.genRand.Next(1, 3) * num);
             int num11 = 0;
             while (num11 < num10)
             {
                 if (Biomes<CorruptionPitBiome>.Place(WorldGen.RandomWorldPoint((int)Main.worldSurface, 50, 500, 50), structures))
                 {
                     num11++;
                 }
             }
         }
         TrackGenerator.Run((int)(10f * num), (int)(num * 25f) + 250);
         progress.Set(1f);
     });
     WorldGen.AddGenerationPass("Final Cleanup", delegate (GenerationProgress progress)
     {
         for (int k = 0; k < Main.maxTilesX; k++)
         {
             for (int l = 0; l < Main.maxTilesY; l++)
             {
                 if (Main.tile[k, l].active() && (!WorldGen.SolidTile(k, l + 1) || !WorldGen.SolidTile(k, l + 2)))
                 {
                     ushort type = Main.tile[k, l].type;
                     if (type <= 112)
                     {
                         if (type != 53)
                         {
                             if (type == 112)
                             {
                                 Main.tile[k, l].type = 398;
                             }
                         }
                         else
                         {
                             Main.tile[k, l].type = 397;
                         }
                     }
                     else if (type != 123)
                     {
                         if (type != 224)
                         {
                             if (type == 234)
                             {
                                 Main.tile[k, l].type = 399;
                             }
                         }
                         else
                         {
                             Main.tile[k, l].type = 147;
                         }
                     }
                     else
                     {
                         Main.tile[k, l].type = 1;
                     }
                 }
             }
         }
         WorldGen.noTileActions = false;
         WorldGen.gen = false;
         Main.AnglerQuestSwap();
     });
     WorldGen._generator.GenerateWorld(customProgressObject);
     Main.WorldFileMetadata = FileMetadata.FromCurrentSettings(FileType.World);
 }
Ejemplo n.º 20
0
 public abstract void Apply(GenerationProgress progress);
        public void End()
        {
            GenerationProgress currentPassWeight = this;

            currentPassWeight._totalProgress = currentPassWeight._totalProgress + this.CurrentPassWeight;
        }
Ejemplo n.º 22
0
 public override void Apply(GenerationProgress progress)
 {
     this._method(progress);
 }