Exemplo n.º 1
0
 public override bool Place(Point origin, StructureMap structures)
 {
     Dictionary<ushort, int> nums = new Dictionary<ushort, int>();
     Point point = new Point(origin.X - 25, origin.Y - 25);
     Shapes.Rectangle rectangle = new Shapes.Rectangle(50, 50);
     ushort[] numArray = new ushort[] { 0, 59, 147, 1 };
     WorldUtils.Gen(point, rectangle, (new Actions.TileScanner(numArray)).Output(nums));
     int item = nums[0] + nums[1];
     int num = nums[59];
     int item1 = nums[147];
     if (item1 <= num || item1 <= item)
     {
         return false;
     }
     int num1 = 0;
     for (int i = GenBase._random.Next(10, 15); i > 5; i--)
     {
         int num2 = GenBase._random.Next(-5, 5);
         Point point1 = new Point(origin.X + num2, origin.Y + num1);
         Shapes.Circle circle = new Shapes.Circle(i);
         GenAction[] blotch = new GenAction[] { new Modifiers.Blotches(4, 0.3), null, null };
         ushort[] numArray1 = new ushort[] { 147, 161, 224, 0, 1 };
         blotch[1] = new Modifiers.OnlyTiles(numArray1);
         blotch[2] = new Actions.SetTile(162, true, true);
         WorldUtils.Gen(point1, circle, Actions.Chain(blotch));
         Point point2 = new Point(origin.X + num2, origin.Y + num1);
         Shapes.Circle circle1 = new Shapes.Circle(i);
         GenAction[] genActionArray = new GenAction[] { new Modifiers.Blotches(4, 0.3), new Modifiers.HasLiquid(-1, -1), new Actions.SetTile(162, true, true), new Actions.SetLiquid(0, 0) };
         WorldUtils.Gen(point2, circle1, Actions.Chain(genActionArray));
         num1 = num1 + (i - 2);
     }
     return true;
 }
Exemplo n.º 2
0
        public override bool Place(Point origin, StructureMap structures)
        {
            if (GenBase._tiles[origin.X, origin.Y].active() && WorldGen.SolidTile(origin.X, origin.Y))
                return false;

            Point result;
            if (!WorldUtils.Find(origin, Searches.Chain(new Searches.Down(80), new Conditions.IsSolid()), out result))
                return false;

            result.Y += 2;
            Ref<int> count = new Ref<int>(0);
            WorldUtils.Gen(result, new Shapes.Circle(8), Actions.Chain(new Modifiers.IsSolid(), new Actions.Scanner(count)));
            if (count.Value < 20 || !structures.CanPlace(new Microsoft.Xna.Framework.Rectangle(result.X - 8, result.Y - 8, 16, 16), 0))
                return false;

            WorldUtils.Gen(result, new Shapes.Circle(8), Actions.Chain(new Modifiers.RadialDither(0.0f, 10f), new Modifiers.IsSolid(), new Actions.SetTile(229, true, true)));
            ShapeData data = new ShapeData();
            WorldUtils.Gen(result, new Shapes.Circle(4, 3), Actions.Chain(new Modifiers.Blotches(2, 0.3), new Modifiers.IsSolid(), new Actions.ClearTile(true),
                new Modifiers.RectangleMask(-6, 6, 0, 3).Output(data), new Actions.SetLiquid(2, byte.MaxValue)));
            WorldUtils.Gen(new Point(result.X, result.Y + 1), new ModShapes.InnerOutline(data, true), Actions.Chain(new Modifiers.IsEmpty(), new Modifiers.RectangleMask(-6, 6, 1, 3),
                new Actions.SetTile(59, true, true)));

            structures.AddStructure(new Microsoft.Xna.Framework.Rectangle(result.X - 8, result.Y - 8, 16, 16), 0);
            return true;
        }
Exemplo n.º 3
0
        public override bool Place(Point origin, StructureMap structures)
        {
            Ref<int> count1 = new Ref<int>(0);
            Ref<int> count2 = new Ref<int>(0);
            WorldUtils.Gen(origin, new Shapes.Circle(10), Actions.Chain(new Actions.Scanner(count2), new Modifiers.IsSolid(), new Actions.Scanner(count1)));
            if (count1.Value < count2.Value - 5)
                return false;

            int radius = GenBase._random.Next(6, 10);
            int num1 = GenBase._random.Next(5);
            if (!structures.CanPlace(new Microsoft.Xna.Framework.Rectangle(origin.X - radius, origin.Y - radius, radius * 2, radius * 2), 0))
                return false;

            ShapeData data = new ShapeData();
            WorldUtils.Gen(origin, new Shapes.Slime(radius), Actions.Chain(new Modifiers.Blotches(num1, num1, num1, 1, 0.3).Output(data), 
                new Modifiers.Offset(0, -2), new Modifiers.OnlyTiles(new ushort[1] { 53 }), new Actions.SetTile(397, true, true), 
                new Modifiers.OnlyWalls(new byte[1]), new Actions.PlaceWall(16, true)));
            WorldUtils.Gen(origin, new ModShapes.All(data), Actions.Chain(new Actions.ClearTile(false), new Actions.SetLiquid(0, 0), 
                new Actions.SetFrames(true), new Modifiers.OnlyWalls(new byte[1]), new Actions.PlaceWall(16, true)));

            Point result;
            if (!WorldUtils.Find(origin, Searches.Chain(new Searches.Down(10), new Conditions.IsSolid()), out result))
                return false;

            int j = result.Y - 1;
            bool flag = GenBase._random.Next() % 2 == 0;
            if (GenBase._random.Next() % 10 != 0)
            {
                int num2 = GenBase._random.Next(1, 4);
                int num3 = flag ? 4 : -(radius >> 1);
                for (int index1 = 0; index1 < num2; ++index1)
                {
                    int num4 = GenBase._random.Next(1, 3);
                    for (int index2 = 0; index2 < num4; ++index2)
                        WorldGen.PlaceTile(origin.X + num3 - index1, j - index2, 331, false, false, -1, 0);
                }
            }

            int num5 = (radius - 3) * (flag ? -1 : 1);
            if (GenBase._random.Next() % 10 != 0)
                WorldGen.PlaceTile(origin.X + num5, j, 186, false, false, -1, 0);
            if (GenBase._random.Next() % 10 != 0)
            {
                WorldGen.PlaceTile(origin.X, j, 215, true, false, -1, 0);
                if (GenBase._tiles[origin.X, j].active() && GenBase._tiles[origin.X, j].type == 215)
                {
                    GenBase._tiles[origin.X, j].frameY += 36;
                    GenBase._tiles[origin.X - 1, j].frameY += 36;
                    GenBase._tiles[origin.X + 1, j].frameY += 36;
                    GenBase._tiles[origin.X, j - 1].frameY += 36;
                    GenBase._tiles[origin.X - 1, j - 1].frameY += 36;
                    GenBase._tiles[origin.X + 1, j - 1].frameY += 36;
                }
            }

            structures.AddStructure(new Microsoft.Xna.Framework.Rectangle(origin.X - radius, origin.Y - radius, radius * 2, radius * 2), 4);
            return true;
        }
		public override bool Place(Point origin, StructureMap structures)
		{
			if (GenBase._tiles[origin.X, origin.Y].active() && WorldGen.SolidTile(origin.X, origin.Y))
			{
				return false;
			}
			Point origin2;
			if (!WorldUtils.Find(origin, Searches.Chain(new Searches.Down(80), new GenCondition[]
			{
				new Conditions.IsSolid()
			}), out origin2))
			{
				return false;
			}
			origin2.Y += 2;
			Ref<int> @ref = new Ref<int>(0);
			WorldUtils.Gen(origin2, new Shapes.Circle(8), Actions.Chain(new GenAction[]
			{
				new Modifiers.IsSolid(),
				new Actions.Scanner(@ref)
			}));
			if (@ref.Value < 20)
			{
				return false;
			}
			if (!structures.CanPlace(new Rectangle(origin2.X - 8, origin2.Y - 8, 16, 16), 0))
			{
				return false;
			}
			WorldUtils.Gen(origin2, new Shapes.Circle(8), Actions.Chain(new GenAction[]
			{
				new Modifiers.RadialDither(0f, 10f),
				new Modifiers.IsSolid(),
				new Actions.SetTile(229, true, true)
			}));
			ShapeData data = new ShapeData();
			WorldUtils.Gen(origin2, new Shapes.Circle(4, 3), Actions.Chain(new GenAction[]
			{
				new Modifiers.Blotches(2, 0.3),
				new Modifiers.IsSolid(),
				new Actions.ClearTile(true),
				new Modifiers.RectangleMask(-6, 6, 0, 3).Output(data),
				new Actions.SetLiquid(2, 255)
			}));
			WorldUtils.Gen(new Point(origin2.X, origin2.Y + 1), new ModShapes.InnerOutline(data, true), Actions.Chain(new GenAction[]
			{
				new Modifiers.IsEmpty(),
				new Modifiers.RectangleMask(-6, 6, 1, 3),
				new Actions.SetTile(59, true, true)
			}));
			structures.AddStructure(new Rectangle(origin2.X - 8, origin2.Y - 8, 16, 16), 0);
			return true;
		}
 public override bool Place(Point origin, StructureMap structures)
 {
     if (WorldGen.SolidTile(origin.X, origin.Y))
         return false;
     ushort type = Utils.SelectRandom<ushort>(GenBase._random, WorldGen.goldBar == 19 ? (ushort)8 : (ushort)169, WorldGen.silverBar == 21 ? (ushort)9 : (ushort)168, WorldGen.ironBar == 22 ? (ushort)6 : (ushort)167, WorldGen.copperBar == 20 ? (ushort)7 : (ushort)166);
     double num = GenBase._random.NextDouble() * 2.0 - 1.0;
     if (!WorldUtils.Find(origin, Searches.Chain(num > 0.0 ? (GenSearch)new Searches.Right(40) : (GenSearch)new Searches.Left(40), (GenCondition)new Conditions.IsSolid()), out origin))
         return false;
     if (!WorldUtils.Find(origin, Searches.Chain((GenSearch)new Searches.Down(80), (GenCondition)new Conditions.IsSolid()), out origin))
         return false;
     ShapeData shapeData = new ShapeData();
     Ref<int> count1 = new Ref<int>(0);
     Ref<int> count2 = new Ref<int>(0);
     WorldUtils.Gen(origin, new ShapeRunner(10f, 20, new Vector2((float)num, 1f)).Output(shapeData), Actions.Chain((GenAction)new Modifiers.Blotches(2, 0.3), (GenAction)new Actions.Scanner(count1), (GenAction)new Modifiers.IsSolid(), (GenAction)new Actions.Scanner(count2)));
     if (count2.Value < count1.Value / 2)
         return false;
     Rectangle area = new Rectangle(origin.X - 15, origin.Y - 10, 30, 20);
     if (!structures.CanPlace(area, 0))
         return false;
     WorldUtils.Gen(origin, (GenShape)new ModShapes.All(shapeData), (GenAction)new Actions.SetTile(type, true, true));
     WorldUtils.Gen(new Point(origin.X - (int)(num * -5.0), origin.Y - 5), (GenShape)new Shapes.Circle(5), Actions.Chain((GenAction)new Modifiers.Blotches(2, 0.3), (GenAction)new Actions.ClearTile(true)));
     Point result1;
     Point result2;
     if (((((true ? 1 : 0) & (WorldUtils.Find(new Point(origin.X - (num > 0.0 ? 3 : -3), origin.Y - 3), Searches.Chain((GenSearch)new Searches.Down(10), (GenCondition)new Conditions.IsSolid()), out result1) ? 1 : 0)) != 0 ? 1 : 0) & (WorldUtils.Find(new Point(origin.X - (num > 0.0 ? -3 : 3), origin.Y - 3), Searches.Chain((GenSearch)new Searches.Down(10), (GenCondition)new Conditions.IsSolid()), out result2) ? 1 : 0)) == 0)
         return false;
     --result1.Y;
     --result2.Y;
     Tile tile1 = GenBase._tiles[result1.X, result1.Y + 1];
     tile1.slope((byte)0);
     tile1.halfBrick(false);
     for (int index = -1; index <= 1; ++index)
     {
         WorldUtils.ClearTile(result2.X + index, result2.Y, false);
         Tile tile2 = GenBase._tiles[result2.X + index, result2.Y + 1];
         if (!WorldGen.SolidOrSlopedTile(tile2))
         {
             tile2.ResetToType((ushort)1);
             tile2.active(true);
         }
         tile2.slope((byte)0);
         tile2.halfBrick(false);
         WorldUtils.TileFrame(result2.X + index, result2.Y + 1, true);
     }
     WorldGen.PlaceTile(result1.X, result1.Y, 141, false, false, -1, 0);
     WorldGen.PlaceTile(result2.X, result2.Y, 411, true, true, -1, 0);
     WorldUtils.WireLine(result1, result2);
     structures.AddStructure(area, 5);
     return true;
 }
Exemplo n.º 6
0
 public override bool Place(Point origin, StructureMap structures)
 {
     if (!structures.CanPlace(new Microsoft.Xna.Framework.Rectangle(origin.X, origin.Y, this._width, this._height), 0))
         return false;
     for (int index1 = 0; index1 < this._width; ++index1)
     {
         for (int index2 = 0; index2 < this._height; ++index2)
         {
             int num1 = this._xMirror ? -index1 : index1;
             int num2 = this._yMirror ? -index2 : index2;
             if (this._data[index1, index2] != -1 && !this._actions[this._data[index1, index2]].Apply(origin, num1 + origin.X, num2 + origin.Y))
                 return false;
         }
     }
     structures.AddStructure(new Microsoft.Xna.Framework.Rectangle(origin.X, origin.Y, this._width, this._height), 0);
     return true;
 }
		public override bool Place(Point origin, StructureMap structures)
		{
			Dictionary<ushort, int> dictionary = new Dictionary<ushort, int>();
			WorldUtils.Gen(new Point(origin.X - 25, origin.Y - 25), new Shapes.Rectangle(50, 50), new Actions.TileScanner(new ushort[]
			{
				0,
				59,
				147,
				1
			}).Output(dictionary));
			int num = dictionary[0] + dictionary[1];
			int num2 = dictionary[59];
			int num3 = dictionary[147];
			if (num3 <= num2 || num3 <= num)
			{
				return false;
			}
			int num4 = 0;
			for (int i = GenBase._random.Next(10, 15); i > 5; i--)
			{
				int num5 = GenBase._random.Next(-5, 5);
				WorldUtils.Gen(new Point(origin.X + num5, origin.Y + num4), new Shapes.Circle(i), Actions.Chain(new GenAction[]
				{
					new Modifiers.Blotches(4, 0.3),
					new Modifiers.OnlyTiles(new ushort[]
					{
						147,
						161,
						224,
						0,
						1
					}),
					new Actions.SetTile(162, true, true)
				}));
				WorldUtils.Gen(new Point(origin.X + num5, origin.Y + num4), new Shapes.Circle(i), Actions.Chain(new GenAction[]
				{
					new Modifiers.Blotches(4, 0.3),
					new Modifiers.HasLiquid(-1, -1),
					new Actions.SetTile(162, true, true),
					new Actions.SetLiquid(0, 0)
				}));
				num4 += i - 2;
			}
			return true;
		}
		public override bool Place(Point origin, StructureMap structures)
		{
			if (!structures.CanPlace(new Rectangle(origin.X, origin.Y, this._width, this._height), 0))
			{
				return false;
			}
			for (int i = 0; i < this._width; i++)
			{
				for (int j = 0; j < this._height; j++)
				{
					int num = this._xMirror ? (-i) : i;
					int num2 = this._yMirror ? (-j) : j;
					if (this._data[i, j] != -1 && !this._actions[this._data[i, j]].Apply(origin, num + origin.X, num2 + origin.Y, new object[0]))
					{
						return false;
					}
				}
			}
			structures.AddStructure(new Rectangle(origin.X, origin.Y, this._width, this._height), 0);
			return true;
		}
Exemplo n.º 9
0
 public override bool Place(Point origin, StructureMap structures)
 {
     Point y;
     if (GenBase._tiles[origin.X, origin.Y].active() && WorldGen.SolidTile(origin.X, origin.Y))
     {
         return false;
     }
     Searches.Down down = new Searches.Down(80);
     GenCondition[] isSolid = new GenCondition[] { new Conditions.IsSolid() };
     if (!WorldUtils.Find(origin, Searches.Chain(down, isSolid), out y))
     {
         return false;
     }
     y.Y = y.Y + 2;
     Ref<int> @ref = new Ref<int>(0);
     Shapes.Circle circle = new Shapes.Circle(8);
     GenAction[] genActionArray = new GenAction[] { new Modifiers.IsSolid(), new Actions.Scanner(@ref) };
     WorldUtils.Gen(y, circle, Actions.Chain(genActionArray));
     if (@ref.Value < 20)
     {
         return false;
     }
     if (!structures.CanPlace(new Rectangle(y.X - 8, y.Y - 8, 16, 16), 0))
     {
         return false;
     }
     Shapes.Circle circle1 = new Shapes.Circle(8);
     GenAction[] radialDither = new GenAction[] { new Modifiers.RadialDither(0f, 10f), new Modifiers.IsSolid(), new Actions.SetTile(229, true, true) };
     WorldUtils.Gen(y, circle1, Actions.Chain(radialDither));
     ShapeData shapeDatum = new ShapeData();
     Shapes.Circle circle2 = new Shapes.Circle(4, 3);
     GenAction[] blotch = new GenAction[] { new Modifiers.Blotches(2, 0.3), new Modifiers.IsSolid(), new Actions.ClearTile(true), (new Modifiers.RectangleMask(-6, 6, 0, 3)).Output(shapeDatum), new Actions.SetLiquid(2, 255) };
     WorldUtils.Gen(y, circle2, Actions.Chain(blotch));
     Point point = new Point(y.X, y.Y + 1);
     ModShapes.InnerOutline innerOutline = new ModShapes.InnerOutline(shapeDatum, true);
     GenAction[] isEmpty = new GenAction[] { new Modifiers.IsEmpty(), new Modifiers.RectangleMask(-6, 6, 1, 3), new Actions.SetTile(59, true, true) };
     WorldUtils.Gen(point, innerOutline, Actions.Chain(isEmpty));
     structures.AddStructure(new Rectangle(y.X - 8, y.Y - 8, 16, 16), 0);
     return true;
 }
Exemplo n.º 10
0
        public override bool Place(Point origin, StructureMap structures)
        {
            if (WorldGen.SolidTile(origin.X, origin.Y) && GenBase._tiles[origin.X, origin.Y].wall == 3)
                return false;

            if (!WorldUtils.Find(origin, Searches.Chain(new Searches.Down(100), new Conditions.IsSolid()), out origin))
                return false;

            Point result;
            if (!WorldUtils.Find(new Point(origin.X - 4, origin.Y), Searches.Chain(new Searches.Down(5), new Conditions.IsTile(new ushort[1] { 25 }).AreaAnd(8, 1)), out result))
                return false;

            ShapeData data1 = new ShapeData();
            ShapeData shapeData1 = new ShapeData();
            ShapeData shapeData2 = new ShapeData();
            for (int index = 0; index < 6; ++index)
                WorldUtils.Gen(origin, new Shapes.Circle(GenBase._random.Next(10, 12) + index), Actions.Chain(new Modifiers.Offset(0, 5 * index + 5), new Modifiers.Blotches(3, 0.3).Output(data1)));
            for (int index = 0; index < 6; ++index)
                WorldUtils.Gen(origin, new Shapes.Circle(GenBase._random.Next(5, 7) + index), Actions.Chain(new Modifiers.Offset(0, 2 * index + 18), new Modifiers.Blotches(3, 0.3).Output(shapeData1)));
            for (int index = 0; index < 6; ++index)
                WorldUtils.Gen(origin, new Shapes.Circle(GenBase._random.Next(4, 6) + index / 2), Actions.Chain(new Modifiers.Offset(0, (int)(7.5 * (double)index) - 10), new Modifiers.Blotches(3, 0.3).Output(shapeData2)));

            ShapeData data2 = new ShapeData(shapeData1);
            shapeData1.Subtract(shapeData2, origin, origin);
            data2.Subtract(shapeData1, origin, origin);
            Microsoft.Xna.Framework.Rectangle bounds = ShapeData.GetBounds(origin, data1, shapeData2);
            if (!structures.CanPlace(bounds, CorruptionPitBiome.ValidTiles, 2))
                return false;

            WorldUtils.Gen(origin, new ModShapes.All(data1), Actions.Chain(new Actions.SetTile((ushort)25, true, true), new Actions.PlaceWall(3, true)));
            WorldUtils.Gen(origin, new ModShapes.All(shapeData1), new Actions.SetTile(0, true, true));
            WorldUtils.Gen(origin, new ModShapes.All(shapeData2), new Actions.ClearTile(true));
            WorldUtils.Gen(origin, new ModShapes.All(shapeData1), Actions.Chain(new Modifiers.IsTouchingAir(true), new Modifiers.NotTouching(0 != 0, new ushort[1] { 25 }), new Actions.SetTile(23, true, true)));
            WorldUtils.Gen(origin, new ModShapes.All(data2), new Actions.PlaceWall(69, true));

            structures.AddStructure(bounds, 2);
            return true;
        }
Exemplo n.º 11
0
        public override bool Place(Point origin, StructureMap structures)
        {
            Dictionary<ushort, int> resultsOutput = new Dictionary<ushort, int>();
            WorldUtils.Gen(new Point(origin.X - 25, origin.Y - 25), new Shapes.Rectangle(50, 50), new Actions.TileScanner(new ushort[4] { 0, 59, 147, 1 }).Output(resultsOutput));
            int num1 = resultsOutput[0] + resultsOutput[1];
            int num2 = resultsOutput[59];
            int num3 = resultsOutput[147];
            if (num3 <= num2 || num3 <= num1)
                return false;

            int num4 = 0;
            for (int radius = GenBase._random.Next(10, 15); radius > 5; --radius)
            {
                int num5 = GenBase._random.Next(-5, 5);
                WorldUtils.Gen(new Point(origin.X + num5, origin.Y + num4), new Shapes.Circle(radius), Actions.Chain(new Modifiers.Blotches(4, 0.3),
                    new Modifiers.OnlyTiles(new ushort[5] { 147, 161, 224, 0, 1 }), new Actions.SetTile(162, true, true)));
                WorldUtils.Gen(new Point(origin.X + num5, origin.Y + num4), new Shapes.Circle(radius), Actions.Chain(new Modifiers.Blotches(4, 0.3),
                    new Modifiers.HasLiquid(-1, -1), new Actions.SetTile(162, true, true), new Actions.SetLiquid(0, 0)));
                num4 += radius - 2;
            }

            return true;
        }
Exemplo n.º 12
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);
 }
Exemplo n.º 13
0
 public override bool Place(Point origin, StructureMap structures)
 {
     if (WorldGen.SolidTile(origin.X, origin.Y))
     {
         return false;
     }
     ushort type = Utils.SelectRandom<ushort>(GenBase._random, new ushort[]
     {
         (ushort)((WorldGen.goldBar == 19) ? 8 : 169),
         (ushort)((WorldGen.silverBar == 21) ? 9 : 168),
         (ushort)((WorldGen.ironBar == 22) ? 6 : 167),
         (ushort)((WorldGen.copperBar == 20) ? 7 : 166)
     });
     double num = GenBase._random.NextDouble() * 2.0 - 1.0;
     GenSearch genSearch;
     if (num > 0.0)
     {
         genSearch = new Searches.Right(40);
     } else {
         genSearch = new Searches.Left(40);
     }
     if (!WorldUtils.Find(origin, Searches.Chain(genSearch, new GenCondition[]
     {
         new Conditions.IsSolid()
     }), out origin))
     {
         return false;
     }
     if (!WorldUtils.Find(origin, Searches.Chain(new Searches.Down(80), new GenCondition[]
     {
         new Conditions.IsSolid()
     }), out origin))
     {
         return false;
     }
     ShapeData shapeData = new ShapeData();
     Ref<int> @ref = new Ref<int>(0);
     Ref<int> ref2 = new Ref<int>(0);
     WorldUtils.Gen(origin, new ShapeRunner(10f, 20, new Vector2((float)num, 1f)).Output(shapeData), Actions.Chain(new GenAction[]
     {
         new Modifiers.Blotches(2, 0.3),
         new Actions.Scanner(@ref),
         new Modifiers.IsSolid(),
         new Actions.Scanner(ref2)
     }));
     if (ref2.Value < @ref.Value / 2)
     {
         return false;
     }
     Rectangle area = new Rectangle(origin.X - 15, origin.Y - 10, 30, 20);
     if (!structures.CanPlace(area, 0))
     {
         return false;
     }
     WorldUtils.Gen(origin, new ModShapes.All(shapeData), new Actions.SetTile(type, true, true));
     WorldUtils.Gen(new Point(origin.X - (int)(num * -5.0), origin.Y - 5), new Shapes.Circle(5), Actions.Chain(new GenAction[]
     {
         new Modifiers.Blotches(2, 0.3),
         new Actions.ClearTile(true)
     }));
     bool flag = true;
     Point start;
     flag &= WorldUtils.Find(new Point(origin.X - ((num > 0.0) ? 3 : -3), origin.Y - 3), Searches.Chain(new Searches.Down(10), new GenCondition[]
     {
         new Conditions.IsSolid()
     }), out start);
     Point end;
     if (!(flag & WorldUtils.Find(new Point(origin.X - ((num > 0.0) ? -3 : 3), origin.Y - 3), Searches.Chain(new Searches.Down(10), new GenCondition[]
     {
         new Conditions.IsSolid()
     }), out end)))
     {
         return false;
     }
     start.Y--;
     end.Y--;
     Tile tile = GenBase._tiles[start.X, start.Y + 1];
     tile.slope(0);
     tile.halfBrick(false);
     for (int i = -1; i <= 1; i++)
     {
         WorldUtils.ClearTile(end.X + i, end.Y, false);
         Tile tile2 = GenBase._tiles[end.X + i, end.Y + 1];
         if (!WorldGen.SolidOrSlopedTile(tile2))
         {
             tile2.ResetToType(1);
             tile2.active(true);
         }
         tile2.slope(0);
         tile2.halfBrick(false);
         WorldUtils.TileFrame(end.X + i, end.Y + 1, true);
     }
     WorldGen.PlaceTile(start.X, start.Y, 141, false, false, -1, 0);
     WorldGen.PlaceTile(end.X, end.Y, 411, true, true, -1, 0);
     WorldUtils.WireLine(start, end);
     structures.AddStructure(area, 5);
     return true;
 }
Exemplo n.º 14
0
 public override bool Place(Point origin, StructureMap structures)
 {
     MarbleBiome.SlabState slabState;
     bool flag;
     if (this._slabs == null)
     {
         this._slabs = new MarbleBiome.Slab[56, 26];
     }
     int num = GenBase._random.Next(80, 150) / 3;
     int num1 = GenBase._random.Next(40, 60) / 3;
     int num2 = (num1 * 3 - GenBase._random.Next(20, 30)) / 3;
     origin.X = origin.X - num * 3 / 2;
     origin.Y = origin.Y - num1 * 3 / 2;
     for (int i = -1; i < num + 1; i++)
     {
         float single = (float)(i - num / 2) / (float)num + 0.5f;
         int num3 = (int)((0.5f - Math.Abs(single - 0.5f)) * 5f) - 2;
         for (int j = -1; j < num1 + 1; j++)
         {
             bool flag1 = true;
             bool flag2 = false;
             bool flag3 = this.IsGroupSolid(i * 3 + origin.X, j * 3 + origin.Y, 3);
             int num4 = Math.Abs(j - num1 / 2);
             int num5 = num4 - num2 / 4 + num3;
             if (num5 > 3)
             {
                 flag2 = flag3;
                 flag1 = false;
             }
             else if (num5 > 0)
             {
                 flag2 = (j - num1 / 2 > 0 ? true : flag3);
                 flag1 = (j - num1 / 2 < 0 ? true : num5 <= 2);
             }
             else if (num5 == 0)
             {
                 if (GenBase._random.Next(2) != 0)
                 {
                     flag = false;
                 }
                 else
                 {
                     flag = (j - num1 / 2 > 0 ? true : flag3);
                 }
                 flag2 = flag;
             }
             if (Math.Abs(single - 0.5f) > 0.35f + GenBase._random.NextFloat() * 0.1f && !flag3)
             {
                 flag1 = false;
                 flag2 = false;
             }
             slabState = (flag2 ? new MarbleBiome.SlabState(MarbleBiome.SlabStates.Solid) : new MarbleBiome.SlabState(MarbleBiome.SlabStates.Empty));
             this._slabs[i + 1, j + 1] = MarbleBiome.Slab.Create(slabState, flag1);
         }
     }
     for (int k = 0; k < num; k++)
     {
         for (int l = 0; l < num1; l++)
         {
             this.SmoothSlope(k + 1, l + 1);
         }
     }
     int num6 = num / 2;
     int num7 = num1 / 2;
     int num8 = (num7 + 1) * (num7 + 1);
     float single1 = GenBase._random.NextFloat() * 2f - 1f;
     float single2 = GenBase._random.NextFloat() * 2f - 1f;
     float single3 = GenBase._random.NextFloat() * 2f - 1f;
     float single4 = 0f;
     for (int m = 0; m <= num; m++)
     {
         float single5 = (float)num7 / (float)num6 * (float)(m - num6);
         int num9 = Math.Min(num7, (int)Math.Sqrt((double)Math.Max(0f, (float)num8 - single5 * single5)));
         single4 = (m >= num / 2 ? single4 + MathHelper.Lerp(single2, single3, (float)m / (float)(num / 2) - 1f) : single4 + MathHelper.Lerp(single1, single2, (float)m / (float)(num / 2)));
         for (int n = num7 - num9; n <= num7 + num9; n++)
         {
             this.PlaceSlab(this._slabs[m + 1, n + 1], m * 3 + origin.X, n * 3 + origin.Y + (int)single4, 3);
         }
     }
     return true;
 }
		public override bool Place(Point origin, StructureMap structures)
		{
			if (this._slabs == null)
			{
				this._slabs = new MarbleBiome.Slab[56, 26];
			}
			int num = GenBase._random.Next(80, 150) / 3;
			int num2 = GenBase._random.Next(40, 60) / 3;
			int num3 = (num2 * 3 - GenBase._random.Next(20, 30)) / 3;
			origin.X -= num * 3 / 2;
			origin.Y -= num2 * 3 / 2;
			for (int i = -1; i < num + 1; i++)
			{
				float num4 = (float)(i - num / 2) / (float)num + 0.5f;
				int num5 = (int)((0.5f - Math.Abs(num4 - 0.5f)) * 5f) - 2;
				for (int j = -1; j < num2 + 1; j++)
				{
					bool hasWall = true;
					bool flag = false;
					bool flag2 = this.IsGroupSolid(i * 3 + origin.X, j * 3 + origin.Y, 3);
					int num6 = Math.Abs(j - num2 / 2);
					int num7 = num6 - num3 / 4 + num5;
					if (num7 > 3)
					{
						flag = flag2;
						hasWall = false;
					}
					else if (num7 > 0)
					{
						flag = (j - num2 / 2 > 0 || flag2);
						hasWall = (j - num2 / 2 < 0 || num7 <= 2);
					}
					else if (num7 == 0)
					{
						flag = (GenBase._random.Next(2) == 0 && (j - num2 / 2 > 0 || flag2));
					}
					if (Math.Abs(num4 - 0.5f) > 0.35f + GenBase._random.NextFloat() * 0.1f && !flag2)
					{
						hasWall = false;
						flag = false;
					}
					this._slabs[i + 1, j + 1] = MarbleBiome.Slab.Create(flag ? new MarbleBiome.SlabState(MarbleBiome.SlabStates.Solid) : new MarbleBiome.SlabState(MarbleBiome.SlabStates.Empty), hasWall);
				}
			}
			for (int k = 0; k < num; k++)
			{
				for (int l = 0; l < num2; l++)
				{
					this.SmoothSlope(k + 1, l + 1);
				}
			}
			int num8 = num / 2;
			int num9 = num2 / 2;
			int num10 = (num9 + 1) * (num9 + 1);
			float value = GenBase._random.NextFloat() * 2f - 1f;
			float num11 = GenBase._random.NextFloat() * 2f - 1f;
			float value2 = GenBase._random.NextFloat() * 2f - 1f;
			float num12 = 0f;
			for (int m = 0; m <= num; m++)
			{
				float num13 = (float)num9 / (float)num8 * (float)(m - num8);
				int num14 = Math.Min(num9, (int)Math.Sqrt((double)Math.Max(0f, (float)num10 - num13 * num13)));
				if (m < num / 2)
				{
					num12 += MathHelper.Lerp(value, num11, (float)m / (float)(num / 2));
				}
				else
				{
					num12 += MathHelper.Lerp(num11, value2, (float)m / (float)(num / 2) - 1f);
				}
				for (int n = num9 - num14; n <= num9 + num14; n++)
				{
					this.PlaceSlab(this._slabs[m + 1, n + 1], m * 3 + origin.X, n * 3 + origin.Y + (int)num12, 3);
				}
			}
			return true;
		}
 public override bool Place(Point origin, StructureMap structures)
 {
     Point y;
     Point point;
     Dictionary<ushort, int> nums = new Dictionary<ushort, int>();
     Point point1 = new Point(origin.X - 25, origin.Y - 25);
     Shapes.Rectangle rectangle = new Shapes.Rectangle(50, 50);
     ushort[] numArray = new ushort[] { 0, 1 };
     WorldUtils.Gen(point1, rectangle, (new Actions.TileScanner(numArray)).Output(nums));
     if (nums[0] + nums[1] < 1250)
     {
         return false;
     }
     Searches.Up up = new Searches.Up(1000);
     GenCondition[] genConditionArray = new GenCondition[] { (new Conditions.IsSolid()).AreaOr(1, 50).Not() };
     bool flag = WorldUtils.Find(origin, Searches.Chain(up, genConditionArray), out y);
     Point point2 = origin;
     Searches.Up up1 = new Searches.Up(origin.Y - y.Y);
     GenCondition[] isTile = new GenCondition[1];
     ushort[] numArray1 = new ushort[] { 53 };
     isTile[0] = new Conditions.IsTile(numArray1);
     if (WorldUtils.Find(point2, Searches.Chain(up1, isTile), out point))
     {
         return false;
     }
     if (!flag)
     {
         return false;
     }
     y.Y = y.Y + 50;
     ShapeData shapeDatum = new ShapeData();
     ShapeData shapeDatum1 = new ShapeData();
     Point point3 = new Point(origin.X, origin.Y + 20);
     Point point4 = new Point(origin.X, origin.Y + 30);
     float single = 0.8f + GenBase._random.NextFloat() * 0.5f;
     if (!structures.CanPlace(new Rectangle(point3.X - (int)(20f * single), point3.Y - 20, (int)(40f * single), 40), 0))
     {
         return false;
     }
     if (!structures.CanPlace(new Rectangle(origin.X, y.Y + 10, 1, origin.Y - y.Y - 9), 2))
     {
         return false;
     }
     Shapes.Slime slime = new Shapes.Slime(20, single, 1f);
     GenAction[] blotch = new GenAction[] { new Modifiers.Blotches(2, 0.4), (new Actions.ClearTile(true)).Output(shapeDatum) };
     WorldUtils.Gen(point3, slime, Actions.Chain(blotch));
     Shapes.Mound mound = new Shapes.Mound(14, 14);
     GenAction[] genActionArray = new GenAction[] { new Modifiers.Blotches(2, 1, 0.8), new Actions.SetTile(0, false, true), (new Actions.SetFrames(true)).Output(shapeDatum1) };
     WorldUtils.Gen(point4, mound, Actions.Chain(genActionArray));
     shapeDatum.Subtract(shapeDatum1, point3, point4);
     ModShapes.InnerOutline innerOutline = new ModShapes.InnerOutline(shapeDatum, true);
     GenAction[] setTile = new GenAction[] { new Actions.SetTile(2, false, true), new Actions.SetFrames(true) };
     WorldUtils.Gen(point3, innerOutline, Actions.Chain(setTile));
     ModShapes.All all = new ModShapes.All(shapeDatum);
     GenAction[] rectangleMask = new GenAction[] { new Modifiers.RectangleMask(-40, 40, 0, 40), new Modifiers.IsEmpty(), new Actions.SetLiquid(0, 255) };
     WorldUtils.Gen(point3, all, Actions.Chain(rectangleMask));
     ModShapes.All all1 = new ModShapes.All(shapeDatum);
     GenAction[] placeWall = new GenAction[] { new Actions.PlaceWall(68, true), null, null, null };
     ushort[] numArray2 = new ushort[] { 2 };
     placeWall[1] = new Modifiers.OnlyTiles(numArray2);
     placeWall[2] = new Modifiers.Offset(0, 1);
     placeWall[3] = new ActionVines(3, 5, 52);
     WorldUtils.Gen(point3, all1, Actions.Chain(placeWall));
     ShapeData shapeDatum2 = new ShapeData();
     Point point5 = new Point(origin.X, y.Y + 10);
     Shapes.Rectangle rectangle1 = new Shapes.Rectangle(1, origin.Y - y.Y - 9);
     GenAction[] onlyTile = new GenAction[] { new Modifiers.Blotches(2, 0.2), (new Actions.ClearTile(false)).Output(shapeDatum2), new Modifiers.Expand(1), null, null };
     ushort[] numArray3 = new ushort[] { 53 };
     onlyTile[3] = new Modifiers.OnlyTiles(numArray3);
     onlyTile[4] = (new Actions.SetTile(397, false, true)).Output(shapeDatum2);
     WorldUtils.Gen(point5, rectangle1, Actions.Chain(onlyTile));
     WorldUtils.Gen(new Point(origin.X, y.Y + 10), new ModShapes.All(shapeDatum2), new Actions.SetFrames(true));
     if (GenBase._random.Next(3) != 0)
     {
         WorldGen.PlaceTile(point4.X, point4.Y - 15, 186, true, false, -1, 15);
     }
     else
     {
         WorldGen.PlaceTile(point4.X, point4.Y - 15, 187, true, false, -1, 17);
     }
     ModShapes.All all2 = new ModShapes.All(shapeDatum1);
     GenAction[] offset = new GenAction[] { new Modifiers.Offset(0, -1), null, null, null };
     ushort[] numArray4 = new ushort[] { 2 };
     offset[1] = new Modifiers.OnlyTiles(numArray4);
     offset[2] = new Modifiers.Offset(0, -1);
     offset[3] = new ActionGrass();
     WorldUtils.Gen(point4, all2, Actions.Chain(offset));
     structures.AddStructure(new Rectangle(point3.X - (int)(20f * single), point3.Y - 20, (int)(40f * single), 40), 4);
     return true;
 }
Exemplo n.º 17
0
 public override bool Place(Point origin, StructureMap structures)
 {
     Ref<int> @ref = new Ref<int>(0);
     Ref<int> ref1 = new Ref<int>(0);
     Ref<int> ref2 = new Ref<int>(0);
     Ref<int> ref3 = new Ref<int>(0);
     Shapes.Circle circle = new Shapes.Circle(15);
     GenAction[] scanner = new GenAction[] { new Actions.Scanner(ref2), new Modifiers.IsSolid(), new Actions.Scanner(@ref), null, null, null, null };
     ushort[] numArray = new ushort[] { 60, 59 };
     scanner[3] = new Modifiers.OnlyTiles(numArray);
     scanner[4] = new Actions.Scanner(ref1);
     ushort[] numArray1 = new ushort[] { 60 };
     scanner[5] = new Modifiers.OnlyTiles(numArray1);
     scanner[6] = new Actions.Scanner(ref3);
     WorldUtils.Gen(origin, circle, Actions.Chain(scanner));
     if ((float)ref1.Value / (float)@ref.Value < 0.75f || ref3.Value < 2)
     {
         return false;
     }
     if (!structures.CanPlace(new Rectangle(origin.X - 50, origin.Y - 50, 100, 100), 0))
     {
         return false;
     }
     int x = origin.X;
     int y = origin.Y;
     int num = 150;
     for (int i = x - num; i < x + num; i = i + 10)
     {
         if (i > 0 && i <= Main.maxTilesX - 1)
         {
             for (int j = y - num; j < y + num; j = j + 10)
             {
                 if (j > 0 && j <= Main.maxTilesY - 1)
                 {
                     if (Main.tile[i, j].active() && Main.tile[i, j].type == 226)
                     {
                         return false;
                     }
                     if (Main.tile[i, j].wall == 87 || Main.tile[i, j].wall == 3 || Main.tile[i, j].wall == 83)
                     {
                         return false;
                     }
                 }
             }
         }
     }
     int x1 = origin.X;
     int y1 = origin.Y;
     int num1 = 0;
     int[] x2 = new int[10];
     int[] y2 = new int[10];
     Vector2 vector2 = new Vector2((float)x1, (float)y1);
     Vector2 vector21 = vector2;
     int num2 = WorldGen.genRand.Next(2, 5);
     for (int k = 0; k < num2; k++)
     {
         int num3 = WorldGen.genRand.Next(2, 5);
         for (int l = 0; l < num3; l++)
         {
             vector21 = WorldGen.Hive((int)vector2.X, (int)vector2.Y);
         }
         vector2 = vector21;
         x2[num1] = (int)vector2.X;
         y2[num1] = (int)vector2.Y;
         num1++;
     }
     for (int m = 0; m < num1; m++)
     {
         int num4 = x2[m];
         int num5 = y2[m];
         bool flag = false;
         int num6 = 1;
         if (WorldGen.genRand.Next(2) == 0)
         {
             num6 = -1;
         }
         while (num4 > 10 && num4 < Main.maxTilesX - 10 && num5 > 10 && num5 < Main.maxTilesY - 10 && (!Main.tile[num4, num5].active() || !Main.tile[num4, num5 + 1].active() || !Main.tile[num4 + 1, num5].active() || !Main.tile[num4 + 1, num5 + 1].active()))
         {
             num4 = num4 + num6;
             if (Math.Abs(num4 - x2[m]) <= 50)
             {
                 continue;
             }
             flag = true;
             break;
         }
         if (!flag)
         {
             num4 = num4 + num6;
             for (int n = num4 - 1; n <= num4 + 2; n++)
             {
                 for (int o = num5 - 1; o <= num5 + 2; o++)
                 {
                     if (n < 10 || n > Main.maxTilesX - 10)
                     {
                         flag = true;
                     }
                     else if (Main.tile[n, o].active() && Main.tile[n, o].type != 225)
                     {
                         flag = true;
                         break;
                     }
                 }
             }
             if (!flag)
             {
                 for (int p = num4 - 1; p <= num4 + 2; p++)
                 {
                     for (int q = num5 - 1; q <= num5 + 2; q++)
                     {
                         if (p < num4 || p > num4 + 1 || q < num5 || q > num5 + 1)
                         {
                             Main.tile[p, q].active(true);
                             Main.tile[p, q].type = 225;
                         }
                         else
                         {
                             Main.tile[p, q].active(false);
                             Main.tile[p, q].liquid = 255;
                             Main.tile[p, q].honey(true);
                         }
                     }
                 }
                 num6 = num6 * -1;
                 num5++;
                 int num7 = 0;
                 while ((num7 < 4 || WorldGen.SolidTile(num4, num5)) && num4 > 10 && num4 < Main.maxTilesX - 10)
                 {
                     num7++;
                     num4 = num4 + num6;
                     if (!WorldGen.SolidTile(num4, num5))
                     {
                         continue;
                     }
                     WorldGen.PoundTile(num4, num5);
                     if (Main.tile[num4, num5 + 1].active())
                     {
                         continue;
                     }
                     Main.tile[num4, num5 + 1].active(true);
                     Main.tile[num4, num5 + 1].type = 225;
                 }
             }
         }
     }
     WorldGen.larvaX[WorldGen.numLarva] = Utils.Clamp<int>((int)vector2.X, 5, Main.maxTilesX - 5);
     WorldGen.larvaY[WorldGen.numLarva] = Utils.Clamp<int>((int)vector2.Y, 5, Main.maxTilesY - 5);
     WorldGen.numLarva = WorldGen.numLarva + 1;
     int x3 = (int)vector2.X;
     int y3 = (int)vector2.Y;
     for (int r = x3 - 1; r <= x3 + 1 && r > 0 && r < Main.maxTilesX; r++)
     {
         for (int s = y3 - 2; s <= y3 + 1 && s > 0 && s < Main.maxTilesY; s++)
         {
             if (s == y3 + 1)
             {
                 Main.tile[r, s].active(true);
                 Main.tile[r, s].type = 225;
                 Main.tile[r, s].slope(0);
                 Main.tile[r, s].halfBrick(false);
             }
             else
             {
                 Main.tile[r, s].active(false);
             }
         }
     }
     structures.AddStructure(new Rectangle(origin.X - 50, origin.Y - 50, 100, 100), 5);
     return true;
 }
Exemplo n.º 18
0
 // Token: 0x06000929 RID: 2345 RVA: 0x003B5320 File Offset: 0x003B3520
 public static bool Place(Point origin, StructureMap structures)
 {
     return(Biomes <T> ._microBiome.Place(origin, structures));
 }
Exemplo n.º 19
0
 public override bool Place(Point origin, StructureMap structures)
 {
     Point point;
     Point point1;
     Point point2 = new Point(origin.X - 3, origin.Y);
     Searches.Down down = new Searches.Down(200);
     GenCondition[] genConditionArray = new GenCondition[] { (new Conditions.IsSolid()).AreaAnd(6, 1) };
     if (!WorldUtils.Find(point2, Searches.Chain(down, genConditionArray), out point))
     {
         return false;
     }
     Point point3 = new Point(point.X, point.Y - 5);
     Searches.Up up = new Searches.Up(120);
     GenCondition[] genConditionArray1 = new GenCondition[] { (new Conditions.IsSolid()).AreaOr(6, 1) };
     if (!WorldUtils.Find(point3, Searches.Chain(up, genConditionArray1), out point1) || point.Y - 5 - point1.Y > 60)
     {
         return false;
     }
     if (point.Y - point1.Y < 30)
     {
         return false;
     }
     if (!structures.CanPlace(new Rectangle(point.X - 30, point.Y - 60, 60, 90), 0))
     {
         return false;
     }
     Dictionary<ushort, int> nums = new Dictionary<ushort, int>();
     Point point4 = new Point(point.X - 25, point.Y - 25);
     Shapes.Rectangle rectangle = new Shapes.Rectangle(50, 50);
     ushort[] numArray = new ushort[] { 0, 59, 147, 1 };
     WorldUtils.Gen(point4, rectangle, (new Actions.TileScanner(numArray)).Output(nums));
     int item = nums[0] + nums[1];
     int num = nums[59];
     if (nums[147] > num || item > num || num < 50)
     {
         return false;
     }
     int y = (point.Y - point1.Y - 9) / 5;
     int num1 = y * 5;
     int num2 = 0;
     double num3 = GenBase._random.NextDouble() + 1;
     double num4 = GenBase._random.NextDouble() + 2;
     if (GenBase._random.Next(2) == 0)
     {
         num4 = -num4;
     }
     for (int i = 0; i < y; i++)
     {
         double num5 = (double)(i + 1) / 12;
         int num6 = (int)(Math.Sin(num5 * num3 * 3.14159274101257) * num4);
         int num7 = (num6 < num2 ? num6 - num2 : 0);
         Point point5 = new Point(point.X + num2 + num7, point.Y - (i + 1) * 5);
         Shapes.Rectangle rectangle1 = new Shapes.Rectangle(6 + Math.Abs(num6 - num2), 7);
         GenAction[] removeWall = new GenAction[] { new Actions.RemoveWall(), new Actions.SetTile(383, false, true), new Actions.SetFrames(false) };
         WorldUtils.Gen(point5, rectangle1, Actions.Chain(removeWall));
         Point point6 = new Point(point.X + num2 + num7 + 2, point.Y - (i + 1) * 5);
         Shapes.Rectangle rectangle2 = new Shapes.Rectangle(2 + Math.Abs(num6 - num2), 5);
         GenAction[] clearTile = new GenAction[] { new Actions.ClearTile(true), new Actions.PlaceWall(78, true) };
         WorldUtils.Gen(point6, rectangle2, Actions.Chain(clearTile));
         Point point7 = new Point(point.X + num2 + 2, point.Y - i * 5);
         Shapes.Rectangle rectangle3 = new Shapes.Rectangle(2, 2);
         GenAction[] genActionArray = new GenAction[] { new Actions.ClearTile(true), new Actions.PlaceWall(78, true) };
         WorldUtils.Gen(point7, rectangle3, Actions.Chain(genActionArray));
         num2 = num6;
     }
     int num8 = 6;
     if (num4 < 0)
     {
         num8 = 0;
     }
     List<Point> points = new List<Point>();
     for (int j = 0; j < 2; j++)
     {
         double num9 = ((double)j + 1) / 3;
         int num10 = num8 + (int)(Math.Sin((double)y * num9 / 12 * num3 * 3.14159274101257) * num4);
         double num11 = GenBase._random.NextDouble() * 0.785398185253143 - 0.785398185253143 - 0.200000002980232;
         if (num8 == 0)
         {
             num11 = num11 - 1.57079637050629;
         }
         Point point8 = new Point(point.X + num10, point.Y - (int)((double)(y * 5) * num9));
         ShapeBranch shapeBranch = (new ShapeBranch(num11, (double)GenBase._random.Next(12, 16))).OutputEndpoints(points);
         GenAction[] setTile = new GenAction[] { new Actions.SetTile(383, false, true), new Actions.SetFrames(true) };
         WorldUtils.Gen(point8, shapeBranch, Actions.Chain(setTile));
         num8 = 6 - num8;
     }
     int num12 = (int)(Math.Sin((double)y / 12 * num3 * 3.14159274101257) * num4);
     Point point9 = new Point(point.X + 6 + num12, point.Y - num1);
     ShapeBranch shapeBranch1 = (new ShapeBranch(-0.685398185253143, (double)GenBase._random.Next(16, 22))).OutputEndpoints(points);
     GenAction[] setTile1 = new GenAction[] { new Actions.SetTile(383, false, true), new Actions.SetFrames(true) };
     WorldUtils.Gen(point9, shapeBranch1, Actions.Chain(setTile1));
     Point point10 = new Point(point.X + num12, point.Y - num1);
     ShapeBranch shapeBranch2 = (new ShapeBranch(-2.45619455575943, (double)GenBase._random.Next(16, 22))).OutputEndpoints(points);
     GenAction[] genActionArray1 = new GenAction[] { new Actions.SetTile(383, false, true), new Actions.SetFrames(true) };
     WorldUtils.Gen(point10, shapeBranch2, Actions.Chain(genActionArray1));
     foreach (Point point11 in points)
     {
         Shapes.Circle circle = new Shapes.Circle(4);
         GenAction[] blotch = new GenAction[] { new Modifiers.Blotches(4, 2, 0.3), null, null, null, null };
         ushort[] numArray1 = new ushort[] { 383 };
         blotch[1] = new Modifiers.SkipTiles(numArray1);
         byte[] numArray2 = new byte[] { 78 };
         blotch[2] = new Modifiers.SkipWalls(numArray2);
         blotch[3] = new Actions.SetTile(384, false, true);
         blotch[4] = new Actions.SetFrames(true);
         WorldUtils.Gen(point11, circle, Actions.Chain(blotch));
     }
     for (int k = 0; k < 4; k++)
     {
         float single = (float)k / 3f * 2f + 0.57075f;
         WorldUtils.Gen(point, new ShapeRoot(single, (float)GenBase._random.Next(40, 60), 4f, 1f), new Actions.SetTile(383, true, true));
     }
     WorldGen.AddBuriedChest(point.X + 3, point.Y - 1, (GenBase._random.Next(4) == 0 ? 0 : WorldGen.GetNextJungleChestItem()), false, 10);
     structures.AddStructure(new Rectangle(point.X - 30, point.Y - 30, 60, 60), 0);
     return true;
 }
Exemplo n.º 20
0
 public static bool Place(int x, int y, StructureMap structures)
 {
     return(Biomes <T> ._microBiome.Place(new Point(x, y), structures));
 }
		public override bool Place(Point origin, StructureMap structures)
		{
			Dictionary<ushort, int> dictionary = new Dictionary<ushort, int>();
			WorldUtils.Gen(new Point(origin.X - 25, origin.Y - 25), new Shapes.Rectangle(50, 50), new Actions.TileScanner(new ushort[]
			{
				0,
				1
			}).Output(dictionary));
			int num = dictionary[0] + dictionary[1];
			if (num < 1250)
			{
				return false;
			}
			Point point;
			bool flag = WorldUtils.Find(origin, Searches.Chain(new Searches.Up(1000), new GenCondition[]
			{
				new Conditions.IsSolid().AreaOr(1, 50).Not()
			}), out point);
			Point point2;
			bool flag2 = WorldUtils.Find(origin, Searches.Chain(new Searches.Up(origin.Y - point.Y), new GenCondition[]
			{
				new Conditions.IsTile(new ushort[]
				{
					53
				})
			}), out point2);
			if (flag2)
			{
				return false;
			}
			if (!flag)
			{
				return false;
			}
			point.Y += 50;
			ShapeData shapeData = new ShapeData();
			ShapeData shapeData2 = new ShapeData();
			Point point3 = new Point(origin.X, origin.Y + 20);
			Point point4 = new Point(origin.X, origin.Y + 30);
			float num2 = 0.8f + GenBase._random.NextFloat() * 0.5f;
			if (!structures.CanPlace(new Rectangle(point3.X - (int)(20f * num2), point3.Y - 20, (int)(40f * num2), 40), 0))
			{
				return false;
			}
			if (!structures.CanPlace(new Rectangle(origin.X, point.Y + 10, 1, origin.Y - point.Y - 9), 2))
			{
				return false;
			}
			WorldUtils.Gen(point3, new Shapes.Slime(20, num2, 1f), Actions.Chain(new GenAction[]
			{
				new Modifiers.Blotches(2, 0.4),
				new Actions.ClearTile(true).Output(shapeData)
			}));
			WorldUtils.Gen(point4, new Shapes.Mound(14, 14), Actions.Chain(new GenAction[]
			{
				new Modifiers.Blotches(2, 1, 0.8),
				new Actions.SetTile(0, false, true),
				new Actions.SetFrames(true).Output(shapeData2)
			}));
			shapeData.Subtract(shapeData2, point3, point4);
			WorldUtils.Gen(point3, new ModShapes.InnerOutline(shapeData, true), Actions.Chain(new GenAction[]
			{
				new Actions.SetTile(2, false, true),
				new Actions.SetFrames(true)
			}));
			WorldUtils.Gen(point3, new ModShapes.All(shapeData), Actions.Chain(new GenAction[]
			{
				new Modifiers.RectangleMask(-40, 40, 0, 40),
				new Modifiers.IsEmpty(),
				new Actions.SetLiquid(0, 255)
			}));
			WorldUtils.Gen(point3, new ModShapes.All(shapeData), Actions.Chain(new GenAction[]
			{
				new Actions.PlaceWall(68, true),
				new Modifiers.OnlyTiles(new ushort[]
				{
					2
				}),
				new Modifiers.Offset(0, 1),
				new ActionVines(3, 5, 52)
			}));
			ShapeData data = new ShapeData();
			WorldUtils.Gen(new Point(origin.X, point.Y + 10), new Shapes.Rectangle(1, origin.Y - point.Y - 9), Actions.Chain(new GenAction[]
			{
				new Modifiers.Blotches(2, 0.2),
				new Actions.ClearTile(false).Output(data),
				new Modifiers.Expand(1),
				new Modifiers.OnlyTiles(new ushort[]
				{
					53
				}),
				new Actions.SetTile(397, false, true).Output(data)
			}));
			WorldUtils.Gen(new Point(origin.X, point.Y + 10), new ModShapes.All(data), new Actions.SetFrames(true));
			if (GenBase._random.Next(3) == 0)
			{
				WorldGen.PlaceTile(point4.X, point4.Y - 15, 187, true, false, -1, 17);
			}
			else
			{
				WorldGen.PlaceTile(point4.X, point4.Y - 15, 186, true, false, -1, 15);
			}
			WorldUtils.Gen(point4, new ModShapes.All(shapeData2), Actions.Chain(new GenAction[]
			{
				new Modifiers.Offset(0, -1),
				new Modifiers.OnlyTiles(new ushort[]
				{
					2
				}),
				new Modifiers.Offset(0, -1),
				new ActionGrass()
			}));
			structures.AddStructure(new Rectangle(point3.X - (int)(20f * num2), point3.Y - 20, (int)(40f * num2), 40), 4);
			return true;
		}
		public override bool Place(Point origin, StructureMap structures)
		{
			Ref<int> @ref = new Ref<int>(0);
			Ref<int> ref2 = new Ref<int>(0);
			Ref<int> count = new Ref<int>(0);
			Ref<int> ref3 = new Ref<int>(0);
			WorldUtils.Gen(origin, new Shapes.Circle(15), Actions.Chain(new GenAction[]
			{
				new Actions.Scanner(count),
				new Modifiers.IsSolid(),
				new Actions.Scanner(@ref),
				new Modifiers.OnlyTiles(new ushort[]
				{
					60,
					59
				}),
				new Actions.Scanner(ref2),
				new Modifiers.OnlyTiles(new ushort[]
				{
					60
				}),
				new Actions.Scanner(ref3)
			}));
			if ((float)ref2.Value / (float)@ref.Value < 0.75f || ref3.Value < 2)
			{
				return false;
			}
			if (!structures.CanPlace(new Rectangle(origin.X - 50, origin.Y - 50, 100, 100), 0))
			{
				return false;
			}
			int x = origin.X;
			int y = origin.Y;
			int num = 150;
			for (int i = x - num; i < x + num; i += 10)
			{
				if (i > 0 && i <= Main.maxTilesX - 1)
				{
					for (int j = y - num; j < y + num; j += 10)
					{
						if (j > 0 && j <= Main.maxTilesY - 1)
						{
							if (Main.tile[i, j].active() && Main.tile[i, j].type == 226)
							{
								return false;
							}
							if (Main.tile[i, j].wall == 87 || Main.tile[i, j].wall == 3 || Main.tile[i, j].wall == 83)
							{
								return false;
							}
						}
					}
				}
			}
			int x2 = origin.X;
			int y2 = origin.Y;
			int num2 = 0;
			int[] array = new int[10];
			int[] array2 = new int[10];
			Vector2 vector = new Vector2((float)x2, (float)y2);
			Vector2 vector2 = vector;
			int num3 = WorldGen.genRand.Next(2, 5);
			for (int k = 0; k < num3; k++)
			{
				int num4 = WorldGen.genRand.Next(2, 5);
				for (int l = 0; l < num4; l++)
				{
					vector2 = WorldGen.Hive((int)vector.X, (int)vector.Y);
				}
				vector = vector2;
				array[num2] = (int)vector.X;
				array2[num2] = (int)vector.Y;
				num2++;
			}
			for (int m = 0; m < num2; m++)
			{
				int num5 = array[m];
				int num6 = array2[m];
				bool flag = false;
				int num7 = 1;
				if (WorldGen.genRand.Next(2) == 0)
				{
					num7 = -1;
				}
				while (num5 > 10 && num5 < Main.maxTilesX - 10 && num6 > 10 && num6 < Main.maxTilesY - 10 && (!Main.tile[num5, num6].active() || !Main.tile[num5, num6 + 1].active() || !Main.tile[num5 + 1, num6].active() || !Main.tile[num5 + 1, num6 + 1].active()))
				{
					num5 += num7;
					if (Math.Abs(num5 - array[m]) > 50)
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					num5 += num7;
					for (int n = num5 - 1; n <= num5 + 2; n++)
					{
						for (int num8 = num6 - 1; num8 <= num6 + 2; num8++)
						{
							if (n < 10 || n > Main.maxTilesX - 10)
							{
								flag = true;
							}
							else if (Main.tile[n, num8].active() && Main.tile[n, num8].type != 225)
							{
								flag = true;
								break;
							}
						}
					}
					if (!flag)
					{
						for (int num9 = num5 - 1; num9 <= num5 + 2; num9++)
						{
							for (int num10 = num6 - 1; num10 <= num6 + 2; num10++)
							{
								if (num9 >= num5 && num9 <= num5 + 1 && num10 >= num6 && num10 <= num6 + 1)
								{
									Main.tile[num9, num10].active(false);
									Main.tile[num9, num10].liquid = 255;
									Main.tile[num9, num10].honey(true);
								}
								else
								{
									Main.tile[num9, num10].active(true);
									Main.tile[num9, num10].type = 225;
								}
							}
						}
						num7 *= -1;
						num6++;
						int num11 = 0;
						while ((num11 < 4 || WorldGen.SolidTile(num5, num6)) && num5 > 10 && num5 < Main.maxTilesX - 10)
						{
							num11++;
							num5 += num7;
							if (WorldGen.SolidTile(num5, num6))
							{
								WorldGen.PoundTile(num5, num6);
								if (!Main.tile[num5, num6 + 1].active())
								{
									Main.tile[num5, num6 + 1].active(true);
									Main.tile[num5, num6 + 1].type = 225;
								}
							}
						}
					}
				}
			}
			WorldGen.larvaX[WorldGen.numLarva] = Utils.Clamp<int>((int)vector.X, 5, Main.maxTilesX - 5);
			WorldGen.larvaY[WorldGen.numLarva] = Utils.Clamp<int>((int)vector.Y, 5, Main.maxTilesY - 5);
			WorldGen.numLarva++;
			int num12 = (int)vector.X;
			int num13 = (int)vector.Y;
			int num14 = num12 - 1;
			while (num14 <= num12 + 1 && num14 > 0 && num14 < Main.maxTilesX)
			{
				int num15 = num13 - 2;
				while (num15 <= num13 + 1 && num15 > 0 && num15 < Main.maxTilesY)
				{
					if (num15 != num13 + 1)
					{
						Main.tile[num14, num15].active(false);
					}
					else
					{
						Main.tile[num14, num15].active(true);
						Main.tile[num14, num15].type = 225;
						Main.tile[num14, num15].slope(0);
						Main.tile[num14, num15].halfBrick(false);
					}
					num15++;
				}
				num14++;
			}
			structures.AddStructure(new Rectangle(origin.X - 50, origin.Y - 50, 100, 100), 5);
			return true;
		}
		public override bool Place(Point origin, StructureMap structures)
		{
			if (WorldGen.SolidTile(origin.X, origin.Y) && GenBase._tiles[origin.X, origin.Y].wall == 3)
			{
				return false;
			}
			if (!WorldUtils.Find(origin, Searches.Chain(new Searches.Down(100), new GenCondition[]
			{
				new Conditions.IsSolid()
			}), out origin))
			{
				return false;
			}
			Point point;
			if (!WorldUtils.Find(new Point(origin.X - 4, origin.Y), Searches.Chain(new Searches.Down(5), new GenCondition[]
			{
				new Conditions.IsTile(new ushort[]
				{
					25
				}).AreaAnd(8, 1)
			}), out point))
			{
				return false;
			}
			ShapeData shapeData = new ShapeData();
			ShapeData shapeData2 = new ShapeData();
			ShapeData shapeData3 = new ShapeData();
			for (int i = 0; i < 6; i++)
			{
				WorldUtils.Gen(origin, new Shapes.Circle(GenBase._random.Next(10, 12) + i), Actions.Chain(new GenAction[]
				{
					new Modifiers.Offset(0, 5 * i + 5),
					new Modifiers.Blotches(3, 0.3).Output(shapeData)
				}));
			}
			for (int j = 0; j < 6; j++)
			{
				WorldUtils.Gen(origin, new Shapes.Circle(GenBase._random.Next(5, 7) + j), Actions.Chain(new GenAction[]
				{
					new Modifiers.Offset(0, 2 * j + 18),
					new Modifiers.Blotches(3, 0.3).Output(shapeData2)
				}));
			}
			for (int k = 0; k < 6; k++)
			{
				WorldUtils.Gen(origin, new Shapes.Circle(GenBase._random.Next(4, 6) + k / 2), Actions.Chain(new GenAction[]
				{
					new Modifiers.Offset(0, (int)(7.5f * (float)k) - 10),
					new Modifiers.Blotches(3, 0.3).Output(shapeData3)
				}));
			}
			ShapeData shapeData4 = new ShapeData(shapeData2);
			shapeData2.Subtract(shapeData3, origin, origin);
			shapeData4.Subtract(shapeData2, origin, origin);
			Rectangle bounds = ShapeData.GetBounds(origin, new ShapeData[]
			{
				shapeData,
				shapeData3
			});
			if (!structures.CanPlace(bounds, CorruptionPitBiome.ValidTiles, 2))
			{
				return false;
			}
			WorldUtils.Gen(origin, new ModShapes.All(shapeData), Actions.Chain(new GenAction[]
			{
				new Actions.SetTile(25, true, true),
				new Actions.PlaceWall(3, true)
			}));
			WorldUtils.Gen(origin, new ModShapes.All(shapeData2), new Actions.SetTile(0, true, true));
			WorldUtils.Gen(origin, new ModShapes.All(shapeData3), new Actions.ClearTile(true));
			WorldUtils.Gen(origin, new ModShapes.All(shapeData2), Actions.Chain(new GenAction[]
			{
				new Modifiers.IsTouchingAir(true),
				new Modifiers.NotTouching(false, new ushort[]
				{
					25
				}),
				new Actions.SetTile(23, true, true)
			}));
			WorldUtils.Gen(origin, new ModShapes.All(shapeData4), new Actions.PlaceWall(69, true));
			structures.AddStructure(bounds, 2);
			return true;
		}
 public override bool Place(Point origin, StructureMap structures)
 {
     Point point;
     if (WorldGen.SolidTile(origin.X, origin.Y) && GenBase._tiles[origin.X, origin.Y].wall == 3)
     {
         return false;
     }
     Searches.Down down = new Searches.Down(100);
     GenCondition[] isSolid = new GenCondition[] { new Conditions.IsSolid() };
     if (!WorldUtils.Find(origin, Searches.Chain(down, isSolid), out origin))
     {
         return false;
     }
     Point point1 = new Point(origin.X - 4, origin.Y);
     Searches.Down down1 = new Searches.Down(5);
     GenCondition[] genConditionArray = new GenCondition[1];
     ushort[] numArray = new ushort[] { 25 };
     genConditionArray[0] = (new Conditions.IsTile(numArray)).AreaAnd(8, 1);
     if (!WorldUtils.Find(point1, Searches.Chain(down1, genConditionArray), out point))
     {
         return false;
     }
     ShapeData shapeDatum = new ShapeData();
     ShapeData shapeDatum1 = new ShapeData();
     ShapeData shapeDatum2 = new ShapeData();
     for (int i = 0; i < 6; i++)
     {
         Shapes.Circle circle = new Shapes.Circle(GenBase._random.Next(10, 12) + i);
         GenAction[] offset = new GenAction[] { new Modifiers.Offset(0, 5 * i + 5), (new Modifiers.Blotches(3, 0.3)).Output(shapeDatum) };
         WorldUtils.Gen(origin, circle, Actions.Chain(offset));
     }
     for (int j = 0; j < 6; j++)
     {
         Shapes.Circle circle1 = new Shapes.Circle(GenBase._random.Next(5, 7) + j);
         GenAction[] genActionArray = new GenAction[] { new Modifiers.Offset(0, 2 * j + 18), (new Modifiers.Blotches(3, 0.3)).Output(shapeDatum1) };
         WorldUtils.Gen(origin, circle1, Actions.Chain(genActionArray));
     }
     for (int k = 0; k < 6; k++)
     {
         Shapes.Circle circle2 = new Shapes.Circle(GenBase._random.Next(4, 6) + k / 2);
         GenAction[] offset1 = new GenAction[] { new Modifiers.Offset(0, (int)(7.5f * (float)k) - 10), (new Modifiers.Blotches(3, 0.3)).Output(shapeDatum2) };
         WorldUtils.Gen(origin, circle2, Actions.Chain(offset1));
     }
     ShapeData shapeDatum3 = new ShapeData(shapeDatum1);
     shapeDatum1.Subtract(shapeDatum2, origin, origin);
     shapeDatum3.Subtract(shapeDatum1, origin, origin);
     ShapeData[] shapeDataArray = new ShapeData[] { shapeDatum, shapeDatum2 };
     Rectangle bounds = ShapeData.GetBounds(origin, shapeDataArray);
     if (!structures.CanPlace(bounds, CorruptionPitBiome.ValidTiles, 2))
     {
         return false;
     }
     ModShapes.All all = new ModShapes.All(shapeDatum);
     GenAction[] setTile = new GenAction[] { new Actions.SetTile(25, true, true), new Actions.PlaceWall(3, true) };
     WorldUtils.Gen(origin, all, Actions.Chain(setTile));
     WorldUtils.Gen(origin, new ModShapes.All(shapeDatum1), new Actions.SetTile(0, true, true));
     WorldUtils.Gen(origin, new ModShapes.All(shapeDatum2), new Actions.ClearTile(true));
     ModShapes.All all1 = new ModShapes.All(shapeDatum1);
     GenAction[] isTouchingAir = new GenAction[] { new Modifiers.IsTouchingAir(true), null, null };
     ushort[] numArray1 = new ushort[] { 25 };
     isTouchingAir[1] = new Modifiers.NotTouching(false, numArray1);
     isTouchingAir[2] = new Actions.SetTile(23, true, true);
     WorldUtils.Gen(origin, all1, Actions.Chain(isTouchingAir));
     WorldUtils.Gen(origin, new ModShapes.All(shapeDatum3), new Actions.PlaceWall(69, true));
     structures.AddStructure(bounds, 2);
     return true;
 }
Exemplo n.º 25
0
 public abstract bool Place(Point origin, StructureMap structures);
Exemplo n.º 26
0
 public override bool Place(Point origin, StructureMap structures)
 {
     if (GenBase._tiles[origin.X, origin.Y].active())
     {
         return false;
     }
     int length = GraniteBiome._sourceMagmaMap.GetLength(0);
     int num = GraniteBiome._sourceMagmaMap.GetLength(1);
     int num1 = length / 2;
     int num2 = num / 2;
     origin.X = origin.X - num1;
     origin.Y = origin.Y - num2;
     for (int i = 0; i < length; i++)
     {
         for (int j = 0; j < num; j++)
         {
             GraniteBiome._sourceMagmaMap[i, j] = GraniteBiome.Magma.CreateEmpty((WorldGen.SolidTile(i + origin.X, j + origin.Y) ? 4f : 1f));
             GraniteBiome._targetMagmaMap[i, j] = GraniteBiome._sourceMagmaMap[i, j];
         }
     }
     int num3 = num1;
     int num4 = num1;
     int num5 = num2;
     int num6 = num2;
     for (int k = 0; k < 300; k++)
     {
         for (int l = num3; l <= num4; l++)
         {
             for (int m = num5; m <= num6; m++)
             {
                 GraniteBiome.Magma magma = GraniteBiome._sourceMagmaMap[l, m];
                 if (magma.IsActive)
                 {
                     float single = 0f;
                     Vector2 zero = Vector2.Zero;
                     for (int n = -1; n <= 1; n++)
                     {
                         for (int o = -1; o <= 1; o++)
                         {
                             if (n != 0 || o != 0)
                             {
                                 Vector2 vector2 = new Vector2((float)n, (float)o);
                                 vector2.Normalize();
                                 GraniteBiome.Magma magma1 = GraniteBiome._sourceMagmaMap[l + n, m + o];
                                 if (magma.Pressure > 0.01f && !magma1.IsActive)
                                 {
                                     if (n != -1)
                                     {
                                         num4 = Utils.Clamp<int>(l + n, num4, length - 2);
                                     }
                                     else
                                     {
                                         num3 = Utils.Clamp<int>(l + n, 1, num3);
                                     }
                                     if (o != -1)
                                     {
                                         num6 = Utils.Clamp<int>(m + o, num6, num - 2);
                                     }
                                     else
                                     {
                                         num5 = Utils.Clamp<int>(m + o, 1, num5);
                                     }
                                     GraniteBiome._targetMagmaMap[l + n, m + o] = magma1.ToFlow();
                                 }
                                 float pressure = magma1.Pressure;
                                 single = single + pressure;
                                 zero = zero + (pressure * vector2);
                             }
                         }
                     }
                     single = single / 8f;
                     if (single > magma.Resistance)
                     {
                         float single1 = zero.Length() / 8f;
                         float single2 = Math.Max(single - single1 - magma.Pressure, 0f) + single1 + magma.Pressure * 0.875f - magma.Resistance;
                         single2 = Math.Max(0f, single2);
                         GraniteBiome._targetMagmaMap[l, m] = GraniteBiome.Magma.CreateFlow(single2, Math.Max(0f, magma.Resistance - single2 * 0.02f));
                     }
                 }
             }
         }
         if (k < 2)
         {
             GraniteBiome._targetMagmaMap[num1, num2] = GraniteBiome.Magma.CreateFlow(25f, 0f);
         }
         Utils.Swap<GraniteBiome.Magma[,]>(ref GraniteBiome._sourceMagmaMap, ref GraniteBiome._targetMagmaMap);
     }
     bool y = origin.Y + num2 > WorldGen.lavaLine - 30;
     bool flag = false;
     for (int p = -50; p < 50 && !flag; p++)
     {
         for (int q = -50; q < 50 && !flag; q++)
         {
             if (GenBase._tiles[origin.X + num1 + p, origin.Y + num2 + q].active())
             {
                 ushort num7 = GenBase._tiles[origin.X + num1 + p, origin.Y + num2 + q].type;
                 if (num7 != 147)
                 {
                     switch (num7)
                     {
                         case 161:
                         case 162:
                         case 163:
                             {
                                 break;
                             }
                         default:
                             {
                                 if (num7 != 200)
                                 {
                                     continue;
                                 }
                                 else
                                 {
                                     break;
                                 }
                             }
                     }
                 }
                 y = false;
                 flag = true;
             }
         }
     }
     for (int r = num3; r <= num4; r++)
     {
         for (int s = num5; s <= num6; s++)
         {
             GraniteBiome.Magma magma2 = GraniteBiome._sourceMagmaMap[r, s];
             if (magma2.IsActive)
             {
                 Tile tile = GenBase._tiles[origin.X + r, origin.Y + s];
                 float single3 = (float)Math.Sin((double)((float)(origin.Y + s) * 0.4f)) * 0.7f + 1.2f;
                 float single4 = 0.2f + 0.5f / (float)Math.Sqrt((double)Math.Max(0f, magma2.Pressure - magma2.Resistance));
                 float single5 = 1f - Math.Max(0f, single3 * single4);
                 single5 = Math.Max(single5, magma2.Pressure / 15f);
                 if (single5 > 0.35f + (WorldGen.SolidTile(origin.X + r, origin.Y + s) ? 0f : 0.5f))
                 {
                     if (!TileID.Sets.Ore[tile.type])
                     {
                         tile.ResetToType(368);
                     }
                     else
                     {
                         tile.ResetToType(tile.type);
                     }
                     tile.wall = 180;
                 }
                 else if (magma2.Resistance < 0.01f)
                 {
                     WorldUtils.ClearTile(origin.X + r, origin.Y + s, false);
                     tile.wall = 180;
                 }
                 if (tile.liquid > 0 && y)
                 {
                     tile.liquidType(1);
                 }
             }
         }
     }
     List<Point16> point16s = new List<Point16>();
     for (int t = num3; t <= num4; t++)
     {
         for (int u = num5; u <= num6; u++)
         {
             if (GraniteBiome._sourceMagmaMap[t, u].IsActive)
             {
                 int num8 = 0;
                 int x = t + origin.X;
                 int y1 = u + origin.Y;
                 if (WorldGen.SolidTile(x, y1))
                 {
                     for (int v = -1; v <= 1; v++)
                     {
                         for (int w = -1; w <= 1; w++)
                         {
                             if (WorldGen.SolidTile(x + v, y1 + w))
                             {
                                 num8++;
                             }
                         }
                     }
                     if (num8 < 3)
                     {
                         point16s.Add(new Point16(x, y1));
                     }
                 }
             }
         }
     }
     foreach (Point16 point16 in point16s)
     {
         int x1 = point16.X;
         int y2 = point16.Y;
         WorldUtils.ClearTile(x1, y2, true);
         GenBase._tiles[x1, y2].wall = 180;
     }
     point16s.Clear();
     for (int x2 = num3; x2 <= num4; x2++)
     {
         for (int y3 = num5; y3 <= num6; y3++)
         {
             GraniteBiome.Magma magma3 = GraniteBiome._sourceMagmaMap[x2, y3];
             int x3 = x2 + origin.X;
             int y4 = y3 + origin.Y;
             if (magma3.IsActive)
             {
                 WorldUtils.TileFrame(x3, y4, false);
                 WorldGen.SquareWallFrame(x3, y4, true);
                 if (GenBase._random.Next(8) == 0 && GenBase._tiles[x3, y4].active())
                 {
                     if (!GenBase._tiles[x3, y4 + 1].active())
                     {
                         WorldGen.PlaceTight(x3, y4 + 1, 165, false);
                     }
                     if (!GenBase._tiles[x3, y4 - 1].active())
                     {
                         WorldGen.PlaceTight(x3, y4 - 1, 165, false);
                     }
                 }
                 if (GenBase._random.Next(2) == 0)
                 {
                     Tile.SmoothSlope(x3, y4, true);
                 }
             }
         }
     }
     return true;
 }
Exemplo n.º 27
0
        public override bool Place(Point origin, StructureMap structures)
        {
            if (_slabs == null)
                _slabs = new Slab[56, 26];

            int num1 = GenBase._random.Next(80, 150) / 3;
            int num2 = GenBase._random.Next(40, 60) / 3;
            int num3 = (num2 * 3 - GenBase._random.Next(20, 30)) / 3;
            origin.X -= num1 * 3 / 2;
            origin.Y -= num2 * 3 / 2;
            for (int index1 = -1; index1 < num1 + 1; ++index1)
            {
                float num4 = (float)((index1 - num1 / 2) / num1 + 0.5);
                int num5 = (int)((0.5 - (double)Math.Abs(num4 - 0.5f)) * 5.0) - 2;
                for (int index2 = -1; index2 < num2 + 1; ++index2)
                {
                    bool hasWall = true;
                    bool flag1 = false;
                    bool flag2 = IsGroupSolid(index1 * 3 + origin.X, index2 * 3 + origin.Y, 3);
                    int num6 = Math.Abs(index2 - num2 / 2) - num3 / 4 + num5;
                    if (num6 > 3)
                    {
                        flag1 = flag2;
                        hasWall = false;
                    }
                    else if (num6 > 0)
                    {
                        flag1 = index2 - num2 / 2 > 0 || flag2;
                        hasWall = index2 - num2 / 2 < 0 || num6 <= 2;
                    }
                    else if (num6 == 0)
                        flag1 = GenBase._random.Next(2) == 0 && (index2 - num2 / 2 > 0 || flag2);

                    if ((double)Math.Abs(num4 - 0.5f) > 0.349999994039536 + (double)Utils.NextFloat(GenBase._random) * 0.100000001490116 && !flag2)
                    {
                        hasWall = false;
                        flag1 = false;
                    }

                    _slabs[index1 + 1, index2 + 1] = Slab.Create(flag1 ? new SlabState(SlabStates.Solid) : new SlabState(SlabStates.Empty), hasWall);
                }
            }

            for (int index1 = 0; index1 < num1; ++index1)
            {
                for (int index2 = 0; index2 < num2; ++index2)
                    SmoothSlope(index1 + 1, index2 + 1);
            }

            int num7 = num1 / 2;
            int val1 = num2 / 2;
            int num8 = (val1 + 1) * (val1 + 1);
            float num9 = (float)(Utils.NextFloat(GenBase._random) * 2.0 - 1.0);
            float num10 = (float)(Utils.NextFloat(GenBase._random) * 2.0 - 1.0);
            float num11 = (float)(Utils.NextFloat(GenBase._random) * 2.0 - 1.0);
            float num12 = 0.0f;
            for (int index1 = 0; index1 <= num1; ++index1)
            {
                float num4 = (float)val1 / (float)num7 * (float)(index1 - num7);
                int num5 = Math.Min(val1, (int)Math.Sqrt(Math.Max(0.0f, (float)num8 - num4 * num4)));
                if (index1 < num1 / 2)
                    num12 += MathHelper.Lerp(num9, num10, (float)index1 / (float)(num1 / 2));
                else
                    num12 += MathHelper.Lerp(num10, num11, (float)(index1 / (num1 / 2) - 1.0));

                for (int index2 = val1 - num5; index2 <= val1 + num5; ++index2)
                    PlaceSlab(_slabs[index1 + 1, index2 + 1], index1 * 3 + origin.X, index2 * 3 + origin.Y + (int)num12, 3);
            }

            return true;
        }
		public override bool Place(Point origin, StructureMap structures)
		{
			Point origin2;
			if (!WorldUtils.Find(new Point(origin.X - 3, origin.Y), Searches.Chain(new Searches.Down(200), new GenCondition[]
			{
				new Conditions.IsSolid().AreaAnd(6, 1)
			}), out origin2))
			{
				return false;
			}
			Point point;
			bool flag = WorldUtils.Find(new Point(origin2.X, origin2.Y - 5), Searches.Chain(new Searches.Up(120), new GenCondition[]
			{
				new Conditions.IsSolid().AreaOr(6, 1)
			}), out point);
			if (!flag || origin2.Y - 5 - point.Y > 60)
			{
				return false;
			}
			if (origin2.Y - point.Y < 30)
			{
				return false;
			}
			if (!structures.CanPlace(new Rectangle(origin2.X - 30, origin2.Y - 60, 60, 90), 0))
			{
				return false;
			}
			Dictionary<ushort, int> dictionary = new Dictionary<ushort, int>();
			WorldUtils.Gen(new Point(origin2.X - 25, origin2.Y - 25), new Shapes.Rectangle(50, 50), new Actions.TileScanner(new ushort[]
			{
				0,
				59,
				147,
				1
			}).Output(dictionary));
			int num = dictionary[0] + dictionary[1];
			int num2 = dictionary[59];
			int num3 = dictionary[147];
			if (num3 > num2 || num > num2 || num2 < 50)
			{
				return false;
			}
			int num4 = (origin2.Y - point.Y - 9) / 5;
			int num5 = num4 * 5;
			int num6 = 0;
			double num7 = GenBase._random.NextDouble() + 1.0;
			double num8 = GenBase._random.NextDouble() + 2.0;
			if (GenBase._random.Next(2) == 0)
			{
				num8 = -num8;
			}
			for (int i = 0; i < num4; i++)
			{
				double num9 = (double)(i + 1) / 12.0;
				int num10 = (int)(Math.Sin(num9 * num7 * 3.1415927410125732) * num8);
				int num11 = (num10 < num6) ? (num10 - num6) : 0;
				WorldUtils.Gen(new Point(origin2.X + num6 + num11, origin2.Y - (i + 1) * 5), new Shapes.Rectangle(6 + Math.Abs(num10 - num6), 7), Actions.Chain(new GenAction[]
				{
					new Actions.RemoveWall(),
					new Actions.SetTile(383, false, true),
					new Actions.SetFrames(false)
				}));
				WorldUtils.Gen(new Point(origin2.X + num6 + num11 + 2, origin2.Y - (i + 1) * 5), new Shapes.Rectangle(2 + Math.Abs(num10 - num6), 5), Actions.Chain(new GenAction[]
				{
					new Actions.ClearTile(true),
					new Actions.PlaceWall(78, true)
				}));
				WorldUtils.Gen(new Point(origin2.X + num6 + 2, origin2.Y - i * 5), new Shapes.Rectangle(2, 2), Actions.Chain(new GenAction[]
				{
					new Actions.ClearTile(true),
					new Actions.PlaceWall(78, true)
				}));
				num6 = num10;
			}
			int num12 = 6;
			if (num8 < 0.0)
			{
				num12 = 0;
			}
			List<Point> list = new List<Point>();
			for (int j = 0; j < 2; j++)
			{
				double num13 = ((double)j + 1.0) / 3.0;
				int num14 = num12 + (int)(Math.Sin((double)num4 * num13 / 12.0 * num7 * 3.1415927410125732) * num8);
				double num15 = GenBase._random.NextDouble() * 0.78539818525314331 - 0.78539818525314331 - 0.20000000298023224;
				if (num12 == 0)
				{
					num15 -= 1.5707963705062866;
				}
				WorldUtils.Gen(new Point(origin2.X + num14, origin2.Y - (int)((double)(num4 * 5) * num13)), new ShapeBranch(num15, (double)GenBase._random.Next(12, 16)).OutputEndpoints(list), Actions.Chain(new GenAction[]
				{
					new Actions.SetTile(383, false, true),
					new Actions.SetFrames(true)
				}));
				num12 = 6 - num12;
			}
			int num16 = (int)(Math.Sin((double)num4 / 12.0 * num7 * 3.1415927410125732) * num8);
			WorldUtils.Gen(new Point(origin2.X + 6 + num16, origin2.Y - num5), new ShapeBranch(-0.68539818525314333, (double)GenBase._random.Next(16, 22)).OutputEndpoints(list), Actions.Chain(new GenAction[]
			{
				new Actions.SetTile(383, false, true),
				new Actions.SetFrames(true)
			}));
			WorldUtils.Gen(new Point(origin2.X + num16, origin2.Y - num5), new ShapeBranch(-2.45619455575943, (double)GenBase._random.Next(16, 22)).OutputEndpoints(list), Actions.Chain(new GenAction[]
			{
				new Actions.SetTile(383, false, true),
				new Actions.SetFrames(true)
			}));
			foreach (Point current in list)
			{
				WorldUtils.Gen(current, new Shapes.Circle(4), Actions.Chain(new GenAction[]
				{
					new Modifiers.Blotches(4, 2, 0.3),
					new Modifiers.SkipTiles(new ushort[]
					{
						383
					}),
					new Modifiers.SkipWalls(new byte[]
					{
						78
					}),
					new Actions.SetTile(384, false, true),
					new Actions.SetFrames(true)
				}));
			}
			for (int k = 0; k < 4; k++)
			{
				float angle = (float)k / 3f * 2f + 0.57075f;
				WorldUtils.Gen(origin2, new ShapeRoot(angle, (float)GenBase._random.Next(40, 60), 4f, 1f), new Actions.SetTile(383, true, true));
			}
			WorldGen.AddBuriedChest(origin2.X + 3, origin2.Y - 1, (GenBase._random.Next(4) == 0) ? 0 : WorldGen.GetNextJungleChestItem(), false, 10);
			structures.AddStructure(new Rectangle(origin2.X - 30, origin2.Y - 30, 60, 60), 0);
			return true;
		}
Exemplo n.º 29
0
 public override bool Place(Point origin, StructureMap structures)
 {
     Point point;
     Ref<int> @ref = new Ref<int>(0);
     Ref<int> ref1 = new Ref<int>(0);
     Shapes.Circle circle = new Shapes.Circle(10);
     GenAction[] scanner = new GenAction[] { new Actions.Scanner(ref1), new Modifiers.IsSolid(), new Actions.Scanner(@ref) };
     WorldUtils.Gen(origin, circle, Actions.Chain(scanner));
     if (@ref.Value < ref1.Value - 5)
     {
         return false;
     }
     int num = GenBase._random.Next(6, 10);
     int num1 = GenBase._random.Next(5);
     if (!structures.CanPlace(new Rectangle(origin.X - num, origin.Y - num, num * 2, num * 2), 0))
     {
         return false;
     }
     ShapeData shapeDatum = new ShapeData();
     Shapes.Slime slime = new Shapes.Slime(num);
     GenAction[] onlyTile = new GenAction[] { (new Modifiers.Blotches(num1, num1, num1, 1, 0.3)).Output(shapeDatum), new Modifiers.Offset(0, -2), null, null, null, null };
     ushort[] numArray = new ushort[] { 53 };
     onlyTile[2] = new Modifiers.OnlyTiles(numArray);
     onlyTile[3] = new Actions.SetTile(397, true, true);
     onlyTile[4] = new Modifiers.OnlyWalls(new byte[1]);
     onlyTile[5] = new Actions.PlaceWall(16, true);
     WorldUtils.Gen(origin, slime, Actions.Chain(onlyTile));
     ModShapes.All all = new ModShapes.All(shapeDatum);
     GenAction[] clearTile = new GenAction[] { new Actions.ClearTile(false), new Actions.SetLiquid(0, 0), new Actions.SetFrames(true), new Modifiers.OnlyWalls(new byte[1]), new Actions.PlaceWall(16, true) };
     WorldUtils.Gen(origin, all, Actions.Chain(clearTile));
     Searches.Down down = new Searches.Down(10);
     GenCondition[] isSolid = new GenCondition[] { new Conditions.IsSolid() };
     if (!WorldUtils.Find(origin, Searches.Chain(down, isSolid), out point))
     {
         return false;
     }
     int y = point.Y - 1;
     bool flag = GenBase._random.Next() % 2 == 0;
     if (GenBase._random.Next() % 10 != 0)
     {
         int num2 = GenBase._random.Next(1, 4);
         int num3 = (flag ? 4 : -(num >> 1));
         for (int i = 0; i < num2; i++)
         {
             int num4 = GenBase._random.Next(1, 3);
             for (int j = 0; j < num4; j++)
             {
                 WorldGen.PlaceTile(origin.X + num3 - i, y - j, 331, false, false, -1, 0);
             }
         }
     }
     int num5 = (num - 3) * (flag ? -1 : 1);
     if (GenBase._random.Next() % 10 != 0)
     {
         WorldGen.PlaceTile(origin.X + num5, y, 186, false, false, -1, 0);
     }
     if (GenBase._random.Next() % 10 != 0)
     {
         WorldGen.PlaceTile(origin.X, y, 215, true, false, -1, 0);
         if (GenBase._tiles[origin.X, y].active() && GenBase._tiles[origin.X, y].type == 215)
         {
             Tile tile = GenBase._tiles[origin.X, y];
             tile.frameY = (short)(tile.frameY + 36);
             Tile tile1 = GenBase._tiles[origin.X - 1, y];
             tile1.frameY = (short)(tile1.frameY + 36);
             Tile tile2 = GenBase._tiles[origin.X + 1, y];
             tile2.frameY = (short)(tile2.frameY + 36);
             Tile tile3 = GenBase._tiles[origin.X, y - 1];
             tile3.frameY = (short)(tile3.frameY + 36);
             Tile tile4 = GenBase._tiles[origin.X - 1, y - 1];
             tile4.frameY = (short)(tile4.frameY + 36);
             Tile tile5 = GenBase._tiles[origin.X + 1, y - 1];
             tile5.frameY = (short)(tile5.frameY + 36);
         }
     }
     structures.AddStructure(new Rectangle(origin.X - num, origin.Y - num, num * 2, num * 2), 4);
     return true;
 }
Exemplo n.º 30
0
        public override bool Place(Point origin, StructureMap structures)
        {
            Ref<int> count1 = new Ref<int>(0);
            Ref<int> count2 = new Ref<int>(0);
            Ref<int> count3 = new Ref<int>(0);
            Ref<int> count4 = new Ref<int>(0);
            WorldUtils.Gen(origin, new Shapes.Circle(15), Actions.Chain(new Actions.Scanner(count3), new Modifiers.IsSolid(),
                new Actions.Scanner(count1), new Modifiers.OnlyTiles(new ushort[2] { 60, 59 }), new Actions.Scanner(count2), new Modifiers.OnlyTiles(new ushort[1] { 60 }), new Actions.Scanner(count4)));
            if (((((float)count2.Value) / ((float)count1.Value)) < 0.75) || count4.Value < 2 || !structures.CanPlace(new Microsoft.Xna.Framework.Rectangle(origin.X - 50, origin.Y - 50, 100, 100), 0))
                return false;

            int num1 = origin.X;
            int num2 = origin.Y;
            int num3 = 150;
            int index1 = num1 - num3;
            while (index1 < num1 + num3)
            {
                if (index1 > 0 && index1 <= Main.maxTilesX - 1)
                {
                    int index2 = num2 - num3;
                    while (index2 < num2 + num3)
                    {
                        if (index2 > 0 && index2 <= Main.maxTilesY - 1 && (Main.tile[index1, index2].active() && Main.tile[index1, index2].type == 226 ||
                            (Main.tile[index1, index2].wall == 87 || Main.tile[index1, index2].wall == 3) || Main.tile[index1, index2].wall == 83))
                            return false;
                        index2 += 10;
                    }
                }
                index1 += 10;
            }

            int num4 = origin.X;
            int num5 = origin.Y;
            int index3 = 0;
            int[] numArray1 = new int[10];
            int[] numArray2 = new int[10];
            Vector2 vector2_1 = new Vector2((float)num4, (float)num5);
            Vector2 vector2_2 = vector2_1;
            int num6 = WorldGen.genRand.Next(2, 5);
            for (int index2 = 0; index2 < num6; ++index2)
            {
                int num7 = WorldGen.genRand.Next(2, 5);
                for (int index4 = 0; index4 < num7; ++index4)
                    vector2_2 = WorldGen.Hive((int)vector2_1.X, (int)vector2_1.Y);
                vector2_1 = vector2_2;
                numArray1[index3] = (int)vector2_1.X;
                numArray2[index3] = (int)vector2_1.Y;
                ++index3;
            }

            for (int index2 = 0; index2 < index3; ++index2)
            {
                int index4 = numArray1[index2];
                int index5 = numArray2[index2];
                bool flag = false;
                int num7 = 1;
                if (WorldGen.genRand.Next(2) == 0)
                    num7 = -1;
                while (index4 > 10 && index4 < Main.maxTilesX - 10 && (index5 > 10 && index5 < Main.maxTilesY - 10) && (!Main.tile[index4, index5].active() ||
                    !Main.tile[index4, index5 + 1].active() || (!Main.tile[index4 + 1, index5].active() || !Main.tile[index4 + 1, index5 + 1].active())))
                {
                    index4 += num7;
                    if (Math.Abs(index4 - numArray1[index2]) > 50)
                    {
                        flag = true;
                        break;
                    }
                }

                if (!flag)
                {
                    int i = index4 + num7;
                    for (int index6 = i - 1; index6 <= i + 2; ++index6)
                    {
                        for (int index7 = index5 - 1; index7 <= index5 + 2; ++index7)
                        {
                            if (index6 < 10 || index6 > Main.maxTilesX - 10)
                                flag = true;
                            else if (Main.tile[index6, index7].active() && (int)Main.tile[index6, index7].type != 225)
                            {
                                flag = true;
                                break;
                            }
                        }
                    }

                    if (!flag)
                    {
                        for (int index6 = i - 1; index6 <= i + 2; ++index6)
                        {
                            for (int index7 = index5 - 1; index7 <= index5 + 2; ++index7)
                            {
                                if (index6 >= i && index6 <= i + 1 && (index7 >= index5 && index7 <= index5 + 1))
                                {
                                    Main.tile[index6, index7].active(false);
                                    Main.tile[index6, index7].liquid = byte.MaxValue;
                                    Main.tile[index6, index7].honey(true);
                                }
                                else
                                {
                                    Main.tile[index6, index7].active(true);
                                    Main.tile[index6, index7].type = (ushort)225;
                                }
                            }
                        }

                        int num8 = num7 * -1;
                        int j = index5 + 1;
                        int num9 = 0;
                        while ((num9 < 4 || WorldGen.SolidTile(i, j)) && (i > 10 && i < Main.maxTilesX - 10))
                        {
                            ++num9;
                            i += num8;
                            if (WorldGen.SolidTile(i, j))
                            {
                                WorldGen.PoundTile(i, j);
                                if (!Main.tile[i, j + 1].active())
                                {
                                    Main.tile[i, j + 1].active(true);
                                    Main.tile[i, j + 1].type = (ushort)225;
                                }
                            }
                        }
                    }
                }
            }

            WorldGen.larvaX[WorldGen.numLarva] = Utils.Clamp<int>((int)vector2_1.X, 5, Main.maxTilesX - 5);
            WorldGen.larvaY[WorldGen.numLarva] = Utils.Clamp<int>((int)vector2_1.Y, 5, Main.maxTilesY - 5);
            ++WorldGen.numLarva;
            int num10 = (int)vector2_1.X;
            int num11 = (int)vector2_1.Y;
            for (int index2 = num10 - 1; index2 <= num10 + 1 && (index2 > 0 && index2 < Main.maxTilesX); ++index2)
            {
                for (int index4 = num11 - 2; index4 <= num11 + 1 && (index4 > 0 && index4 < Main.maxTilesY); ++index4)
                {
                    if (index4 != num11 + 1)
                        Main.tile[index2, index4].active(false);
                    else
                    {
                        Main.tile[index2, index4].active(true);
                        Main.tile[index2, index4].type = (ushort)225;
                        Main.tile[index2, index4].slope((byte)0);
                        Main.tile[index2, index4].halfBrick(false);
                    }
                }
            }

            structures.AddStructure(new Microsoft.Xna.Framework.Rectangle(origin.X - 50, origin.Y - 50, 100, 100), 5);
            return true;
        }
Exemplo n.º 31
0
 public override bool Place(Point origin, StructureMap structures)
 {
     Point point;
     bool flag = WorldUtils.Find(origin, Searches.Chain(new Searches.Down(200), new GenCondition[]
     {
         new Conditions.IsSolid()
     }), out point);
     if (!flag || point == origin)
     {
         return false;
     }
     Rectangle room = this.GetRoom(point);
     Rectangle rectangle = this.GetRoom(new Point(room.Center.X, room.Y + 1));
     Rectangle rectangle2 = this.GetRoom(new Point(room.Center.X, room.Y + room.Height + 10));
     rectangle2.Y = room.Y + room.Height - 1;
     float num = this.RoomSolidPrecentage(rectangle);
     float num2 = this.RoomSolidPrecentage(rectangle2);
     room.Y += 3;
     rectangle.Y += 3;
     rectangle2.Y += 3;
     List<Rectangle> list = new List<Rectangle>();
     if (GenBase._random.NextFloat() > num + 0.2f)
     {
         list.Add(rectangle);
     }
     else
     {
         rectangle = room;
     }
     list.Add(room);
     if (GenBase._random.NextFloat() > num2 + 0.2f)
     {
         list.Add(rectangle2);
     }
     else
     {
         rectangle2 = room;
     }
     Dictionary<ushort, int> dictionary = new Dictionary<ushort, int>();
     foreach (Rectangle current in list)
     {
         WorldUtils.Gen(new Point(current.X - 5, current.Y - 5), new Shapes.Rectangle(current.Width + 10, current.Height + 10), new Actions.TileScanner(new ushort[]
         {
             0,
             59,
             147,
             1,
             161,
             53,
             396,
             397,
             368,
             367,
             60,
             70
         }).Output(dictionary));
     }
     List<Tuple<CaveHouseBiome.BuildData, int>> list2 = new List<Tuple<CaveHouseBiome.BuildData, int>>();
     list2.Add(Tuple.Create<CaveHouseBiome.BuildData, int>(CaveHouseBiome.BuildData.Default, dictionary[0] + dictionary[1]));
     list2.Add(Tuple.Create<CaveHouseBiome.BuildData, int>(CaveHouseBiome.BuildData.Jungle, dictionary[59] + dictionary[60] * 10));
     list2.Add(Tuple.Create<CaveHouseBiome.BuildData, int>(CaveHouseBiome.BuildData.Mushroom, dictionary[59] + dictionary[70] * 10));
     list2.Add(Tuple.Create<CaveHouseBiome.BuildData, int>(CaveHouseBiome.BuildData.Snow, dictionary[147] + dictionary[161]));
     list2.Add(Tuple.Create<CaveHouseBiome.BuildData, int>(CaveHouseBiome.BuildData.Desert, dictionary[397] + dictionary[396] + dictionary[53]));
     list2.Add(Tuple.Create<CaveHouseBiome.BuildData, int>(CaveHouseBiome.BuildData.Granite, dictionary[368]));
     list2.Add(Tuple.Create<CaveHouseBiome.BuildData, int>(CaveHouseBiome.BuildData.Marble, dictionary[367]));
     list2.Sort(new Comparison<Tuple<CaveHouseBiome.BuildData, int>>(this.SortBiomeResults));
     CaveHouseBiome.BuildData item = list2[0].Item1;
     foreach (Rectangle current2 in list)
     {
         if (item != CaveHouseBiome.BuildData.Granite)
         {
             Point point2;
             bool flag2 = WorldUtils.Find(new Point(current2.X - 2, current2.Y - 2), Searches.Chain(new Searches.Rectangle(current2.Width + 4, current2.Height + 4).RequireAll(false), new GenCondition[]
             {
                 new Conditions.HasLava()
             }), out point2);
             if (flag2)
             {
                 bool result = false;
                 return result;
             }
         }
         if (!structures.CanPlace(current2, CaveHouseBiome._blacklistedTiles, 5))
         {
             bool result = false;
             return result;
         }
     }
     int num3 = room.X;
     int num4 = room.X + room.Width - 1;
     List<Rectangle> list3 = new List<Rectangle>();
     foreach (Rectangle current3 in list)
     {
         num3 = Math.Min(num3, current3.X);
         num4 = Math.Max(num4, current3.X + current3.Width - 1);
     }
     int num5 = 6;
     while (num5 > 4 && (num4 - num3) % num5 != 0)
     {
         num5--;
     }
     for (int i = num3; i <= num4; i += num5)
     {
         for (int j = 0; j < list.Count; j++)
         {
             Rectangle rectangle3 = list[j];
             if (i >= rectangle3.X && i < rectangle3.X + rectangle3.Width)
             {
                 int num6 = rectangle3.Y + rectangle3.Height;
                 int num7 = 50;
                 for (int k = j + 1; k < list.Count; k++)
                 {
                     if (i >= list[k].X && i < list[k].X + list[k].Width)
                     {
                         num7 = Math.Min(num7, list[k].Y - num6);
                     }
                 }
                 if (num7 > 0)
                 {
                     Point point3;
                     bool flag3 = WorldUtils.Find(new Point(i, num6), Searches.Chain(new Searches.Down(num7), new GenCondition[]
                     {
                         new Conditions.IsSolid()
                     }), out point3);
                     if (num7 < 50)
                     {
                         flag3 = true;
                         point3 = new Point(i, num6 + num7);
                     }
                     if (flag3)
                     {
                         list3.Add(new Rectangle(i, num6, 1, point3.Y - num6));
                     }
                 }
             }
         }
     }
     List<Point> list4 = new List<Point>();
     foreach (Rectangle current4 in list)
     {
         int num8;
         bool flag4 = this.FindSideExit(new Rectangle(current4.X + current4.Width, current4.Y + 1, 1, current4.Height - 2), false, out num8);
         if (flag4)
         {
             list4.Add(new Point(current4.X + current4.Width - 1, num8));
         }
         flag4 = this.FindSideExit(new Rectangle(current4.X, current4.Y + 1, 1, current4.Height - 2), true, out num8);
         if (flag4)
         {
             list4.Add(new Point(current4.X, num8));
         }
     }
     List<Tuple<Point, Point>> list5 = new List<Tuple<Point, Point>>();
     for (int l = 1; l < list.Count; l++)
     {
         Rectangle rectangle4 = list[l];
         Rectangle rectangle5 = list[l - 1];
         int num9 = rectangle5.X - rectangle4.X;
         int num10 = rectangle4.X + rectangle4.Width - (rectangle5.X + rectangle5.Width);
         if (num9 > num10)
         {
             list5.Add(new Tuple<Point, Point>(new Point(rectangle4.X + rectangle4.Width - 1, rectangle4.Y + 1), new Point(rectangle4.X + rectangle4.Width - rectangle4.Height + 1, rectangle4.Y + rectangle4.Height - 1)));
         }
         else
         {
             list5.Add(new Tuple<Point, Point>(new Point(rectangle4.X, rectangle4.Y + 1), new Point(rectangle4.X + rectangle4.Height - 1, rectangle4.Y + rectangle4.Height - 1)));
         }
     }
     List<Point> list6 = new List<Point>();
     int num11;
     bool flag5 = this.FindVerticalExit(new Rectangle(rectangle.X + 2, rectangle.Y, rectangle.Width - 4, 1), true, out num11);
     if (flag5)
     {
         list6.Add(new Point(num11, rectangle.Y));
     }
     flag5 = this.FindVerticalExit(new Rectangle(rectangle2.X + 2, rectangle2.Y + rectangle2.Height - 1, rectangle2.Width - 4, 1), false, out num11);
     if (flag5)
     {
         list6.Add(new Point(num11, rectangle2.Y + rectangle2.Height - 1));
     }
     foreach (Rectangle current5 in list)
     {
         WorldUtils.Gen(new Point(current5.X, current5.Y), new Shapes.Rectangle(current5.Width, current5.Height), Actions.Chain(new GenAction[]
         {
             new Actions.SetTile(item.Tile, false, true),
             new Actions.SetFrames(true)
         }));
         WorldUtils.Gen(new Point(current5.X + 1, current5.Y + 1), new Shapes.Rectangle(current5.Width - 2, current5.Height - 2), Actions.Chain(new GenAction[]
         {
             new Actions.ClearTile(true),
             new Actions.PlaceWall(item.Wall, true)
         }));
         structures.AddStructure(current5, 8);
     }
     foreach (Tuple<Point, Point> current6 in list5)
     {
         Point item2 = current6.Item1;
         Point item3 = current6.Item2;
         int num12 = (item3.X > item2.X) ? 1 : -1;
         ShapeData shapeData = new ShapeData();
         for (int m = 0; m < item3.Y - item2.Y; m++)
         {
             shapeData.Add(num12 * (m + 1), m);
         }
         WorldUtils.Gen(item2, new ModShapes.All(shapeData), Actions.Chain(new GenAction[]
         {
             new Actions.PlaceTile(19, item.PlatformStyle),
             new Actions.SetSlope((num12 == 1) ? 1 : 2),
             new Actions.SetFrames(true)
         }));
         WorldUtils.Gen(new Point(item2.X + ((num12 == 1) ? 1 : -4), item2.Y - 1), new Shapes.Rectangle(4, 1), Actions.Chain(new GenAction[]
         {
             new Actions.Clear(),
             new Actions.PlaceWall(item.Wall, true),
             new Actions.PlaceTile(19, item.PlatformStyle),
             new Actions.SetFrames(true)
         }));
     }
     foreach (Point current7 in list4)
     {
         WorldUtils.Gen(current7, new Shapes.Rectangle(1, 3), new Actions.ClearTile(true));
         WorldGen.PlaceTile(current7.X, current7.Y, 10, true, true, -1, item.DoorStyle);
     }
     foreach (Point current8 in list6)
     {
         WorldUtils.Gen(current8, new Shapes.Rectangle(3, 1), Actions.Chain(new GenAction[]
         {
             new Actions.ClearMetadata(),
             new Actions.PlaceTile(19, item.PlatformStyle),
             new Actions.SetFrames(true)
         }));
     }
     foreach (Rectangle current9 in list3)
     {
         if (current9.Height > 1 && GenBase._tiles[current9.X, current9.Y - 1].type != 19)
         {
             WorldUtils.Gen(new Point(current9.X, current9.Y), new Shapes.Rectangle(current9.Width, current9.Height), Actions.Chain(new GenAction[]
             {
                 new Actions.SetTile(124, false, true),
                 new Actions.SetFrames(true)
             }));
             Tile tile = GenBase._tiles[current9.X, current9.Y + current9.Height];
             tile.slope(0);
             tile.halfBrick(false);
         }
     }
     Point[] choices = new Point[]
     {
         new Point(14, item.TableStyle),
         new Point(16, 0),
         new Point(18, item.WorkbenchStyle),
         new Point(86, 0),
         new Point(87, item.PianoStyle),
         new Point(94, 0),
         new Point(101, item.BookcaseStyle)
     };
     foreach (Rectangle current10 in list)
     {
         int num13 = current10.Width / 8;
         int num14 = current10.Width / (num13 + 1);
         int num15 = GenBase._random.Next(2);
         for (int n = 0; n < num13; n++)
         {
             int num16 = (n + 1) * num14 + current10.X;
             switch (n + num15 % 2)
             {
                 case 0:
                     {
                         int num17 = current10.Y + Math.Min(current10.Height / 2, current10.Height - 5);
                         Vector2 vector = WorldGen.randHousePicture();
                         int type = (int)vector.X;
                         int style = (int)vector.Y;
                         if (!WorldGen.nearPicture(num16, num17))
                         {
                             WorldGen.PlaceTile(num16, num17, type, true, false, -1, style);
                         }
                         break;
                     }
                 case 1:
                     {
                         int num17 = current10.Y + 1;
                         WorldGen.PlaceTile(num16, num17, 34, true, false, -1, GenBase._random.Next(6));
                         for (int num18 = -1; num18 < 2; num18++)
                         {
                             for (int num19 = 0; num19 < 3; num19++)
                             {
                                 Tile expr_E29 = GenBase._tiles[num18 + num16, num19 + num17];
                                 expr_E29.frameX += 54;
                             }
                         }
                         break;
                     }
             }
         }
         int num20 = current10.Width / 8 + 3;
         WorldGen.SetupStatueList();
         while (num20 > 0)
         {
             int num21 = GenBase._random.Next(current10.Width - 3) + 1 + current10.X;
             int num22 = current10.Y + current10.Height - 2;
             switch (GenBase._random.Next(4))
             {
                 case 0:
                     WorldGen.PlaceSmallPile(num21, num22, GenBase._random.Next(31, 34), 1, 185);
                     break;
                 case 1:
                     WorldGen.PlaceTile(num21, num22, 186, true, false, -1, GenBase._random.Next(22, 26));
                     break;
                 case 2:
                     {
                         int num23 = GenBase._random.Next(2, WorldGen.statueList.Length);
                         WorldGen.PlaceTile(num21, num22, (int)WorldGen.statueList[num23].X, true, false, -1, (int)WorldGen.statueList[num23].Y);
                         if (WorldGen.StatuesWithTraps.Contains(num23))
                         {
                             WorldGen.PlaceStatueTrap(num21, num22);
                         }
                         break;
                     }
                 case 3:
                     {
                         Point point4 = Utils.SelectRandom<Point>(GenBase._random, choices);
                         WorldGen.PlaceTile(num21, num22, point4.X, true, false, -1, point4.Y);
                         break;
                     }
             }
             num20--;
         }
     }
     foreach (Rectangle current11 in list)
     {
         item.ProcessRoom(current11);
     }
     bool flag6 = false;
     foreach (Rectangle current12 in list)
     {
         int num24 = current12.Height - 1 + current12.Y;
         int style2 = (num24 > (int)Main.worldSurface) ? item.ChestStyle : 0;
         for (int num25 = 0; num25 < 10; num25++)
         {
             int i2 = GenBase._random.Next(2, current12.Width - 2) + current12.X;
             if (flag6 = WorldGen.AddBuriedChest(i2, num24, 0, false, style2))
             {
                 break;
             }
         }
         if (flag6)
         {
             break;
         }
         int num26 = current12.X + 2;
         while (num26 <= current12.X + current12.Width - 2 && !(flag6 = WorldGen.AddBuriedChest(num26, num24, 0, false, style2)))
         {
             num26++;
         }
         if (flag6)
         {
             break;
         }
     }
     if (!flag6)
     {
         foreach (Rectangle current13 in list)
         {
             int num27 = current13.Y - 1;
             int style3 = (num27 > (int)Main.worldSurface) ? item.ChestStyle : 0;
             for (int num28 = 0; num28 < 10; num28++)
             {
                 int i3 = GenBase._random.Next(2, current13.Width - 2) + current13.X;
                 if (flag6 = WorldGen.AddBuriedChest(i3, num27, 0, false, style3))
                 {
                     break;
                 }
             }
             if (flag6)
             {
                 break;
             }
             int num29 = current13.X + 2;
             while (num29 <= current13.X + current13.Width - 2 && !(flag6 = WorldGen.AddBuriedChest(num29, num27, 0, false, style3)))
             {
                 num29++;
             }
             if (flag6)
             {
                 break;
             }
         }
     }
     if (!flag6)
     {
         for (int num30 = 0; num30 < 1000; num30++)
         {
             int i4 = GenBase._random.Next(list[0].X - 30, list[0].X + 30);
             int num31 = GenBase._random.Next(list[0].Y - 30, list[0].Y + 30);
             int style4 = (num31 > (int)Main.worldSurface) ? item.ChestStyle : 0;
             if (flag6 = WorldGen.AddBuriedChest(i4, num31, 0, false, style4))
             {
                 break;
             }
         }
     }
     if (item == CaveHouseBiome.BuildData.Jungle && this._sharpenerCount < GenBase._random.Next(2, 5))
     {
         bool flag7 = false;
         foreach (Rectangle current14 in list)
         {
             int num32 = current14.Height - 2 + current14.Y;
             for (int num33 = 0; num33 < 10; num33++)
             {
                 int num34 = GenBase._random.Next(2, current14.Width - 2) + current14.X;
                 WorldGen.PlaceTile(num34, num32, 377, true, true, -1, 0);
                 if (flag7 = (GenBase._tiles[num34, num32].active() && GenBase._tiles[num34, num32].type == 377))
                 {
                     break;
                 }
             }
             if (flag7)
             {
                 break;
             }
             int num35 = current14.X + 2;
             while (num35 <= current14.X + current14.Width - 2 && !(flag7 = WorldGen.PlaceTile(num35, num32, 377, true, true, -1, 0)))
             {
                 num35++;
             }
             if (flag7)
             {
                 break;
             }
         }
         if (flag7)
         {
             this._sharpenerCount++;
         }
     }
     if (item == CaveHouseBiome.BuildData.Desert && this._extractinatorCount < GenBase._random.Next(2, 5))
     {
         bool flag8 = false;
         foreach (Rectangle current15 in list)
         {
             int num36 = current15.Height - 2 + current15.Y;
             for (int num37 = 0; num37 < 10; num37++)
             {
                 int num38 = GenBase._random.Next(2, current15.Width - 2) + current15.X;
                 WorldGen.PlaceTile(num38, num36, 219, true, true, -1, 0);
                 if (flag8 = (GenBase._tiles[num38, num36].active() && GenBase._tiles[num38, num36].type == 219))
                 {
                     break;
                 }
             }
             if (flag8)
             {
                 break;
             }
             int num39 = current15.X + 2;
             while (num39 <= current15.X + current15.Width - 2 && !(flag8 = WorldGen.PlaceTile(num39, num36, 219, true, true, -1, 0)))
             {
                 num39++;
             }
             if (flag8)
             {
                 break;
             }
         }
         if (flag8)
         {
             this._extractinatorCount++;
         }
     }
     return true;
 }
		public override bool Place(Point origin, StructureMap structures)
		{
			if (GenBase._tiles[origin.X, origin.Y].active())
			{
				return false;
			}
			int length = GraniteBiome._sourceMagmaMap.GetLength(0);
			int length2 = GraniteBiome._sourceMagmaMap.GetLength(1);
			int num = length / 2;
			int num2 = length2 / 2;
			origin.X -= num;
			origin.Y -= num2;
			for (int i = 0; i < length; i++)
			{
				for (int j = 0; j < length2; j++)
				{
					int i2 = i + origin.X;
					int j2 = j + origin.Y;
					GraniteBiome._sourceMagmaMap[i, j] = GraniteBiome.Magma.CreateEmpty(WorldGen.SolidTile(i2, j2) ? 4f : 1f);
					GraniteBiome._targetMagmaMap[i, j] = GraniteBiome._sourceMagmaMap[i, j];
				}
			}
			int num3 = num;
			int num4 = num;
			int num5 = num2;
			int num6 = num2;
			for (int k = 0; k < 300; k++)
			{
				for (int l = num3; l <= num4; l++)
				{
					for (int m = num5; m <= num6; m++)
					{
						GraniteBiome.Magma magma = GraniteBiome._sourceMagmaMap[l, m];
						if (magma.IsActive)
						{
							float num7 = 0f;
							Vector2 value = Vector2.Zero;
							for (int n = -1; n <= 1; n++)
							{
								for (int num8 = -1; num8 <= 1; num8++)
								{
									if (n != 0 || num8 != 0)
									{
										Vector2 value2 = new Vector2((float)n, (float)num8);
										value2.Normalize();
										GraniteBiome.Magma magma2 = GraniteBiome._sourceMagmaMap[l + n, m + num8];
										if (magma.Pressure > 0.01f && !magma2.IsActive)
										{
											if (n == -1)
											{
												num3 = Utils.Clamp<int>(l + n, 1, num3);
											}
											else
											{
												num4 = Utils.Clamp<int>(l + n, num4, length - 2);
											}
											if (num8 == -1)
											{
												num5 = Utils.Clamp<int>(m + num8, 1, num5);
											}
											else
											{
												num6 = Utils.Clamp<int>(m + num8, num6, length2 - 2);
											}
											GraniteBiome._targetMagmaMap[l + n, m + num8] = magma2.ToFlow();
										}
										float pressure = magma2.Pressure;
										num7 += pressure;
										value += pressure * value2;
									}
								}
							}
							num7 /= 8f;
							if (num7 > magma.Resistance)
							{
								float num9 = value.Length() / 8f;
								float num10 = Math.Max(num7 - num9 - magma.Pressure, 0f) + num9 + magma.Pressure * 0.875f - magma.Resistance;
								num10 = Math.Max(0f, num10);
								GraniteBiome._targetMagmaMap[l, m] = GraniteBiome.Magma.CreateFlow(num10, Math.Max(0f, magma.Resistance - num10 * 0.02f));
							}
						}
					}
				}
				if (k < 2)
				{
					GraniteBiome._targetMagmaMap[num, num2] = GraniteBiome.Magma.CreateFlow(25f, 0f);
				}
				Utils.Swap<GraniteBiome.Magma[,]>(ref GraniteBiome._sourceMagmaMap, ref GraniteBiome._targetMagmaMap);
			}
			bool flag = origin.Y + num2 > WorldGen.lavaLine - 30;
			bool flag2 = false;
			int num11 = -50;
			while (num11 < 50 && !flag2)
			{
				int num12 = -50;
				while (num12 < 50 && !flag2)
				{
					if (GenBase._tiles[origin.X + num + num11, origin.Y + num2 + num12].active())
					{
						ushort type = GenBase._tiles[origin.X + num + num11, origin.Y + num2 + num12].type;
						if (type != 147)
						{
							switch (type)
							{
							case 161:
							case 162:
							case 163:
								break;
							default:
								if (type != 200)
								{
									goto IL_400;
								}
								break;
							}
						}
						flag = false;
						flag2 = true;
					}
					IL_400:
					num12++;
				}
				num11++;
			}
			for (int num13 = num3; num13 <= num4; num13++)
			{
				for (int num14 = num5; num14 <= num6; num14++)
				{
					GraniteBiome.Magma magma3 = GraniteBiome._sourceMagmaMap[num13, num14];
					if (magma3.IsActive)
					{
						Tile tile = GenBase._tiles[origin.X + num13, origin.Y + num14];
						float num15 = (float)Math.Sin((double)((float)(origin.Y + num14) * 0.4f)) * 0.7f + 1.2f;
						float num16 = 0.2f + 0.5f / (float)Math.Sqrt((double)Math.Max(0f, magma3.Pressure - magma3.Resistance));
						float num17 = 1f - Math.Max(0f, num15 * num16);
						num17 = Math.Max(num17, magma3.Pressure / 15f);
						if (num17 > 0.35f + (WorldGen.SolidTile(origin.X + num13, origin.Y + num14) ? 0f : 0.5f))
						{
							if (TileID.Sets.Ore[(int)tile.type])
							{
								tile.ResetToType(tile.type);
							}
							else
							{
								tile.ResetToType(368);
							}
							tile.wall = 180;
						}
						else if (magma3.Resistance < 0.01f)
						{
							WorldUtils.ClearTile(origin.X + num13, origin.Y + num14, false);
							tile.wall = 180;
						}
						if (tile.liquid > 0 && flag)
						{
							tile.liquidType(1);
						}
					}
				}
			}
			List<Point16> list = new List<Point16>();
			for (int num18 = num3; num18 <= num4; num18++)
			{
				for (int num19 = num5; num19 <= num6; num19++)
				{
					GraniteBiome.Magma magma4 = GraniteBiome._sourceMagmaMap[num18, num19];
					if (magma4.IsActive)
					{
						int num20 = 0;
						int num21 = num18 + origin.X;
						int num22 = num19 + origin.Y;
						if (WorldGen.SolidTile(num21, num22))
						{
							for (int num23 = -1; num23 <= 1; num23++)
							{
								for (int num24 = -1; num24 <= 1; num24++)
								{
									if (WorldGen.SolidTile(num21 + num23, num22 + num24))
									{
										num20++;
									}
								}
							}
							if (num20 < 3)
							{
								list.Add(new Point16(num21, num22));
							}
						}
					}
				}
			}
			foreach (Point16 current in list)
			{
				int x = (int)current.X;
				int y = (int)current.Y;
				WorldUtils.ClearTile(x, y, true);
				GenBase._tiles[x, y].wall = 180;
			}
			list.Clear();
			for (int num25 = num3; num25 <= num4; num25++)
			{
				for (int num26 = num5; num26 <= num6; num26++)
				{
					GraniteBiome.Magma magma5 = GraniteBiome._sourceMagmaMap[num25, num26];
					int num27 = num25 + origin.X;
					int num28 = num26 + origin.Y;
					if (magma5.IsActive)
					{
						WorldUtils.TileFrame(num27, num28, false);
						WorldGen.SquareWallFrame(num27, num28, true);
						if (GenBase._random.Next(8) == 0 && GenBase._tiles[num27, num28].active())
						{
							if (!GenBase._tiles[num27, num28 + 1].active())
							{
								WorldGen.PlaceTight(num27, num28 + 1, 165, false);
							}
							if (!GenBase._tiles[num27, num28 - 1].active())
							{
								WorldGen.PlaceTight(num27, num28 - 1, 165, false);
							}
						}
						if (GenBase._random.Next(2) == 0)
						{
							Tile.SmoothSlope(num27, num28, true);
						}
					}
				}
			}
			return true;
		}
		public override bool Place(Point origin, StructureMap structures)
		{
			Ref<int> @ref = new Ref<int>(0);
			Ref<int> ref2 = new Ref<int>(0);
			WorldUtils.Gen(origin, new Shapes.Circle(10), Actions.Chain(new GenAction[]
			{
				new Actions.Scanner(ref2),
				new Modifiers.IsSolid(),
				new Actions.Scanner(@ref)
			}));
			if (@ref.Value < ref2.Value - 5)
			{
				return false;
			}
			int num = GenBase._random.Next(6, 10);
			int num2 = GenBase._random.Next(5);
			if (!structures.CanPlace(new Rectangle(origin.X - num, origin.Y - num, num * 2, num * 2), 0))
			{
				return false;
			}
			ShapeData data = new ShapeData();
			Point arg_12A_0 = origin;
			GenShape arg_12A_1 = new Shapes.Slime(num);
			GenAction[] array = new GenAction[6];
			array[0] = new Modifiers.Blotches(num2, num2, num2, 1, 0.3).Output(data);
			array[1] = new Modifiers.Offset(0, -2);
			array[2] = new Modifiers.OnlyTiles(new ushort[]
			{
				53
			});
			array[3] = new Actions.SetTile(397, true, true);
			GenAction[] arg_116_0 = array;
			int arg_116_1 = 4;
			byte[] types = new byte[1];
			arg_116_0[arg_116_1] = new Modifiers.OnlyWalls(types);
			array[5] = new Actions.PlaceWall(16, true);
			WorldUtils.Gen(arg_12A_0, arg_12A_1, Actions.Chain(array));
			Point arg_185_0 = origin;
			GenShape arg_185_1 = new ModShapes.All(data);
			GenAction[] array2 = new GenAction[5];
			array2[0] = new Actions.ClearTile(false);
			array2[1] = new Actions.SetLiquid(0, 0);
			array2[2] = new Actions.SetFrames(true);
			GenAction[] arg_171_0 = array2;
			int arg_171_1 = 3;
			byte[] types2 = new byte[1];
			arg_171_0[arg_171_1] = new Modifiers.OnlyWalls(types2);
			array2[4] = new Actions.PlaceWall(16, true);
			WorldUtils.Gen(arg_185_0, arg_185_1, Actions.Chain(array2));
			Point point;
			if (!WorldUtils.Find(origin, Searches.Chain(new Searches.Down(10), new GenCondition[]
			{
				new Conditions.IsSolid()
			}), out point))
			{
				return false;
			}
			int num3 = point.Y - 1;
			bool flag = GenBase._random.Next() % 2 == 0;
			if (GenBase._random.Next() % 10 != 0)
			{
				int num4 = GenBase._random.Next(1, 4);
				int num5 = flag ? 4 : (-(num >> 1));
				for (int i = 0; i < num4; i++)
				{
					int num6 = GenBase._random.Next(1, 3);
					for (int j = 0; j < num6; j++)
					{
						WorldGen.PlaceTile(origin.X + num5 - i, num3 - j, 331, false, false, -1, 0);
					}
				}
			}
			int num7 = (num - 3) * (flag ? -1 : 1);
			if (GenBase._random.Next() % 10 != 0)
			{
				WorldGen.PlaceTile(origin.X + num7, num3, 186, false, false, -1, 0);
			}
			if (GenBase._random.Next() % 10 != 0)
			{
				WorldGen.PlaceTile(origin.X, num3, 215, true, false, -1, 0);
				if (GenBase._tiles[origin.X, num3].active() && GenBase._tiles[origin.X, num3].type == 215)
				{
					Tile expr_305 = GenBase._tiles[origin.X, num3];
					expr_305.frameY += 36;
					Tile expr_329 = GenBase._tiles[origin.X - 1, num3];
					expr_329.frameY += 36;
					Tile expr_34D = GenBase._tiles[origin.X + 1, num3];
					expr_34D.frameY += 36;
					Tile expr_371 = GenBase._tiles[origin.X, num3 - 1];
					expr_371.frameY += 36;
					Tile expr_397 = GenBase._tiles[origin.X - 1, num3 - 1];
					expr_397.frameY += 36;
					Tile expr_3BD = GenBase._tiles[origin.X + 1, num3 - 1];
					expr_3BD.frameY += 36;
				}
			}
			structures.AddStructure(new Rectangle(origin.X - num, origin.Y - num, num * 2, num * 2), 4);
			return true;
		}