Ejemplo n.º 1
0
 public TileEvent(Tile tile, Player player, int changeType)
     : base(player)
 {
     base.setState(false);
     this.tile = tile;
     this.changeType = changeType;
 }
Ejemplo n.º 2
0
 public bool isTheSameAs(Tile compTile)
 {
     if (this.active != compTile.active)
     {
         return false;
     }
     if (this.active)
     {
         if (this.type != compTile.type)
         {
             return false;
         }
         if (Main.tileFrameImportant[(int)this.type])
         {
             if (this.frameX != compTile.frameX)
             {
                 return false;
             }
             if (this.frameY != compTile.frameY)
             {
                 return false;
             }
         }
     }
     return this.wall == compTile.wall && this.liquid == compTile.liquid && this.lava == compTile.lava && this.wire == compTile.wire;
 }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public override bool SetTile(Vector position, Tile tile)
        {
            var x            = position.X;
            var y            = position.Y;
            var terrariaTile = _terrariaTiles[x, y];

            if (terrariaTile == null)
            {
                terrariaTile         = new TerrariaTile();
                _terrariaTiles[x, y] = terrariaTile;
            }

            // Avoid constructing a TerrariaTile whenever possible. This reduces GC pressure.
            terrariaTile.type        = tile.BlockId;
            terrariaTile.bTileHeader = tile.BTileHeader;
            terrariaTile.frameX      = tile.FrameX;
            terrariaTile.frameY      = tile.FrameY;
            terrariaTile.liquid      = tile.Liquid;
            terrariaTile.sTileHeader = tile.STileHeader;
            terrariaTile.wall        = tile.WallId;

            lock (_sectionLock)
            {
                _dirtySections.Add(new Vector(x / SectionWidth, y / SectionHeight));
            }
            return(true);
        }
Ejemplo n.º 4
0
 static LiquidRenderer()
 {
     LiquidRenderer.WATERFALL_LENGTH = new int[] { 10, 3, 2 };
     LiquidRenderer.DEFAULT_OPACITY = new float[] { 0.6f, 0.95f, 0.95f };
     LiquidRenderer.EMPTY_TILE = new Tile();
     LiquidRenderer.Instance = new LiquidRenderer();
 }
        public static bool IsTileTheSame(Tile tile1, Tile tile2)
        {
            if (tile1.active() != tile2.active())
                return false;

            if (tile1.active())
            {
                if (tile1.type != tile2.type)
                    return false;

                if (Main.tileFrameImportant[(int)tile1.type])
                {
                    if ((tile1.frameX != tile2.frameX) || (tile1.frameX != tile2.frameX))
                        return false;
                }
            }
            return
                tile1.wall == tile2.wall
                &&
                tile1.liquid == tile2.liquid
                &&
                tile1.lava() == tile2.lava()
                &&
                tile1.wire() == tile2.wire()
                &&
                tile1.wire2() == tile2.wire2()
                &&
                tile1.wire3() == tile2.wire3();
        }
Ejemplo n.º 6
0
		public Tile(Tile copy)
		{
			if (copy == null)
			{
				this.type = 0;
				this.wall = 0;
				this.liquid = 0;
				this.sTileHeader = 0;
				this.bTileHeader = 0;
				this.bTileHeader2 = 0;
				this.bTileHeader3 = 0;
				this.frameX = 0;
				this.frameY = 0;
				return;
			}
			this.type = copy.type;
			this.wall = copy.wall;
			this.liquid = copy.liquid;
			this.sTileHeader = copy.sTileHeader;
			this.bTileHeader = copy.bTileHeader;
			this.bTileHeader2 = copy.bTileHeader2;
			this.bTileHeader3 = copy.bTileHeader3;
			this.frameX = copy.frameX;
			this.frameY = copy.frameY;
		}
Ejemplo n.º 7
0
 public static Tile GetTileSafely(int i, int j)
 {
     Tile tile = Main.tile[i, j];
     if (tile == null)
     {
         tile = new Tile();
         Main.tile[i, j] = tile;
     }
     return tile;
 }
Ejemplo n.º 8
0
 public WorldRenderer(Tile[,] tiles, int worldWidth, int worldHeight, double worldSurface, double rockLayer)
 {
     Tiles = tiles;
     MaxX = worldWidth;
     MaxY = worldHeight;
     SurfaceY = (int)worldSurface;
     RockLayerY = (int)rockLayer + (600 / 16);
     HellLayerY = MaxY - 195;
     Colors = TerrariaColors.GetColors();
 }
Ejemplo n.º 9
0
		public static Tile[,] LoadWorldData(string path)
		{
			Tile[,] tile;
			using (BinaryReader reader = new BinaryReader(new FileStream(path, FileMode.Open)))
			{
				int xLen = reader.ReadInt32();
				int yLen = reader.ReadInt32();
				tile = new Tile[xLen, yLen];

				for (int i = 0; i < xLen; i++)
				{
					for (int j = 0; j < yLen; j++)
					{
						tile[i, j] = ReadTile(reader);
					}
				}
				return tile;
			}
		}
Ejemplo n.º 10
0
 public bool isTheSameAs(Tile compTile)
 {
     if (this.active != compTile.active)
     {
         return false;
     }
     if (this.active)
     {
         if (this.type != compTile.type)
         {
             return false;
         }
         if (Main.tileFrameImportant[this.type])
         {
             if (this.frameX != compTile.frameX)
             {
                 return false;
             }
             if (this.frameY != compTile.frameY)
             {
                 return false;
             }
         }
     }
     if (this.wall != compTile.wall)
     {
         return false;
     }
     if (this.liquid != compTile.liquid)
     {
         return false;
     }
     if (this.lava != compTile.lava)
     {
         return false;
     }
     if (this.wire != compTile.wire)
     {
         return false;
     }
     return true;
 }
Ejemplo n.º 11
0
		public static Tile[,] LoadWorldData(string path)
		{
			Tile[,] tile;
			// GZipStream is already buffered, but it's much faster to have a 1 MB buffer.
			using (var reader =
				new BinaryReader(
					new BufferedStream(
						new GZipStream(File.Open(path, FileMode.Open), CompressionMode.Decompress), BUFFER_SIZE)))
			{
				reader.ReadInt32();
				reader.ReadInt32();
				int width = reader.ReadInt32();
				int height = reader.ReadInt32();
				tile = new Tile[width, height];

				for (int i = 0; i < width; i++)
				{
					for (int j = 0; j < height; j++)
						tile[i, j] = ReadTile(reader);
				}
				return tile;
			}
		}
Ejemplo n.º 12
0
		public void k_Constructor(Tile copy)
		{
			if (copy == null)
			{
				k_block = null;
				k_wall_protoID = 0;
				k_wall_variant = 0;
				k_wall_colourID = 0;
				k_liquid_protoID = 0;
				k_liquid_amount = 0;
				k_wireFlags = 0;
			}
			else
			{
				k_block = copy.k_block.Copy();
				k_wall_protoID = copy.k_wall_protoID;
				k_wall_variant = copy.k_wall_variant;
				k_wall_colourID = copy.k_wall_colourID;
				k_liquid_protoID = copy.k_liquid_protoID;
				k_liquid_amount = copy.k_liquid_amount;
				k_wireFlags = copy.k_wireFlags;
			}
		}
Ejemplo n.º 13
0
        public static void DecompressTileBlock_Inner(BinaryReader reader, int xStart, int yStart, int width, int height)
        {
            Tile tile = (Tile)null;
            int num1 = 0;
            for (int index1 = yStart; index1 < yStart + height; ++index1)
            {
                for (int index2 = xStart; index2 < xStart + width; ++index2)
                {
                    if (num1 != 0)
                    {
                        --num1;
                        if (Main.tile[index2, index1] == null)
                            Main.tile[index2, index1] = new Tile(tile);
                        else
                            Main.tile[index2, index1].CopyFrom(tile);
                    }
                    else
                    {
                        byte num2;
                        byte num3 = num2 = (byte)0;
                        tile = Main.tile[index2, index1];
                        if (tile == null)
                        {
                            tile = new Tile();
                            Main.tile[index2, index1] = tile;
                        }
                        else
                            tile.ClearEverything();
                        byte num4 = reader.ReadByte();
                        if (((int)num4 & 1) == 1)
                        {
                            num3 = reader.ReadByte();
                            if (((int)num3 & 1) == 1)
                                num2 = reader.ReadByte();
                        }
                        bool flag = tile.active();
                        if (((int)num4 & 2) == 2)
                        {
                            tile.active(true);
                            ushort num5 = tile.type;
                            int index3;
                            if (((int)num4 & 32) == 32)
                            {
                                byte num6 = reader.ReadByte();
                                index3 = (int)reader.ReadByte() << 8 | (int)num6;
                            }
                            else
                                index3 = (int)reader.ReadByte();
                            tile.type = (ushort)index3;
                            if (Main.tileFrameImportant[index3])
                            {
                                tile.frameX = reader.ReadInt16();
                                tile.frameY = reader.ReadInt16();
                            }
                            else if (!flag || (int)tile.type != (int)num5)
                            {
                                tile.frameX = (short)-1;
                                tile.frameY = (short)-1;
                            }
                            if (((int)num2 & 8) == 8)
                                tile.color(reader.ReadByte());
                        }
                        if (((int)num4 & 4) == 4)
                        {
                            tile.wall = reader.ReadByte();
                            if (((int)num2 & 16) == 16)
                                tile.wallColor(reader.ReadByte());
                        }
                        byte num7 = (byte)(((int)num4 & 24) >> 3);
                        if ((int)num7 != 0)
                        {
                            tile.liquid = reader.ReadByte();
                            if ((int)num7 > 1)
                            {
                                if ((int)num7 == 2)
                                    tile.lava(true);
                                else
                                    tile.honey(true);
                            }
                        }
						var wireFlag = k_WireFlags.WIRE_NONE;
                        if ((int)num3 > 1)
                        {
							if (((int)num3 & 2) == 2)
								wireFlag |= k_WireFlags.WIRE_RED;
							if (((int)num3 & 4) == 4)
								wireFlag |= k_WireFlags.WIRE_GREEN;
							if (((int)num3 & 8) == 8)
								wireFlag |= k_WireFlags.WIRE_BLUE;
                            byte num5 = (byte)(((int)num3 & 112) >> 4);
                            if ((int)num5 != 0 && Main.tileSolid[(int)tile.type])
                            {
                                if ((int)num5 == 1)
                                    tile.halfBrick(true);
                                else
                                    tile.slope((byte)((uint)num5 - 1U));
                            }
                        }
                        if ((int)num2 > 0)
                        {
							if (((int)num2 & 2) == 2)
								wireFlag |= k_WireFlags.WIRE_ACTUATOR;
                            if (((int)num2 & 4) == 4)
                                tile.inActive(true);
                        }
						tile.k_wireFlags = wireFlag;
						switch ((byte)(((int)num4 & 192) >> 6))
                        {
                            case (byte)0:
                                num1 = 0;
                                continue;
                            case (byte)1:
                                num1 = (int)reader.ReadByte();
                                continue;
                            default:
                                num1 = (int)reader.ReadInt16();
                                continue;
                        }
                    }
                }
            }
            short num8 = reader.ReadInt16();
            for (int index = 0; index < (int)num8; ++index)
            {
                short num2 = reader.ReadInt16();
                short num3 = reader.ReadInt16();
                short num4 = reader.ReadInt16();
                string str = reader.ReadString();
                if ((int)num2 >= 0 && (int)num2 < 1000)
                {
                    if (Main.chest[(int)num2] == null)
                        Main.chest[(int)num2] = new Chest(false);
                    Main.chest[(int)num2].name = str;
                    Main.chest[(int)num2].x = (int)num3;
                    Main.chest[(int)num2].y = (int)num4;
                }
            }
            short num9 = reader.ReadInt16();
            for (int index = 0; index < (int)num9; ++index)
            {
                short num2 = reader.ReadInt16();
                short num3 = reader.ReadInt16();
                short num4 = reader.ReadInt16();
                string str = reader.ReadString();
                if ((int)num2 >= 0 && (int)num2 < 1000)
                {
                    if (Main.sign[(int)num2] == null)
                        Main.sign[(int)num2] = new Sign();
                    Main.sign[(int)num2].text = str;
                    Main.sign[(int)num2].x = (int)num3;
                    Main.sign[(int)num2].y = (int)num4;
                }
            }
            short num10 = reader.ReadInt16();
            for (int index = 0; index < (int)num10; ++index)
            {
                TileEntity tileEntity = TileEntity.Read(reader);
                TileEntity.ByID[tileEntity.ID] = tileEntity;
                TileEntity.ByPosition[tileEntity.Position] = tileEntity;
            }
        }
Ejemplo n.º 14
0
 protected void DrawBlack()
 {
     Stopwatch stopwatch = new Stopwatch();
     stopwatch.Start();
     Vector2 vector = new Vector2((float)offScreenRange, (float)offScreenRange);
     if (drawToScreen)
     {
         vector = new Vector2();
     }
     int num = ((tileColor.R + tileColor.G) + tileColor.B) / 3;
     float num2 = ((float)(num * 0.4)) / 255f;
     if (Lighting.lightMode == 2)
     {
         num2 = ((float)(tileColor.R - 0x37)) / 255f;
     }
     else if (Lighting.lightMode == 3)
     {
         num2 = ((float)(num - 0x37)) / 255f;
     }
     int num3 = (int)(((screenPosition.X - vector.X) / 16f) - 1f);
     int num4 = ((int)(((screenPosition.X + screenWidth) + vector.X) / 16f)) + 2;
     int num5 = (int)(((screenPosition.Y - vector.Y) / 16f) - 1f);
     int num6 = ((int)(((screenPosition.Y + screenHeight) + vector.Y) / 16f)) + 5;
     int num7 = offScreenRange / 0x10;
     int num8 = offScreenRange / 0x10;
     if ((num3 - num7) < 0)
     {
         num3 = num7;
     }
     if ((num4 + num7) > maxTilesX)
     {
         num4 = maxTilesX - num7;
     }
     if ((num5 - num8) < 0)
     {
         num5 = num8;
     }
     if ((num6 + num8) > maxTilesY)
     {
         num6 = maxTilesY - num8;
     }
     for (int i = num5 - num8; i < (num6 + num8); i++)
     {
         if (i <= worldSurface)
         {
             for (int j = num3 - num7; j < (num4 + num7); j++)
             {
                 if (tile[j, i] == null)
                 {
                     tile[j, i] = new Tile();
                 }
                 if ((Lighting.Brightness(j, i) < num2) && (((tile[j, i].liquid < 250) || WorldGen.SolidTile(j, i)) || ((tile[j, i].liquid > 250) && (Lighting.Brightness(j, i) == 0f))))
                 {
                     int num11 = j;
                     j++;
                     while (((tile[j, i] != null) && (Lighting.Brightness(j, i) < num2)) && (((tile[j, i].liquid < 250) || WorldGen.SolidTile(j, i)) || ((tile[j, i].liquid > 250) && (Lighting.Brightness(j, i) == 0f))))
                     {
                         j++;
                         if (j >= (num4 + num7))
                         {
                             break;
                         }
                     }
                     j--;
                     int width = ((j - num11) + 1) * 0x10;
                     Vector2 origin = new Vector2();
                     this.spriteBatch.Draw(blackTileTexture, new Vector2((float)((num11 * 0x10) - ((int)screenPosition.X)), (float)((i * 0x10) - ((int)screenPosition.Y))) + vector, new Rectangle(0, 0, width, 0x10), Color.Black, 0f, origin, (float)1f, SpriteEffects.None, 0f);
                 }
             }
         }
     }
     renderTimer[5] = stopwatch.ElapsedMilliseconds;
 }
Ejemplo n.º 15
0
        protected void DrawBackground()
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            int num = (int)((255f * (1f - gfxQuality)) + (140f * gfxQuality));
            int num2 = (int)((200f * (1f - gfxQuality)) + (40f * gfxQuality));
            int num3 = 0x60;
            Vector2 vector = new Vector2((float)offScreenRange, (float)offScreenRange);
            if (drawToScreen)
            {
                vector = new Vector2();
            }
            float num4 = 0.9f;
            float num5 = num4;
            float num6 = num4;
            float num7 = num4;
            float num8 = 0f;
            if (holyTiles > evilTiles)
            {
                num8 = ((float)holyTiles) / 800f;
            }
            else if (evilTiles > holyTiles)
            {
                num8 = ((float)evilTiles) / 800f;
            }
            if (num8 > 1f)
            {
                num8 = 1f;
            }
            if (num8 < 0f)
            {
                num8 = 0f;
            }
            float num9 = (screenPosition.Y - ((float)(worldSurface * 16.0))) / 300f;
            if (num9 < 0f)
            {
                num9 = 0f;
            }
            else if (num9 > 1f)
            {
                num9 = 1f;
            }
            float num10 = (1f * (1f - num9)) + (num5 * num9);
            Lighting.brightness = (Lighting.defBrightness * (1f - num9)) + (1f * num9);
            float num11 = (((screenPosition.Y - (screenHeight / 2)) + 200f) - ((float)(rockLayer * 16.0))) / 300f;
            if (num11 < 0f)
            {
                num11 = 0f;
            }
            else if (num11 > 1f)
            {
                num11 = 1f;
            }
            if (evilTiles > 0)
            {
                num5 = (0.8f * num8) + (num5 * (1f - num8));
                num6 = (0.75f * num8) + (num6 * (1f - num8));
                num7 = (1.1f * num8) + (num7 * (1f - num8));
            }
            else if (holyTiles > 0)
            {
                num5 = (1f * num8) + (num5 * (1f - num8));
                num6 = (0.7f * num8) + (num6 * (1f - num8));
                num7 = (0.9f * num8) + (num7 * (1f - num8));
            }
            num5 = (1f * (num10 - num11)) + (num5 * num11);
            num6 = (1f * (num10 - num11)) + (num6 * num11);
            num7 = (1f * (num10 - num11)) + (num7 * num11);
            Lighting.defBrightness = (1.2f * (1f - num11)) + (1f * num11);
            this.bgParrallax = caveParrallax;
            this.bgStart = ((int)-Math.IEEERemainder(screenPosition.X * this.bgParrallax, (double)num3)) - (num3 / 2);
            this.bgLoops = (screenWidth / num3) + 2;
            this.bgTop = (int)((((((int)worldSurface) * 0x10) - backgroundHeight[1]) - screenPosition.Y) + 16f);
            for (int i = 0; i < this.bgLoops; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    float num14 = this.bgStart + screenPosition.X;
                    num14 = -((float)Math.IEEERemainder((double)num14, 16.0));
                    num14 = (float)Math.Round((double)num14);
                    int num15 = (int)num14;
                    if (num15 == -8)
                    {
                        num15 = 8;
                    }
                    float num16 = ((this.bgStart + (num3 * i)) + (j * 0x10)) + 8;
                    float bgTop = this.bgTop;
                    Color color = Lighting.GetColor((int)((num16 + screenPosition.X) / 16f), (int)((screenPosition.Y + bgTop) / 16f));
                    color.R = (byte)(color.R * num5);
                    color.G = (byte)(color.G * num6);
                    color.B = (byte)(color.B * num7);
                    this.spriteBatch.Draw(backgroundTexture[1], new Vector2((float)(((this.bgStart + (num3 * i)) + (0x10 * j)) + num15), (float)this.bgTop) + vector, new Rectangle(((0x10 * j) + num15) + 0x10, 0, 0x10, 0x10), color);
                }
            }
            double num18 = maxTilesY - 230;
            double num19 = ((int)((num18 - worldSurface) / 6.0)) * 6;
            num18 = (worldSurface + num19) - 5.0;
            bool flag = false;
            bool flag2 = false;
            this.bgTop = (int)(((((int)worldSurface) * 0x10) - screenPosition.Y) + 16f);
            if ((worldSurface * 16.0) <= ((screenPosition.Y + screenHeight) + offScreenRange))
            {
                this.bgParrallax = caveParrallax;
                this.bgStart = (((int)-Math.IEEERemainder(96.0 + (screenPosition.X * this.bgParrallax), (double)num3)) - (num3 / 2)) - ((int)vector.X);
                this.bgLoops = ((screenWidth + (((int)vector.X) * 2)) / num3) + 2;
                if ((worldSurface * 16.0) < (screenPosition.Y - 16f))
                {
                    this.bgStartY = ((int)Math.IEEERemainder((double)this.bgTop, (double)backgroundHeight[2])) - backgroundHeight[2];
                    this.bgLoopsY = (((screenHeight - this.bgStartY) + (((int)vector.Y) * 2)) / backgroundHeight[2]) + 1;
                }
                else
                {
                    this.bgStartY = this.bgTop;
                    this.bgLoopsY = (((screenHeight - this.bgTop) + (((int)vector.Y) * 2)) / backgroundHeight[2]) + 1;
                }
                if ((rockLayer * 16.0) < (screenPosition.Y + 600f))
                {
                    this.bgLoopsY = (((int)(((rockLayer * 16.0) - screenPosition.Y) + 600.0)) - this.bgStartY) / backgroundHeight[2];
                    flag2 = true;
                }
                float num20 = this.bgStart + screenPosition.X;
                num20 = -((float)Math.IEEERemainder((double)num20, 16.0));
                num20 = (float)Math.Round((double)num20);
                int num21 = (int)num20;
                if (num21 == -8)
                {
                    num21 = 8;
                }
                for (int k = 0; k < this.bgLoops; k++)
                {
                    for (int m = 0; m < this.bgLoopsY; m++)
                    {
                        for (int n = 0; n < 6; n++)
                        {
                            for (int num25 = 0; num25 < 6; num25++)
                            {
                                float num26 = ((this.bgStartY + (m * 0x60)) + (num25 * 0x10)) + 8;
                                float num27 = ((this.bgStart + (num3 * k)) + (n * 0x10)) + 8;
                                int x = (int)((num27 + screenPosition.X) / 16f);
                                int y = (int)((num26 + screenPosition.Y) / 16f);
                                Color color2 = Lighting.GetColor(x, y);
                                if (tile[x, y] == null)
                                {
                                    tile[x, y] = new Tile();
                                }
                                if (((color2.R > 0) || (color2.G > 0)) || (color2.B > 0))
                                {
                                    if ((((color2.R > num) || (color2.G > (num * 1.1))) || (color2.B > (num * 1.2))) && (!tile[x, y].active && ((tile[x, y].wall == 0) || (tile[x, y].wall == 0x15))))
                                    {
                                        try
                                        {
                                            for (int num30 = 0; num30 < 9; num30++)
                                            {
                                                int num31 = 0;
                                                int num32 = 0;
                                                int width = 4;
                                                int height = 4;
                                                Color color3 = color2;
                                                Color color4 = color2;
                                                if ((num30 == 0) && !tile[x - 1, y - 1].active)
                                                {
                                                    color4 = Lighting.GetColor(x - 1, y - 1);
                                                }
                                                if (num30 == 1)
                                                {
                                                    width = 8;
                                                    num31 = 4;
                                                    if (!tile[x, y - 1].active)
                                                    {
                                                        color4 = Lighting.GetColor(x, y - 1);
                                                    }
                                                }
                                                if (num30 == 2)
                                                {
                                                    if (!tile[x + 1, y - 1].active)
                                                    {
                                                        color4 = Lighting.GetColor(x + 1, y - 1);
                                                    }
                                                    if (tile[x + 1, y - 1] == null)
                                                    {
                                                        tile[x + 1, y - 1] = new Tile();
                                                    }
                                                    num31 = 12;
                                                }
                                                if (num30 == 3)
                                                {
                                                    if (!tile[x - 1, y].active)
                                                    {
                                                        color4 = Lighting.GetColor(x - 1, y);
                                                    }
                                                    height = 8;
                                                    num32 = 4;
                                                }
                                                switch (num30)
                                                {
                                                    case 4:
                                                        width = 8;
                                                        height = 8;
                                                        num31 = 4;
                                                        num32 = 4;
                                                        break;

                                                    case 5:
                                                        num31 = 12;
                                                        num32 = 4;
                                                        height = 8;
                                                        if (!tile[x + 1, y].active)
                                                        {
                                                            color4 = Lighting.GetColor(x + 1, y);
                                                        }
                                                        break;
                                                }
                                                if (num30 == 6)
                                                {
                                                    if (!tile[x - 1, y + 1].active)
                                                    {
                                                        color4 = Lighting.GetColor(x - 1, y + 1);
                                                    }
                                                    num32 = 12;
                                                }
                                                if (num30 == 7)
                                                {
                                                    width = 8;
                                                    height = 4;
                                                    num31 = 4;
                                                    num32 = 12;
                                                    if (!tile[x, y + 1].active)
                                                    {
                                                        color4 = Lighting.GetColor(x, y + 1);
                                                    }
                                                }
                                                if (num30 == 8)
                                                {
                                                    if (!tile[x + 1, y + 1].active)
                                                    {
                                                        color4 = Lighting.GetColor(x + 1, y + 1);
                                                    }
                                                    num31 = 12;
                                                    num32 = 12;
                                                }
                                                color3.R = (byte)((color2.R + color4.R) / 2);
                                                color3.G = (byte)((color2.G + color4.G) / 2);
                                                color3.B = (byte)((color2.B + color4.B) / 2);
                                                color3.R = (byte)(color3.R * num5);
                                                color3.G = (byte)(color3.G * num6);
                                                color3.B = (byte)(color3.B * num7);
                                                this.spriteBatch.Draw(backgroundTexture[2], new Vector2((float)((((this.bgStart + (num3 * k)) + (0x10 * n)) + num31) + num21), (float)(((this.bgStartY + (backgroundHeight[2] * m)) + (0x10 * num25)) + num32)) + vector, new Rectangle((((0x10 * n) + num31) + num21) + 0x10, (0x10 * num25) + num32, width, height), color3);
                                            }
                                        }
                                        catch
                                        {
                                            color2.R = (byte)(color2.R * num5);
                                            color2.G = (byte)(color2.G * num6);
                                            color2.B = (byte)(color2.B * num7);
                                            this.spriteBatch.Draw(backgroundTexture[2], new Vector2((float)(((this.bgStart + (num3 * k)) + (0x10 * n)) + num21), (float)((this.bgStartY + (backgroundHeight[2] * m)) + (0x10 * num25))) + vector, new Rectangle(((0x10 * n) + num21) + 0x10, 0x10 * num25, 0x10, 0x10), color2);
                                        }
                                    }
                                    else if (((color2.R > num2) || (color2.G > (num2 * 1.1))) || (color2.B > (num2 * 1.2)))
                                    {
                                        for (int num35 = 0; num35 < 4; num35++)
                                        {
                                            int num36 = 0;
                                            int num37 = 0;
                                            Color color5 = color2;
                                            Color color6 = color2;
                                            switch (num35)
                                            {
                                                case 0:
                                                    if (Lighting.Brighter(x, y - 1, x - 1, y))
                                                    {
                                                        color6 = Lighting.GetColor(x - 1, y);
                                                    }
                                                    else
                                                    {
                                                        color6 = Lighting.GetColor(x, y - 1);
                                                    }
                                                    break;

                                                case 1:
                                                    if (Lighting.Brighter(x, y - 1, x + 1, y))
                                                    {
                                                        color6 = Lighting.GetColor(x + 1, y);
                                                    }
                                                    else
                                                    {
                                                        color6 = Lighting.GetColor(x, y - 1);
                                                    }
                                                    num36 = 8;
                                                    break;

                                                case 2:
                                                    if (Lighting.Brighter(x, y + 1, x - 1, y))
                                                    {
                                                        color6 = Lighting.GetColor(x - 1, y);
                                                    }
                                                    else
                                                    {
                                                        color6 = Lighting.GetColor(x, y + 1);
                                                    }
                                                    num37 = 8;
                                                    break;

                                                case 3:
                                                    if (Lighting.Brighter(x, y + 1, x + 1, y))
                                                    {
                                                        color6 = Lighting.GetColor(x + 1, y);
                                                    }
                                                    else
                                                    {
                                                        color6 = Lighting.GetColor(x, y + 1);
                                                    }
                                                    num36 = 8;
                                                    num37 = 8;
                                                    break;
                                            }
                                            color5.R = (byte)((color2.R + color6.R) / 2);
                                            color5.G = (byte)((color2.G + color6.G) / 2);
                                            color5.B = (byte)((color2.B + color6.B) / 2);
                                            color5.R = (byte)(color5.R * num5);
                                            color5.G = (byte)(color5.G * num6);
                                            color5.B = (byte)(color5.B * num7);
                                            this.spriteBatch.Draw(backgroundTexture[2], new Vector2((float)((((this.bgStart + (num3 * k)) + (0x10 * n)) + num36) + num21), (float)(((this.bgStartY + (backgroundHeight[2] * m)) + (0x10 * num25)) + num37)) + vector, new Rectangle((((0x10 * n) + num36) + num21) + 0x10, (0x10 * num25) + num37, 8, 8), color5);
                                        }
                                    }
                                    else
                                    {
                                        color2.R = (byte)(color2.R * num5);
                                        color2.G = (byte)(color2.G * num6);
                                        color2.B = (byte)(color2.B * num7);
                                        this.spriteBatch.Draw(backgroundTexture[2], new Vector2((float)(((this.bgStart + (num3 * k)) + (0x10 * n)) + num21), (float)((this.bgStartY + (backgroundHeight[2] * m)) + (0x10 * num25))) + vector, new Rectangle(((0x10 * n) + num21) + 0x10, 0x10 * num25, 0x10, 0x10), color2);
                                    }
                                }
                                else
                                {
                                    color2.R = (byte)(color2.R * num5);
                                    color2.G = (byte)(color2.G * num6);
                                    color2.B = (byte)(color2.B * num7);
                                    this.spriteBatch.Draw(backgroundTexture[2], new Vector2((float)(((this.bgStart + (num3 * k)) + (0x10 * n)) + num21), (float)((this.bgStartY + (backgroundHeight[2] * m)) + (0x10 * num25))) + vector, new Rectangle(((0x10 * n) + num21) + 0x10, 0x10 * num25, 0x10, 0x10), color2);
                                }
                            }
                        }
                    }
                }
                if (flag2)
                {
                    this.bgParrallax = caveParrallax;
                    this.bgStart = ((int)-Math.IEEERemainder(screenPosition.X * this.bgParrallax, (double)num3)) - (num3 / 2);
                    this.bgLoops = ((screenWidth + (((int)vector.X) * 2)) / num3) + 2;
                    this.bgTop = this.bgStartY + (this.bgLoopsY * backgroundHeight[2]);
                    if (this.bgTop > -32)
                    {
                        for (int num38 = 0; num38 < this.bgLoops; num38++)
                        {
                            for (int num39 = 0; num39 < 6; num39++)
                            {
                                float num40 = ((this.bgStart + (num3 * num38)) + (num39 * 0x10)) + 8;
                                float num41 = this.bgTop;
                                Color color7 = Lighting.GetColor((int)((num40 + screenPosition.X) / 16f), (int)((screenPosition.Y + num41) / 16f));
                                color7.R = (byte)(color7.R * num5);
                                color7.G = (byte)(color7.G * num6);
                                color7.B = (byte)(color7.B * num7);
                                this.spriteBatch.Draw(backgroundTexture[4], new Vector2((float)(((this.bgStart + (num3 * num38)) + (0x10 * num39)) + num21), (float)this.bgTop) + vector, new Rectangle(((0x10 * num39) + num21) + 0x10, 0, 0x10, 0x10), color7);
                            }
                        }
                    }
                }
            }
            this.bgTop = (int)(((((((int)rockLayer) * 0x10) - screenPosition.Y) + 16f) + 600f) - 8f);
            if ((rockLayer * 16.0) <= (screenPosition.Y + 600f))
            {
                this.bgParrallax = caveParrallax;
                this.bgStart = (((int)-Math.IEEERemainder(96.0 + (screenPosition.X * this.bgParrallax), (double)num3)) - (num3 / 2)) - ((int)vector.X);
                this.bgLoops = ((screenWidth + (((int)vector.X) * 2)) / num3) + 2;
                if (((rockLayer * 16.0) + screenHeight) < (screenPosition.Y - 16f))
                {
                    this.bgStartY = ((int)Math.IEEERemainder((double)this.bgTop, (double)backgroundHeight[3])) - backgroundHeight[3];
                    this.bgLoopsY = (((screenHeight - this.bgStartY) + (((int)vector.Y) * 2)) / backgroundHeight[2]) + 1;
                }
                else
                {
                    this.bgStartY = this.bgTop;
                    this.bgLoopsY = (((screenHeight - this.bgTop) + (((int)vector.Y) * 2)) / backgroundHeight[2]) + 1;
                }
                if ((num18 * 16.0) < (screenPosition.Y + 600f))
                {
                    this.bgLoopsY = (((int)(((num18 * 16.0) - screenPosition.Y) + 600.0)) - this.bgStartY) / backgroundHeight[2];
                    flag = true;
                }
                float num42 = this.bgStart + screenPosition.X;
                num42 = -((float)Math.IEEERemainder((double)num42, 16.0));
                num42 = (float)Math.Round((double)num42);
                int num43 = (int)num42;
                if (num43 == -8)
                {
                    num43 = 8;
                }
                for (int num44 = 0; num44 < this.bgLoops; num44++)
                {
                    for (int num45 = 0; num45 < this.bgLoopsY; num45++)
                    {
                        for (int num46 = 0; num46 < 6; num46++)
                        {
                            for (int num47 = 0; num47 < 6; num47++)
                            {
                                float num48 = ((this.bgStartY + (num45 * 0x60)) + (num47 * 0x10)) + 8;
                                float num49 = ((this.bgStart + (num3 * num44)) + (num46 * 0x10)) + 8;
                                int num50 = (int)((num49 + screenPosition.X) / 16f);
                                int num51 = (int)((num48 + screenPosition.Y) / 16f);
                                Color color8 = Lighting.GetColor(num50, num51);
                                if (tile[num50, num51] == null)
                                {
                                    tile[num50, num51] = new Tile();
                                }
                                bool flag3 = false;
                                if (caveParrallax != 0f)
                                {
                                    if (tile[num50 - 1, num51] == null)
                                    {
                                        tile[num50 - 1, num51] = new Tile();
                                    }
                                    if (tile[num50 + 1, num51] == null)
                                    {
                                        tile[num50 + 1, num51] = new Tile();
                                    }
                                    if ((((tile[num50, num51].wall == 0) || (tile[num50, num51].wall == 0x15)) || ((tile[num50 - 1, num51].wall == 0) || (tile[num50 - 1, num51].wall == 0x15))) || ((tile[num50 + 1, num51].wall == 0) || (tile[num50 + 1, num51].wall == 0x15)))
                                    {
                                        flag3 = true;
                                    }
                                }
                                else if ((tile[num50, num51].wall == 0) || (tile[num50, num51].wall == 0x15))
                                {
                                    flag3 = true;
                                }
                                if ((((flag3 || (color8.R == 0)) || ((color8.G == 0) || (color8.B == 0))) && (((color8.R > 0) || (color8.G > 0)) || (color8.B > 0))) && (((tile[num50, num51].wall == 0) || (tile[num50, num51].wall == 0x15)) || (caveParrallax != 0f)))
                                {
                                    if (((Lighting.lightMode < 2) && (color8.R < 230)) && ((color8.G < 230) && (color8.B < 230)))
                                    {
                                        if ((((color8.R > num) || (color8.G > (num * 1.1))) || (color8.B > (num * 1.2))) && !tile[num50, num51].active)
                                        {
                                            for (int num52 = 0; num52 < 9; num52++)
                                            {
                                                int num53 = 0;
                                                int num54 = 0;
                                                int num55 = 4;
                                                int num56 = 4;
                                                Color color9 = color8;
                                                Color color10 = color8;
                                                if ((num52 == 0) && !tile[num50 - 1, num51 - 1].active)
                                                {
                                                    color10 = Lighting.GetColor(num50 - 1, num51 - 1);
                                                }
                                                if (num52 == 1)
                                                {
                                                    num55 = 8;
                                                    num53 = 4;
                                                    if (!tile[num50, num51 - 1].active)
                                                    {
                                                        color10 = Lighting.GetColor(num50, num51 - 1);
                                                    }
                                                }
                                                if (num52 == 2)
                                                {
                                                    if (!tile[num50 + 1, num51 - 1].active)
                                                    {
                                                        color10 = Lighting.GetColor(num50 + 1, num51 - 1);
                                                    }
                                                    num53 = 12;
                                                }
                                                if (num52 == 3)
                                                {
                                                    if (!tile[num50 - 1, num51].active)
                                                    {
                                                        color10 = Lighting.GetColor(num50 - 1, num51);
                                                    }
                                                    num56 = 8;
                                                    num54 = 4;
                                                }
                                                switch (num52)
                                                {
                                                    case 4:
                                                        num55 = 8;
                                                        num56 = 8;
                                                        num53 = 4;
                                                        num54 = 4;
                                                        break;

                                                    case 5:
                                                        num53 = 12;
                                                        num54 = 4;
                                                        num56 = 8;
                                                        if (!tile[num50 + 1, num51].active)
                                                        {
                                                            color10 = Lighting.GetColor(num50 + 1, num51);
                                                        }
                                                        break;
                                                }
                                                if (num52 == 6)
                                                {
                                                    if (!tile[num50 - 1, num51 + 1].active)
                                                    {
                                                        color10 = Lighting.GetColor(num50 - 1, num51 + 1);
                                                    }
                                                    num54 = 12;
                                                }
                                                if (num52 == 7)
                                                {
                                                    num55 = 8;
                                                    num56 = 4;
                                                    num53 = 4;
                                                    num54 = 12;
                                                    if (!tile[num50, num51 + 1].active)
                                                    {
                                                        color10 = Lighting.GetColor(num50, num51 + 1);
                                                    }
                                                }
                                                if (num52 == 8)
                                                {
                                                    if (!tile[num50 + 1, num51 + 1].active)
                                                    {
                                                        color10 = Lighting.GetColor(num50 + 1, num51 + 1);
                                                    }
                                                    num53 = 12;
                                                    num54 = 12;
                                                }
                                                color9.R = (byte)((color8.R + color10.R) / 2);
                                                color9.G = (byte)((color8.G + color10.G) / 2);
                                                color9.B = (byte)((color8.B + color10.B) / 2);
                                                color9.R = (byte)(color9.R * num5);
                                                color9.G = (byte)(color9.G * num6);
                                                color9.B = (byte)(color9.B * num7);
                                                this.spriteBatch.Draw(backgroundTexture[3], new Vector2((float)((((this.bgStart + (num3 * num44)) + (0x10 * num46)) + num53) + num43), (float)(((this.bgStartY + (backgroundHeight[2] * num45)) + (0x10 * num47)) + num54)) + vector, new Rectangle((((0x10 * num46) + num53) + num43) + 0x10, (0x10 * num47) + num54, num55, num56), color9);
                                            }
                                        }
                                        else if (((color8.R > num2) || (color8.G > (num2 * 1.1))) || (color8.B > (num2 * 1.2)))
                                        {
                                            for (int num57 = 0; num57 < 4; num57++)
                                            {
                                                int num58 = 0;
                                                int num59 = 0;
                                                Color color11 = color8;
                                                Color color12 = color8;
                                                switch (num57)
                                                {
                                                    case 0:
                                                        if (Lighting.Brighter(num50, num51 - 1, num50 - 1, num51))
                                                        {
                                                            color12 = Lighting.GetColor(num50 - 1, num51);
                                                        }
                                                        else
                                                        {
                                                            color12 = Lighting.GetColor(num50, num51 - 1);
                                                        }
                                                        break;

                                                    case 1:
                                                        if (Lighting.Brighter(num50, num51 - 1, num50 + 1, num51))
                                                        {
                                                            color12 = Lighting.GetColor(num50 + 1, num51);
                                                        }
                                                        else
                                                        {
                                                            color12 = Lighting.GetColor(num50, num51 - 1);
                                                        }
                                                        num58 = 8;
                                                        break;

                                                    case 2:
                                                        if (Lighting.Brighter(num50, num51 + 1, num50 - 1, num51))
                                                        {
                                                            color12 = Lighting.GetColor(num50 - 1, num51);
                                                        }
                                                        else
                                                        {
                                                            color12 = Lighting.GetColor(num50, num51 + 1);
                                                        }
                                                        num59 = 8;
                                                        break;

                                                    case 3:
                                                        if (Lighting.Brighter(num50, num51 + 1, num50 + 1, num51))
                                                        {
                                                            color12 = Lighting.GetColor(num50 + 1, num51);
                                                        }
                                                        else
                                                        {
                                                            color12 = Lighting.GetColor(num50, num51 + 1);
                                                        }
                                                        num58 = 8;
                                                        num59 = 8;
                                                        break;
                                                }
                                                color11.R = (byte)((color8.R + color12.R) / 2);
                                                color11.G = (byte)((color8.G + color12.G) / 2);
                                                color11.B = (byte)((color8.B + color12.B) / 2);
                                                color11.R = (byte)(color11.R * num5);
                                                color11.G = (byte)(color11.G * num6);
                                                color11.B = (byte)(color11.B * num7);
                                                this.spriteBatch.Draw(backgroundTexture[3], new Vector2((float)((((this.bgStart + (num3 * num44)) + (0x10 * num46)) + num58) + num43), (float)(((this.bgStartY + (backgroundHeight[2] * num45)) + (0x10 * num47)) + num59)) + vector, new Rectangle((((0x10 * num46) + num58) + num43) + 0x10, (0x10 * num47) + num59, 8, 8), color11);
                                            }
                                        }
                                        else
                                        {
                                            color8.R = (byte)(color8.R * num5);
                                            color8.G = (byte)(color8.G * num6);
                                            color8.B = (byte)(color8.B * num7);
                                            this.spriteBatch.Draw(backgroundTexture[3], new Vector2((float)(((this.bgStart + (num3 * num44)) + (0x10 * num46)) + num43), (float)((this.bgStartY + (backgroundHeight[2] * num45)) + (0x10 * num47))) + vector, new Rectangle(((0x10 * num46) + num43) + 0x10, 0x10 * num47, 0x10, 0x10), color8);
                                        }
                                    }
                                    else
                                    {
                                        color8.R = (byte)(color8.R * num5);
                                        color8.G = (byte)(color8.G * num6);
                                        color8.B = (byte)(color8.B * num7);
                                        this.spriteBatch.Draw(backgroundTexture[3], new Vector2((float)(((this.bgStart + (num3 * num44)) + (0x10 * num46)) + num43), (float)((this.bgStartY + (backgroundHeight[2] * num45)) + (0x10 * num47))) + vector, new Rectangle(((0x10 * num46) + num43) + 0x10, 0x10 * num47, 0x10, 0x10), color8);
                                    }
                                }
                            }
                        }
                    }
                }
                if (flag)
                {
                    this.bgParrallax = caveParrallax;
                    this.bgStart = ((int)-Math.IEEERemainder(screenPosition.X * this.bgParrallax, (double)num3)) - (num3 / 2);
                    this.bgLoops = (screenWidth / num3) + 2;
                    this.bgTop = this.bgStartY + (this.bgLoopsY * backgroundHeight[2]);
                    for (int num60 = 0; num60 < this.bgLoops; num60++)
                    {
                        for (int num61 = 0; num61 < 6; num61++)
                        {
                            float num62 = ((this.bgStart + (num3 * num60)) + (num61 * 0x10)) + 8;
                            float num63 = this.bgTop;
                            Color color13 = Lighting.GetColor((int)((num62 + screenPosition.X) / 16f), (int)((screenPosition.Y + num63) / 16f));
                            color13.R = (byte)(color13.R * num5);
                            color13.G = (byte)(color13.G * num6);
                            color13.B = (byte)(color13.B * num7);
                            this.spriteBatch.Draw(backgroundTexture[6], new Vector2((float)(((this.bgStart + (num3 * num60)) + (0x10 * num61)) + num43), (float)this.bgTop) + vector, new Rectangle(((0x10 * num61) + num43) + 0x10, magmaBGFrame * 0x10, 0x10, 0x10), color13);
                        }
                    }
                }
            }
            this.bgTop = ((int)((((((int)num18) * 0x10) - screenPosition.Y) + 16f) + 600f)) - 8;
            if ((num18 * 16.0) <= (screenPosition.Y + 600f))
            {
                this.bgStart = (((int)-Math.IEEERemainder(96.0 + (screenPosition.X * this.bgParrallax), (double)num3)) - (num3 / 2)) - ((int)vector.X);
                this.bgLoops = ((screenWidth + (((int)vector.X) * 2)) / num3) + 2;
                if (((num18 * 16.0) + screenHeight) < (screenPosition.Y - 16f))
                {
                    this.bgStartY = ((int)Math.IEEERemainder((double)this.bgTop, (double)backgroundHeight[2])) - backgroundHeight[2];
                    this.bgLoopsY = (((screenHeight - this.bgStartY) + (((int)vector.Y) * 2)) / backgroundHeight[2]) + 1;
                }
                else
                {
                    this.bgStartY = this.bgTop;
                    this.bgLoopsY = (((screenHeight - this.bgTop) + (((int)vector.Y) * 2)) / backgroundHeight[2]) + 1;
                }
                num = (int)(num * 1.5);
                num2 = (int)(num2 * 1.5);
                float num64 = this.bgStart + screenPosition.X;
                num64 = -((float)Math.IEEERemainder((double)num64, 16.0));
                num64 = (float)Math.Round((double)num64);
                int num65 = (int)num64;
                if (num65 == -8)
                {
                    num65 = 8;
                }
                for (int num66 = 0; num66 < this.bgLoops; num66++)
                {
                    for (int num67 = 0; num67 < this.bgLoopsY; num67++)
                    {
                        for (int num68 = 0; num68 < 6; num68++)
                        {
                            for (int num69 = 0; num69 < 6; num69++)
                            {
                                float num70 = ((this.bgStartY + (num67 * 0x60)) + (num69 * 0x10)) + 8;
                                float num71 = ((this.bgStart + (num3 * num66)) + (num68 * 0x10)) + 8;
                                int num72 = (int)((num71 + screenPosition.X) / 16f);
                                int num73 = (int)((num70 + screenPosition.Y) / 16f);
                                Color color14 = Lighting.GetColor(num72, num73);
                                if (tile[num72, num73] == null)
                                {
                                    tile[num72, num73] = new Tile();
                                }
                                bool flag4 = false;
                                if (caveParrallax != 0f)
                                {
                                    if (tile[num72 - 1, num73] == null)
                                    {
                                        tile[num72 - 1, num73] = new Tile();
                                    }
                                    if (tile[num72 + 1, num73] == null)
                                    {
                                        tile[num72 + 1, num73] = new Tile();
                                    }
                                    if ((((tile[num72, num73].wall == 0) || (tile[num72, num73].wall == 0x15)) || ((tile[num72 - 1, num73].wall == 0) || (tile[num72 - 1, num73].wall == 0x15))) || ((tile[num72 + 1, num73].wall == 0) || (tile[num72 + 1, num73].wall == 0x15)))
                                    {
                                        flag4 = true;
                                    }
                                }
                                else if ((tile[num72, num73].wall == 0) || (tile[num72, num73].wall == 0x15))
                                {
                                    flag4 = true;
                                }
                                if ((((flag4 || (color14.R == 0)) || ((color14.G == 0) || (color14.B == 0))) && (((color14.R > 0) || (color14.G > 0)) || (color14.B > 0))) && (((tile[num72, num73].wall == 0) || (tile[num72, num73].wall == 0x15)) || (caveParrallax != 0f)))
                                {
                                    Vector2 vector2;
                                    if (((Lighting.lightMode < 2) && (color14.R < 230)) && ((color14.G < 230) && (color14.B < 230)))
                                    {
                                        if ((((color14.R > num) || (color14.G > (num * 1.1))) || (color14.B > (num * 1.2))) && !tile[num72, num73].active)
                                        {
                                            for (int num74 = 0; num74 < 9; num74++)
                                            {
                                                int num75 = 0;
                                                int num76 = 0;
                                                int num77 = 4;
                                                int num78 = 4;
                                                Color color15 = color14;
                                                Color color16 = color14;
                                                if ((num74 == 0) && !tile[num72 - 1, num73 - 1].active)
                                                {
                                                    color16 = Lighting.GetColor(num72 - 1, num73 - 1);
                                                }
                                                if (num74 == 1)
                                                {
                                                    num77 = 8;
                                                    num75 = 4;
                                                    if (!tile[num72, num73 - 1].active)
                                                    {
                                                        color16 = Lighting.GetColor(num72, num73 - 1);
                                                    }
                                                }
                                                if (num74 == 2)
                                                {
                                                    if (!tile[num72 + 1, num73 - 1].active)
                                                    {
                                                        color16 = Lighting.GetColor(num72 + 1, num73 - 1);
                                                    }
                                                    num75 = 12;
                                                }
                                                if (num74 == 3)
                                                {
                                                    if (!tile[num72 - 1, num73].active)
                                                    {
                                                        color16 = Lighting.GetColor(num72 - 1, num73);
                                                    }
                                                    num78 = 8;
                                                    num76 = 4;
                                                }
                                                switch (num74)
                                                {
                                                    case 4:
                                                        num77 = 8;
                                                        num78 = 8;
                                                        num75 = 4;
                                                        num76 = 4;
                                                        break;

                                                    case 5:
                                                        num75 = 12;
                                                        num76 = 4;
                                                        num78 = 8;
                                                        if (!tile[num72 + 1, num73].active)
                                                        {
                                                            color16 = Lighting.GetColor(num72 + 1, num73);
                                                        }
                                                        break;
                                                }
                                                if (num74 == 6)
                                                {
                                                    if (!tile[num72 - 1, num73 + 1].active)
                                                    {
                                                        color16 = Lighting.GetColor(num72 - 1, num73 + 1);
                                                    }
                                                    num76 = 12;
                                                }
                                                if (num74 == 7)
                                                {
                                                    num77 = 8;
                                                    num78 = 4;
                                                    num75 = 4;
                                                    num76 = 12;
                                                    if (!tile[num72, num73 + 1].active)
                                                    {
                                                        color16 = Lighting.GetColor(num72, num73 + 1);
                                                    }
                                                }
                                                if (num74 == 8)
                                                {
                                                    if (!tile[num72 + 1, num73 + 1].active)
                                                    {
                                                        color16 = Lighting.GetColor(num72 + 1, num73 + 1);
                                                    }
                                                    num75 = 12;
                                                    num76 = 12;
                                                }
                                                color15.R = (byte)((color14.R + color16.R) / 2);
                                                color15.G = (byte)((color14.G + color16.G) / 2);
                                                color15.B = (byte)((color14.B + color16.B) / 2);
                                                color15.R = (byte)(color15.R * num5);
                                                color15.G = (byte)(color15.G * num6);
                                                color15.B = (byte)(color15.B * num7);
                                                vector2 = new Vector2();
                                                this.spriteBatch.Draw(backgroundTexture[5], new Vector2((float)((((this.bgStart + (num3 * num66)) + (0x10 * num68)) + num75) + num65), (float)(((this.bgStartY + (backgroundHeight[2] * num67)) + (0x10 * num69)) + num76)) + vector, new Rectangle((((0x10 * num68) + num75) + num65) + 0x10, ((0x10 * num69) + (backgroundHeight[2] * magmaBGFrame)) + num76, num77, num78), color15, 0f, vector2, (float)1f, SpriteEffects.None, 0f);
                                            }
                                        }
                                        else if (((color14.R > num2) || (color14.G > (num2 * 1.1))) || (color14.B > (num2 * 1.2)))
                                        {
                                            for (int num79 = 0; num79 < 4; num79++)
                                            {
                                                int num80 = 0;
                                                int num81 = 0;
                                                Color color17 = color14;
                                                Color color18 = color14;
                                                switch (num79)
                                                {
                                                    case 0:
                                                        if (Lighting.Brighter(num72, num73 - 1, num72 - 1, num73))
                                                        {
                                                            color18 = Lighting.GetColor(num72 - 1, num73);
                                                        }
                                                        else
                                                        {
                                                            color18 = Lighting.GetColor(num72, num73 - 1);
                                                        }
                                                        break;

                                                    case 1:
                                                        if (Lighting.Brighter(num72, num73 - 1, num72 + 1, num73))
                                                        {
                                                            color18 = Lighting.GetColor(num72 + 1, num73);
                                                        }
                                                        else
                                                        {
                                                            color18 = Lighting.GetColor(num72, num73 - 1);
                                                        }
                                                        num80 = 8;
                                                        break;

                                                    case 2:
                                                        if (Lighting.Brighter(num72, num73 + 1, num72 - 1, num73))
                                                        {
                                                            color18 = Lighting.GetColor(num72 - 1, num73);
                                                        }
                                                        else
                                                        {
                                                            color18 = Lighting.GetColor(num72, num73 + 1);
                                                        }
                                                        num81 = 8;
                                                        break;

                                                    case 3:
                                                        if (Lighting.Brighter(num72, num73 + 1, num72 + 1, num73))
                                                        {
                                                            color18 = Lighting.GetColor(num72 + 1, num73);
                                                        }
                                                        else
                                                        {
                                                            color18 = Lighting.GetColor(num72, num73 + 1);
                                                        }
                                                        num80 = 8;
                                                        num81 = 8;
                                                        break;
                                                }
                                                color17.R = (byte)((color14.R + color18.R) / 2);
                                                color17.G = (byte)((color14.G + color18.G) / 2);
                                                color17.B = (byte)((color14.B + color18.B) / 2);
                                                color17.R = (byte)(color17.R * num5);
                                                color17.G = (byte)(color17.G * num6);
                                                color17.B = (byte)(color17.B * num7);
                                                vector2 = new Vector2();
                                                this.spriteBatch.Draw(backgroundTexture[5], new Vector2((float)((((this.bgStart + (num3 * num66)) + (0x10 * num68)) + num80) + num65), (float)(((this.bgStartY + (backgroundHeight[2] * num67)) + (0x10 * num69)) + num81)) + vector, new Rectangle((((0x10 * num68) + num80) + num65) + 0x10, ((0x10 * num69) + (backgroundHeight[2] * magmaBGFrame)) + num81, 8, 8), color17, 0f, vector2, (float)1f, SpriteEffects.None, 0f);
                                            }
                                        }
                                        else
                                        {
                                            color14.R = (byte)(color14.R * num5);
                                            color14.G = (byte)(color14.G * num6);
                                            color14.B = (byte)(color14.B * num7);
                                            vector2 = new Vector2();
                                            this.spriteBatch.Draw(backgroundTexture[5], new Vector2((float)(((this.bgStart + (num3 * num66)) + (0x10 * num68)) + num65), (float)((this.bgStartY + (backgroundHeight[2] * num67)) + (0x10 * num69))) + vector, new Rectangle(((0x10 * num68) + num65) + 0x10, (0x10 * num69) + (backgroundHeight[2] * magmaBGFrame), 0x10, 0x10), color14, 0f, vector2, (float)1f, SpriteEffects.None, 0f);
                                        }
                                    }
                                    else
                                    {
                                        color14.R = (byte)(color14.R * num5);
                                        color14.G = (byte)(color14.G * num6);
                                        color14.B = (byte)(color14.B * num7);
                                        vector2 = new Vector2();
                                        this.spriteBatch.Draw(backgroundTexture[5], new Vector2((float)(((this.bgStart + (num3 * num66)) + (0x10 * num68)) + num65), (float)((this.bgStartY + (backgroundHeight[2] * num67)) + (0x10 * num69))) + vector, new Rectangle(((0x10 * num68) + num65) + 0x10, (0x10 * num69) + (backgroundHeight[2] * magmaBGFrame), 0x10, 0x10), color14, 0f, vector2, (float)1f, SpriteEffects.None, 0f);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Lighting.brightness = Lighting.defBrightness;
            renderTimer[3] = stopwatch.ElapsedMilliseconds;
        }
Ejemplo n.º 16
0
        public static void SmoothSlope(int x, int y, bool applyToNeighbors = true, bool sync = false)
        {
            if (applyToNeighbors)
            {
                Tile.SmoothSlope(x + 1, y, false, sync);
                Tile.SmoothSlope(x - 1, y, false, sync);
                Tile.SmoothSlope(x, y + 1, false, sync);
                Tile.SmoothSlope(x, y - 1, false, sync);
            }
            Tile tile = Main.tile[x, y];

            if (!WorldGen.CanPoundTile(x, y) || !WorldGen.SolidOrSlopedTile(x, y))
            {
                return;
            }
            bool flag1 = !WorldGen.TileEmpty(x, y - 1);
            bool flag2 = !WorldGen.SolidOrSlopedTile(x, y - 1) & flag1;
            bool flag3 = WorldGen.SolidOrSlopedTile(x, y + 1);
            bool flag4 = WorldGen.SolidOrSlopedTile(x - 1, y);
            bool flag5 = WorldGen.SolidOrSlopedTile(x + 1, y);
            int  num1  = (flag1 ? 1 : 0) << 3 | (flag3 ? 1 : 0) << 2 | (flag4 ? 1 : 0) << 1 | (flag5 ? 1 : 0);
            bool flag6 = tile.halfBrick();
            int  num2  = (int)tile.slope();

            switch (num1)
            {
            case 4:
                tile.slope((byte)0);
                tile.halfBrick(true);
                break;

            case 5:
                tile.halfBrick(false);
                tile.slope((byte)2);
                break;

            case 6:
                tile.halfBrick(false);
                tile.slope((byte)1);
                break;

            case 9:
                if (!flag2)
                {
                    tile.halfBrick(false);
                    tile.slope((byte)4);
                    break;
                }
                break;

            case 10:
                if (!flag2)
                {
                    tile.halfBrick(false);
                    tile.slope((byte)3);
                    break;
                }
                break;

            default:
                tile.halfBrick(false);
                tile.slope((byte)0);
                break;
            }
            if (!sync)
            {
                return;
            }
            int  num3  = (int)tile.slope();
            bool flag7 = flag6 != tile.halfBrick();
            bool flag8 = num2 != num3;

            if (flag7 & flag8)
            {
                NetMessage.SendData(17, -1, -1, (NetworkText)null, 23, (float)x, (float)y, (float)num3, 0, 0, 0);
            }
            else if (flag7)
            {
                NetMessage.SendData(17, -1, -1, (NetworkText)null, 7, (float)x, (float)y, 1f, 0, 0, 0);
            }
            else
            {
                if (!flag8)
                {
                    return;
                }
                NetMessage.SendData(17, -1, -1, (NetworkText)null, 14, (float)x, (float)y, (float)num3, 0, 0, 0);
            }
        }
		private void DrawWaterfall(SpriteBatch spriteBatch, int Style = 0, float Alpha = 1f)
		{
			float num = 0f;
			float num2 = 99999f;
			float num3 = 99999f;
			int num4 = -1;
			int num5 = -1;
			float num6 = 0f;
			float num7 = 99999f;
			float num8 = 99999f;
			int num9 = -1;
			int num10 = -1;
			int i = 0;
			while (i < this.currentMax)
			{
				int num11 = 0;
				int num12 = this.waterfalls[i].type;
				int num13 = this.waterfalls[i].x;
				int num14 = this.waterfalls[i].y;
				int num15 = 0;
				int num16 = 0;
				int num17 = 0;
				int num18 = 0;
				int num19 = 0;
				int num20 = 0;
				int num22;
                int num21;
				if (num12 == 1 || num12 == 14)
				{
					if (!Main.drewLava && this.waterfalls[i].stopAtStep != 0)
					{
						num21 = 32 * this.slowFrame;
						goto IL_3FA;
					}
				}
				else
				{
					if (num12 != 11)
					{
						if (num12 == 0)
						{
							num12 = Style;
						}
						else
						{
							if (num12 == 2 && Main.drewLava)
							{
								goto IL_1879;
							}
						}
						num21 = 32 * this.regularFrame;
						goto IL_3FA;
					}
					if (!Main.drewLava)
					{
						num22 = this.waterfallDist / 4;
						if (this.waterfalls[i].stopAtStep > num22)
						{
							this.waterfalls[i].stopAtStep = num22;
						}
						if (this.waterfalls[i].stopAtStep != 0 && (float)(num14 + num22) >= Main.screenPosition.Y / 16f && (float)num13 >= Main.screenPosition.X / 16f - 1f && (float)num13 <= (Main.screenPosition.X + (float)Main.screenWidth) / 16f + 1f)
						{
							int num23;
							int num24;
							if (num13 % 2 == 0)
							{
								num23 = this.rainFrameForeground + 3;
								if (num23 > 7)
								{
									num23 -= 8;
								}
								num24 = this.rainFrameBackground + 2;
								if (num24 > 7)
								{
									num24 -= 8;
								}
							}
							else
							{
								num23 = this.rainFrameForeground;
								num24 = this.rainFrameBackground;
							}
							Rectangle value = new Rectangle(num24 * 18, 0, 16, 16);
							Rectangle value2 = new Rectangle(num23 * 18, 0, 16, 16);
							Vector2 origin = new Vector2(8f, 8f);
							Vector2 position;
							if (num14 % 2 == 0)
							{
								position = new Vector2((float)(num13 * 16 + 9), (float)(num14 * 16 + 8)) - Main.screenPosition;
							}
							else
							{
								position = new Vector2((float)(num13 * 16 + 8), (float)(num14 * 16 + 8)) - Main.screenPosition;
							}
							bool flag = false;
							for (int j = 0; j < num22; j++)
							{
								Color color = Lighting.GetColor(num13, num14);
								float num25 = 0.6f;
								float num26 = 0.3f;
								if (j > num22 - 8)
								{
									float num27 = (float)(num22 - j) / 8f;
									num25 *= num27;
									num26 *= num27;
								}
								Color color2 = color * num25;
								Color color3 = color * num26;
								spriteBatch.Draw(this.waterfallTexture[12], position, new Rectangle?(value), color3, 0f, origin, 1f, SpriteEffects.None, 0f);
								spriteBatch.Draw(this.waterfallTexture[11], position, new Rectangle?(value2), color2, 0f, origin, 1f, SpriteEffects.None, 0f);
								if (flag)
								{
									break;
								}
								num14++;
								Tile tile = Main.tile[num13, num14];
								if (WorldGen.SolidTile(tile))
								{
									flag = true;
								}
								if (tile.liquid > 0)
								{
									int num28 = (int)(16f * ((float)tile.liquid / 255f)) & 254;
									if (num28 >= 15)
									{
										break;
									}
									value2.Height -= num28;
									value.Height -= num28;
								}
								if (num14 % 2 == 0)
								{
									position.X += 1f;
								}
								else
								{
									position.X -= 1f;
								}
								position.Y += 16f;
							}
							this.waterfalls[i].stopAtStep = 0;
						}
					}
				}
				IL_1879:
				i++;
				continue;
				IL_3FA:
				int num29 = 0;
				num22 = this.waterfallDist;
				Color color4 = Color.White;
				for (int k = 0; k < num22; k++)
				{
					if (num29 < 2)
					{
						int num30 = num12;
						switch (num30)
						{
						case 1:
						{
							float num31 = 0.55f;
							num31 += (float)(270 - (int)Main.mouseTextColor) / 900f;
							num31 *= 0.4f;
							float num32 = num31;
							float num33 = num31 * 0.3f;
							float num34 = num31 * 0.1f;
							Lighting.addLight(num13, num14, num32, num33, num34);
							break;
						}
						case 2:
						{
							float num32 = (float)Main.DiscoR / 255f;
							float num33 = (float)Main.DiscoG / 255f;
							float num34 = (float)Main.DiscoB / 255f;
							num32 *= 0.2f;
							num33 *= 0.2f;
							num34 *= 0.2f;
							Lighting.addLight(num13, num14, num32, num33, num34);
							break;
						}
						default:
							switch (num30)
							{
							case 15:
							{
								float num32 = 0f;
								float num33 = 0f;
								float num34 = 0.2f;
								Lighting.addLight(num13, num14, num32, num33, num34);
								break;
							}
							case 16:
							{
								float num32 = 0f;
								float num33 = 0.2f;
								float num34 = 0f;
								Lighting.addLight(num13, num14, num32, num33, num34);
								break;
							}
							case 17:
							{
								float num32 = 0f;
								float num33 = 0f;
								float num34 = 0.2f;
								Lighting.addLight(num13, num14, num32, num33, num34);
								break;
							}
							case 18:
							{
								float num32 = 0f;
								float num33 = 0.2f;
								float num34 = 0f;
								Lighting.addLight(num13, num14, num32, num33, num34);
								break;
							}
							case 19:
							{
								float num32 = 0.2f;
								float num33 = 0f;
								float num34 = 0f;
								Lighting.addLight(num13, num14, num32, num33, num34);
								break;
							}
							case 20:
								Lighting.addLight(num13, num14, 0.2f, 0.2f, 0.2f);
								break;
							case 21:
							{
								float num32 = 0.2f;
								float num33 = 0f;
								float num34 = 0f;
								Lighting.addLight(num13, num14, num32, num33, num34);
								break;
							}
							}
							break;
						}
						Tile tile2 = Main.tile[num13, num14];
						if (tile2 == null)
						{
							tile2 = new Tile();
							Main.tile[num13, num14] = tile2;
						}
						Tile tile3 = Main.tile[num13 - 1, num14];
						if (tile3 == null)
						{
							tile3 = new Tile();
							Main.tile[num13 - 1, num14] = tile3;
						}
						Tile tile4 = Main.tile[num13, num14 + 1];
						if (tile4 == null)
						{
							tile4 = new Tile();
							Main.tile[num13, num14 + 1] = tile4;
						}
						Tile tile5 = Main.tile[num13 + 1, num14];
						if (tile5 == null)
						{
							tile5 = new Tile();
							Main.tile[num13 + 1, num14] = tile5;
						}
						int num35 = (int)(tile2.liquid / 16);
						int num36 = 0;
						int num37 = num18;
						int num38;
						int num39;
						if (tile4.topSlope())
						{
							if (tile4.slope() == 1)
							{
								num36 = 1;
								num38 = 1;
								num17 = 1;
								num18 = num17;
							}
							else
							{
								num36 = -1;
								num38 = -1;
								num17 = -1;
								num18 = num17;
							}
							num39 = 1;
						}
						else
						{
							if ((((!WorldGen.SolidTile(tile4) && !tile4.bottomSlope()) || tile4.type == 162) && !tile2.halfBrick()) || (!tile4.active() && !tile2.halfBrick()))
							{
								num29 = 0;
								num39 = 1;
								num38 = 0;
							}
							else
							{
								if ((WorldGen.SolidTile(tile3) || tile3.topSlope() || tile3.liquid > 0) && !WorldGen.SolidTile(tile5) && tile5.liquid == 0)
								{
									if (num17 == -1)
									{
										num29++;
									}
									num38 = 1;
									num39 = 0;
									num17 = 1;
								}
								else
								{
									if ((WorldGen.SolidTile(tile5) || tile5.topSlope() || tile5.liquid > 0) && !WorldGen.SolidTile(tile3) && tile3.liquid == 0)
									{
										if (num17 == 1)
										{
											num29++;
										}
										num38 = -1;
										num39 = 0;
										num17 = -1;
									}
									else
									{
										if (((!WorldGen.SolidTile(tile5) && !tile2.topSlope()) || tile5.liquid == 0) && !WorldGen.SolidTile(tile3) && !tile2.topSlope() && tile3.liquid == 0)
										{
											num39 = 0;
											num38 = num17;
										}
										else
										{
											num29++;
											num39 = 0;
											num38 = 0;
										}
									}
								}
							}
						}
						if (num29 >= 2)
						{
							num17 *= -1;
							num38 *= -1;
						}
						int num40 = -1;
						if (num12 != 1 && num12 != 14)
						{
							if (tile4.active())
							{
								num40 = (int)tile4.type;
							}
							if (tile2.active())
							{
								num40 = (int)tile2.type;
							}
						}
						if (num40 != -1)
						{
							if (num40 == 160)
							{
								num12 = 2;
							}
							else
							{
								if (num40 >= 262 && num40 <= 268)
								{
									num12 = 15 + num40 - 262;
								}
							}
						}
						if (WorldGen.SolidTile(tile4) && !tile2.halfBrick())
						{
							num11 = 8;
						}
						else
						{
							if (num16 != 0)
							{
								num11 = 0;
							}
						}
						Color color5 = Lighting.GetColor(num13, num14);
						Color color6 = color5;
						float num41;
						if (num12 == 1)
						{
							num41 = 1f;
						}
						else
						{
							if (num12 == 14)
							{
								num41 = 0.8f;
							}
							else
							{
								if (tile2.wall == 0 && (double)num14 < Main.worldSurface)
								{
									num41 = Alpha;
								}
								else
								{
									num41 = 0.6f * Alpha;
								}
							}
						}
						if (k > num22 - 10)
						{
							num41 *= (float)(num22 - k) / 10f;
						}
						float num42 = (float)color5.R * num41;
						float num43 = (float)color5.G * num41;
						float num44 = (float)color5.B * num41;
						float num45 = (float)color5.A * num41;
						if (num12 == 1)
						{
							if (num42 < 190f * num41)
							{
								num42 = 190f * num41;
							}
							if (num43 < 190f * num41)
							{
								num43 = 190f * num41;
							}
							if (num44 < 190f * num41)
							{
								num44 = 190f * num41;
							}
						}
						else
						{
							if (num12 == 2)
							{
								num42 = (float)Main.DiscoR * num41;
								num43 = (float)Main.DiscoG * num41;
								num44 = (float)Main.DiscoB * num41;
							}
							else
							{
								if (num12 >= 15 && num12 <= 21)
								{
									num42 = 255f * num41;
									num43 = 255f * num41;
									num44 = 255f * num41;
								}
							}
						}
						color5 = new Color((int)num42, (int)num43, (int)num44, (int)num45);
						if (num12 == 1)
						{
							float num46 = Math.Abs((float)(num13 * 16 + 8) - (Main.screenPosition.X + (float)(Main.screenWidth / 2)));
							float num47 = Math.Abs((float)(num14 * 16 + 8) - (Main.screenPosition.Y + (float)(Main.screenHeight / 2)));
							if (num46 < (float)(Main.screenWidth * 2) && num47 < (float)(Main.screenHeight * 2))
							{
								float num48 = (float)Math.Sqrt((double)(num46 * num46 + num47 * num47));
								float num49 = 1f - num48 / ((float)Main.screenWidth * 0.75f);
								if (num49 > 0f)
								{
									num6 += num49;
								}
							}
							if (num46 < num7)
							{
								num7 = num46;
								num9 = num13 * 16 + 8;
							}
							if (num47 < num8)
							{
								num8 = num46;
								num10 = num14 * 16 + 8;
							}
						}
						else
						{
							if (num12 != 1 && num12 != 14 && num12 != 11 && num12 != 12)
							{
								float num50 = Math.Abs((float)(num13 * 16 + 8) - (Main.screenPosition.X + (float)(Main.screenWidth / 2)));
								float num51 = Math.Abs((float)(num14 * 16 + 8) - (Main.screenPosition.Y + (float)(Main.screenHeight / 2)));
								if (num50 < (float)(Main.screenWidth * 2) && num51 < (float)(Main.screenHeight * 2))
								{
									float num52 = (float)Math.Sqrt((double)(num50 * num50 + num51 * num51));
									float num53 = 1f - num52 / ((float)Main.screenWidth * 0.75f);
									if (num53 > 0f)
									{
										num += num53;
									}
								}
								if (num50 < num2)
								{
									num2 = num50;
									num4 = num13 * 16 + 8;
								}
								if (num51 < num3)
								{
									num3 = num50;
									num5 = num14 * 16 + 8;
								}
							}
						}
						if (k > 50 && (color6.R > 20 || color6.B > 20 || color6.G > 20))
						{
							float num54 = (float)color6.R;
							if ((float)color6.G > num54)
							{
								num54 = (float)color6.G;
							}
							if ((float)color6.B > num54)
							{
								num54 = (float)color6.B;
							}
							if ((float)Main.rand.Next(20000) < num54 / 30f)
							{
								int num55 = Dust.NewDust(new Vector2((float)(num13 * 16 - num17 * 7), (float)(num14 * 16 + 6)), 10, 8, 43, 0f, 0f, 254, Color.White, 0.5f);
								Main.dust[num55].velocity *= 0f;
							}
						}
						if (num15 == 0 && num36 != 0 && num16 == 1 && num17 != num18)
						{
							num36 = 0;
							num17 = num18;
							color5 = Color.White;
							if (num17 == 1)
							{
								spriteBatch.Draw(this.waterfallTexture[num12], new Vector2((float)(num13 * 16 - 16), (float)(num14 * 16 + 16)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 24, 32, 16 - num35)), color5, 0f, Vector2.Zero, 1f, SpriteEffects.FlipHorizontally, 0f);
							}
							else
							{
								spriteBatch.Draw(this.waterfallTexture[num12], new Vector2((float)(num13 * 16 - 16), (float)(num14 * 16 + 16)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 24, 32, 8)), color5, 0f, Vector2.Zero, 1f, SpriteEffects.FlipHorizontally, 0f);
							}
						}
						if (num19 != 0 && num38 == 0 && num39 == 1)
						{
							if (num17 == 1)
							{
								if (num20 != num12)
								{
									spriteBatch.Draw(this.waterfallTexture[num20], new Vector2((float)(num13 * 16), (float)(num14 * 16 + num11 + 8)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 0, 16, 16 - num35 - 8)), color4, 0f, Vector2.Zero, 1f, SpriteEffects.FlipHorizontally, 0f);
								}
								else
								{
									spriteBatch.Draw(this.waterfallTexture[num12], new Vector2((float)(num13 * 16), (float)(num14 * 16 + num11 + 8)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 0, 16, 16 - num35 - 8)), color5, 0f, Vector2.Zero, 1f, SpriteEffects.FlipHorizontally, 0f);
								}
							}
							else
							{
								spriteBatch.Draw(this.waterfallTexture[num12], new Vector2((float)(num13 * 16), (float)(num14 * 16 + num11 + 8)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 0, 16, 16 - num35 - 8)), color5, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
							}
						}
						if (num11 == 8 && num16 == 1 && num19 == 0)
						{
							if (num18 == -1)
							{
								if (num20 != num12)
								{
									spriteBatch.Draw(this.waterfallTexture[num20], new Vector2((float)(num13 * 16), (float)(num14 * 16)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 24, 32, 8)), color4, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
								}
								else
								{
									spriteBatch.Draw(this.waterfallTexture[num12], new Vector2((float)(num13 * 16), (float)(num14 * 16)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 24, 32, 8)), color5, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
								}
							}
							else
							{
								if (num20 != num12)
								{
									spriteBatch.Draw(this.waterfallTexture[num20], new Vector2((float)(num13 * 16 - 16), (float)(num14 * 16)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 24, 32, 8)), color4, 0f, default(Vector2), 1f, SpriteEffects.FlipHorizontally, 0f);
								}
								else
								{
									spriteBatch.Draw(this.waterfallTexture[num12], new Vector2((float)(num13 * 16 - 16), (float)(num14 * 16)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 24, 32, 8)), color5, 0f, default(Vector2), 1f, SpriteEffects.FlipHorizontally, 0f);
								}
							}
						}
						if (num36 != 0 && num15 == 0)
						{
							if (num37 == 1)
							{
								if (num20 != num12)
								{
									spriteBatch.Draw(this.waterfallTexture[num20], new Vector2((float)(num13 * 16 - 16), (float)(num14 * 16)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 24, 32, 16 - num35)), color4, 0f, default(Vector2), 1f, SpriteEffects.FlipHorizontally, 0f);
								}
								else
								{
									spriteBatch.Draw(this.waterfallTexture[num12], new Vector2((float)(num13 * 16 - 16), (float)(num14 * 16)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 24, 32, 16 - num35)), color5, 0f, default(Vector2), 1f, SpriteEffects.FlipHorizontally, 0f);
								}
							}
							else
							{
								if (num20 != num12)
								{
									spriteBatch.Draw(this.waterfallTexture[num20], new Vector2((float)(num13 * 16), (float)(num14 * 16)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 24, 32, 16 - num35)), color4, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
								}
								else
								{
									spriteBatch.Draw(this.waterfallTexture[num12], new Vector2((float)(num13 * 16), (float)(num14 * 16)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 24, 32, 16 - num35)), color5, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
								}
							}
						}
						if (num39 == 1 && num36 == 0 && num19 == 0)
						{
							if (num17 == -1)
							{
								if (num16 == 0)
								{
									spriteBatch.Draw(this.waterfallTexture[num12], new Vector2((float)(num13 * 16), (float)(num14 * 16 + num11)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 0, 16, 16 - num35)), color5, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
								}
								else
								{
									if (num20 != num12)
									{
										spriteBatch.Draw(this.waterfallTexture[num20], new Vector2((float)(num13 * 16), (float)(num14 * 16)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 24, 32, 16 - num35)), color4, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
									}
									else
									{
										spriteBatch.Draw(this.waterfallTexture[num12], new Vector2((float)(num13 * 16), (float)(num14 * 16)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 24, 32, 16 - num35)), color5, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
									}
								}
							}
							else
							{
								if (num16 == 0)
								{
									spriteBatch.Draw(this.waterfallTexture[num12], new Vector2((float)(num13 * 16), (float)(num14 * 16 + num11)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 0, 16, 16 - num35)), color5, 0f, default(Vector2), 1f, SpriteEffects.FlipHorizontally, 0f);
								}
								else
								{
									if (num20 != num12)
									{
										spriteBatch.Draw(this.waterfallTexture[num20], new Vector2((float)(num13 * 16 - 16), (float)(num14 * 16)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 24, 32, 16 - num35)), color4, 0f, default(Vector2), 1f, SpriteEffects.FlipHorizontally, 0f);
									}
									else
									{
										spriteBatch.Draw(this.waterfallTexture[num12], new Vector2((float)(num13 * 16 - 16), (float)(num14 * 16)) - Main.screenPosition, new Rectangle?(new Rectangle(num21, 24, 32, 16 - num35)), color5, 0f, default(Vector2), 1f, SpriteEffects.FlipHorizontally, 0f);
									}
								}
							}
						}
						else
						{
							if (num38 == 1)
							{
								if (Main.tile[num13, num14].liquid <= 0 || Main.tile[num13, num14].halfBrick())
								{
									if (num36 == 1)
									{
										for (int l = 0; l < 8; l++)
										{
											int num56 = l * 2;
											int num57 = 14 - l * 2;
											int num58 = num56;
											num11 = 8;
											if (num15 == 0 && l < 2)
											{
												num58 = 4;
											}
											spriteBatch.Draw(this.waterfallTexture[num12], new Vector2((float)(num13 * 16 + num56), (float)(num14 * 16 + num11 + num58)) - Main.screenPosition, new Rectangle?(new Rectangle(16 + num21 + num57, 0, 2, 16 - num11)), color5, 0f, default(Vector2), 1f, SpriteEffects.FlipHorizontally, 0f);
										}
									}
									else
									{
										spriteBatch.Draw(this.waterfallTexture[num12], new Vector2((float)(num13 * 16), (float)(num14 * 16 + num11)) - Main.screenPosition, new Rectangle?(new Rectangle(16 + num21, 0, 16, 16)), color5, 0f, default(Vector2), 1f, SpriteEffects.FlipHorizontally, 0f);
									}
								}
							}
							else
							{
								if (num38 == -1)
								{
									if (Main.tile[num13, num14].liquid <= 0 || Main.tile[num13, num14].halfBrick())
									{
										if (num36 == -1)
										{
											for (int m = 0; m < 8; m++)
											{
												int num59 = m * 2;
												int num60 = m * 2;
												int num61 = 14 - m * 2;
												num11 = 8;
												if (num15 == 0 && m > 5)
												{
													num61 = 4;
												}
												spriteBatch.Draw(this.waterfallTexture[num12], new Vector2((float)(num13 * 16 + num59), (float)(num14 * 16 + num11 + num61)) - Main.screenPosition, new Rectangle?(new Rectangle(16 + num21 + num60, 0, 2, 16 - num11)), color5, 0f, default(Vector2), 1f, SpriteEffects.FlipHorizontally, 0f);
											}
										}
										else
										{
											spriteBatch.Draw(this.waterfallTexture[num12], new Vector2((float)(num13 * 16), (float)(num14 * 16 + num11)) - Main.screenPosition, new Rectangle?(new Rectangle(16 + num21, 0, 16, 16)), color5, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
										}
									}
								}
								else
								{
									if (num38 == 0 && num39 == 0)
									{
										if (Main.tile[num13, num14].liquid <= 0 || Main.tile[num13, num14].halfBrick())
										{
											spriteBatch.Draw(this.waterfallTexture[num12], new Vector2((float)(num13 * 16), (float)(num14 * 16 + num11)) - Main.screenPosition, new Rectangle?(new Rectangle(16 + num21, 0, 16, 16)), color5, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
										}
										k = 1000;
									}
								}
							}
						}
						if (tile2.liquid > 0 && !tile2.halfBrick())
						{
							k = 1000;
						}
						num16 = num39;
						num18 = num17;
						num15 = num38;
						num13 += num38;
						num14 += num39;
						num19 = num36;
						color4 = color5;
						if (num20 != num12)
						{
							num20 = num12;
						}
						if ((tile3.active() && (tile3.type == 189 || tile3.type == 196)) || (tile5.active() && (tile5.type == 189 || tile5.type == 196)) || (tile4.active() && (tile4.type == 189 || tile4.type == 196)))
						{
							num22 = (int)((float)(40 * (Main.maxTilesX / 4200)) * Main.gfxQuality);
						}
					}
				}
				goto IL_1879;
			}
			Main.ambientWaterfallX = (float)num4;
			Main.ambientWaterfallY = (float)num5;
			Main.ambientWaterfallStrength = num;
			Main.ambientLavafallX = (float)num9;
			Main.ambientLavafallY = (float)num10;
			Main.ambientLavafallStrength = num6;
		}
		public static bool SolidTile(Tile testTile)
		{
			try
			{
				if (testTile == null)
				{
					bool result = true;
					return result;
				}
				if (testTile.active() && Main.tileSolid[(int)testTile.type] && !Main.tileSolidTop[(int)testTile.type] && !testTile.halfBrick() && testTile.slope() == 0 && !testTile.inActive())
				{
					bool result = true;
					return result;
				}
			}
			catch
			{
			}
			return false;
		}
Ejemplo n.º 19
0
        public static void SelfFrame8Way(int i, int j, Tile centerTile, bool resetFrame)
        {
            if (!centerTile.active())
            {
                return;
            }
            BlockStyle blockStyle  = FindBlockStyle(centerTile);
            int        num         = 0;
            BlockStyle blockStyle2 = default(BlockStyle);

            if (blockStyle.top)
            {
                Tile tileSafely = GetTileSafely(i, j - 1);
                if (tileSafely.active() && WillItBlend(centerTile.type, tileSafely.type))
                {
                    blockStyle2 = FindBlockStyle(tileSafely);
                    if (blockStyle2.bottom)
                    {
                        num |= 1;
                    }
                    else
                    {
                        blockStyle2.Clear();
                    }
                }
            }
            BlockStyle blockStyle3 = default(BlockStyle);

            if (blockStyle.left)
            {
                Tile tileSafely2 = GetTileSafely(i - 1, j);
                if (tileSafely2.active() && WillItBlend(centerTile.type, tileSafely2.type))
                {
                    blockStyle3 = FindBlockStyle(tileSafely2);
                    if (blockStyle3.right)
                    {
                        num |= 2;
                    }
                    else
                    {
                        blockStyle3.Clear();
                    }
                }
            }
            BlockStyle blockStyle4 = default(BlockStyle);

            if (blockStyle.right)
            {
                Tile tileSafely3 = GetTileSafely(i + 1, j);
                if (tileSafely3.active() && WillItBlend(centerTile.type, tileSafely3.type))
                {
                    blockStyle4 = FindBlockStyle(tileSafely3);
                    if (blockStyle4.left)
                    {
                        num |= 4;
                    }
                    else
                    {
                        blockStyle4.Clear();
                    }
                }
            }
            BlockStyle blockStyle5 = default(BlockStyle);

            if (blockStyle.bottom)
            {
                Tile tileSafely4 = GetTileSafely(i, j + 1);
                if (tileSafely4.active() && WillItBlend(centerTile.type, tileSafely4.type))
                {
                    blockStyle5 = FindBlockStyle(tileSafely4);
                    if (blockStyle5.top)
                    {
                        num |= 8;
                    }
                    else
                    {
                        blockStyle5.Clear();
                    }
                }
            }
            if (blockStyle2.left && blockStyle3.top)
            {
                Tile tileSafely5 = GetTileSafely(i - 1, j - 1);
                if (tileSafely5.active() && WillItBlend(centerTile.type, tileSafely5.type))
                {
                    BlockStyle blockStyle6 = FindBlockStyle(tileSafely5);
                    if (blockStyle6.right && blockStyle6.bottom)
                    {
                        num |= 0x10;
                    }
                }
            }
            if (blockStyle2.right && blockStyle4.top)
            {
                Tile tileSafely6 = GetTileSafely(i + 1, j - 1);
                if (tileSafely6.active() && WillItBlend(centerTile.type, tileSafely6.type))
                {
                    BlockStyle blockStyle7 = FindBlockStyle(tileSafely6);
                    if (blockStyle7.left && blockStyle7.bottom)
                    {
                        num |= 0x20;
                    }
                }
            }
            if (blockStyle5.left && blockStyle3.bottom)
            {
                Tile tileSafely7 = GetTileSafely(i - 1, j + 1);
                if (tileSafely7.active() && WillItBlend(centerTile.type, tileSafely7.type))
                {
                    BlockStyle blockStyle8 = FindBlockStyle(tileSafely7);
                    if (blockStyle8.right && blockStyle8.top)
                    {
                        num |= 0x40;
                    }
                }
            }
            if (blockStyle5.right && blockStyle4.bottom)
            {
                Tile tileSafely8 = GetTileSafely(i + 1, j + 1);
                if (tileSafely8.active() && WillItBlend(centerTile.type, tileSafely8.type))
                {
                    BlockStyle blockStyle9 = FindBlockStyle(tileSafely8);
                    if (blockStyle9.left && blockStyle9.top)
                    {
                        num |= 0x80;
                    }
                }
            }
            if (resetFrame)
            {
                centerTile.frameNumber((byte)WorldGen.genRand.Next(0, 3));
            }
            Point16 point = selfFrame8WayLookup[num][centerTile.frameNumber()];

            centerTile.frameX = point.X;
            centerTile.frameY = point.Y;
        }
Ejemplo n.º 20
0
 public static void PreRenderPhase()
 {
     float num1 = (float)Main.tileColor.R / (float)byte.MaxValue;
     float num2 = (float)Main.tileColor.G / (float)byte.MaxValue;
     float num3 = (float)Main.tileColor.B / (float)byte.MaxValue;
     Stopwatch stopwatch = new Stopwatch();
     stopwatch.Start();
     int num4 = 0;
     int num5 = Main.screenWidth / 16 + Lighting.offScreenTiles * 2 + 10;
     int num6 = 0;
     int num7 = Main.screenHeight / 16 + Lighting.offScreenTiles * 2 + 10;
     Lighting.minX = num5;
     Lighting.maxX = num4;
     Lighting.minY = num7;
     Lighting.maxY = num6;
     Lighting.RGB = Lighting.lightMode == 0 || Lighting.lightMode == 3;
     for (int index1 = num4; index1 < num5; ++index1)
     {
         Lighting.LightingState[] lightingStateArray = Lighting.states[index1];
         for (int index2 = num6; index2 < num7; ++index2)
         {
             Lighting.LightingState lightingState = lightingStateArray[index2];
             lightingState.r2 = 0.0f;
             lightingState.g2 = 0.0f;
             lightingState.b2 = 0.0f;
             lightingState.stopLight = false;
             lightingState.wetLight = false;
             lightingState.honeyLight = false;
         }
     }
     if (Main.wof >= 0)
     {
         if (Main.player[Main.myPlayer].gross)
         {
             try
             {
                 int num8 = (int)Main.screenPosition.Y / 16 - 10;
                 int num9 = (int)((double)Main.screenPosition.Y + (double)Main.screenHeight) / 16 + 10;
                 int num10 = (int)Main.npc[Main.wof].position.X / 16;
                 int num11 = Main.npc[Main.wof].direction <= 0 ? num10 + 2 : num10 - 3;
                 int num12 = num11 + 8;
                 float num13 = (float)(0.5 * (double)Main.demonTorch + 1.0 * (1.0 - (double)Main.demonTorch));
                 float num14 = 0.3f;
                 float num15 = (float)(1.0 * (double)Main.demonTorch + 0.5 * (1.0 - (double)Main.demonTorch));
                 float num16 = num13 * 0.2f;
                 float num17 = num14 * 0.1f;
                 float num18 = num15 * 0.3f;
                 for (int index1 = num11; index1 <= num12; ++index1)
                 {
                     Lighting.LightingState[] lightingStateArray = Lighting.states[index1 - num11];
                     for (int index2 = num8; index2 <= num9; ++index2)
                     {
                         Lighting.LightingState lightingState = lightingStateArray[index2 - Lighting.firstToLightY];
                         if ((double)lightingState.r2 < (double)num16)
                             lightingState.r2 = num16;
                         if ((double)lightingState.g2 < (double)num17)
                             lightingState.g2 = num17;
                         if ((double)lightingState.b2 < (double)num18)
                             lightingState.b2 = num18;
                     }
                 }
             }
             catch
             {
             }
         }
     }
     Main.sandTiles = 0;
     Main.evilTiles = 0;
     Main.bloodTiles = 0;
     Main.shroomTiles = 0;
     Main.snowTiles = 0;
     Main.holyTiles = 0;
     Main.meteorTiles = 0;
     Main.jungleTiles = 0;
     Main.dungeonTiles = 0;
     Main.campfire = false;
     Main.sunflower = false;
     Main.starInBottle = false;
     Main.heartLantern = false;
     Main.campfire = false;
     Main.clock = false;
     Main.musicBox = -1;
     Main.waterCandles = 0;
     for (int index = 0; index < Main.player[Main.myPlayer].NPCBannerBuff.Length; ++index)
         Main.player[Main.myPlayer].NPCBannerBuff[index] = false;
     Main.player[Main.myPlayer].hasBanner = false;
     int[] numArray = WorldGen.tileCounts;
     int num19 = Lighting.firstToLightX;
     int num20 = Lighting.lastToLightX;
     int num21 = Lighting.firstToLightY;
     int num22 = Lighting.lastToLightY;
     int num23 = (num20 - num19 - Main.zoneX) / 2;
     int num24 = (num22 - num21 - Main.zoneY) / 2;
     Main.fountainColor = -1;
     Main.monolithType = -1;
     for (int index1 = num19; index1 < num20; ++index1)
     {
         Lighting.LightingState[] lightingStateArray = Lighting.states[index1 - Lighting.firstToLightX];
         for (int index2 = num21; index2 < num22; ++index2)
         {
             Lighting.LightingState lightingState = lightingStateArray[index2 - Lighting.firstToLightY];
             Tile tile = Main.tile[index1, index2];
             if (tile == null)
             {
                 tile = new Tile();
                 Main.tile[index1, index2] = tile;
             }
             float num8 = 0.0f;
             float num9 = 0.0f;
             float num10 = 0.0f;
             if ((double)index2 < Main.worldSurface)
             {
                 if ((!tile.active() || !Main.tileNoSunLight[(int)tile.type] || ((int)tile.slope() != 0 || tile.halfBrick()) && ((int)Main.tile[index1, index2 - 1].liquid == 0 && (int)Main.tile[index1, index2 + 1].liquid == 0) && ((int)Main.tile[index1 - 1, index2].liquid == 0 && (int)Main.tile[index1 + 1, index2].liquid == 0)) && ((double)lightingState.r2 < (double)Lighting.skyColor && (Main.wallLight[(int)tile.wall] || (int)tile.wall == 73) && ((int)tile.liquid < 200 && (!tile.halfBrick() || (int)Main.tile[index1, index2 - 1].liquid < 200))))
                 {
                     num8 = num1;
                     num9 = num2;
                     num10 = num3;
                 }
                 if ((!tile.active() || tile.halfBrick() || !Main.tileNoSunLight[(int)tile.type]) && ((int)tile.wall >= 88 && (int)tile.wall <= 93 && (int)tile.liquid < (int)byte.MaxValue))
                 {
                     num8 = num1;
                     num9 = num2;
                     num10 = num3;
                     switch (tile.wall)
                     {
                         case (byte)88:
                             num8 *= 0.9f;
                             num9 *= 0.15f;
                             num10 *= 0.9f;
                             break;
                         case (byte)89:
                             num8 *= 0.9f;
                             num9 *= 0.9f;
                             num10 *= 0.15f;
                             break;
                         case (byte)90:
                             num8 *= 0.15f;
                             num9 *= 0.15f;
                             num10 *= 0.9f;
                             break;
                         case (byte)91:
                             num8 *= 0.15f;
                             num9 *= 0.9f;
                             num10 *= 0.15f;
                             break;
                         case (byte)92:
                             num8 *= 0.9f;
                             num9 *= 0.15f;
                             num10 *= 0.15f;
                             break;
                         case (byte)93:
                             float num11 = 0.2f;
                             float num12 = 0.7f - num11;
                             num8 *= num12 + (float)Main.DiscoR / (float)byte.MaxValue * num11;
                             num9 *= num12 + (float)Main.DiscoG / (float)byte.MaxValue * num11;
                             num10 *= num12 + (float)Main.DiscoB / (float)byte.MaxValue * num11;
                             break;
                     }
                 }
                 if (!Lighting.RGB)
                 {
                     double num11;
                     num10 = (float)(num11 = ((double)num8 + (double)num9 + (double)num10) / 3.0);
                     num9 = (float)num11;
                     num8 = (float)num11;
                 }
                 if ((double)lightingState.r2 < (double)num8)
                     lightingState.r2 = num8;
                 if ((double)lightingState.g2 < (double)num9)
                     lightingState.g2 = num9;
                 if ((double)lightingState.b2 < (double)num10)
                     lightingState.b2 = num10;
             }
             float num13 = (float)(0.550000011920929 + Math.Sin((double)Main.GlobalTime * 2.0) * 0.0799999982118607);
             if (index2 > Main.maxTilesY - 200)
             {
                 if ((!tile.active() || !Main.tileNoSunLight[(int)tile.type] || ((int)tile.slope() != 0 || tile.halfBrick()) && ((int)Main.tile[index1, index2 - 1].liquid == 0 && (int)Main.tile[index1, index2 + 1].liquid == 0) && ((int)Main.tile[index1 - 1, index2].liquid == 0 && (int)Main.tile[index1 + 1, index2].liquid == 0)) && ((double)lightingState.r2 < (double)num13 && (Main.wallLight[(int)tile.wall] || (int)tile.wall == 73) && ((int)tile.liquid < 200 && (!tile.halfBrick() || (int)Main.tile[index1, index2 - 1].liquid < 200))))
                 {
                     num8 = num13;
                     num9 = num13 * 0.6f;
                     num10 = num13 * 0.2f;
                 }
                 if ((!tile.active() || tile.halfBrick() || !Main.tileNoSunLight[(int)tile.type]) && ((int)tile.wall >= 88 && (int)tile.wall <= 93 && (int)tile.liquid < (int)byte.MaxValue))
                 {
                     num8 = num13;
                     num9 = num13 * 0.6f;
                     num10 = num13 * 0.2f;
                     switch (tile.wall)
                     {
                         case (byte)88:
                             num8 *= 0.9f;
                             num9 *= 0.15f;
                             num10 *= 0.9f;
                             break;
                         case (byte)89:
                             num8 *= 0.9f;
                             num9 *= 0.9f;
                             num10 *= 0.15f;
                             break;
                         case (byte)90:
                             num8 *= 0.15f;
                             num9 *= 0.15f;
                             num10 *= 0.9f;
                             break;
                         case (byte)91:
                             num8 *= 0.15f;
                             num9 *= 0.9f;
                             num10 *= 0.15f;
                             break;
                         case (byte)92:
                             num8 *= 0.9f;
                             num9 *= 0.15f;
                             num10 *= 0.15f;
                             break;
                         case (byte)93:
                             float num11 = 0.2f;
                             float num12 = 0.7f - num11;
                             num8 *= num12 + (float)Main.DiscoR / (float)byte.MaxValue * num11;
                             num9 *= num12 + (float)Main.DiscoG / (float)byte.MaxValue * num11;
                             num10 *= num12 + (float)Main.DiscoB / (float)byte.MaxValue * num11;
                             break;
                     }
                 }
                 if (!Lighting.RGB)
                 {
                     double num11;
                     num10 = (float)(num11 = ((double)num8 + (double)num9 + (double)num10) / 3.0);
                     num9 = (float)num11;
                     num8 = (float)num11;
                 }
                 if ((double)lightingState.r2 < (double)num8)
                     lightingState.r2 = num8;
                 if ((double)lightingState.g2 < (double)num9)
                     lightingState.g2 = num9;
                 if ((double)lightingState.b2 < (double)num10)
                     lightingState.b2 = num10;
             }
             byte num14 = tile.wall;
             if ((uint)num14 <= 137U)
             {
                 if ((int)num14 != 33)
                 {
                     if ((int)num14 != 44)
                     {
                         if ((int)num14 == 137 && (!tile.active() || !Main.tileBlockLight[(int)tile.type]))
                         {
                             float num11 = 0.4f + (float)(270 - (int)Main.mouseTextColor) / 1500f + (float)Main.rand.Next(0, 50) * 0.0005f;
                             num8 = 1f * num11;
                             num9 = 0.5f * num11;
                             num10 = 0.1f * num11;
                         }
                     }
                     else if (!tile.active() || !Main.tileBlockLight[(int)tile.type])
                     {
                         num8 = (float)((double)Main.DiscoR / (double)byte.MaxValue * 0.150000005960464);
                         num9 = (float)((double)Main.DiscoG / (double)byte.MaxValue * 0.150000005960464);
                         num10 = (float)((double)Main.DiscoB / (double)byte.MaxValue * 0.150000005960464);
                     }
                 }
                 else if (!tile.active() || !Main.tileBlockLight[(int)tile.type])
                 {
                     num8 = 0.09f;
                     num9 = 0.0525f;
                     num10 = 0.24f;
                 }
             }
             else if ((uint)num14 <= 166U)
             {
                 switch (num14)
                 {
                     case (byte)153:
                         num8 = 0.6f;
                         num9 = 0.3f;
                         break;
                     case (byte)154:
                         num8 = 0.6f;
                         num10 = 0.6f;
                         break;
                     case (byte)155:
                         num8 = 0.6f;
                         num9 = 0.6f;
                         num10 = 0.6f;
                         break;
                     case (byte)156:
                         num9 = 0.6f;
                         break;
                     case (byte)164:
                         num8 = 0.6f;
                         break;
                     case (byte)165:
                         num10 = 0.6f;
                         break;
                     case (byte)166:
                         num8 = 0.6f;
                         num9 = 0.6f;
                         break;
                 }
             }
             else
             {
                 switch (num14)
                 {
                     case (byte)174:
                         if (!tile.active() || !Main.tileBlockLight[(int)tile.type])
                         {
                             num8 = 0.2975f;
                             break;
                         }
                         break;
                     case (byte)175:
                         if (!tile.active() || !Main.tileBlockLight[(int)tile.type])
                         {
                             num8 = 0.075f;
                             num9 = 0.15f;
                             num10 = 0.4f;
                             break;
                         }
                         break;
                     case (byte)176:
                         if (!tile.active() || !Main.tileBlockLight[(int)tile.type])
                         {
                             num8 = 0.1f;
                             num9 = 0.1f;
                             num10 = 0.1f;
                             break;
                         }
                         break;
                     case (byte)182:
                         if (!tile.active() || !Main.tileBlockLight[(int)tile.type])
                         {
                             num8 = 0.24f;
                             num9 = 0.12f;
                             num10 = 0.09f;
                             break;
                         }
                         break;
                 }
             }
             if (tile.active())
             {
                 if (index1 > num19 + num23 && index1 < num20 - num23 && (index2 > num21 + num24 && index2 < num22 - num24))
                 {
                     ++numArray[(int)tile.type];
                     if ((int)tile.type == 215 && (int)tile.frameY < 36)
                         Main.campfire = true;
                     if ((int)tile.type == 405)
                         Main.campfire = true;
                     if ((int)tile.type == 42 && (int)tile.frameY >= 324 && (int)tile.frameY <= 358)
                         Main.heartLantern = true;
                     if ((int)tile.type == 42 && (int)tile.frameY >= 252 && (int)tile.frameY <= 286)
                         Main.starInBottle = true;
                     if ((int)tile.type == 91 && ((int)tile.frameX >= 396 || (int)tile.frameY >= 54))
                     {
                         int index3 = (int)tile.frameX / 18 - 21;
                         int num11 = (int)tile.frameY;
                         while (num11 >= 54)
                         {
                             index3 = index3 + 90 + 21;
                             num11 -= 54;
                         }
                         Main.player[Main.myPlayer].NPCBannerBuff[index3] = true;
                         Main.player[Main.myPlayer].hasBanner = true;
                     }
                 }
                 switch (tile.type)
                 {
                     case (ushort)139:
                         if ((int)tile.frameX >= 36)
                         {
                             Main.musicBox = (int)tile.frameY / 36;
                             break;
                         }
                         break;
                     case (ushort)207:
                         if ((int)tile.frameY >= 72)
                         {
                             switch ((int)tile.frameX / 36)
                             {
                                 case 0:
                                     Main.fountainColor = 0;
                                     break;
                                 case 1:
                                     Main.fountainColor = 6;
                                     break;
                                 case 2:
                                     Main.fountainColor = 3;
                                     break;
                                 case 3:
                                     Main.fountainColor = 5;
                                     break;
                                 case 4:
                                     Main.fountainColor = 2;
                                     break;
                                 case 5:
                                     Main.fountainColor = 10;
                                     break;
                                 case 6:
                                     Main.fountainColor = 4;
                                     break;
                                 case 7:
                                     Main.fountainColor = 9;
                                     break;
                                 default:
                                     Main.fountainColor = -1;
                                     break;
                             }
                         }
                         else
                             break;
                         break;
                     case (ushort)410:
                         if ((int)tile.frameY >= 56)
                         {
                             Main.monolithType = (int)tile.frameX / 36;
                             break;
                         }
                         break;
                 }
                 if (Main.tileBlockLight[(int)tile.type] && (Lighting.lightMode >= 2 || (int)tile.type != 131 && !tile.inActive() && (int)tile.slope() == 0))
                     lightingState.stopLight = true;
                 if ((int)tile.type == 104)
                     Main.clock = true;
                 if (Main.tileLighted[(int)tile.type])
                 {
                     ushort num11 = tile.type;
                     if ((uint)num11 <= 160U)
                     {
                         if ((uint)num11 <= 72U)
                         {
                             if ((uint)num11 <= 37U)
                             {
                                 if ((uint)num11 <= 17U)
                                 {
                                     if ((int)num11 != 4)
                                     {
                                         if ((int)num11 == 17)
                                             goto label_331;
                                         else
                                             goto label_405;
                                     }
                                     else if ((int)tile.frameX < 66)
                                     {
                                         switch ((int)tile.frameY / 22)
                                         {
                                             case 0:
                                                 num8 = 1f;
                                                 num9 = 0.95f;
                                                 num10 = 0.8f;
                                                 goto label_405;
                                             case 1:
                                                 num8 = 0.0f;
                                                 num9 = 0.1f;
                                                 num10 = 1.3f;
                                                 goto label_405;
                                             case 2:
                                                 num8 = 1f;
                                                 num9 = 0.1f;
                                                 num10 = 0.1f;
                                                 goto label_405;
                                             case 3:
                                                 num8 = 0.0f;
                                                 num9 = 1f;
                                                 num10 = 0.1f;
                                                 goto label_405;
                                             case 4:
                                                 num8 = 0.9f;
                                                 num9 = 0.0f;
                                                 num10 = 0.9f;
                                                 goto label_405;
                                             case 5:
                                                 num8 = 1.3f;
                                                 num9 = 1.3f;
                                                 num10 = 1.3f;
                                                 goto label_405;
                                             case 6:
                                                 num8 = 0.9f;
                                                 num9 = 0.9f;
                                                 num10 = 0.0f;
                                                 goto label_405;
                                             case 7:
                                                 num8 = (float)(0.5 * (double)Main.demonTorch + 1.0 * (1.0 - (double)Main.demonTorch));
                                                 num9 = 0.3f;
                                                 num10 = (float)(1.0 * (double)Main.demonTorch + 0.5 * (1.0 - (double)Main.demonTorch));
                                                 goto label_405;
                                             case 8:
                                                 num8 = 0.85f;
                                                 num9 = 1f;
                                                 num10 = 0.7f;
                                                 goto label_405;
                                             case 9:
                                                 num8 = 0.7f;
                                                 num9 = 0.85f;
                                                 num10 = 1f;
                                                 goto label_405;
                                             case 10:
                                                 num8 = 1f;
                                                 num9 = 0.5f;
                                                 num10 = 0.0f;
                                                 goto label_405;
                                             case 11:
                                                 num8 = 1.25f;
                                                 num9 = 1.25f;
                                                 num10 = 0.8f;
                                                 goto label_405;
                                             case 12:
                                                 num8 = 0.75f;
                                                 num9 = 1.2825f;
                                                 num10 = 1.2f;
                                                 goto label_405;
                                             case 13:
                                                 num8 = 0.95f;
                                                 num9 = 0.65f;
                                                 num10 = 1.3f;
                                                 goto label_405;
                                             case 14:
                                                 num8 = (float)Main.DiscoR / (float)byte.MaxValue;
                                                 num9 = (float)Main.DiscoG / (float)byte.MaxValue;
                                                 num10 = (float)Main.DiscoB / (float)byte.MaxValue;
                                                 goto label_405;
                                             case 15:
                                                 num8 = 1f;
                                                 num9 = 0.0f;
                                                 num10 = 1f;
                                                 goto label_405;
                                             default:
                                                 num8 = 1f;
                                                 num9 = 0.95f;
                                                 num10 = 0.8f;
                                                 goto label_405;
                                         }
                                     }
                                     else
                                         goto label_405;
                                 }
                                 else
                                 {
                                     switch (num11)
                                     {
                                         case (ushort)22:
                                             break;
                                         case (ushort)26:
                                         case (ushort)31:
                                             if ((int)tile.type == 31 && (int)tile.frameX >= 36 || (int)tile.type == 26 && (int)tile.frameX >= 54)
                                             {
                                                 float num12 = (float)Main.rand.Next(-5, 6) * (1.0f / 400.0f);
                                                 num8 = (float)(0.5 + (double)num12 * 2.0);
                                                 num9 = 0.2f + num12;
                                                 num10 = 0.1f;
                                                 goto label_405;
                                             }
                                             else
                                             {
                                                 float num12 = (float)Main.rand.Next(-5, 6) * (1.0f / 400.0f);
                                                 num8 = 0.31f + num12;
                                                 num9 = 0.1f;
                                                 num10 = (float)(0.439999997615814 + (double)num12 * 2.0);
                                                 goto label_405;
                                             }
                                         case (ushort)27:
                                             if ((int)tile.frameY < 36)
                                             {
                                                 num8 = 0.3f;
                                                 num9 = 0.27f;
                                                 goto label_405;
                                             }
                                             else
                                                 goto label_405;
                                         case (ushort)33:
                                             if ((int)tile.frameX == 0)
                                             {
                                                 switch ((int)tile.frameY / 22)
                                                 {
                                                     case 19:
                                                         num8 = 0.37f;
                                                         num9 = 0.8f;
                                                         num10 = 1f;
                                                         goto label_405;
                                                     case 20:
                                                         num8 = 0.0f;
                                                         num9 = 0.9f;
                                                         num10 = 1f;
                                                         goto label_405;
                                                     case 21:
                                                         num8 = 0.25f;
                                                         num9 = 0.7f;
                                                         num10 = 1f;
                                                         goto label_405;
                                                     case 25:
                                                         num8 = (float)(0.5 * (double)Main.demonTorch + 1.0 * (1.0 - (double)Main.demonTorch));
                                                         num9 = 0.3f;
                                                         num10 = (float)(1.0 * (double)Main.demonTorch + 0.5 * (1.0 - (double)Main.demonTorch));
                                                         goto label_405;
                                                     case 28:
                                                         num8 = 0.9f;
                                                         num9 = 0.75f;
                                                         num10 = 1f;
                                                         goto label_405;
                                                     case 0:
                                                         num8 = 1f;
                                                         num9 = 0.95f;
                                                         num10 = 0.65f;
                                                         goto label_405;
                                                     case 1:
                                                         num8 = 0.55f;
                                                         num9 = 0.85f;
                                                         num10 = 0.35f;
                                                         goto label_405;
                                                     case 2:
                                                         num8 = 0.65f;
                                                         num9 = 0.95f;
                                                         num10 = 0.5f;
                                                         goto label_405;
                                                     case 3:
                                                         num8 = 0.2f;
                                                         num9 = 0.75f;
                                                         num10 = 1f;
                                                         goto label_405;
                                                     case 14:
                                                         num8 = 1f;
                                                         num9 = 1f;
                                                         num10 = 0.6f;
                                                         goto label_405;
                                                     default:
                                                         num8 = 1f;
                                                         num9 = 0.95f;
                                                         num10 = 0.65f;
                                                         goto label_405;
                                                 }
                                             }
                                             else
                                                 goto label_405;
                                         case (ushort)34:
                                             if ((int)tile.frameX < 54)
                                             {
                                                 switch ((int)tile.frameY / 54)
                                                 {
                                                     case 7:
                                                         num8 = 0.95f;
                                                         num9 = 0.95f;
                                                         num10 = 0.5f;
                                                         goto label_405;
                                                     case 8:
                                                         num8 = 0.85f;
                                                         num9 = 0.6f;
                                                         num10 = 1f;
                                                         goto label_405;
                                                     case 9:
                                                         num8 = 1f;
                                                         num9 = 0.6f;
                                                         num10 = 0.6f;
                                                         goto label_405;
                                                     case 11:
                                                     case 17:
                                                         num8 = 0.75f;
                                                         num9 = 0.9f;
                                                         num10 = 1f;
                                                         goto label_405;
                                                     case 15:
                                                         num8 = 1f;
                                                         num9 = 1f;
                                                         num10 = 0.7f;
                                                         goto label_405;
                                                     case 18:
                                                         num8 = 1f;
                                                         num9 = 1f;
                                                         num10 = 0.6f;
                                                         goto label_405;
                                                     case 24:
                                                         num8 = 0.37f;
                                                         num9 = 0.8f;
                                                         num10 = 1f;
                                                         goto label_405;
                                                     case 25:
                                                         num8 = 0.0f;
                                                         num9 = 0.9f;
                                                         num10 = 1f;
                                                         goto label_405;
                                                     case 26:
                                                         num8 = 0.25f;
                                                         num9 = 0.7f;
                                                         num10 = 1f;
                                                         goto label_405;
                                                     case 27:
                                                         num8 = 0.55f;
                                                         num9 = 0.85f;
                                                         num10 = 0.35f;
                                                         goto label_405;
                                                     case 28:
                                                         num8 = 0.65f;
                                                         num9 = 0.95f;
                                                         num10 = 0.5f;
                                                         goto label_405;
                                                     case 29:
                                                         num8 = 0.2f;
                                                         num9 = 0.75f;
                                                         num10 = 1f;
                                                         goto label_405;
                                                     case 32:
                                                         num8 = (float)(0.5 * (double)Main.demonTorch + 1.0 * (1.0 - (double)Main.demonTorch));
                                                         num9 = 0.3f;
                                                         num10 = (float)(1.0 * (double)Main.demonTorch + 0.5 * (1.0 - (double)Main.demonTorch));
                                                         goto label_405;
                                                     case 35:
                                                         num8 = 0.9f;
                                                         num9 = 0.75f;
                                                         num10 = 1f;
                                                         goto label_405;
                                                     default:
                                                         num8 = 1f;
                                                         num9 = 0.95f;
                                                         num10 = 0.8f;
                                                         goto label_405;
                                                 }
                                             }
                                             else
                                                 goto label_405;
                                         case (ushort)35:
                                             if ((int)tile.frameX < 36)
                                             {
                                                 num8 = 0.75f;
                                                 num9 = 0.6f;
                                                 num10 = 0.3f;
                                                 goto label_405;
                                             }
                                             else
                                                 goto label_405;
                                         case (ushort)37:
                                             num8 = 0.56f;
                                             num9 = 0.43f;
                                             num10 = 0.15f;
                                             goto label_405;
                                         default:
                                             goto label_405;
                                     }
                                 }
                             }
                             else if ((uint)num11 <= 49U)
                             {
                                 if ((int)num11 != 42)
                                 {
                                     if ((int)num11 == 49)
                                     {
                                         num8 = 0.0f;
                                         num9 = 0.35f;
                                         num10 = 0.8f;
                                         goto label_405;
                                     }
                                     else
                                         goto label_405;
                                 }
                                 else if ((int)tile.frameX == 0)
                                 {
                                     switch ((int)tile.frameY / 36)
                                     {
                                         case 0:
                                             num8 = 0.7f;
                                             num9 = 0.65f;
                                             num10 = 0.55f;
                                             goto label_405;
                                         case 1:
                                             num8 = 0.9f;
                                             num9 = 0.75f;
                                             num10 = 0.6f;
                                             goto label_405;
                                         case 2:
                                             num8 = 0.8f;
                                             num9 = 0.6f;
                                             num10 = 0.6f;
                                             goto label_405;
                                         case 3:
                                             num8 = 0.65f;
                                             num9 = 0.5f;
                                             num10 = 0.2f;
                                             goto label_405;
                                         case 4:
                                             num8 = 0.5f;
                                             num9 = 0.7f;
                                             num10 = 0.4f;
                                             goto label_405;
                                         case 5:
                                             num8 = 0.9f;
                                             num9 = 0.4f;
                                             num10 = 0.2f;
                                             goto label_405;
                                         case 6:
                                             num8 = 0.7f;
                                             num9 = 0.75f;
                                             num10 = 0.3f;
                                             goto label_405;
                                         case 7:
                                             float num15 = Main.demonTorch * 0.2f;
                                             num8 = 0.9f - num15;
                                             num9 = 0.9f - num15;
                                             num10 = 0.7f + num15;
                                             goto label_405;
                                         case 8:
                                             num8 = 0.75f;
                                             num9 = 0.6f;
                                             num10 = 0.3f;
                                             goto label_405;
                                         case 9:
                                             float num16 = 1f;
                                             float num17 = 0.3f;
                                             num10 = 0.5f + Main.demonTorch * 0.2f;
                                             num8 = num16 - Main.demonTorch * 0.1f;
                                             num9 = num17 - Main.demonTorch * 0.2f;
                                             goto label_405;
                                         case 28:
                                             num8 = 0.37f;
                                             num9 = 0.8f;
                                             num10 = 1f;
                                             goto label_405;
                                         case 29:
                                             num8 = 0.0f;
                                             num9 = 0.9f;
                                             num10 = 1f;
                                             goto label_405;
                                         case 30:
                                             num8 = 0.25f;
                                             num9 = 0.7f;
                                             num10 = 1f;
                                             goto label_405;
                                         case 32:
                                             num8 = (float)(0.5 * (double)Main.demonTorch + 1.0 * (1.0 - (double)Main.demonTorch));
                                             num9 = 0.3f;
                                             num10 = (float)(1.0 * (double)Main.demonTorch + 0.5 * (1.0 - (double)Main.demonTorch));
                                             goto label_405;
                                         case 35:
                                             num8 = 0.7f;
                                             num9 = 0.6f;
                                             num10 = 0.9f;
                                             goto label_405;
                                         default:
                                             num8 = 1f;
                                             num9 = 1f;
                                             num10 = 1f;
                                             goto label_405;
                                     }
                                 }
                                 else
                                     goto label_405;
                             }
                             else
                             {
                                 switch (num11)
                                 {
                                     case (ushort)61:
                                         if ((int)tile.frameX == 144)
                                         {
                                             float num12 = (float)(1.0 + (double)(270 - (int)Main.mouseTextColor) / 400.0);
                                             float num18 = (float)(0.800000011920929 - (double)(270 - (int)Main.mouseTextColor) / 400.0);
                                             num8 = 0.42f * num18;
                                             num9 = 0.81f * num12;
                                             num10 = 0.52f * num18;
                                             goto label_405;
                                         }
                                         else
                                             goto label_405;
                                     case (ushort)70:
                                     case (ushort)71:
                                     case (ushort)72:
                                         goto label_371;
                                     default:
                                         goto label_405;
                                 }
                             }
                         }
                         else if ((uint)num11 <= 129U)
                         {
                             if ((uint)num11 <= 84U)
                             {
                                 switch (num11)
                                 {
                                     case (ushort)77:
                                         num8 = 0.75f;
                                         num9 = 0.45f;
                                         num10 = 0.25f;
                                         goto label_405;
                                     case (ushort)83:
                                         if ((int)tile.frameX == 18 && !Main.dayTime)
                                         {
                                             num8 = 0.1f;
                                             num9 = 0.4f;
                                             num10 = 0.6f;
                                             goto label_405;
                                         }
                                         else
                                             goto label_405;
                                     case (ushort)84:
                                         int num25 = (int)tile.frameX / 18;
                                         if (num25 == 2)
                                         {
                                             float num12 = (float)(270 - (int)Main.mouseTextColor) / 800f;
                                             if ((double)num12 > 1.0)
                                                 num12 = 1f;
                                             else if ((double)num12 < 0.0)
                                                 num12 = 0.0f;
                                             num8 = num12 * 0.7f;
                                             num9 = num12;
                                             num10 = num12 * 0.1f;
                                             goto label_405;
                                         }
                                         else if (num25 == 5)
                                         {
                                             float num12 = 0.9f;
                                             num8 = num12;
                                             num9 = num12 * 0.8f;
                                             num10 = num12 * 0.2f;
                                             goto label_405;
                                         }
                                         else if (num25 == 6)
                                         {
                                             float num12 = 0.08f;
                                             num9 = num12 * 0.8f;
                                             num10 = num12;
                                             goto label_405;
                                         }
                                         else
                                             goto label_405;
                                     default:
                                         goto label_405;
                                 }
                             }
                             else
                             {
                                 switch (num11)
                                 {
                                     case (ushort)92:
                                         if ((int)tile.frameY <= 18 && (int)tile.frameX == 0)
                                         {
                                             num8 = 1f;
                                             num9 = 1f;
                                             num10 = 1f;
                                             goto label_405;
                                         }
                                         else
                                             goto label_405;
                                     case (ushort)93:
                                         if ((int)tile.frameX == 0)
                                         {
                                             switch ((int)tile.frameY / 54)
                                             {
                                                 case 1:
                                                     num8 = 0.95f;
                                                     num9 = 0.95f;
                                                     num10 = 0.5f;
                                                     goto label_405;
                                                 case 2:
                                                     num8 = 0.85f;
                                                     num9 = 0.6f;
                                                     num10 = 1f;
                                                     goto label_405;
                                                 case 3:
                                                     num8 = 0.75f;
                                                     num9 = 1f;
                                                     num10 = 0.6f;
                                                     goto label_405;
                                                 case 4:
                                                 case 5:
                                                     num8 = 0.75f;
                                                     num9 = 0.9f;
                                                     num10 = 1f;
                                                     goto label_405;
                                                 case 9:
                                                     num8 = 1f;
                                                     num9 = 1f;
                                                     num10 = 0.7f;
                                                     goto label_405;
                                                 case 13:
                                                     num8 = 1f;
                                                     num9 = 1f;
                                                     num10 = 0.6f;
                                                     goto label_405;
                                                 case 19:
                                                     num8 = 0.37f;
                                                     num9 = 0.8f;
                                                     num10 = 1f;
                                                     goto label_405;
                                                 case 20:
                                                     num8 = 0.0f;
                                                     num9 = 0.9f;
                                                     num10 = 1f;
                                                     goto label_405;
                                                 case 21:
                                                     num8 = 0.25f;
                                                     num9 = 0.7f;
                                                     num10 = 1f;
                                                     goto label_405;
                                                 case 23:
                                                     num8 = (float)(0.5 * (double)Main.demonTorch + 1.0 * (1.0 - (double)Main.demonTorch));
                                                     num9 = 0.3f;
                                                     num10 = (float)(1.0 * (double)Main.demonTorch + 0.5 * (1.0 - (double)Main.demonTorch));
                                                     goto label_405;
                                                 case 24:
                                                     num8 = 0.35f;
                                                     num9 = 0.5f;
                                                     num10 = 0.3f;
                                                     goto label_405;
                                                 case 25:
                                                     num8 = 0.34f;
                                                     num9 = 0.4f;
                                                     num10 = 0.31f;
                                                     goto label_405;
                                                 case 26:
                                                     num8 = 0.25f;
                                                     num9 = 0.32f;
                                                     num10 = 0.5f;
                                                     goto label_405;
                                                 case 29:
                                                     num8 = 0.9f;
                                                     num9 = 0.75f;
                                                     num10 = 1f;
                                                     goto label_405;
                                                 default:
                                                     num8 = 1f;
                                                     num9 = 0.97f;
                                                     num10 = 0.85f;
                                                     goto label_405;
                                             }
                                         }
                                         else
                                             goto label_405;
                                     case (ushort)95:
                                         if ((int)tile.frameX < 36)
                                         {
                                             num8 = 1f;
                                             num9 = 0.95f;
                                             num10 = 0.8f;
                                             goto label_405;
                                         }
                                         else
                                             goto label_405;
                                     case (ushort)96:
                                         if ((int)tile.frameX >= 36)
                                             num8 = 0.5f;
                                         num9 = 0.35f;
                                         num10 = 0.1f;
                                         goto label_405;
                                     case (ushort)98:
                                         if ((int)tile.frameY == 0)
                                             num8 = 1f;
                                         num9 = 0.97f;
                                         num10 = 0.85f;
                                         goto label_405;
                                     case (ushort)100:
                                         goto label_294;
                                     case (ushort)125:
                                         float num26 = (float)Main.rand.Next(28, 42) * 0.01f + (float)(270 - (int)Main.mouseTextColor) / 800f;
                                         num9 = lightingState.g2 = 0.3f * num26;
                                         num10 = lightingState.b2 = 0.6f * num26;
                                         goto label_405;
                                     case (ushort)126:
                                         if ((int)tile.frameX < 36)
                                         {
                                             num8 = (float)Main.DiscoR / (float)byte.MaxValue;
                                             num9 = (float)Main.DiscoG / (float)byte.MaxValue;
                                             num10 = (float)Main.DiscoB / (float)byte.MaxValue;
                                             goto label_405;
                                         }
                                         else
                                             goto label_405;
                                     case (ushort)129:
                                         switch ((int)tile.frameX / 18 % 3)
                                         {
                                             case 0:
                                                 num8 = 0.0f;
                                                 num9 = 0.05f;
                                                 num10 = 0.25f;
                                                 goto label_405;
                                             case 1:
                                                 num8 = 0.2f;
                                                 num9 = 0.0f;
                                                 num10 = 0.15f;
                                                 goto label_405;
                                             case 2:
                                                 num8 = 0.1f;
                                                 num9 = 0.0f;
                                                 num10 = 0.2f;
                                                 goto label_405;
                                             default:
                                                 goto label_405;
                                         }
                                     default:
                                         goto label_405;
                                 }
                             }
                         }
                         else if ((uint)num11 <= 140U)
                         {
                             if ((int)num11 != 133)
                             {
                                 if ((int)num11 != 140)
                                     goto label_405;
                             }
                             else
                                 goto label_331;
                         }
                         else if ((int)num11 != 149)
                         {
                             if ((int)num11 == 160)
                             {
                                 num8 = (float)((double)Main.DiscoR / (double)byte.MaxValue * 0.25);
                                 num9 = (float)((double)Main.DiscoG / (double)byte.MaxValue * 0.25);
                                 num10 = (float)((double)Main.DiscoB / (double)byte.MaxValue * 0.25);
                                 goto label_405;
                             }
                             else
                                 goto label_405;
                         }
                         else if ((int)tile.frameX <= 36)
                         {
                             switch ((int)tile.frameX / 18)
                             {
                                 case 0:
                                     num8 = 0.1f;
                                     num9 = 0.2f;
                                     num10 = 0.5f;
                                     break;
                                 case 1:
                                     num8 = 0.5f;
                                     num9 = 0.1f;
                                     num10 = 0.1f;
                                     break;
                                 case 2:
                                     num8 = 0.2f;
                                     num9 = 0.5f;
                                     num10 = 0.1f;
                                     break;
                             }
                             num8 *= (float)Main.rand.Next(970, 1031) * (1 / 1000);
                             num9 *= (float)Main.rand.Next(970, 1031) * (1 / 1000);
                             num10 *= (float)Main.rand.Next(970, 1031) * (1 / 1000);
                             goto label_405;
                         }
                         else
                             goto label_405;
                         num8 = 0.12f;
                         num9 = 0.07f;
                         num10 = 0.32f;
                         goto label_405;
                     }
                     else
                     {
                         if ((uint)num11 <= 286U)
                         {
                             if ((uint)num11 <= 204U)
                             {
                                 if ((uint)num11 <= 184U)
                                 {
                                     switch (num11)
                                     {
                                         case (ushort)171:
                                             int index3 = index1;
                                             int index4 = index2;
                                             if ((int)tile.frameX < 10)
                                             {
                                                 index3 -= (int)tile.frameX;
                                                 index4 -= (int)tile.frameY;
                                             }
                                             switch (((int)Main.tile[index3, index4].frameY & 15360) >> 10)
                                             {
                                                 case 1:
                                                     num8 = 0.1f;
                                                     num9 = 0.1f;
                                                     num10 = 0.1f;
                                                     break;
                                                 case 2:
                                                     num8 = 0.2f;
                                                     break;
                                                 case 3:
                                                     num9 = 0.2f;
                                                     break;
                                                 case 4:
                                                     num10 = 0.2f;
                                                     break;
                                                 case 5:
                                                     num8 = 0.125f;
                                                     num9 = 0.125f;
                                                     break;
                                                 case 6:
                                                     num8 = 0.2f;
                                                     num9 = 0.1f;
                                                     break;
                                                 case 7:
                                                     num8 = 0.125f;
                                                     num9 = 0.125f;
                                                     break;
                                                 case 8:
                                                     num8 = 0.08f;
                                                     num9 = 0.175f;
                                                     break;
                                                 case 9:
                                                     num9 = 0.125f;
                                                     num10 = 0.125f;
                                                     break;
                                                 case 10:
                                                     num8 = 0.125f;
                                                     num10 = 0.125f;
                                                     break;
                                                 case 11:
                                                     num8 = 0.1f;
                                                     num9 = 0.1f;
                                                     num10 = 0.2f;
                                                     break;
                                                 default:
                                                     double num12;
                                                     num10 = (float)(num12 = 0.0);
                                                     num9 = (float)num12;
                                                     num8 = (float)num12;
                                                     break;
                                             }
                                             num8 *= 0.5f;
                                             num9 *= 0.5f;
                                             num10 *= 0.5f;
                                             goto label_405;
                                         case (ushort)173:
                                             goto label_294;
                                         case (ushort)174:
                                             if ((int)tile.frameX == 0)
                                             {
                                                 num8 = 1f;
                                                 num9 = 0.95f;
                                                 num10 = 0.65f;
                                                 goto label_405;
                                             }
                                             else
                                                 goto label_405;
                                         case (ushort)184:
                                             if ((int)tile.frameX == 110)
                                             {
                                                 num8 = 0.25f;
                                                 num9 = 0.1f;
                                                 num10 = 0.0f;
                                                 goto label_405;
                                             }
                                             else
                                                 goto label_405;
                                         default:
                                             goto label_405;
                                     }
                                 }
                                 else if ((int)num11 != 190)
                                 {
                                     if ((int)num11 != 204)
                                         goto label_405;
                                 }
                                 else
                                     goto label_371;
                             }
                             else if ((uint)num11 <= 238U)
                             {
                                 switch (num11)
                                 {
                                     case (ushort)215:
                                         if ((int)tile.frameY < 36)
                                         {
                                             float num15 = (float)Main.rand.Next(28, 42) * 0.005f + (float)(270 - (int)Main.mouseTextColor) / 700f;
                                             float num16;
                                             float num17;
                                             float num18;
                                             switch ((int)tile.frameX / 54)
                                             {
                                                 case 1:
                                                     num16 = 0.7f;
                                                     num17 = 1f;
                                                     num18 = 0.5f;
                                                     break;
                                                 case 2:
                                                     num16 = (float)(0.5 * (double)Main.demonTorch + 1.0 * (1.0 - (double)Main.demonTorch));
                                                     num17 = 0.3f;
                                                     num18 = (float)(1.0 * (double)Main.demonTorch + 0.5 * (1.0 - (double)Main.demonTorch));
                                                     break;
                                                 case 3:
                                                     num16 = 0.45f;
                                                     num17 = 0.75f;
                                                     num18 = 1f;
                                                     break;
                                                 case 4:
                                                     num16 = 1.15f;
                                                     num17 = 1.15f;
                                                     num18 = 0.5f;
                                                     break;
                                                 case 5:
                                                     num16 = (float)Main.DiscoR / (float)byte.MaxValue;
                                                     num17 = (float)Main.DiscoG / (float)byte.MaxValue;
                                                     num18 = (float)Main.DiscoB / (float)byte.MaxValue;
                                                     break;
                                                 default:
                                                     num16 = 0.9f;
                                                     num17 = 0.3f;
                                                     num18 = 0.1f;
                                                     break;
                                             }
                                             num8 = num16 + num15;
                                             num9 = num17 + num15;
                                             num10 = num18 + num15;
                                             goto label_405;
                                         }
                                         else
                                             goto label_405;
                                     case (ushort)235:
                                         if ((double)lightingState.r2 < 0.6)
                                             lightingState.r2 = 0.6f;
                                         if ((double)lightingState.g2 < 0.6)
                                         {
                                             lightingState.g2 = 0.6f;
                                             goto label_405;
                                         }
                                         else
                                             goto label_405;
                                     case (ushort)237:
                                         num8 = 0.1f;
                                         num9 = 0.1f;
                                         goto label_405;
                                     case (ushort)238:
                                         if ((double)lightingState.r2 < 0.5)
                                             lightingState.r2 = 0.5f;
                                         if ((double)lightingState.b2 < 0.5)
                                         {
                                             lightingState.b2 = 0.5f;
                                             goto label_405;
                                         }
                                         else
                                             goto label_405;
                                     default:
                                         goto label_405;
                                 }
                             }
                             else
                             {
                                 switch (num11)
                                 {
                                     case (ushort)262:
                                         num8 = 0.75f;
                                         num10 = 0.75f;
                                         goto label_405;
                                     case (ushort)263:
                                         num8 = 0.75f;
                                         num9 = 0.75f;
                                         goto label_405;
                                     case (ushort)264:
                                         num10 = 0.75f;
                                         goto label_405;
                                     case (ushort)265:
                                         num9 = 0.75f;
                                         goto label_405;
                                     case (ushort)266:
                                         num8 = 0.75f;
                                         goto label_405;
                                     case (ushort)267:
                                         num8 = 0.75f;
                                         num9 = 0.75f;
                                         num10 = 0.75f;
                                         goto label_405;
                                     case (ushort)268:
                                         num8 = 0.75f;
                                         num9 = 0.375f;
                                         goto label_405;
                                     case (ushort)270:
                                         num8 = 0.73f;
                                         num9 = 1f;
                                         num10 = 0.41f;
                                         goto label_405;
                                     case (ushort)271:
                                         num8 = 0.45f;
                                         num9 = 0.95f;
                                         num10 = 1f;
                                         goto label_405;
                                     case (ushort)286:
                                         num8 = 0.1f;
                                         num9 = 0.2f;
                                         num10 = 0.7f;
                                         goto label_405;
                                     default:
                                         goto label_405;
                                 }
                             }
                         }
                         else if ((uint)num11 <= 350U)
                         {
                             if ((uint)num11 <= 318U)
                             {
                                 switch (num11)
                                 {
                                     case (ushort)302:
                                         goto label_331;
                                     case (ushort)316:
                                     case (ushort)317:
                                     case (ushort)318:
                                         int index5 = (index1 - (int)tile.frameX / 18) / 2 * ((index2 - (int)tile.frameY / 18) / 3) % Main.cageFrames;
                                         bool flag = (int)Main.jellyfishCageMode[(int)tile.type - 316, index5] == 2;
                                         if ((int)tile.type == 316)
                                         {
                                             if (flag)
                                             {
                                                 num8 = 0.2f;
                                                 num9 = 0.3f;
                                                 num10 = 0.8f;
                                             }
                                             else
                                             {
                                                 num8 = 0.1f;
                                                 num9 = 0.2f;
                                                 num10 = 0.5f;
                                             }
                                         }
                                         if ((int)tile.type == 317)
                                         {
                                             if (flag)
                                             {
                                                 num8 = 0.2f;
                                                 num9 = 0.7f;
                                                 num10 = 0.3f;
                                             }
                                             else
                                             {
                                                 num8 = 0.05f;
                                                 num9 = 0.45f;
                                                 num10 = 0.1f;
                                             }
                                         }
                                         if ((int)tile.type == 318)
                                         {
                                             if (flag)
                                             {
                                                 num8 = 0.7f;
                                                 num9 = 0.2f;
                                                 num10 = 0.5f;
                                                 goto label_405;
                                             }
                                             else
                                             {
                                                 num8 = 0.4f;
                                                 num9 = 0.1f;
                                                 num10 = 0.25f;
                                                 goto label_405;
                                             }
                                         }
                                         else
                                             goto label_405;
                                     default:
                                         goto label_405;
                                 }
                             }
                             else
                             {
                                 switch (num11)
                                 {
                                     case (ushort)327:
                                         float num25 = 0.5f + (float)(270 - (int)Main.mouseTextColor) / 1500f + (float)Main.rand.Next(0, 50) * 0.0005f;
                                         num8 = 1f * num25;
                                         num9 = 0.5f * num25;
                                         num10 = 0.1f * num25;
                                         goto label_405;
                                     case (ushort)336:
                                         num8 = 0.85f;
                                         num9 = 0.5f;
                                         num10 = 0.3f;
                                         goto label_405;
                                     case (ushort)340:
                                         num8 = 0.45f;
                                         num9 = 1f;
                                         num10 = 0.45f;
                                         goto label_405;
                                     case (ushort)341:
                                         num8 = (float)(0.400000005960464 * (double)Main.demonTorch + 0.600000023841858 * (1.0 - (double)Main.demonTorch));
                                         num9 = 0.35f;
                                         num10 = (float)(1.0 * (double)Main.demonTorch + 0.600000023841858 * (1.0 - (double)Main.demonTorch));
                                         goto label_405;
                                     case (ushort)342:
                                         num8 = 0.5f;
                                         num9 = 0.5f;
                                         num10 = 1.1f;
                                         goto label_405;
                                     case (ushort)343:
                                         num8 = 0.85f;
                                         num9 = 0.85f;
                                         num10 = 0.3f;
                                         goto label_405;
                                     case (ushort)344:
                                         num8 = 0.6f;
                                         num9 = 1.026f;
                                         num10 = 0.96f;
                                         goto label_405;
                                     case (ushort)347:
                                         break;
                                     case (ushort)348:
                                     case (ushort)349:
                                         goto label_371;
                                     case (ushort)350:
                                         double num26 = Main.time * 0.08;
                                         float num27 = (float)(-Math.Cos((int)(num26 / 6.283) % 3 == 1 ? num26 : 0.0) * 0.1 + 0.1);
                                         num8 = num27;
                                         num9 = num27;
                                         num10 = num27;
                                         goto label_405;
                                     default:
                                         goto label_405;
                                 }
                             }
                         }
                         else if ((uint)num11 <= 381U)
                         {
                             switch (num11)
                             {
                                 case (ushort)370:
                                     num8 = 0.32f;
                                     num9 = 0.16f;
                                     num10 = 0.12f;
                                     goto label_405;
                                 case (ushort)372:
                                     if ((int)tile.frameX == 0)
                                     {
                                         num8 = 0.9f;
                                         num9 = 0.1f;
                                         num10 = 0.75f;
                                         goto label_405;
                                     }
                                     else
                                         goto label_405;
                                 case (ushort)381:
                                     num8 = 0.25f;
                                     num9 = 0.1f;
                                     num10 = 0.0f;
                                     goto label_405;
                                 default:
                                     goto label_405;
                             }
                         }
                         else
                         {
                             switch (num11)
                             {
                                 case (ushort)390:
                                     num8 = 0.4f;
                                     num9 = 0.2f;
                                     num10 = 0.1f;
                                     goto label_405;
                                 case (ushort)391:
                                     num8 = 0.3f;
                                     num9 = 0.1f;
                                     num10 = 0.25f;
                                     goto label_405;
                                 case (ushort)405:
                                     if ((int)tile.frameX < 54)
                                     {
                                         float num15 = (float)Main.rand.Next(28, 42) * 0.005f + (float)(270 - (int)Main.mouseTextColor) / 700f;
                                         float num16;
                                         float num17;
                                         float num18;
                                         switch ((int)tile.frameX / 54)
                                         {
                                             case 1:
                                                 num16 = 0.7f;
                                                 num17 = 1f;
                                                 num18 = 0.5f;
                                                 break;
                                             case 2:
                                                 num16 = (float)(0.5 * (double)Main.demonTorch + 1.0 * (1.0 - (double)Main.demonTorch));
                                                 num17 = 0.3f;
                                                 num18 = (float)(1.0 * (double)Main.demonTorch + 0.5 * (1.0 - (double)Main.demonTorch));
                                                 break;
                                             case 3:
                                                 num16 = 0.45f;
                                                 num17 = 0.75f;
                                                 num18 = 1f;
                                                 break;
                                             case 4:
                                                 num16 = 1.15f;
                                                 num17 = 1.15f;
                                                 num18 = 0.5f;
                                                 break;
                                             case 5:
                                                 num16 = (float)Main.DiscoR / (float)byte.MaxValue;
                                                 num17 = (float)Main.DiscoG / (float)byte.MaxValue;
                                                 num18 = (float)Main.DiscoB / (float)byte.MaxValue;
                                                 break;
                                             default:
                                                 num16 = 0.9f;
                                                 num17 = 0.3f;
                                                 num18 = 0.1f;
                                                 break;
                                         }
                                         num8 = num16 + num15;
                                         num9 = num17 + num15;
                                         num10 = num18 + num15;
                                         goto label_405;
                                     }
                                     else
                                         goto label_405;
                                 case (ushort)415:
                                     num8 = 0.7f;
                                     num9 = 0.5f;
                                     num10 = 0.1f;
                                     goto label_405;
                                 case (ushort)416:
                                     num8 = 0.0f;
                                     num9 = 0.6f;
                                     num10 = 0.7f;
                                     goto label_405;
                                 case (ushort)417:
                                     num8 = 0.6f;
                                     num9 = 0.2f;
                                     num10 = 0.6f;
                                     goto label_405;
                                 case (ushort)418:
                                     num8 = 0.6f;
                                     num9 = 0.6f;
                                     num10 = 0.9f;
                                     goto label_405;
                                 default:
                                     goto label_405;
                             }
                         }
                         num8 = 0.35f;
                         goto label_405;
                     }
                 label_294:
                     if ((int)tile.frameX < 36)
                     {
                         switch ((int)tile.frameY / 36)
                         {
                             case 1:
                                 num8 = 0.95f;
                                 num9 = 0.95f;
                                 num10 = 0.5f;
                                 goto label_405;
                             case 3:
                                 num8 = 1f;
                                 num9 = 0.6f;
                                 num10 = 0.6f;
                                 goto label_405;
                             case 6:
                             case 9:
                                 num8 = 0.75f;
                                 num9 = 0.9f;
                                 num10 = 1f;
                                 goto label_405;
                             case 11:
                                 num8 = 1f;
                                 num9 = 1f;
                                 num10 = 0.7f;
                                 goto label_405;
                             case 13:
                                 num8 = 1f;
                                 num9 = 1f;
                                 num10 = 0.6f;
                                 goto label_405;
                             case 19:
                                 num8 = 0.37f;
                                 num9 = 0.8f;
                                 num10 = 1f;
                                 goto label_405;
                             case 20:
                                 num8 = 0.0f;
                                 num9 = 0.9f;
                                 num10 = 1f;
                                 goto label_405;
                             case 21:
                                 num8 = 0.25f;
                                 num9 = 0.7f;
                                 num10 = 1f;
                                 goto label_405;
                             case 22:
                                 num8 = 0.35f;
                                 num9 = 0.5f;
                                 num10 = 0.3f;
                                 goto label_405;
                             case 23:
                                 num8 = 0.34f;
                                 num9 = 0.4f;
                                 num10 = 0.31f;
                                 goto label_405;
                             case 24:
                                 num8 = 0.25f;
                                 num9 = 0.32f;
                                 num10 = 0.5f;
                                 goto label_405;
                             case 25:
                                 num8 = (float)(0.5 * (double)Main.demonTorch + 1.0 * (1.0 - (double)Main.demonTorch));
                                 num9 = 0.3f;
                                 num10 = (float)(1.0 * (double)Main.demonTorch + 0.5 * (1.0 - (double)Main.demonTorch));
                                 goto label_405;
                             case 29:
                                 num8 = 0.9f;
                                 num9 = 0.75f;
                                 num10 = 1f;
                                 goto label_405;
                             default:
                                 num8 = 1f;
                                 num9 = 0.95f;
                                 num10 = 0.65f;
                                 goto label_405;
                         }
                     }
                     else
                         goto label_405;
                 label_331:
                     num8 = 0.83f;
                     num9 = 0.6f;
                     num10 = 0.5f;
                     goto label_405;
                 label_371:
                     if ((int)tile.type != 349 || (int)tile.frameX >= 36)
                     {
                         float num12 = (float)Main.rand.Next(28, 42) * 0.005f + (float)(270 - (int)Main.mouseTextColor) / 1000f;
                         num8 = 0.1f;
                         num9 = (float)(0.200000002980232 + (double)num12 / 2.0);
                         num10 = 0.7f + num12;
                     }
                 }
             }
         label_405:
             if (Lighting.RGB)
             {
                 if ((double)lightingState.r2 < (double)num8)
                     lightingState.r2 = num8;
                 if ((double)lightingState.g2 < (double)num9)
                     lightingState.g2 = num9;
                 if ((double)lightingState.b2 < (double)num10)
                     lightingState.b2 = num10;
             }
             else
             {
                 float num11 = (float)(((double)num8 + (double)num9 + (double)num10) / 3.0);
                 if ((double)lightingState.r2 < (double)num11)
                     lightingState.r2 = num11;
             }
             if (tile.lava() && (int)tile.liquid > 0)
             {
                 if (Lighting.RGB)
                 {
                     float num11 = (float)((double)((int)tile.liquid / (int)byte.MaxValue) * 0.409999996423721 + 0.140000000596046);
                     float num12 = 0.55f + (float)(270 - (int)Main.mouseTextColor) / 900f;
                     if ((double)lightingState.r2 < (double)num12)
                         lightingState.r2 = num12;
                     if ((double)lightingState.g2 < (double)num12)
                         lightingState.g2 = num12 * 0.6f;
                     if ((double)lightingState.b2 < (double)num12)
                         lightingState.b2 = num12 * 0.2f;
                 }
                 else
                 {
                     float num11 = (float)((double)((int)tile.liquid / (int)byte.MaxValue) * 0.379999995231628 + 0.0799999982118607) + (float)(270 - (int)Main.mouseTextColor) / 2000f;
                     if ((double)lightingState.r2 < (double)num11)
                         lightingState.r2 = num11;
                 }
             }
             else if ((int)tile.liquid > 128)
             {
                 lightingState.wetLight = true;
                 if (tile.honey())
                     lightingState.honeyLight = true;
             }
             if ((double)lightingState.r2 > 0.0 || Lighting.RGB && ((double)lightingState.g2 > 0.0 || (double)lightingState.b2 > 0.0))
             {
                 int num11 = index1 - Lighting.firstToLightX;
                 int num12 = index2 - Lighting.firstToLightY;
                 if (Lighting.minX > num11)
                     Lighting.minX = num11;
                 if (Lighting.maxX < num11 + 1)
                     Lighting.maxX = num11 + 1;
                 if (Lighting.minY > num12)
                     Lighting.minY = num12;
                 if (Lighting.maxY < num12 + 1)
                     Lighting.maxY = num12 + 1;
             }
         }
     }
     foreach (KeyValuePair<Point16, Lighting.ColorTriplet> keyValuePair in Lighting.tempLights)
     {
         int index1 = (int)keyValuePair.Key.X - Lighting.firstTileX + Lighting.offScreenTiles;
         int index2 = (int)keyValuePair.Key.Y - Lighting.firstTileY + Lighting.offScreenTiles;
         if (index1 >= 0 && index1 < Main.screenWidth / 16 + Lighting.offScreenTiles * 2 + 10 && (index2 >= 0 && index2 < Main.screenHeight / 16 + Lighting.offScreenTiles * 2 + 10))
         {
             Lighting.LightingState lightingState = Lighting.states[index1][index2];
             if ((double)lightingState.r2 < (double)keyValuePair.Value.r)
                 lightingState.r2 = keyValuePair.Value.r;
             if ((double)lightingState.g2 < (double)keyValuePair.Value.g)
                 lightingState.g2 = keyValuePair.Value.g;
             if ((double)lightingState.b2 < (double)keyValuePair.Value.b)
                 lightingState.b2 = keyValuePair.Value.b;
             if (index1 < Lighting.minX)
                 Lighting.minX = index1;
             if (index1 > Lighting.maxX)
                 Lighting.maxX = index1;
             if (index2 < Lighting.minY)
                 Lighting.minY = index2;
             if (index2 > Lighting.maxY)
                 Lighting.maxY = index2;
         }
     }
     if (!Main.gamePaused)
         Lighting.tempLights.Clear();
     if (numArray[27] > 0)
         Main.sunflower = true;
     Main.holyTiles = numArray[109] + numArray[110] + numArray[113] + numArray[117] + numArray[116] + numArray[164] + numArray[403] + numArray[402];
     Main.evilTiles = numArray[23] + numArray[24] + numArray[25] + numArray[32] + numArray[112] + numArray[163] + numArray[400] + numArray[398] + -5 * numArray[27];
     Main.bloodTiles = numArray[199] + numArray[203] + numArray[200] + numArray[401] + numArray[399] + numArray[234] + numArray[352] - 5 * numArray[27];
     Main.snowTiles = numArray[147] + numArray[148] + numArray[161] + numArray[162] + numArray[164] + numArray[163] + numArray[200];
     Main.jungleTiles = numArray[60] + numArray[61] + numArray[62] + numArray[74] + numArray[226];
     Main.shroomTiles = numArray[70] + numArray[71] + numArray[72];
     Main.meteorTiles = numArray[37];
     Main.dungeonTiles = numArray[41] + numArray[43] + numArray[44];
     Main.sandTiles = numArray[53] + numArray[112] + numArray[116] + numArray[234] + numArray[397] + numArray[398] + numArray[402] + numArray[399] + numArray[396] + numArray[400] + numArray[403] + numArray[401];
     Main.waterCandles = numArray[49];
     Main.peaceCandles = numArray[372];
     if (Main.player[Main.myPlayer].accOreFinder)
     {
         Main.player[Main.myPlayer].bestOre = -1;
         for (int index = 0; index < 419; ++index)
         {
             if (numArray[index] > 0 && (int)Main.tileValue[index] > 0 && (Main.player[Main.myPlayer].bestOre < 0 || (int)Main.tileValue[index] > (int)Main.tileValue[Main.player[Main.myPlayer].bestOre]))
                 Main.player[Main.myPlayer].bestOre = index;
         }
     }
     Array.Clear((Array)numArray, 0, numArray.Length);
     if (Main.holyTiles < 0)
         Main.holyTiles = 0;
     if (Main.evilTiles < 0)
         Main.evilTiles = 0;
     if (Main.bloodTiles < 0)
         Main.bloodTiles = 0;
     int num28 = Main.holyTiles;
     Main.holyTiles -= Main.evilTiles;
     Main.holyTiles -= Main.bloodTiles;
     Main.evilTiles -= num28;
     Main.bloodTiles -= num28;
     if (Main.holyTiles < 0)
         Main.holyTiles = 0;
     if (Main.evilTiles < 0)
         Main.evilTiles = 0;
     if (Main.bloodTiles < 0)
         Main.bloodTiles = 0;
     Lighting.minX += Lighting.firstToLightX;
     Lighting.maxX += Lighting.firstToLightX;
     Lighting.minY += Lighting.firstToLightY;
     Lighting.maxY += Lighting.firstToLightY;
     Lighting.minX7 = Lighting.minX;
     Lighting.maxX7 = Lighting.maxX;
     Lighting.minY7 = Lighting.minY;
     Lighting.maxY7 = Lighting.maxY;
     Lighting.firstTileX7 = Lighting.firstTileX;
     Lighting.lastTileX7 = Lighting.lastTileX;
     Lighting.lastTileY7 = Lighting.lastTileY;
     Lighting.firstTileY7 = Lighting.firstTileY;
     Lighting.firstToLightX7 = Lighting.firstToLightX;
     Lighting.lastToLightX7 = Lighting.lastToLightX;
     Lighting.firstToLightY7 = Lighting.firstToLightY;
     Lighting.lastToLightY7 = Lighting.lastToLightY;
     Lighting.firstToLightX27 = Lighting.firstTileX - Lighting.offScreenTiles2;
     Lighting.firstToLightY27 = Lighting.firstTileY - Lighting.offScreenTiles2;
     Lighting.lastToLightX27 = Lighting.lastTileX + Lighting.offScreenTiles2;
     Lighting.lastToLightY27 = Lighting.lastTileY + Lighting.offScreenTiles2;
     if (Lighting.firstToLightX27 < 0)
         Lighting.firstToLightX27 = 0;
     if (Lighting.lastToLightX27 >= Main.maxTilesX)
         Lighting.lastToLightX27 = Main.maxTilesX - 1;
     if (Lighting.firstToLightY27 < 0)
         Lighting.firstToLightY27 = 0;
     if (Lighting.lastToLightY27 >= Main.maxTilesY)
         Lighting.lastToLightY27 = Main.maxTilesY - 1;
     Lighting.scrX = (int)Main.screenPosition.X / 16;
     Lighting.scrY = (int)Main.screenPosition.Y / 16;
     Main.renderCount = 0;
     TimeLogger.LightingTime(0, stopwatch.Elapsed.TotalMilliseconds);
     Lighting.doColors();
 }
Ejemplo n.º 21
0
        protected override void Update(GameTime gameTime)
        {
            #region Modifier Keys

            // Detect modifier keys
            bool shift = keyState.IsKeyDown(Keys.LeftShift) || keyState.IsKeyDown(Keys.RightShift);
            bool alt = keyState.IsKeyDown(Keys.LeftAlt) || keyState.IsKeyDown(Keys.RightAlt);
            bool ctrl = keyState.IsKeyDown(Keys.LeftControl) || keyState.IsKeyDown(Keys.RightControl);

            #endregion

            #region buildMode

            if (buildMode)
            {
                try
                {
                    FieldInfo tilex = player[myPlayer].GetType().GetField("tileRangeX");
                    FieldInfo tiley = player[myPlayer].GetType().GetField("tileRangeY");
                    tilex.SetValue(player[myPlayer], 1000);
                    tiley.SetValue(player[myPlayer], 1000);

                    for (int i = 0; i < player[myPlayer].inventory.Length; i++)
                    {
                        Item it = player[myPlayer].inventory[i];

                        if (i == 10)
                        {
                            player[myPlayer].inventory[i].SetDefaults(0);
                            player[myPlayer].inventory[i].name = "";
                            player[myPlayer].inventory[i].stack = 0;
                            player[myPlayer].inventory[i].UpdateItem(0);
                        }
                        else if (it.name != "Magic Mirror") // Prevent Magic Mirror being hax'd, which prevents it from working.
                        {
                            if (it.name != "")
                            {
                                #region Item Stack Sizes

                                // Set this to false if you want items to be stacked only to their default max stack size.
                                bool haxItemStack = true;

                                // The amount of items you want in a hax'd stack.
                                int haxItemStackSize = 999;

                                // Note: The haxItemStack toggle has no affect on single-stacked items.
                                // In order to keep them unstackable we need to up their max stack size. 10 is a good, solid, number.
                                if (it.maxStack == 1)
                                {
                                    it.stack = 10;
                                    it.maxStack = 10;
                                }
                                if (haxItemStack)
                                {
                                    it.stack = haxItemStackSize;
                                }
                                else
                                {
                                    it.stack = it.maxStack;
                                }

                                #endregion

                                #region Placeable Items!

                                // ItemName_TileID
                                string[] placeableItems = new string[]
                                {
                                    "Sapphire_63",
                                    "Ruby_64",
                                    "Emerald_65",
                                    "Topaz_66",
                                    "Amethyst_67",
                                    "Diamond_68"
                                };
                                for (int j = 0; j < placeableItems.Length; j++)
                                {
                                    string[] pi = placeableItems[j].Split('_');
                                    if (pi[0] == it.name)
                                    {
                                        it.useTime = 0;
                                        it.createTile = Convert.ToByte(pi[1]);
                                    }

                                }

                                #endregion

                                #region itemHax

                                if (itemHax)
                                {
                                    if (it.name.ToLower().Contains("axe") || it.name.ToLower().Contains("hammer") || it.useTime == 10 || it.useTime == 7 || it.name.ToLower().Contains("phase"))
                                    {
                                        it.autoReuse = true;
                                        it.useTime = 0;
                                    }

                                    if (it.hammer > 0 || it.axe > 0)
                                    {
                                        it.hammer = 300;
                                        it.axe = 300;
                                    }
                                    if (it.pick > 0)
                                    {
                                        it.pick = 300;
                                    }
                                }
                                else
                                {
                                    // Values equal to a Molten Hamaxe
                                    if (it.hammer > 0 || it.axe > 0)
                                    {
                                        it.hammer = 70;
                                        it.axe = 150;
                                        it.useTime = 14;
                                    }
                                    // Values are between a Nightmare Pickaxe and a Molten Pickaxe, favoring each items strong points.
                                    if (it.pick > 0)
                                    {
                                        it.pick = 90;
                                        it.useTime = 12;
                                    }
                                    // Slow down, Spider Man.
                                    if (it.name == "Ivy Whip")
                                    {
                                        it.autoReuse = false;
                                        it.useTime = 20;
                                        it.shoot = 32;
                                        it.shootSpeed = 13;
                                    }
                                    if (it.name == "Grappling Hook")
                                    {
                                        it.autoReuse = false;
                                        it.useTime = 20;
                                        it.shoot = 13;
                                        it.shootSpeed = 11;
                                    }
                                }

                                #endregion
                            }
                        }
                        else
                        {
                            it.SetDefaults(50);
                        }

                        player[myPlayer].inventory[i] = it;
                    }
                }
                catch
                {

                }
            }
            else
            {
                FieldInfo tilex = player[myPlayer].GetType().GetField("tileRangeX");
                FieldInfo tiley = player[myPlayer].GetType().GetField("tileRangeY");
                tilex.SetValue(player[myPlayer], 5);
                tiley.SetValue(player[myPlayer], 4);
            }

            #endregion

            #region Bucket Management

            // Disabled for now.

            /*bool[] lavaBuckets = new bool[40];
            bool[] waterBuckets = new bool[40];
            bool[] emptyBuckets = new bool[40];
            for (int i = 0; i < player[myPlayer].inventory.Length; i++)
            {
                if (player[myPlayer].inventory[i].type == 0xcf)
                {
                    lavaBuckets[i] = true;
                }
                else if (player[myPlayer].inventory[i].type == 0xce)
                {
                    waterBuckets[i] = true;
                }
                else if (player[myPlayer].inventory[i].type == 0xcd)
                {
                    emptyBuckets[i] = true;
                }
            }

            for (int i = 0; i < player[myPlayer].inventory.Length; i++)
            {
                if (player[myPlayer].inventory[i].type == 0xcd)
                {
                    if (lavaBuckets[i] == true)
                    {
                        player[myPlayer].inventory[i].type = 0xcf;
                    }
                    else if (waterBuckets[i] == true)
                    {
                        player[myPlayer].inventory[i].type = 0xce;
                    }
                    else if (emptyBuckets[i] == true)
                    {
                        player[myPlayer].inventory[i].type = 0xcd;
                    }
                }
            }*/

            #endregion

            try
            {
                base.Update(gameTime);
            }
            catch (Exception e)
            {
                Main.NewText(e.Message);
                LoadInventory(0);
                base.Update(gameTime);
            }

            if (gamePaused)
                return;

            trashItem.SetDefaults(0);

            #region NPC Spawning

            if (keyState.IsKeyDown(Keys.C) && oldKeyState.IsKeyUp(Keys.C) && !editSign && !ctrl)
            {
                npcsEnabled = !npcsEnabled;

                if (displayMessages)
                {
                    Main.NewText(npcsEnabled == true ? "Hostile NPCs will now spawn." : "Hostile NPCs will no longer spawn.", Convert.ToByte(otherToggles[0]), Convert.ToByte(otherToggles[1]), Convert.ToByte(otherToggles[2]));
                }
            }

            if (!npcsEnabled)
            {
                foreach (NPC n in npc)
                {
                    if (!n.friendly)
                    {
                        n.life = 0;
                        n.UpdateNPC(0);
                    }
                }
            }

            #endregion

            #region World Items

            if (keyState.IsKeyDown(Keys.M) && oldKeyState.IsKeyUp(Keys.M) && !editSign && !ctrl)
            {
                itemsEnabled = !itemsEnabled;

                if (displayMessages)
                {
                    Main.NewText(itemsEnabled == true ? "Items will now drop to the ground when excavated or dropped." : "Items will no longer be visible when excavated or dropped.", Convert.ToByte(otherToggles[0]), Convert.ToByte(otherToggles[1]), Convert.ToByte(otherToggles[2]));
                }
            }

            if (!itemsEnabled)
            {
                foreach (Item i in item)
                {
                    i.SetDefaults(0);
                    i.stack = 0;
                    i.name = "";
                    i.UpdateItem(0);
                }
            }

            #endregion

            if (menuMode != oldMenuMode)
            {
                sel1 = -Vector2.One;
                sel2 = -Vector2.One;
            }

            if (menuMode != oldMenuMode && menuMode == 10)
            {
                LoadInventory(Inventory.Inventories.Count - 1);
            }
            else if (menuMode == 10) // if in-game ...
            {

                #region Display Chat Messages

                if (keyState.IsKeyDown(Keys.K) && oldKeyState.IsKeyUp(Keys.K) && !editSign && !ctrl && !shift)
                {
                    displayMessages = !displayMessages;

                    Main.NewText(displayMessages == true ? "You will now see messages for toggles." : "You will no longer see messages for toggles.", Convert.ToByte(displayMessagesMsg[0]), Convert.ToByte(displayMessagesMsg[1]), Convert.ToByte(displayMessagesMsg[2]));
                }

                #endregion

                #region ItemHax

                if (keyState.IsKeyDown(Keys.T) && oldKeyState.IsKeyUp(Keys.T) && !editSign && !ctrl && !shift)
                {
                    itemHax = !itemHax;

                    if (displayMessages)
                    {
                        Main.NewText(itemHax == true ? "You are no longer limited while placing or destroying blocks and items." : "Your construction powers have been normalized.", Convert.ToByte(otherToggles[0]), Convert.ToByte(otherToggles[1]), Convert.ToByte(otherToggles[2]));
                    }
                }

                #endregion

                #region Save/Load Inventories File

                if (ctrl && shift && keyState.IsKeyDown(Keys.S) && oldKeyState.IsKeyUp(Keys.S))
                {
                    SaveInventory(inventoryType);
                    Inventory.SaveInventories();
                }

                if (ctrl && shift && keyState.IsKeyDown(Keys.O) && oldKeyState.IsKeyUp(Keys.O))
                    Inventory.LoadInventories();

                #endregion

                #region Ghost/Hover Mode

                if (hover)
                {
                    player[myPlayer].position = lastPosition;
                    float magnitude = 6f;
                    if (shift)
                    {
                        magnitude *= 4;
                    }
                    if (alt && shift)
                    {
                        magnitude *= 8;
                    }
                    if (player[myPlayer].controlUp || player[myPlayer].controlJump)
                    {
                        player[myPlayer].position = new Vector2(player[myPlayer].position.X, player[myPlayer].position.Y - magnitude);
                    }
                    if (player[myPlayer].controlDown)
                    {
                        player[myPlayer].position = new Vector2(player[myPlayer].position.X, player[myPlayer].position.Y + magnitude);
                    }
                    if (player[myPlayer].controlLeft)
                    {
                        player[myPlayer].position = new Vector2(player[myPlayer].position.X - magnitude, player[myPlayer].position.Y);
                    }
                    if (player[myPlayer].controlRight)
                    {
                        player[myPlayer].position = new Vector2(player[myPlayer].position.X + magnitude, player[myPlayer].position.Y);
                    }
                }

                if (keyState.IsKeyDown(Keys.P) && !oldKeyState.IsKeyDown(Keys.P) && !editSign && !ctrl && !shift)
                {
                    hover = !hover;
                    player[myPlayer].fallStart = (int)player[myPlayer].position.Y;
                    player[myPlayer].immune = true;
                    player[myPlayer].immuneTime = 1000;
                    if (!hover)
                    {
                        player[myPlayer].immune = false;
                    }

                    if (displayMessages)
                    {
                        Main.NewText(hover == true ? "You can now fly through any solid object!" : "You can no longer pass through solid objects. :(", Convert.ToByte(otherToggles[0]), Convert.ToByte(otherToggles[1]), Convert.ToByte(otherToggles[2]));
                    }
                }

                #endregion

                #region Grid (ruler)

                if (keyState.IsKeyDown(Keys.R) && oldKeyState.IsKeyUp(Keys.R) && !editSign && !ctrl && !shift)
                {

                    gridMe = !gridMe;
                    if (displayMessages)
                    {
                        Main.NewText(gridMe == true ? "Build free. You now have a 1x1 grid to assist you." : "The 1x1 grid has been hidden.", Convert.ToByte(otherToggles[0]), Convert.ToByte(otherToggles[1]), Convert.ToByte(otherToggles[2]));
                    }
                }
                if (gridMe)
                {
                    player[myPlayer].rulerAcc = true;
                }

                #endregion

                #region God Mode

                if (keyState.IsKeyDown(Keys.G) && oldKeyState.IsKeyUp(Keys.G) && !editSign && !ctrl && !shift)
                {
                    godMode = !godMode;

                    if (displayMessages)
                    {
                        Main.NewText(godMode == true ? "You are now an immortal entity." : "Welcome back to the world of the Normals.", Convert.ToByte(otherToggles[0]), Convert.ToByte(otherToggles[1]), Convert.ToByte(otherToggles[2]));
                    }
                }

                if (godMode)
                {
                    player[myPlayer].accWatch = 3;
                    player[myPlayer].accDepthMeter = 3;
                    player[myPlayer].accCompass = 3;
                    player[myPlayer].accFlipper = true;
                    player[myPlayer].statLife = player[myPlayer].statLifeMax;
                    player[myPlayer].statMana = player[myPlayer].statManaMax;
                    player[myPlayer].dead = false;
                    player[myPlayer].rocketTimeMax = 1000000;
                    player[myPlayer].rocketTime = 1000;
                    player[myPlayer].canRocket = true;
                    player[myPlayer].fallStart = (int)player[myPlayer].position.Y;
                    player[myPlayer].AddBuff(9, 50); // Spelunker effect
                }
                else
                {
                    player[myPlayer].respawnTimer = 1;
                }

                #endregion

                #region Set Default Spawn Location

                if (keyState.IsKeyDown(Keys.L) && oldKeyState.IsKeyUp(Keys.L) && !editSign && !ctrl && !shift)
                {
                    int x = (int)((Main.mouseState.X + Main.screenPosition.X) / 16f);
                    int y = (int)((Main.mouseState.Y + Main.screenPosition.Y) / 16f);

                    Main.spawnTileX = x;
                    Main.spawnTileY = y;

                    if (displayMessages)
                    {
                        Main.NewText("You have successfully set the default spawn location.", Convert.ToByte(setSpawnPoint[0]), Convert.ToByte(setSpawnPoint[1]), Convert.ToByte(setSpawnPoint[2]));
                    }
                }

                #endregion

                #region Built-in Teleport Locations (bound to F1-F?)

                // F1 - Default Spawn Location
                if (keyState.IsKeyDown(Keys.F1) && oldKeyState.IsKeyUp(Keys.F1) && !editSign && !shift && !ctrl)
                {
                    int x = (int)(Main.spawnTileX * 16f);
                    int y = (int)((Main.spawnTileY * 16f) - 16f);

                    player[myPlayer].position = new Vector2(x, y);
                    Main.NewText("You have been teleported to the Default Spawn Location.", Convert.ToByte(teleportMessages[0]), Convert.ToByte(teleportMessages[1]), Convert.ToByte(teleportMessages[2]));
                }

                // F3 - Left Ocean
                if (keyState.IsKeyDown(Keys.F3) && oldKeyState.IsKeyUp(Keys.F3) && !editSign && !shift && !ctrl)
                {
                    int x = (int)(Main.leftWorld + 4048f);
                    int y = (int)((Main.spawnTileY * 16f) - 1024f);

                    hover = true;
                    player[myPlayer].position = new Vector2(x, y);
                    Main.NewText("You have been teleported to the Left Ocean.", Convert.ToByte(teleportMessages[0]), Convert.ToByte(teleportMessages[1]), Convert.ToByte(teleportMessages[2]));
                }

                // F4 - Right Ocean
                if (keyState.IsKeyDown(Keys.F4) && oldKeyState.IsKeyUp(Keys.F4) && !editSign && !shift && !ctrl)
                {
                    int x = (int)((Main.rightWorld) - 4048f);
                    int y = (int)((Main.spawnTileY * 16f) - 1024f);

                    hover = true;
                    player[myPlayer].position = new Vector2(x, y);
                    Main.NewText("You have been teleported to the Right Ocean.", Convert.ToByte(teleportMessages[0]), Convert.ToByte(teleportMessages[1]), Convert.ToByte(teleportMessages[2]));
                }

                #endregion

                #region Custom Teleport Locations (bound to Ctrl + F1-F12)

                if (ctlF1 != null)
                {
                    if (ctrl && keyState.IsKeyDown(Keys.F1) && oldKeyState.IsKeyUp(Keys.F1) && !editSign && !shift)
                    {
                        int x = (int)((Convert.ToSingle(ctlF1[1]) * 16f));
                        int y = (int)((Convert.ToSingle(ctlF1[2]) * 16f) - 16f);

                        player[myPlayer].position = new Vector2(x, y);
                        Main.NewText("You have been teleported to " + ctlF1[0], Convert.ToByte(teleportMessages[0]), Convert.ToByte(teleportMessages[1]), Convert.ToByte(teleportMessages[2]));
                    }
                }

                if (ctlF2 != null)
                {
                    if (ctrl && keyState.IsKeyDown(Keys.F2) && oldKeyState.IsKeyUp(Keys.F2) && !editSign && !shift)
                    {
                        int x = (int)((Convert.ToByte(ctlF2[1]) * 16f));
                        int y = (int)((Convert.ToByte(ctlF2[2]) * 16f) - 16f);

                        player[myPlayer].position = new Vector2(x, y);
                        Main.NewText("You have been teleported to " + ctlF2[0], Convert.ToByte(teleportMessages[0]), Convert.ToByte(teleportMessages[1]), Convert.ToByte(teleportMessages[2]));
                    }
                }

                if (ctlF3 != null)
                {
                    if (ctrl && keyState.IsKeyDown(Keys.F3) && oldKeyState.IsKeyUp(Keys.F3) && !editSign && !shift)
                    {
                        int x = (int)((Convert.ToByte(ctlF3[1]) * 16f));
                        int y = (int)((Convert.ToByte(ctlF3[2]) * 16f) - 16f);

                        player[myPlayer].position = new Vector2(x, y);
                        Main.NewText("You have been teleported to " + ctlF3[0], Convert.ToByte(teleportMessages[0]), Convert.ToByte(teleportMessages[1]), Convert.ToByte(teleportMessages[2]));
                    }
                }

                if (ctlF4 != null)
                {
                    if (ctrl && keyState.IsKeyDown(Keys.F4) && oldKeyState.IsKeyUp(Keys.F4) && !editSign && !shift)
                    {
                        int x = (int)((Convert.ToByte(ctlF4[1]) * 16f));
                        int y = (int)((Convert.ToByte(ctlF4[2]) * 16f) - 16f);

                        player[myPlayer].position = new Vector2(x, y);
                        Main.NewText("You have been teleported to " + ctlF4[0], Convert.ToByte(teleportMessages[0]), Convert.ToByte(teleportMessages[1]), Convert.ToByte(teleportMessages[2]));
                    }
                }

                if (ctlF5 != null)
                {
                    if (ctrl && keyState.IsKeyDown(Keys.F5) && oldKeyState.IsKeyUp(Keys.F5) && !editSign && !shift)
                    {
                        int x = (int)((Convert.ToByte(ctlF5[1]) * 16f));
                        int y = (int)((Convert.ToByte(ctlF5[2]) * 16f) - 16f);

                        player[myPlayer].position = new Vector2(x, y);
                        Main.NewText("You have been teleported to " + ctlF5[0], Convert.ToByte(teleportMessages[0]), Convert.ToByte(teleportMessages[1]), Convert.ToByte(teleportMessages[2]));
                    }
                }

                if (ctlF6 != null)
                {
                    if (ctrl && keyState.IsKeyDown(Keys.F6) && oldKeyState.IsKeyUp(Keys.F6) && !editSign && !shift)
                    {
                        int x = (int)((Convert.ToByte(ctlF6[1]) * 16f));
                        int y = (int)((Convert.ToByte(ctlF6[2]) * 16f) - 16f);

                        player[myPlayer].position = new Vector2(x, y);
                        Main.NewText("You have been teleported to " + ctlF6[0], Convert.ToByte(teleportMessages[0]), Convert.ToByte(teleportMessages[1]), Convert.ToByte(teleportMessages[2]));
                    }
                }

                if (ctlF7 != null)
                {
                    if (ctrl && keyState.IsKeyDown(Keys.F7) && oldKeyState.IsKeyUp(Keys.F7) && !editSign && !shift)
                    {
                        int x = (int)((Convert.ToByte(ctlF7[1]) * 16f));
                        int y = (int)((Convert.ToByte(ctlF7[2]) * 16f) - 16f);

                        player[myPlayer].position = new Vector2(x, y);
                        Main.NewText("You have been teleported to " + ctlF7[0], Convert.ToByte(teleportMessages[0]), Convert.ToByte(teleportMessages[1]), Convert.ToByte(teleportMessages[2]));
                    }
                }

                if (ctlF8 != null)
                {
                    if (ctrl && keyState.IsKeyDown(Keys.F8) && oldKeyState.IsKeyUp(Keys.F8) && !editSign && !shift)
                    {
                        int x = (int)((Convert.ToByte(ctlF8[1]) * 16f));
                        int y = (int)((Convert.ToByte(ctlF8[2]) * 16f) - 16f);

                        player[myPlayer].position = new Vector2(x, y);
                        Main.NewText("You have been teleported to " + ctlF8[0], Convert.ToByte(teleportMessages[0]), Convert.ToByte(teleportMessages[1]), Convert.ToByte(teleportMessages[2]));
                    }
                }

                if (ctlF9 != null)
                {
                    if (ctrl && keyState.IsKeyDown(Keys.F9) && oldKeyState.IsKeyUp(Keys.F9) && !editSign && !shift)
                    {
                        int x = (int)((Convert.ToByte(ctlF9[1]) * 16f));
                        int y = (int)((Convert.ToByte(ctlF9[2]) * 16f) - 16f);

                        player[myPlayer].position = new Vector2(x, y);
                        Main.NewText("You have been teleported to " + ctlF9[0], Convert.ToByte(teleportMessages[0]), Convert.ToByte(teleportMessages[1]), Convert.ToByte(teleportMessages[2]));
                    }
                }

                if (ctlF10 != null)
                {
                    if (ctrl && keyState.IsKeyDown(Keys.F10) && oldKeyState.IsKeyUp(Keys.F10) && !editSign && !shift)
                    {
                        int x = (int)((Convert.ToByte(ctlF10[1]) * 16f));
                        int y = (int)((Convert.ToByte(ctlF10[2]) * 16f) - 16f);

                        player[myPlayer].position = new Vector2(x, y);
                        Main.NewText("You have been teleported to " + ctlF10[0], Convert.ToByte(teleportMessages[0]), Convert.ToByte(teleportMessages[1]), Convert.ToByte(teleportMessages[2]));
                    }
                }

                if (ctlF11 != null)
                {
                    if (ctrl && keyState.IsKeyDown(Keys.F11) && oldKeyState.IsKeyUp(Keys.F11) && !editSign && !shift)
                    {
                        int x = (int)((Convert.ToByte(ctlF11[1]) * 16f));
                        int y = (int)((Convert.ToByte(ctlF11[2]) * 16f) - 16f);

                        player[myPlayer].position = new Vector2(x, y);
                        Main.NewText("You have been teleported to " + ctlF11[0], Convert.ToByte(teleportMessages[0]), Convert.ToByte(teleportMessages[1]), Convert.ToByte(teleportMessages[2]));
                    }
                }

                if (ctlF12 != null)
                {
                    if (ctrl && keyState.IsKeyDown(Keys.F12) && oldKeyState.IsKeyUp(Keys.F12) && !editSign && !shift)
                    {
                        int x = (int)((Convert.ToByte(ctlF12[1]) * 16f));
                        int y = (int)((Convert.ToByte(ctlF12[2]) * 16f) - 16f);

                        player[myPlayer].position = new Vector2(x, y);
                        Main.NewText("You have been teleported to " + ctlF12[0], Convert.ToByte(teleportMessages[0]), Convert.ToByte(teleportMessages[1]), Convert.ToByte(teleportMessages[2]));
                    }
                }

                #endregion

                #region Display Coordinates

                if (keyState.IsKeyDown(Keys.I) && oldKeyState.IsKeyUp(Keys.I) && !editSign && !ctrl && !shift)
                {
                    int x = (int)((Main.mouseState.X + Main.screenPosition.X) / 16f);
                    int y = (int)((Main.mouseState.Y + Main.screenPosition.Y) / 16f);

                    Main.NewText("Your mouse currently points to " + x + ", " + y, Convert.ToByte(mouseCoords[0]), Convert.ToByte(mouseCoords[1]), Convert.ToByte(mouseCoords[2]));
                }

                #endregion

                #region System DateTime Display

                if (ctrl && keyState.IsKeyDown(Keys.T) && oldKeyState.IsKeyUp(Keys.T) && !editSign && !shift)
                {
                    Main.NewText("The current system time is " + DateTime.Now.ToString("t"), Convert.ToByte(timeMessage[0]), Convert.ToByte(timeMessage[1]), Convert.ToByte(timeMessage[2]));
                }

                #endregion

                #region Light Me (unlimited Shine Potion & Night Owl Potion buff)

                if (keyState.IsKeyDown(Keys.F) && !oldKeyState.IsKeyDown(Keys.F) && !editSign && !ctrl && !shift)
                {
                    lightMe = !lightMe;

                    if (displayMessages)
                    {
                        Main.NewText(lightMe == true ? "Let there be light!" : "You casually switch your headlamp off.", Convert.ToByte(lightMeToggle[0]), Convert.ToByte(lightMeToggle[1]), Convert.ToByte(lightMeToggle[2]));
                    }

                }
                if (lightMe)
                {
                    player[myPlayer].AddBuff(11, 50); // Shine effect
                    player[myPlayer].AddBuff(12, 50); // Night Owl effect
                }

                #endregion

                #region Display World Information

                if (alt && keyState.IsKeyDown(Keys.W) && oldKeyState.IsKeyUp(Keys.W) && !editSign && !shift)
                {
                    Main.NewText("World Name: " + worldName.ToString(), Convert.ToByte(otherToggles[0]), Convert.ToByte(otherToggles[1]), Convert.ToByte(otherToggles[2]));
                    Main.NewText("World ID: " + worldID.ToString(), Convert.ToByte(otherToggles[0]), Convert.ToByte(otherToggles[1]), Convert.ToByte(otherToggles[2]));
                }

                #endregion

                bool allowStuff = true; // Disallows most buildaria functionality in-game
                // Set to true if the user may not want certain functions to be happening
                try
                {
                    #region Allow Stuff Detection

                    // Detect if mouse is on a hotbar or inventory is open
                    for (int i = 0; i < 11; i++)
                    {
                        int x = (int)(20f + ((i * 0x38) * inventoryScale));
                        int y = (int)(20f + ((0 * 0x38) * inventoryScale));
                        int index = x;
                        if (((mouseState.X >= x) && (mouseState.X <= (x + (inventoryBackTexture.Width * inventoryScale)))) && ((mouseState.Y >= y) && (mouseState.Y <= (y + (inventoryBackTexture.Height * inventoryScale) + 2))))
                        {
                            i = 11;
                            allowStuff = false;
                            break;
                        }
                    }
                    if (playerInventory || !buildMode || editSign)
                        allowStuff = false;

                    #endregion

                    #region Place Anywhere

                    if (mouseState.LeftButton == ButtonState.Pressed && player[myPlayer].inventory[player[myPlayer].selectedItem].createTile >= 0 && allowStuff)
                    {
                        int x = (int)((Main.mouseState.X + Main.screenPosition.X) / 16f);
                        int y = (int)((Main.mouseState.Y + Main.screenPosition.Y) / 16f);

                        if (Main.tile[x, y].active == false)
                        {
                            byte wall = Main.tile[x, y].wall;
                            Main.tile[x, y] = new Tile();
                            Main.tile[x, y].type = (byte)player[myPlayer].inventory[player[myPlayer].selectedItem].createTile;
                            Main.tile[x, y].wall = wall;
                            Main.tile[x, y].active = true;
                            TileFrame(x, y);
                            SquareWallFrame(x, y, true);
                        }
                    }
                    else if (mouseState.LeftButton == ButtonState.Pressed && player[myPlayer].inventory[player[myPlayer].selectedItem].createWall >= 0 && allowStuff)
                    {
                        int x = (int)((Main.mouseState.X + Main.screenPosition.X) / 16f);
                        int y = (int)((Main.mouseState.Y + Main.screenPosition.Y) / 16f);

                        if (Main.tile[x, y].wall == 0)
                        {
                            if (Main.tile[x, y] == null)
                            {
                                Main.tile[x, y] = new Tile();
                                Main.tile[x, y].type = 0;
                            }

                            Main.tile[x, y].wall = (byte)player[myPlayer].inventory[player[myPlayer].selectedItem].createWall;
                            TileFrame(x, y);
                            SquareWallFrame(x, y, true);
                        }
                    }

                    #endregion

                    #region Inventory Change

                    if (!editSign && !ctrl && !shift)
                    {
                        if (keyState.IsKeyDown(Keys.OemOpenBrackets) && !oldKeyState.IsKeyDown(Keys.OemOpenBrackets) && !editSign)
                        {
                            if (saveInventoriesOnSwitch)
                            {
                                SaveInventory(inventoryType);
                            }
                            /*for (int i = 0; i < Inventories[inventoryType].Length; i++)
                            {
                                player[myPlayer].inventory[i].SetDefaults(Inventories[inventoryType][i].type);
                            }*/
                            LoadInventory(inventoryType - 1);
                        }
                        if (keyState.IsKeyDown(Keys.OemCloseBrackets) && !oldKeyState.IsKeyDown(Keys.OemCloseBrackets) && !editSign)
                        {
                            if (saveInventoriesOnSwitch)
                            {
                                SaveInventory(inventoryType);
                            }
                            /*for (int i = 0; i < Inventories[inventoryType].Length; i++)
                            {
                                player[myPlayer].inventory[i].SetDefaults(Inventories[inventoryType][i].type);
                            }*/
                            LoadInventory(inventoryType + 1);
                        }
                    }

                    #endregion

                    #region Selection Modifications

                    #region Copy/Paste

                    if (ctrl && keyState.IsKeyDown(Keys.C) && oldKeyState.IsKeyUp(Keys.C) && !editSign)
                    {
                        Copied = new Tile[SelectionSize.X, SelectionSize.Y];
                        CopiedSize = new Point(SelectionSize.X, SelectionSize.Y);
                        for (int x = 0; x < SelectionSize.X; x++)
                        {
                            for (int y = 0; y < SelectionSize.Y; y++)
                            {
                                int copyX = x;
                                int copyY = y;
                                if (shift)
                                {
                                    copyX = Math.Abs(copyX - SelectionSize.X);
                                }
                                if (alt)
                                {
                                    copyY = Math.Abs(copyY - SelectionSize.Y);
                                }
                                Copied[copyX, copyY] = new Tile();
                                Copied[copyX, copyY].type = tile[x + SelectionPosition.X, y + SelectionPosition.Y].type;
                                Copied[copyX, copyY].active = tile[x + SelectionPosition.X, y + SelectionPosition.Y].active;
                                Copied[copyX, copyY].wall = tile[x + SelectionPosition.X, y + SelectionPosition.Y].wall;
                                Copied[copyX, copyY].liquid = tile[x + SelectionPosition.X, y + SelectionPosition.Y].liquid;
                                Copied[copyX, copyY].lava = tile[x + SelectionPosition.X, y + SelectionPosition.Y].lava;
                                Copied[copyX, copyY].wire = tile[x + SelectionPosition.X, y + SelectionPosition.Y].wire;
                            }
                        }

                        if (displayMessages)
                        {
                            Main.NewText("Copied Selection", Convert.ToByte(selectionMessages[0]), Convert.ToByte(selectionMessages[1]), Convert.ToByte(selectionMessages[2]));
                        }
                    }

                    if (ctrl && keyState.IsKeyDown(Keys.V) && oldKeyState.IsKeyUp(Keys.V) && !editSign)
                    {
                        if (sel1 != -Vector2.One && sel2 != -Vector2.One)
                        {
                            Undo = new Tile[CopiedSize.X, CopiedSize.Y];
                            UndoPosition = new Point((int)sel1.X, (int)sel1.Y);
                            UndoSize = new Point(CopiedSize.X, CopiedSize.Y);
                            for (int x = 0; x < CopiedSize.X; x++)
                            {
                                for (int y = 0; y < CopiedSize.Y; y++)
                                {
                                    try
                                    {
                                        if (Main.tile[x, y] == null)
                                        {
                                            Main.tile[x, y] = new Tile();
                                            Undo[x, y] = null;
                                        }
                                        else
                                        {
                                            Undo[x, y] = new Tile();
                                            Undo[x, y].type = Main.tile[x, y].type;
                                            Undo[x, y].liquid = Main.tile[x, y].liquid;
                                            Undo[x, y].lava = Main.tile[x, y].lava;
                                            Undo[x, y].wall = Main.tile[x, y].wall;
                                            Undo[x, y].active = Main.tile[x, y].active;
                                            Undo[x, y].wire = Main.tile[x, y].wire;
                                        }

                                        int copyX = x;
                                        int copyY = y;
                                        if (shift)
                                        {
                                            copyX = Math.Abs(copyX - CopiedSize.X);
                                        }
                                        if (alt)
                                        {
                                            copyY = Math.Abs(copyY - CopiedSize.Y);
                                        }
                                        tile[(int)sel1.X + x, (int)sel1.Y + y] = new Tile();
                                        tile[(int)sel1.X + x, (int)sel1.Y + y].type = Copied[copyX, copyY].type;
                                        tile[(int)sel1.X + x, (int)sel1.Y + y].active = Copied[copyX, copyY].active;
                                        tile[(int)sel1.X + x, (int)sel1.Y + y].wall = Copied[copyX, copyY].wall;
                                        tile[(int)sel1.X + x, (int)sel1.Y + y].liquid = Copied[copyX, copyY].liquid;
                                        tile[(int)sel1.X + x, (int)sel1.Y + y].lava = Copied[copyX, copyY].lava;
                                        tile[(int)sel1.X + x, (int)sel1.Y + y].wire = Copied[copyX, copyY].wire;
                                        TileFrame((int)sel1.X + x, (int)sel1.Y + y);
                                        SquareWallFrame((int)sel1.X + x, (int)sel1.Y + y);
                                    }
                                    catch
                                    {

                                    }
                                }
                            }
                        }

                        if (displayMessages)
                        {
                            Main.NewText("Pasted Selection", Convert.ToByte(selectionMessages[0]), Convert.ToByte(selectionMessages[1]), Convert.ToByte(selectionMessages[2]));
                        }
                    }

                    #endregion

                    #region Erasers

                    else if (mouseState.RightButton == ButtonState.Pressed && oldMouseState.RightButton == ButtonState.Released && player[myPlayer].inventory[player[myPlayer].selectedItem].pick >= 55)
                    {
                        Undo = new Tile[SelectionSize.X, SelectionSize.Y];
                        UndoPosition = new Point((int)sel1.X, (int)sel1.Y);
                        UndoSize = new Point(SelectionSize.X, SelectionSize.Y);
                        for (int xp = 0; xp < SelectionSize.X; xp++)
                        {
                            for (int yp = 0; yp < SelectionSize.Y; yp++)
                            {
                                int x = xp + SelectionPosition.X;
                                int y = yp + SelectionPosition.Y;
                                if (SelectedTiles[xp, yp])
                                {
                                    if (Main.tile[x, y] == null)
                                    {
                                        Main.tile[x, y] = new Tile();
                                        Undo[xp, yp] = null;
                                    }
                                    else
                                    {
                                        Undo[xp, yp] = new Tile();
                                        Undo[xp, yp].type = Main.tile[x, y].type;
                                        Undo[xp, yp].liquid = Main.tile[x, y].liquid;
                                        Undo[xp, yp].lava = Main.tile[x, y].lava;
                                        Undo[xp, yp].wall = Main.tile[x, y].wall;
                                        Undo[xp, yp].active = Main.tile[x, y].active;
                                    }

                                    byte wall = Main.tile[x, y].wall;
                                    Main.tile[x, y].type = 0;
                                    Main.tile[x, y].active = false;
                                    Main.tile[x, y].wall = wall;
                                    TileFrame(x, y);
                                    TileFrame(x, y - 1);
                                    TileFrame(x, y + 1);
                                    TileFrame(x - 1, y);
                                    TileFrame(x + 1, y);
                                    SquareWallFrame(x, y, true);
                                }
                            }
                        }

                        if (sel1 != -Vector2.One && sel2 != -Vector2.One && displayMessages)
                            Main.NewText("Cleared Selection of Blocks", Convert.ToByte(selectionMessages[0]), Convert.ToByte(selectionMessages[1]), Convert.ToByte(selectionMessages[2]));
                    }
                    else if (mouseState.RightButton == ButtonState.Pressed && oldMouseState.RightButton == ButtonState.Released && player[myPlayer].inventory[player[myPlayer].selectedItem].hammer >= 55)
                    {
                        Undo = new Tile[SelectionSize.X, SelectionSize.Y];
                        UndoPosition = new Point((int)sel1.X, (int)sel1.Y);
                        UndoSize = new Point(SelectionSize.X, SelectionSize.Y);
                        for (int xp = 0; xp < SelectionSize.X; xp++)
                        {
                            for (int yp = 0; yp < SelectionSize.Y; yp++)
                            {
                                int x = xp + SelectionPosition.X;
                                int y = yp + SelectionPosition.Y;
                                if (SelectedTiles[xp, yp])
                                {
                                    if (Main.tile[x, y] == null)
                                    {
                                        Main.tile[x, y] = new Tile();
                                        Undo[xp, yp] = null;
                                    }
                                    else
                                    {
                                        Undo[xp, yp] = new Tile();
                                        Undo[xp, yp].type = Main.tile[x, y].type;
                                        Undo[xp, yp].liquid = Main.tile[x, y].liquid;
                                        Undo[xp, yp].lava = Main.tile[x, y].lava;
                                        Undo[xp, yp].wall = Main.tile[x, y].wall;
                                        Undo[xp, yp].active = Main.tile[x, y].active;
                                    }

                                    Main.tile[x, y].wall = 0;
                                    TileFrame(x, y);
                                    TileFrame(x, y - 1);
                                    TileFrame(x, y + 1);
                                    TileFrame(x - 1, y);
                                    TileFrame(x + 1, y);
                                    SquareWallFrame(x, y, true);
                                }
                            }
                        }

                        if (displayMessages)
                        {
                            Main.NewText("Cleared Selection of Walls", Convert.ToByte(selectionMessages[0]), Convert.ToByte(selectionMessages[1]), Convert.ToByte(selectionMessages[2]));
                        }
                    }

                    #endregion

                    #region Liquid (Fill/Erase)

                    else if (mouseState.RightButton == ButtonState.Pressed && oldMouseState.RightButton == ButtonState.Released && player[myPlayer].inventory[player[myPlayer].selectedItem].type == 0xcf)
                    {
                        Undo = new Tile[SelectionSize.X, SelectionSize.Y];
                        UndoPosition = new Point((int)sel1.X, (int)sel1.Y);
                        UndoSize = new Point(SelectionSize.X, SelectionSize.Y);
                        for (int xp = 0; xp < SelectionSize.X; xp++)
                        {
                            for (int yp = 0; yp < SelectionSize.Y; yp++)
                            {
                                int x = xp + SelectionPosition.X;
                                int y = yp + SelectionPosition.Y;
                                if (SelectedTiles[xp, yp])
                                {
                                    if (Main.tile[x, y] == null)
                                    {
                                        Main.tile[x, y] = new Tile();
                                        Undo[xp, yp] = null;
                                    }
                                    else
                                    {
                                        Undo[xp, yp] = new Tile();
                                        Undo[xp, yp].type = Main.tile[x, y].type;
                                        Undo[xp, yp].liquid = Main.tile[x, y].liquid;
                                        Undo[xp, yp].lava = Main.tile[x, y].lava;
                                        Undo[xp, yp].wall = Main.tile[x, y].wall;
                                        Undo[xp, yp].active = Main.tile[x, y].active;
                                    }

                                    Main.tile[x, y].liquid = 255;
                                    Main.tile[x, y].lava = true;
                                    TileFrame(x, y);
                                    SquareWallFrame(x, y, true);
                                }
                            }
                        }

                        if (displayMessages)
                        {
                            Main.NewText("Filled Selection with Lava", Convert.ToByte(selectionMessages[0]), Convert.ToByte(selectionMessages[1]), Convert.ToByte(selectionMessages[2]));
                        }
                    }
                    else if (mouseState.RightButton == ButtonState.Pressed && oldMouseState.RightButton == ButtonState.Released && player[myPlayer].inventory[player[myPlayer].selectedItem].type == 0xce)
                    {
                        Undo = new Tile[SelectionSize.X, SelectionSize.Y];
                        UndoPosition = new Point((int)sel1.X, (int)sel1.Y);
                        UndoSize = new Point(SelectionSize.X, SelectionSize.Y);
                        for (int xp = 0; xp < SelectionSize.X; xp++)
                        {
                            for (int yp = 0; yp < SelectionSize.Y; yp++)
                            {
                                int x = xp + SelectionPosition.X;
                                int y = yp + SelectionPosition.Y;
                                if (SelectedTiles[xp, yp])
                                {
                                    if (Main.tile[x, y] == null)
                                    {
                                        Main.tile[x, y] = new Tile();
                                        Undo[xp, yp] = null;
                                    }
                                    else
                                    {
                                        Undo[xp, yp] = new Tile();
                                        Undo[xp, yp].type = Main.tile[x, y].type;
                                        Undo[xp, yp].liquid = Main.tile[x, y].liquid;
                                        Undo[xp, yp].lava = Main.tile[x, y].lava;
                                        Undo[xp, yp].wall = Main.tile[x, y].wall;
                                        Undo[xp, yp].active = Main.tile[x, y].active;
                                    }

                                    Main.tile[x, y].liquid = 255;
                                    Main.tile[x, y].lava = false;
                                    TileFrame(x, y);
                                    SquareWallFrame(x, y, true);
                                }
                            }
                        }

                        if (displayMessages)
                        {
                            Main.NewText("Filled Selection with Water", Convert.ToByte(selectionMessages[0]), Convert.ToByte(selectionMessages[1]), Convert.ToByte(selectionMessages[2]));
                        }
                    }
                    else if (mouseState.RightButton == ButtonState.Pressed && oldMouseState.RightButton == ButtonState.Released && player[myPlayer].inventory[player[myPlayer].selectedItem].type == 0xcd)
                    {
                        Undo = new Tile[SelectionSize.X, SelectionSize.Y];
                        UndoPosition = new Point((int)sel1.X, (int)sel1.Y);
                        UndoSize = new Point(SelectionSize.X, SelectionSize.Y);
                        for (int xp = 0; xp < SelectionSize.X; xp++)
                        {
                            for (int yp = 0; yp < SelectionSize.Y; yp++)
                            {
                                int x = xp + SelectionPosition.X;
                                int y = yp + SelectionPosition.Y;
                                if (SelectedTiles[xp, yp])
                                {
                                    if (Main.tile[x, y] == null)
                                    {
                                        Main.tile[x, y] = new Tile();
                                        Undo[xp, yp] = null;
                                    }
                                    else
                                    {
                                        Undo[xp, yp] = new Tile();
                                        Undo[xp, yp].type = Main.tile[x, y].type;
                                        Undo[xp, yp].liquid = Main.tile[x, y].liquid;
                                        Undo[xp, yp].lava = Main.tile[x, y].lava;
                                        Undo[xp, yp].wall = Main.tile[x, y].wall;
                                        Undo[xp, yp].active = Main.tile[x, y].active;
                                    }

                                    Main.tile[x, y].liquid = 0;
                                    Main.tile[x, y].lava = false;
                                    TileFrame(x, y);
                                    SquareWallFrame(x, y, true);
                                }
                            }
                        }

                        if (displayMessages)
                        {
                            Main.NewText("Drained Selection of Liquid", 50, 50, 255);
                        }
                    }

                    #endregion

                    #region Fills

                    if (mouseState.RightButton == ButtonState.Pressed && oldMouseState.RightButton == ButtonState.Released && player[myPlayer].inventory[player[myPlayer].selectedItem].createTile >= 0)
                    {
                        Undo = new Tile[SelectionSize.X, SelectionSize.Y];
                        UndoPosition = new Point((int)sel1.X, (int)sel1.Y);
                        UndoSize = new Point(SelectionSize.X, SelectionSize.Y);
                        for (int xp = 0; xp < SelectionSize.X; xp++)
                        {
                            for (int yp = 0; yp < SelectionSize.Y; yp++)
                            {
                                int x = xp + SelectionPosition.X;
                                int y = yp + SelectionPosition.Y;
                                if (SelectedTiles[xp, yp])
                                {
                                    if (Main.tile[x, y] == null)
                                    {
                                        Undo[xp, yp] = null;
                                    }
                                    else
                                    {
                                        Undo[xp, yp] = new Tile();
                                        Undo[xp, yp].type = Main.tile[x, y].type;
                                        Undo[xp, yp].liquid = Main.tile[x, y].liquid;
                                        Undo[xp, yp].lava = Main.tile[x, y].lava;
                                        Undo[xp, yp].wall = Main.tile[x, y].wall;
                                        Undo[xp, yp].active = Main.tile[x, y].active;
                                        Undo[xp, yp].wire = Main.tile[x, y].wire;
                                    }

                                    byte wall = Main.tile[x, y].wall;
                                    Main.tile[x, y] = new Tile();
                                    Main.tile[x, y].type = (byte)player[myPlayer].inventory[player[myPlayer].selectedItem].createTile;
                                    Main.tile[x, y].wall = wall;
                                    Main.tile[x, y].active = true;
                                    TileFrame(x, y);
                                    SquareWallFrame(x, y, true);
                                }
                            }
                        }

                        if (displayMessages)
                        {
                            Main.NewText("Filled Selection with " + player[myPlayer].inventory[player[myPlayer].selectedItem].name + "s", Convert.ToByte(selectionMessages[0]), Convert.ToByte(selectionMessages[1]), Convert.ToByte(selectionMessages[2]));
                        }
                    }
                    else if (mouseState.RightButton == ButtonState.Pressed && oldMouseState.RightButton == ButtonState.Released && player[myPlayer].inventory[player[myPlayer].selectedItem].createWall >= 0)
                    {
                        Undo = new Tile[SelectionSize.X, SelectionSize.Y];
                        UndoPosition = new Point((int)sel1.X, (int)sel1.Y);
                        UndoSize = new Point(SelectionSize.X, SelectionSize.Y);
                        for (int xp = 0; xp < SelectionSize.X; xp++)
                        {
                            for (int yp = 0; yp < SelectionSize.Y; yp++)
                            {
                                int x = xp + SelectionPosition.X;
                                int y = yp + SelectionPosition.Y;

                                if (Main.tile[x, y] == null)
                                {
                                    Undo[xp, yp] = null;
                                }
                                else
                                {
                                    Undo[xp, yp] = new Tile();
                                    Undo[xp, yp].type = Main.tile[x, y].type;
                                    Undo[xp, yp].liquid = Main.tile[x, y].liquid;
                                    Undo[xp, yp].lava = Main.tile[x, y].lava;
                                    Undo[xp, yp].wall = Main.tile[x, y].wall;
                                    Undo[xp, yp].active = Main.tile[x, y].active;
                                    Undo[xp, yp].wire = Main.tile[x, y].wire;
                                }

                                if (SelectedTiles[xp, yp])
                                {
                                    if (Main.tile[x, y] == null)
                                    {
                                        Main.tile[x, y] = new Tile();
                                        Main.tile[x, y].type = 0;
                                    }

                                    Main.tile[x, y].wall = (byte)player[myPlayer].inventory[player[myPlayer].selectedItem].createWall;
                                    TileFrame(x, y);
                                    SquareWallFrame(x, y, true);
                                }
                            }
                        }

                        if (displayMessages)
                        {
                            Main.NewText("Filled Selection with " + player[myPlayer].inventory[player[myPlayer].selectedItem].name + "s", Convert.ToByte(selectionMessages[0]), Convert.ToByte(selectionMessages[1]), Convert.ToByte(selectionMessages[2]));
                        }
                    }

                    #endregion

                    #region Undo

                    if (ctrl && keyState.IsKeyDown(Keys.Z) && oldKeyState.IsKeyUp(Keys.Z) && !editSign)
                    {
                        for (int xp = 0; xp < UndoSize.X; xp++)
                        {
                            for (int yp = 0; yp < UndoSize.Y; yp++)
                            {
                                int x = xp + UndoPosition.X;
                                int y = yp + UndoPosition.Y;

                                if (Undo[xp, yp] == null)
                                    tile[x, y] = null;
                                else
                                {
                                    tile[x, y] = new Tile();
                                    tile[x, y].type = Undo[xp, yp].type;
                                    tile[x, y].active = Undo[xp, yp].active;
                                    tile[x, y].wall = Undo[xp, yp].wall;
                                    tile[x, y].liquid = Undo[xp, yp].liquid;
                                    tile[x, y].lava = Undo[xp, yp].lava;
                                    tile[x, y].wire = Undo[xp, yp].wire;
                                    TileFrame(x, y);
                                    SquareWallFrame(x, y);
                                }
                            }
                        }

                        if (displayMessages)
                        {
                            Main.NewText("Undo Complete", Convert.ToByte(undoMessage[0]), Convert.ToByte(undoMessage[1]), Convert.ToByte(undoMessage[2]));
                        }
                    }

                    #endregion

                    #endregion

                    UpdateSelection();

                    if (allowStuff)
                    {
                        #region Alt For Circles

                        if (alt && mouseState.LeftButton == ButtonState.Released)
                        {
                            for (int x = 0; x < SelectionSize.X; x++)
                            {
                                for (int y = 0; y < SelectionSize.Y; y++)
                                {
                                    SelectedTiles[x, y] = false;
                                }
                            }
                            Vector2 center = new Vector2(SelectionSize.X / 2f, SelectionSize.Y / 2f);
                            for (int x = 0; x < SelectionSize.X; x++)
                            {
                                for (int y = 0; y < SelectionSize.Y; y++)
                                {
                                    double dx = (x - center.X + 1) / center.X;
                                    double dy = (y - center.Y + 1) / center.Y;
                                    if (dx * dx + dy * dy < 1)
                                    {
                                        SelectedTiles[x, y] = true;
                                    }
                                }
                            }
                        }

                        #endregion

                        #region Shift For Outline

                        if (shift && mouseState.LeftButton == ButtonState.Released)
                        {
                            bool[,] tempTiles = new bool[SelectionSize.X, SelectionSize.Y];
                            for (int x = 0; x < SelectionSize.X; x++)
                            {
                                for (int y = 0; y < SelectionSize.Y; y++)
                                {
                                    tempTiles[x, y] = SelectedTiles[x, y];
                                }
                            }
                            for (int x = 0; x < SelectionSize.X; x++)
                            {
                                bool found1 = false;
                                bool found2 = false;
                                for (int y = 0; y < SelectionSize.Y; y++)
                                {
                                    if (!found1)
                                    {
                                        found1 = SelectedTiles[x, y];
                                        continue;
                                    }
                                    else if (!found2)
                                    {
                                        if (y + 1 > SelectionSize.Y - 1)
                                        {
                                            found2 = SelectedTiles[x, y];
                                            break;
                                        }
                                        else if (!found2 && !SelectedTiles[x, y + 1])
                                        {
                                            found2 = SelectedTiles[x, y];
                                            break;
                                        }
                                        else
                                        {
                                            SelectedTiles[x, y] = false;
                                        }
                                    }
                                    else if (found1 && found2)
                                        break;
                                }
                            }
                            for (int y = 0; y < SelectionSize.Y; y++)
                            {
                                bool found1 = false;
                                bool found2 = false;
                                for (int x = 0; x < SelectionSize.X; x++)
                                {
                                    if (!found1)
                                    {
                                        found1 = tempTiles[x, y];
                                        continue;
                                    }
                                    else if (!found2)
                                    {
                                        if (x + 1 > SelectionSize.X - 1)
                                        {
                                            found2 = tempTiles[x, y];
                                            break;
                                        }
                                        else if (!found2 && !tempTiles[x + 1, y])
                                        {
                                            found2 = tempTiles[x, y];
                                            break;
                                        }
                                        else
                                        {
                                            tempTiles[x, y] = false;
                                        }
                                    }
                                    else if (found1 && found2)
                                        break;
                                }
                            }
                            for (int x = 0; x < SelectionSize.X; x++)
                            {
                                for (int y = 0; y < SelectionSize.Y; y++)
                                {
                                    SelectedTiles[x, y] = SelectedTiles[x, y] || tempTiles[x, y];
                                }
                            }
                        }

                        #endregion

                        #region Day/Night Skip

                        if (keyState.IsKeyDown(Keys.N) && !oldKeyState.IsKeyDown(Keys.N) && !editSign)
                        {
                            if (dayTime)
                            {
                                time = dayLength + 1;

                                if (displayMessages)
                                {
                                    Main.NewText("You have bent time. The sun is now setting.", Convert.ToByte(otherToggles[0]), Convert.ToByte(otherToggles[1]), Convert.ToByte(otherToggles[2]));
                                }
                            }
                            else
                            {
                                if (displayMessages)
                                {
                                    Main.NewText("You have bent time. The sun is now rising.", Convert.ToByte(otherToggles[0]), Convert.ToByte(otherToggles[1]), Convert.ToByte(otherToggles[2]));
                                }
                                time = nightLength;
                            }
                        }

                        #endregion

                    }
                }
                catch
                {

                }
            }
            oldMenuMode = menuMode;
            lastPosition = player[myPlayer].position;
            oldKeyState = keyState;
        }
Ejemplo n.º 22
0
        public static void WallFrame(int i, int j, bool resetFrame = false)
        {
            if (WorldGen.SkipFramingBecauseOfGen || i <= 0 || j <= 0 || i >= Main.maxTilesX - 1 || j >= Main.maxTilesY - 1 || Main.tile[i, j] == null)
            {
                return;
            }
            WorldGen.UpdateMapTile(i, j);
            Tile tile = Main.tile[i, j];

            if (tile.wall == 0)
            {
                tile.wallColor(0);
                return;
            }
            int num = 0;

            if (j - 1 >= 0)
            {
                Tile tile2 = Main.tile[i, j - 1];
                if (tile2 != null && (tile2.wall > 0 || (tile2.active() && tile2.type == 54)))
                {
                    num = 1;
                }
            }
            if (i - 1 >= 0)
            {
                Tile tile2 = Main.tile[i - 1, j];
                if (tile2 != null && (tile2.wall > 0 || (tile2.active() && tile2.type == 54)))
                {
                    num |= 2;
                }
            }
            if (i + 1 <= Main.maxTilesX - 1)
            {
                Tile tile2 = Main.tile[i + 1, j];
                if (tile2 != null && (tile2.wall > 0 || (tile2.active() && tile2.type == 54)))
                {
                    num |= 4;
                }
            }
            if (j + 1 <= Main.maxTilesY - 1)
            {
                Tile tile2 = Main.tile[i, j + 1];
                if (tile2 != null && (tile2.wall > 0 || (tile2.active() && tile2.type == 54)))
                {
                    num |= 8;
                }
            }
            int num2 = 0;

            if (Main.wallLargeFrames[tile.wall] == 1)
            {
                num2 = phlebasTileFrameNumberLookup[j % 4][i % 3] - 1;
                tile.wallFrameNumber((byte)num2);
            }
            else if (Main.wallLargeFrames[tile.wall] == 2)
            {
                num2 = lazureTileFrameNumberLookup[i % 2][j % 2] - 1;
                tile.wallFrameNumber((byte)num2);
            }
            else if (resetFrame)
            {
                num2 = WorldGen.genRand.Next(0, 3);
                if (tile.wall == 21 && WorldGen.genRand.Next(2) == 0)
                {
                    num2 = 2;
                }
                tile.wallFrameNumber((byte)num2);
            }
            else
            {
                num2 = tile.wallFrameNumber();
            }
            if (num == 15)
            {
                num += centerWallFrameLookup[i % 3][j % 3];
            }
            Point16 point = wallFrameLookup[num][num2];

            tile.wallFrameX(point.X);
            tile.wallFrameY(point.Y);
        }
Ejemplo n.º 23
0
 public Tiles(Tile Maintile, Point Loc)
 {
     this.maintile = Maintile;
      this.loc = Loc;
 }
Ejemplo n.º 24
0
 public static BitsByte TrackCollision(ref Vector2 Position, ref Vector2 Velocity, ref Vector2 lastBoost, int Width, int Height, bool followDown, bool followUp, int fallStart, bool trackOnly)
 {
     int num;
     int num1;
     Matrix matrix;
     Minecart.TrackState trackState;
     if (followDown && followUp)
     {
         followDown = false;
         followUp = false;
     }
     Vector2 vector2 = new Vector2((float)(Width / 2) - 25f, (float)(Height / 2));
     Vector2 position = Position + new Vector2((float)(Width / 2) - 25f, (float)(Height / 2));
     Vector2 vector21 = position + Minecart._trackMagnetOffset;
     Vector2 velocity = Velocity;
     float x = velocity.Length();
     velocity.Normalize();
     Vector2 y = vector21;
     Tile tile = null;
     bool flag = false;
     bool flag1 = true;
     int num2 = -1;
     int num3 = -1;
     int num4 = -1;
     Minecart.TrackState trackState1 = Minecart.TrackState.NoTrack;
     bool flag2 = false;
     bool flag3 = false;
     bool flag4 = false;
     bool flag5 = false;
     Vector2 zero = Vector2.Zero;
     Vector2 zero1 = Vector2.Zero;
     BitsByte bitsByte = new BitsByte();
     while (true)
     {
         int x1 = (int)(y.X / 16f);
         int y1 = (int)(y.Y / 16f);
         int x2 = (int)y.X % 16 / 2;
         if (flag1)
         {
             num4 = x2;
         }
         bool flag6 = x2 != num4;
         if ((trackState1 == Minecart.TrackState.OnBack || trackState1 == Minecart.TrackState.OnTrack || trackState1 == Minecart.TrackState.OnFront) && x1 != num2)
         {
             num = (trackState1 != Minecart.TrackState.OnBack ? tile.FrontTrack() : tile.BackTrack());
             num1 = (velocity.X >= 0f ? Minecart._rightSideConnection[num] : Minecart._leftSideConnection[num]);
             switch (num1)
             {
                 case 0:
                 {
                     y1--;
                     y.Y = y.Y - 2f;
                     break;
                 }
                 case 2:
                 {
                     y1++;
                     y.Y = y.Y + 2f;
                     break;
                 }
             }
         }
         Minecart.TrackState trackState2 = Minecart.TrackState.NoTrack;
         bool flag7 = false;
         if (x1 != num2 || y1 != num3)
         {
             if (!flag1)
             {
                 flag7 = true;
             }
             else
             {
                 flag1 = false;
             }
             tile = Main.tile[x1, y1];
             if (tile == null)
             {
                 tile = new Tile();
                 Main.tile[x1, y1] = tile;
             }
             flag = (!tile.nactive() || tile.type != 314 ? false : true);
         }
         if (flag)
         {
             Minecart.TrackState trackState3 = Minecart.TrackState.NoTrack;
             int num5 = tile.FrontTrack();
             int num6 = tile.BackTrack();
             int num7 = Minecart._tileHeight[num5][x2];
             switch (num7)
             {
                 case -4:
                 {
                     if (trackState1 != Minecart.TrackState.OnFront)
                     {
                         break;
                     }
                     if (!trackOnly)
                     {
                         trackState2 = Minecart.TrackState.NoTrack;
                         flag4 = true;
                         break;
                     }
                     else
                     {
                         y = y - zero1;
                         x = 0f;
                         trackState2 = Minecart.TrackState.OnFront;
                         flag5 = true;
                         break;
                     }
                 }
                 case -3:
                 {
                     if (trackState1 != Minecart.TrackState.OnFront)
                     {
                         break;
                     }
                     trackState1 = Minecart.TrackState.NoTrack;
                     if (Velocity.X <= 0f)
                     {
                         matrix = (Minecart._rightSideConnection[num5] != 2 ? Matrix.CreateRotationZ(-0.7853982f) : Matrix.CreateRotationZ(0.7853982f));
                     }
                     else
                     {
                         matrix = (Minecart._leftSideConnection[num5] != 2 ? Matrix.CreateRotationZ(0.7853982f) : Matrix.CreateRotationZ(-0.7853982f));
                     }
                     zero = Vector2.Transform(new Vector2(Velocity.X, 0f), matrix);
                     zero.X = Velocity.X;
                     flag3 = true;
                     x = 0f;
                     break;
                 }
                 case -2:
                 {
                     if (trackState1 != Minecart.TrackState.OnFront)
                     {
                         break;
                     }
                     if (!trackOnly)
                     {
                         if (velocity.X < 0f)
                         {
                             float single = (float)(x1 * 16 + (x2 + 1) * 2) - y.X;
                             y.X = y.X + single;
                             x = x + single / velocity.X;
                         }
                         velocity.X = -velocity.X;
                         bitsByte[1] = true;
                         trackState2 = Minecart.TrackState.OnFront;
                         break;
                     }
                     else
                     {
                         y = y - zero1;
                         x = 0f;
                         trackState2 = Minecart.TrackState.OnFront;
                         flag5 = true;
                         break;
                     }
                 }
                 case -1:
                 {
                     if (trackState1 != Minecart.TrackState.OnFront)
                     {
                         break;
                     }
                     y = y - zero1;
                     x = 0f;
                     trackState2 = Minecart.TrackState.OnFront;
                     flag5 = true;
                     break;
                 }
                 default:
                 {
                     float single1 = (float)(y1 * 16 + num7);
                     if (x1 != num2 && trackState1 == Minecart.TrackState.NoTrack && y.Y > single1 && y.Y - single1 < 2f)
                     {
                         flag7 = false;
                         trackState1 = Minecart.TrackState.AboveFront;
                     }
                     if (y.Y >= single1)
                     {
                         trackState = (y.Y <= single1 ? Minecart.TrackState.OnTrack : Minecart.TrackState.BelowTrack);
                     }
                     else
                     {
                         trackState = Minecart.TrackState.AboveTrack;
                     }
                     if (num6 != -1)
                     {
                         float single2 = (float)(y1 * 16 + Minecart._tileHeight[num6][x2]);
                         if (y.Y >= single2)
                         {
                             trackState3 = (y.Y <= single2 ? Minecart.TrackState.OnTrack : Minecart.TrackState.BelowTrack);
                         }
                         else
                         {
                             trackState3 = Minecart.TrackState.AboveTrack;
                         }
                     }
                     switch (trackState)
                     {
                         case Minecart.TrackState.AboveTrack:
                         {
                             switch (trackState3)
                             {
                                 case Minecart.TrackState.AboveTrack:
                                 {
                                     trackState2 = Minecart.TrackState.AboveTrack;
                                     break;
                                 }
                                 case Minecart.TrackState.OnTrack:
                                 {
                                     trackState2 = Minecart.TrackState.OnBack;
                                     break;
                                 }
                                 case Minecart.TrackState.BelowTrack:
                                 {
                                     trackState2 = Minecart.TrackState.AboveFront;
                                     break;
                                 }
                                 default:
                                 {
                                     trackState2 = Minecart.TrackState.AboveFront;
                                     break;
                                 }
                             }
                             break;
                         }
                         case Minecart.TrackState.OnTrack:
                         {
                             trackState2 = (trackState3 != Minecart.TrackState.OnTrack ? Minecart.TrackState.OnFront : Minecart.TrackState.OnTrack);
                             break;
                         }
                         case Minecart.TrackState.BelowTrack:
                         {
                             switch (trackState3)
                             {
                                 case Minecart.TrackState.AboveTrack:
                                 {
                                     trackState2 = Minecart.TrackState.AboveBack;
                                     break;
                                 }
                                 case Minecart.TrackState.OnTrack:
                                 {
                                     trackState2 = Minecart.TrackState.OnBack;
                                     break;
                                 }
                                 case Minecart.TrackState.BelowTrack:
                                 {
                                     trackState2 = Minecart.TrackState.BelowTrack;
                                     break;
                                 }
                                 default:
                                 {
                                     trackState2 = Minecart.TrackState.BelowTrack;
                                     break;
                                 }
                             }
                             break;
                         }
                     }
                     break;
                 }
             }
         }
         if (!flag7)
         {
             if (trackState1 != trackState2)
             {
                 bool flag8 = false;
                 if (flag6 || velocity.Y > 0f)
                 {
                     switch (trackState1)
                     {
                         case Minecart.TrackState.AboveTrack:
                         {
                             switch (trackState2)
                             {
                                 case Minecart.TrackState.AboveTrack:
                                 {
                                     trackState2 = Minecart.TrackState.OnTrack;
                                     break;
                                 }
                                 case Minecart.TrackState.AboveFront:
                                 {
                                     trackState2 = Minecart.TrackState.OnBack;
                                     break;
                                 }
                                 case Minecart.TrackState.AboveBack:
                                 {
                                     trackState2 = Minecart.TrackState.OnFront;
                                     break;
                                 }
                                 default:
                                 {
                                     break;
                                 }
                             }
                             goto case Minecart.TrackState.BelowTrack;
                         }
                         case Minecart.TrackState.OnTrack:
                         {
                             int num8 = Minecart._tileHeight[tile.FrontTrack()][x2];
                             int num9 = Minecart._tileHeight[tile.BackTrack()][x2];
                             if (followDown)
                             {
                                 trackState2 = (num8 >= num9 ? Minecart.TrackState.OnFront : Minecart.TrackState.OnBack);
                             }
                             else if (!followUp)
                             {
                                 trackState2 = Minecart.TrackState.OnFront;
                             }
                             else
                             {
                                 trackState2 = (num8 >= num9 ? Minecart.TrackState.OnBack : Minecart.TrackState.OnFront);
                             }
                             flag8 = true;
                             goto case Minecart.TrackState.BelowTrack;
                         }
                         case Minecart.TrackState.BelowTrack:
                         {
                             int num10 = -1;
                             Minecart.TrackState trackState4 = trackState2;
                             if (trackState4 != Minecart.TrackState.OnTrack)
                             {
                                 switch (trackState4)
                                 {
                                     case Minecart.TrackState.OnFront:
                                     {
                                         break;
                                     }
                                     case Minecart.TrackState.OnBack:
                                     {
                                         num10 = tile.BackTrack();
                                         goto Label1;
                                     }
                                     default:
                                     {
                                         goto Label1;
                                     }
                                 }
                             }
                             num10 = tile.FrontTrack();
                         Label1:
                             if (num10 == -1)
                             {
                                 break;
                             }
                             if (trackState1 == Minecart.TrackState.AboveFront && Minecart._trackType[num10] == 1)
                             {
                                 flag2 = true;
                             }
                             velocity.Y = 0f;
                             y.Y = (float)(y1 * 16 + Minecart._tileHeight[num10][x2]);
                             break;
                         }
                         case Minecart.TrackState.AboveFront:
                         {
                             if (trackState2 != Minecart.TrackState.BelowTrack)
                             {
                                 goto case Minecart.TrackState.BelowTrack;
                             }
                             trackState2 = Minecart.TrackState.OnFront;
                             goto case Minecart.TrackState.BelowTrack;
                         }
                         case Minecart.TrackState.AboveBack:
                         {
                             if (trackState2 != Minecart.TrackState.BelowTrack)
                             {
                                 goto case Minecart.TrackState.BelowTrack;
                             }
                             trackState2 = Minecart.TrackState.OnBack;
                             goto case Minecart.TrackState.BelowTrack;
                         }
                         case Minecart.TrackState.OnFront:
                         {
                             trackState2 = Minecart.TrackState.OnFront;
                             flag8 = true;
                             goto case Minecart.TrackState.BelowTrack;
                         }
                         case Minecart.TrackState.OnBack:
                         {
                             trackState2 = Minecart.TrackState.OnBack;
                             flag8 = true;
                             goto case Minecart.TrackState.BelowTrack;
                         }
                         default:
                         {
                             goto case Minecart.TrackState.BelowTrack;
                         }
                     }
                 }
             }
         }
         else if (trackState2 == Minecart.TrackState.OnFront || trackState2 == Minecart.TrackState.OnBack || trackState2 == Minecart.TrackState.OnTrack)
         {
             if (flag && Minecart._trackType[tile.FrontTrack()] == 1)
             {
                 flag2 = true;
             }
             velocity.Y = 0f;
         }
         if (trackState2 == Minecart.TrackState.OnFront)
         {
             int num11 = tile.FrontTrack();
             if (Minecart._trackType[num11] == 2 && lastBoost.X == 0f && lastBoost.Y == 0f)
             {
                 lastBoost = new Vector2((float)x1, (float)y1);
                 if (!Minecart._boostLeft[num11])
                 {
                     bitsByte[5] = true;
                 }
                 else
                 {
                     bitsByte[4] = true;
                 }
             }
         }
         num4 = x2;
         trackState1 = trackState2;
         num2 = x1;
         num3 = y1;
         if (x <= 0f)
         {
             if (lastBoost.X == (float)num2 && lastBoost.Y == (float)num3)
             {
                 break;
             }
             lastBoost = Vector2.Zero;
             break;
         }
         else
         {
             float x3 = y.X % 2f;
             float y2 = y.Y % 2f;
             float single3 = 3f;
             float single4 = 3f;
             if (velocity.X < 0f)
             {
                 single3 = x3 + 0.125f;
             }
             else if (velocity.X > 0f)
             {
                 single3 = 2f - x3;
             }
             if (velocity.Y < 0f)
             {
                 single4 = y2 + 0.125f;
             }
             else if (velocity.Y > 0f)
             {
                 single4 = 2f - y2;
             }
             if (single3 == 3f && single4 == 3f)
             {
                 break;
             }
             float single5 = Math.Abs(single3 / velocity.X);
             float single6 = Math.Abs(single4 / velocity.Y);
             float single7 = (single5 < single6 ? single5 : single6);
             if (single7 <= x)
             {
                 zero1 = velocity * single7;
                 x = x - single7;
             }
             else
             {
                 zero1 = velocity * x;
                 x = 0f;
             }
             y = y + zero1;
         }
     }
     if (flag2)
     {
         bitsByte[3] = true;
     }
     if (flag4)
     {
         Velocity.X = y.X - vector21.X;
         Velocity.Y = Player.defaultGravity;
     }
     else if (flag3)
     {
         bitsByte[2] = true;
         Velocity = zero;
     }
     else if (!bitsByte[1])
     {
         if (flag5)
         {
             Velocity.X = y.X - vector21.X;
         }
         if (velocity.Y == 0f)
         {
             Velocity.Y = 0f;
         }
     }
     else
     {
         Velocity.X = -Velocity.X;
         Position.X = y.X - Minecart._trackMagnetOffset.X - vector2.X - Velocity.X;
         if (velocity.Y == 0f)
         {
             Velocity.Y = 0f;
         }
     }
     Position.Y = Position.Y + (y.Y - vector21.Y - Velocity.Y);
     Position.Y = (float)Math.Round((double)Position.Y, 2);
     Minecart.TrackState trackState5 = trackState1;
     if (trackState5 != Minecart.TrackState.OnTrack)
     {
         switch (trackState5)
         {
             case Minecart.TrackState.OnFront:
             case Minecart.TrackState.OnBack:
             {
                 break;
             }
             default:
             {
                 return bitsByte;
             }
         }
     }
     bitsByte[0] = true;
     return bitsByte;
 }
Ejemplo n.º 25
0
 public static void LightTiles(int firstX, int lastX, int firstY, int lastY)
 {
     Main.render = true;
     Lighting.oldSkyColor = Lighting.skyColor;
     float num1 = (float)Main.tileColor.R / (float)byte.MaxValue;
     float num2 = (float)Main.tileColor.G / (float)byte.MaxValue;
     float num3 = (float)Main.tileColor.B / (float)byte.MaxValue;
     Lighting.skyColor = (float)(((double)num1 + (double)num2 + (double)num3) / 3.0);
     if (Lighting.lightMode < 2)
     {
         Lighting.brightness = 1.2f;
         Lighting.offScreenTiles2 = 34;
         Lighting.offScreenTiles = 40;
     }
     else
     {
         Lighting.brightness = 1f;
         Lighting.offScreenTiles2 = 18;
         Lighting.offScreenTiles = 23;
     }
     if (Main.player[Main.myPlayer].blind)
         Lighting.brightness = 1f;
     Lighting.defBrightness = Lighting.brightness;
     Lighting.firstTileX = firstX;
     Lighting.lastTileX = lastX;
     Lighting.firstTileY = firstY;
     Lighting.lastTileY = lastY;
     Lighting.firstToLightX = Lighting.firstTileX - Lighting.offScreenTiles;
     Lighting.firstToLightY = Lighting.firstTileY - Lighting.offScreenTiles;
     Lighting.lastToLightX = Lighting.lastTileX + Lighting.offScreenTiles;
     Lighting.lastToLightY = Lighting.lastTileY + Lighting.offScreenTiles;
     if (Lighting.firstToLightX < 0)
         Lighting.firstToLightX = 0;
     if (Lighting.lastToLightX >= Main.maxTilesX)
         Lighting.lastToLightX = Main.maxTilesX - 1;
     if (Lighting.firstToLightY < 0)
         Lighting.firstToLightY = 0;
     if (Lighting.lastToLightY >= Main.maxTilesY)
         Lighting.lastToLightY = Main.maxTilesY - 1;
     ++Lighting.lightCounter;
     ++Main.renderCount;
     int num4 = Main.screenWidth / 16 + Lighting.offScreenTiles * 2;
     int num5 = Main.screenHeight / 16 + Lighting.offScreenTiles * 2;
     Vector2 vector2_1 = Main.screenLastPosition;
     if (Main.renderCount < 3)
         Lighting.doColors();
     if (Main.renderCount == 2)
     {
         Vector2 vector2_2 = Main.screenPosition;
         int num6 = (int)((double)Main.screenPosition.X / 16.0) - Lighting.scrX;
         int num7 = (int)((double)Main.screenPosition.Y / 16.0) - Lighting.scrY;
         if (num6 > 16)
             num6 = 0;
         if (num7 > 16)
             num7 = 0;
         int num8 = 0;
         int num9 = num4;
         int num10 = 0;
         int num11 = num5;
         if (num6 < 0)
             num8 -= num6;
         else
             num9 -= num6;
         if (num7 < 0)
             num10 -= num7;
         else
             num11 -= num7;
         if (Lighting.RGB)
         {
             for (int index1 = num8; index1 < num4; ++index1)
             {
                 Lighting.LightingState[] lightingStateArray1 = Lighting.states[index1];
                 Lighting.LightingState[] lightingStateArray2 = Lighting.states[index1 + num6];
                 for (int index2 = num10; index2 < num11; ++index2)
                 {
                     Lighting.LightingState lightingState1 = lightingStateArray1[index2];
                     Lighting.LightingState lightingState2 = lightingStateArray2[index2 + num7];
                     lightingState1.r = lightingState2.r2;
                     lightingState1.g = lightingState2.g2;
                     lightingState1.b = lightingState2.b2;
                 }
             }
         }
         else
         {
             for (int index1 = num8; index1 < num9; ++index1)
             {
                 Lighting.LightingState[] lightingStateArray1 = Lighting.states[index1];
                 Lighting.LightingState[] lightingStateArray2 = Lighting.states[index1 + num6];
                 for (int index2 = num10; index2 < num11; ++index2)
                 {
                     Lighting.LightingState lightingState1 = lightingStateArray1[index2];
                     Lighting.LightingState lightingState2 = lightingStateArray2[index2 + num7];
                     lightingState1.r = lightingState2.r2;
                     lightingState1.g = lightingState2.r2;
                     lightingState1.b = lightingState2.r2;
                 }
             }
         }
     }
     else if (!Main.renderNow)
     {
         int num6 = (int)((double)Main.screenPosition.X / 16.0) - (int)((double)vector2_1.X / 16.0);
         if (num6 > 5 || num6 < -5)
             num6 = 0;
         int num7;
         int num8;
         int num9;
         if (num6 < 0)
         {
             num7 = -1;
             num6 *= -1;
             num8 = num4;
             num9 = num6;
         }
         else
         {
             num7 = 1;
             num8 = 0;
             num9 = num4 - num6;
         }
         int num10 = (int)((double)Main.screenPosition.Y / 16.0) - (int)((double)vector2_1.Y / 16.0);
         if (num10 > 5 || num10 < -5)
             num10 = 0;
         int num11;
         int num12;
         int num13;
         if (num10 < 0)
         {
             num11 = -1;
             num10 *= -1;
             num12 = num5;
             num13 = num10;
         }
         else
         {
             num11 = 1;
             num12 = 0;
             num13 = num5 - num10;
         }
         if (num6 != 0 || num10 != 0)
         {
             int index1 = num8;
             while (index1 != num9)
             {
                 Lighting.LightingState[] lightingStateArray1 = Lighting.states[index1];
                 Lighting.LightingState[] lightingStateArray2 = Lighting.states[index1 + num6 * num7];
                 int index2 = num12;
                 while (index2 != num13)
                 {
                     Lighting.LightingState lightingState1 = lightingStateArray1[index2];
                     Lighting.LightingState lightingState2 = lightingStateArray2[index2 + num10 * num11];
                     lightingState1.r = lightingState2.r;
                     lightingState1.g = lightingState2.g;
                     lightingState1.b = lightingState2.b;
                     index2 += num11;
                 }
                 index1 += num7;
             }
         }
         if (Netplay.Connection.StatusMax > 0)
             Main.mapTime = 1;
         if (Main.mapTime == 0 && Main.mapEnabled)
         {
             if (Main.renderCount == 3)
             {
                 try
                 {
                     Main.mapTime = Main.mapTimeMax;
                     Main.updateMap = true;
                     Main.mapMinX = Lighting.firstToLightX + Lighting.offScreenTiles;
                     Main.mapMaxX = Lighting.lastToLightX - Lighting.offScreenTiles;
                     Main.mapMinY = Lighting.firstToLightY + Lighting.offScreenTiles;
                     Main.mapMaxY = Lighting.lastToLightY - Lighting.offScreenTiles;
                     for (int x = Main.mapMinX; x < Main.mapMaxX; ++x)
                     {
                         Lighting.LightingState[] lightingStateArray = Lighting.states[x - Lighting.firstTileX + Lighting.offScreenTiles];
                         for (int y = Main.mapMinY; y < Main.mapMaxY; ++y)
                         {
                             Lighting.LightingState lightingState = lightingStateArray[y - Lighting.firstTileY + Lighting.offScreenTiles];
                             Tile tile = Main.tile[x, y];
                             float num14 = 0.0f;
                             if ((double)lightingState.r > (double)num14)
                                 num14 = lightingState.r;
                             if ((double)lightingState.g > (double)num14)
                                 num14 = lightingState.g;
                             if ((double)lightingState.b > (double)num14)
                                 num14 = lightingState.b;
                             if (Lighting.lightMode < 2)
                                 num14 *= 1.5f;
                             byte light = (byte)Math.Min((float)byte.MaxValue, num14 * (float)byte.MaxValue);
                             if ((double)y < Main.worldSurface && !tile.active() && ((int)tile.wall == 0 && (int)tile.liquid == 0))
                                 light = (byte)22;
                             if ((int)light > 18 || (int)Main.Map[x, y].Light > 0)
                             {
                                 if ((int)light < 22)
                                     light = (byte)22;
                                 Main.Map.UpdateLighting(x, y, light);
                             }
                         }
                     }
                 }
                 catch
                 {
                 }
             }
         }
         if ((double)Lighting.oldSkyColor != (double)Lighting.skyColor)
         {
             int num14 = Lighting.firstToLightX;
             int num15 = Lighting.firstToLightY;
             int num16 = Lighting.lastToLightX;
             int num17 = (double)Lighting.lastToLightY < Main.worldSurface ? Lighting.lastToLightY : (int)Main.worldSurface - 1;
             if ((double)num15 < Main.worldSurface)
             {
                 for (int index1 = num14; index1 < num16; ++index1)
                 {
                     Lighting.LightingState[] lightingStateArray = Lighting.states[index1 - Lighting.firstToLightX];
                     for (int index2 = num15; index2 < num17; ++index2)
                     {
                         Lighting.LightingState lightingState = lightingStateArray[index2 - Lighting.firstToLightY];
                         Tile tile = Main.tile[index1, index2];
                         if (tile == null)
                         {
                             tile = new Tile();
                             Main.tile[index1, index2] = tile;
                         }
                         if ((!tile.active() || !Main.tileNoSunLight[(int)tile.type]) && ((double)lightingState.r < (double)Lighting.skyColor && (int)tile.liquid < 200) && (Main.wallLight[(int)tile.wall] || (int)tile.wall == 73))
                         {
                             lightingState.r = num1;
                             if ((double)lightingState.g < (double)Lighting.skyColor)
                                 lightingState.g = num2;
                             if ((double)lightingState.b < (double)Lighting.skyColor)
                                 lightingState.b = num3;
                         }
                     }
                 }
             }
         }
     }
     else
         Lighting.lightCounter = 0;
     if (Main.renderCount <= Lighting.maxRenderCount)
         return;
     Lighting.PreRenderPhase();
 }
Ejemplo n.º 26
0
 public static void TrackColors(int i, int j, Tile trackTile, out int frontColor, out int backColor)
 {
     int num;
     int num1;
     Tile tile;
     int num2;
     if (trackTile.type != 314)
     {
         frontColor = 0;
         backColor = 0;
     }
     else
     {
         frontColor = trackTile.color();
         backColor = frontColor;
         if (trackTile.frameY == -1)
         {
             return;
         }
         int num3 = Minecart._leftSideConnection[trackTile.frameX];
         int num4 = Minecart._rightSideConnection[trackTile.frameX];
         int num5 = Minecart._leftSideConnection[trackTile.frameY];
         int num6 = Minecart._rightSideConnection[trackTile.frameY];
         int num7 = 0;
         int num8 = 0;
         int num9 = 0;
         int num10 = 0;
         for (int i1 = 0; i1 < 4; i1++)
         {
             switch (i1)
             {
                 case 1:
                 {
                     num = num4;
                     break;
                 }
                 case 2:
                 {
                     num = num5;
                     break;
                 }
                 case 3:
                 {
                     num = num6;
                     break;
                 }
                 default:
                 {
                     num = num3;
                     break;
                 }
             }
             switch (num)
             {
                 case 0:
                 {
                     num1 = -1;
                     break;
                 }
                 case 1:
                 {
                     num1 = 0;
                     break;
                 }
                 case 2:
                 {
                     num1 = 1;
                     break;
                 }
                 default:
                 {
                     num1 = 0;
                     break;
                 }
             }
             tile = (i1 % 2 != 0 ? Main.tile[i + 1, j + num1] : Main.tile[i - 1, j + num1]);
             if (tile == null || !tile.active() || tile.type != 314)
             {
                 num2 = 0;
             }
             else
             {
                 num2 = tile.color();
             }
             switch (i1)
             {
                 case 1:
                 {
                     num8 = num2;
                     break;
                 }
                 case 2:
                 {
                     num9 = num2;
                     break;
                 }
                 case 3:
                 {
                     num10 = num2;
                     break;
                 }
                 default:
                 {
                     num7 = num2;
                     break;
                 }
             }
         }
         if (num3 == num5)
         {
             if (num8 != 0)
             {
                 frontColor = num8;
             }
             else if (num7 != 0)
             {
                 frontColor = num7;
             }
             if (num10 != 0)
             {
                 backColor = num10;
                 return;
             }
             if (num9 != 0)
             {
                 backColor = num9;
                 return;
             }
         }
         else if (num4 != num6)
         {
             if (num8 == 0)
             {
                 if (num7 != 0)
                 {
                     frontColor = num7;
                 }
             }
             else if (num7 != 0)
             {
                 frontColor = (num4 <= num3 ? num8 : num7);
             }
             if (num10 == 0)
             {
                 if (num9 != 0)
                 {
                     backColor = num9;
                     return;
                 }
             }
             else if (num9 != 0)
             {
                 backColor = (num6 <= num5 ? num10 : num9);
                 return;
             }
         }
         else
         {
             if (num7 != 0)
             {
                 frontColor = num7;
             }
             else if (num8 != 0)
             {
                 frontColor = num8;
             }
             if (num9 != 0)
             {
                 backColor = num9;
                 return;
             }
             if (num10 != 0)
             {
                 backColor = num10;
                 return;
             }
         }
     }
 }
Ejemplo n.º 27
0
 public static void PlaceTrack(Tile trackCache, int style)
 {
     trackCache.active(true);
     trackCache.type = 314;
     trackCache.frameY = -1;
     switch (style)
     {
         case 0:
         {
             trackCache.frameX = -1;
             return;
         }
         case 1:
         {
             trackCache.frameX = Minecart._firstPressureFrame;
             return;
         }
         case 2:
         {
             trackCache.frameX = Minecart._firstLeftBoostFrame;
             return;
         }
         case 3:
         {
             trackCache.frameX = Minecart._firstRightBoostFrame;
             return;
         }
         default:
         {
             return;
         }
     }
 }
Ejemplo n.º 28
0
 private static BlockStyle FindBlockStyle(Tile blockTile)
 {
     return(blockStyleLookup[blockTile.blockType()]);
 }
Ejemplo n.º 29
0
 public static bool FrameTrack(int i, int j, bool pound, bool mute = false)
 {
     int num;
     bool flag;
     int num1 = 0;
     Tile tile = Main.tile[i, j];
     if (tile == null)
     {
         tile = new Tile();
         Main.tile[i, j] = tile;
     }
     if (mute && tile.type != 314)
     {
         return false;
     }
     if (Main.tile[i - 1, j - 1] != null && Main.tile[i - 1, j - 1].type == 314)
     {
         num1++;
     }
     if (Main.tile[i - 1, j] != null && Main.tile[i - 1, j].type == 314)
     {
         num1 = num1 + 2;
     }
     if (Main.tile[i - 1, j + 1] != null && Main.tile[i - 1, j + 1].type == 314)
     {
         num1 = num1 + 4;
     }
     if (Main.tile[i + 1, j - 1] != null && Main.tile[i + 1, j - 1].type == 314)
     {
         num1 = num1 + 8;
     }
     if (Main.tile[i + 1, j] != null && Main.tile[i + 1, j].type == 314)
     {
         num1 = num1 + 16;
     }
     if (Main.tile[i + 1, j + 1] != null && Main.tile[i + 1, j + 1].type == 314)
     {
         num1 = num1 + 32;
     }
     int num2 = tile.FrontTrack();
     int num3 = tile.BackTrack();
     if (Minecart._trackType == null)
     {
         return false;
     }
     num = (num2 < 0 || num2 >= (int)Minecart._trackType.Length ? 0 : Minecart._trackType[num2]);
     int num4 = -1;
     int num5 = -1;
     int[] numArray = Minecart._trackSwitchOptions[num1];
     if (numArray == null)
     {
         if (pound)
         {
             return false;
         }
         tile.FrontTrack(0);
         tile.BackTrack(-1);
         return false;
     }
     if (pound)
     {
         for (int i1 = 0; i1 < (int)numArray.Length; i1++)
         {
             if (num2 == numArray[i1])
             {
                 num4 = i1;
             }
             if (num3 == numArray[i1])
             {
                 num5 = i1;
             }
         }
         int num6 = 0;
         int num7 = 0;
         for (int j1 = 0; j1 < (int)numArray.Length; j1++)
         {
             if (Minecart._trackType[numArray[j1]] == num)
             {
                 if (Minecart._leftSideConnection[numArray[j1]] == -1 || Minecart._rightSideConnection[numArray[j1]] == -1)
                 {
                     num7++;
                 }
                 else
                 {
                     num6++;
                 }
             }
         }
         if (num6 < 2 && num7 < 2)
         {
             return false;
         }
         bool flag1 = num6 == 0;
         bool flag2 = false;
         if (!flag1)
         {
             while (!flag2)
             {
                 num5++;
                 if (num5 < (int)numArray.Length)
                 {
                     if (Minecart._leftSideConnection[numArray[num5]] == Minecart._leftSideConnection[numArray[num4]] && Minecart._rightSideConnection[numArray[num5]] == Minecart._rightSideConnection[numArray[num4]] || Minecart._trackType[numArray[num5]] != num || Minecart._leftSideConnection[numArray[num5]] == -1 || Minecart._rightSideConnection[numArray[num5]] == -1)
                     {
                         continue;
                     }
                     flag2 = true;
                 }
                 else
                 {
                     num5 = -1;
                     break;
                 }
             }
         }
         if (!flag2)
         {
             do
             {
             Label0:
                 num4++;
                 if (num4 >= (int)numArray.Length)
                 {
                     num4 = -1;
                     while (true)
                     {
                         num4++;
                         if (Minecart._trackType[numArray[num4]] == num)
                         {
                             if ((Minecart._leftSideConnection[numArray[num4]] == -1 ? true : Minecart._rightSideConnection[numArray[num4]] == -1) == flag1)
                             {
                                 goto Label1;
                             }
                         }
                     }
                 }
                 else if (Minecart._trackType[numArray[num4]] == num)
                 {
                     flag = (Minecart._leftSideConnection[numArray[num4]] == -1 ? true : Minecart._rightSideConnection[numArray[num4]] == -1);
                 }
                 else
                 {
                     goto Label0;
                 }
             }
             while (flag != flag1);
         }
     }
     else
     {
         int num8 = -1;
         int num9 = -1;
         bool flag3 = false;
         for (int k = 0; k < (int)numArray.Length; k++)
         {
             int num10 = numArray[k];
             if (num3 == numArray[k])
             {
                 num5 = k;
             }
             if (Minecart._trackType[num10] == num)
             {
                 if (Minecart._leftSideConnection[num10] == -1 || Minecart._rightSideConnection[num10] == -1)
                 {
                     if (num2 == numArray[k])
                     {
                         num4 = k;
                         flag3 = true;
                     }
                     if (num8 == -1)
                     {
                         num8 = k;
                     }
                 }
                 else
                 {
                     if (num2 == numArray[k])
                     {
                         num4 = k;
                         flag3 = false;
                     }
                     if (num9 == -1)
                     {
                         num9 = k;
                     }
                 }
             }
         }
         if (num9 == -1)
         {
             if (num4 == -1)
             {
                 if (num == 2)
                 {
                     return false;
                 }
                 if (num == 1)
                 {
                     return false;
                 }
                 num4 = num8;
             }
             num5 = -1;
         }
         else if (num4 == -1 || flag3)
         {
             num4 = num9;
         }
     }
     Label1:
     bool flag4 = false;
     if (num4 == -2)
     {
         if (tile.FrontTrack() != Minecart._firstPressureFrame)
         {
             flag4 = true;
         }
     }
     else if (num4 == -1)
     {
         if (tile.FrontTrack() != 0)
         {
             flag4 = true;
         }
     }
     else if (tile.FrontTrack() != numArray[num4])
     {
         flag4 = true;
     }
     if (num5 == -1)
     {
         if (tile.BackTrack() != -1)
         {
             flag4 = true;
         }
     }
     else if (tile.BackTrack() != numArray[num5])
     {
         flag4 = true;
     }
     if (num4 == -2)
     {
         tile.FrontTrack(Minecart._firstPressureFrame);
     }
     else if (num4 != -1)
     {
         tile.FrontTrack((short)numArray[num4]);
     }
     else
     {
         tile.FrontTrack(0);
     }
     if (num5 != -1)
     {
         tile.BackTrack((short)numArray[num5]);
     }
     else
     {
         tile.BackTrack(-1);
     }
     if (pound && flag4 && !mute)
     {
         WorldGen.KillTile(i, j, true, false, false);
     }
     return true;
 }
Ejemplo n.º 30
0
        protected void DrawTiles(bool solidOnly = true)
        {
            Vector2 vector3;
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            int num = (int)((255f * (1f - gfxQuality)) + (30f * gfxQuality));
            int num2 = (int)((50f * (1f - gfxQuality)) + (2f * gfxQuality));
            Vector2 vector = new Vector2((float)offScreenRange, (float)offScreenRange);
            if (drawToScreen)
            {
                vector = new Vector2();
            }
            int index = 0;
            int[] numArray = new int[0x3e8];
            int[] numArray2 = new int[0x3e8];
            int num4 = (int)(((screenPosition.X - vector.X) / 16f) - 1f);
            int maxTilesX = ((int)(((screenPosition.X + screenWidth) + vector.X) / 16f)) + 2;
            int num6 = (int)(((screenPosition.Y - vector.Y) / 16f) - 1f);
            int maxTilesY = ((int)(((screenPosition.Y + screenHeight) + vector.Y) / 16f)) + 5;
            if (num4 < 0)
            {
                num4 = 0;
            }
            if (maxTilesX > Main.maxTilesX)
            {
                maxTilesX = Main.maxTilesX;
            }
            if (num6 < 0)
            {
                num6 = 0;
            }
            if (maxTilesY > Main.maxTilesY)
            {
                maxTilesY = Main.maxTilesY;
            }
            int height = 0x10;
            int width = 0x10;
            for (int i = num6; i < (maxTilesY + 4); i++)
            {
                for (int k = num4 - 2; k < (maxTilesX + 2); k++)
                {
                    if (tile[k, i] == null)
                    {
                        tile[k, i] = new Tile();
                    }
                    bool flag = tileSolid[tile[k, i].type];
                    if (tile[k, i].type == 11)
                    {
                        flag = true;
                    }
                    if (tile[k, i].active && (flag == solidOnly))
                    {
                        Color color8;
                        Color color = Lighting.GetColor(k, i);
                        int num12 = 0;
                        if ((tile[k, i].type == 0x4e) || (tile[k, i].type == 0x55))
                        {
                            num12 = 2;
                        }
                        if ((tile[k, i].type == 0x21) || (tile[k, i].type == 0x31))
                        {
                            num12 = -4;
                        }
                        if ((((tile[k, i].type == 3) || (tile[k, i].type == 4)) || ((tile[k, i].type == 5) || (tile[k, i].type == 0x18))) || (((tile[k, i].type == 0x21) || (tile[k, i].type == 0x31)) || (((tile[k, i].type == 0x3d) || (tile[k, i].type == 0x47)) || (tile[k, i].type == 110))))
                        {
                            height = 20;
                        }
                        else if (((((tile[k, i].type == 15) || (tile[k, i].type == 14)) || ((tile[k, i].type == 0x10) || (tile[k, i].type == 0x11))) || (((tile[k, i].type == 0x12) || (tile[k, i].type == 20)) || ((tile[k, i].type == 0x15) || (tile[k, i].type == 0x1a)))) || ((((tile[k, i].type == 0x1b) || (tile[k, i].type == 0x20)) || ((tile[k, i].type == 0x45) || (tile[k, i].type == 0x48))) || ((tile[k, i].type == 0x4d) || (tile[k, i].type == 80))))
                        {
                            height = 0x12;
                        }
                        else if (tile[k, i].type == 0x89)
                        {
                            height = 0x12;
                        }
                        else if (tile[k, i].type == 0x87)
                        {
                            num12 = 2;
                            height = 0x12;
                        }
                        else if (tile[k, i].type == 0x84)
                        {
                            num12 = 2;
                            height = 0x12;
                        }
                        else
                        {
                            height = 0x10;
                        }
                        if ((tile[k, i].type == 4) || (tile[k, i].type == 5))
                        {
                            width = 20;
                        }
                        else
                        {
                            width = 0x10;
                        }
                        if (((tile[k, i].type == 0x49) || (tile[k, i].type == 0x4a)) || (tile[k, i].type == 0x71))
                        {
                            num12 -= 12;
                            height = 0x20;
                        }
                        if (tile[k, i].type == 0x51)
                        {
                            num12 -= 8;
                            height = 0x1a;
                            width = 0x18;
                        }
                        if (tile[k, i].type == 0x69)
                        {
                            num12 = 2;
                        }
                        if (tile[k, i].type == 0x7c)
                        {
                            height = 0x12;
                        }
                        if (tile[k, i].type == 0x89)
                        {
                            height = 0x12;
                        }
                        if (tile[k, i].type == 0x8a)
                        {
                            height = 0x12;
                        }
                        if (((tile[k, i].type == 0x8b) || (tile[k, i].type == 0x8e)) || (tile[k, i].type == 0x8f))
                        {
                            num12 = 2;
                        }
                        if (player[myPlayer].findTreasure && ((((((tile[k, i].type == 6) || (tile[k, i].type == 7)) || ((tile[k, i].type == 8) || (tile[k, i].type == 9))) || (((tile[k, i].type == 12) || (tile[k, i].type == 0x15)) || ((tile[k, i].type == 0x16) || (tile[k, i].type == 0x1c)))) || ((((tile[k, i].type == 0x6b) || (tile[k, i].type == 0x6c)) || (tile[k, i].type == 0x6f)) || ((tile[k, i].type >= 0x3f) && (tile[k, i].type <= 0x44)))) || tileAlch[tile[k, i].type]))
                        {
                            if (color.R < (mouseTextColor / 2))
                            {
                                color.R = (byte)(mouseTextColor / 2);
                            }
                            if (color.G < 70)
                            {
                                color.G = 70;
                            }
                            if (color.B < 210)
                            {
                                color.B = 210;
                            }
                            color.A = mouseTextColor;
                            if ((!gamePaused && base.IsActive) && (rand.Next(150) == 0))
                            {
                                color8 = new Color();
                                int num13 = Dust.NewDust(new Vector2((float)(k * 0x10), (float)(i * 0x10)), 0x10, 0x10, 15, 0f, 0f, 150, color8, 0.8f);
                                Dust dust1 = dust[num13];
                                dust1.velocity = (Vector2)(dust1.velocity * 0.1f);
                                dust[num13].noLight = true;
                            }
                        }
                        if (!gamePaused && base.IsActive)
                        {
                            if (((tile[k, i].type == 4) && (rand.Next(40) == 0)) && (tile[k, i].frameX < 0x42))
                            {
                                int type = tile[k, i].frameY / 0x16;
                                switch (type)
                                {
                                    case 0:
                                        type = 6;
                                        break;

                                    case 8:
                                        type = 0x4b;
                                        break;

                                    default:
                                        type = 0x3a + type;
                                        break;
                                }
                                if (tile[k, i].frameX == 0x16)
                                {
                                    color8 = new Color();
                                    Dust.NewDust(new Vector2((float)((k * 0x10) + 6), (float)(i * 0x10)), 4, 4, type, 0f, 0f, 100, color8, 1f);
                                }
                                if (tile[k, i].frameX == 0x2c)
                                {
                                    color8 = new Color();
                                    Dust.NewDust(new Vector2((float)((k * 0x10) + 2), (float)(i * 0x10)), 4, 4, type, 0f, 0f, 100, color8, 1f);
                                }
                                else
                                {
                                    color8 = new Color();
                                    Dust.NewDust(new Vector2((float)((k * 0x10) + 4), (float)(i * 0x10)), 4, 4, type, 0f, 0f, 100, color8, 1f);
                                }
                            }
                            if (((tile[k, i].type == 0x21) && (rand.Next(40) == 0)) && (tile[k, i].frameX == 0))
                            {
                                color8 = new Color();
                                Dust.NewDust(new Vector2((float)((k * 0x10) + 4), (float)((i * 0x10) - 4)), 4, 4, 6, 0f, 0f, 100, color8, 1f);
                            }
                            if (((tile[k, i].type == 0x5d) && (rand.Next(40) == 0)) && ((tile[k, i].frameX == 0) && (tile[k, i].frameY == 0)))
                            {
                                color8 = new Color();
                                Dust.NewDust(new Vector2((float)((k * 0x10) + 4), (float)((i * 0x10) + 2)), 4, 4, 6, 0f, 0f, 100, color8, 1f);
                            }
                            if (((tile[k, i].type == 100) && (rand.Next(40) == 0)) && ((tile[k, i].frameX < 0x24) && (tile[k, i].frameY == 0)))
                            {
                                if (tile[k, i].frameX == 0)
                                {
                                    if (rand.Next(3) == 0)
                                    {
                                        color8 = new Color();
                                        Dust.NewDust(new Vector2((float)((k * 0x10) + 4), (float)((i * 0x10) + 2)), 4, 4, 6, 0f, 0f, 100, color8, 1f);
                                    }
                                    else
                                    {
                                        color8 = new Color();
                                        Dust.NewDust(new Vector2((float)((k * 0x10) + 14), (float)((i * 0x10) + 2)), 4, 4, 6, 0f, 0f, 100, color8, 1f);
                                    }
                                }
                                else if (rand.Next(3) == 0)
                                {
                                    color8 = new Color();
                                    Dust.NewDust(new Vector2((float)((k * 0x10) + 6), (float)((i * 0x10) + 2)), 4, 4, 6, 0f, 0f, 100, color8, 1f);
                                }
                                else
                                {
                                    color8 = new Color();
                                    Dust.NewDust(new Vector2((float)(k * 0x10), (float)((i * 0x10) + 2)), 4, 4, 6, 0f, 0f, 100, color8, 1f);
                                }
                            }
                            if (((tile[k, i].type == 0x62) && (rand.Next(40) == 0)) && ((tile[k, i].frameY == 0) && (tile[k, i].frameX == 0)))
                            {
                                color8 = new Color();
                                Dust.NewDust(new Vector2((float)((k * 0x10) + 12), (float)((i * 0x10) + 2)), 4, 4, 6, 0f, 0f, 100, color8, 1f);
                            }
                            if ((tile[k, i].type == 0x31) && (rand.Next(20) == 0))
                            {
                                color8 = new Color();
                                Dust.NewDust(new Vector2((float)((k * 0x10) + 4), (float)((i * 0x10) - 4)), 4, 4, 0x1d, 0f, 0f, 100, color8, 1f);
                            }
                            if ((((tile[k, i].type == 0x22) || (tile[k, i].type == 0x23)) || (tile[k, i].type == 0x24)) && ((((rand.Next(40) == 0) && (tile[k, i].frameX < 0x36)) && (tile[k, i].frameY == 0x12)) && ((tile[k, i].frameX == 0) || (tile[k, i].frameX == 0x24))))
                            {
                                color8 = new Color();
                                Dust.NewDust(new Vector2((float)(k * 0x10), (float)((i * 0x10) + 2)), 14, 6, 6, 0f, 0f, 100, color8, 1f);
                            }
                            if ((tile[k, i].type == 0x16) && (rand.Next(400) == 0))
                            {
                                color8 = new Color();
                                Dust.NewDust(new Vector2((float)(k * 0x10), (float)(i * 0x10)), 0x10, 0x10, 14, 0f, 0f, 0, color8, 1f);
                            }
                            else if ((((tile[k, i].type == 0x17) || (tile[k, i].type == 0x18)) || (tile[k, i].type == 0x20)) && (rand.Next(500) == 0))
                            {
                                color8 = new Color();
                                Dust.NewDust(new Vector2((float)(k * 0x10), (float)(i * 0x10)), 0x10, 0x10, 14, 0f, 0f, 0, color8, 1f);
                            }
                            else if ((tile[k, i].type == 0x19) && (rand.Next(700) == 0))
                            {
                                color8 = new Color();
                                Dust.NewDust(new Vector2((float)(k * 0x10), (float)(i * 0x10)), 0x10, 0x10, 14, 0f, 0f, 0, color8, 1f);
                            }
                            else if ((tile[k, i].type == 0x70) && (rand.Next(700) == 0))
                            {
                                color8 = new Color();
                                Dust.NewDust(new Vector2((float)(k * 0x10), (float)(i * 0x10)), 0x10, 0x10, 14, 0f, 0f, 0, color8, 1f);
                            }
                            else if ((tile[k, i].type == 0x1f) && (rand.Next(20) == 0))
                            {
                                color8 = new Color();
                                Dust.NewDust(new Vector2((float)(k * 0x10), (float)(i * 0x10)), 0x10, 0x10, 14, 0f, 0f, 100, color8, 1f);
                            }
                            else if ((tile[k, i].type == 0x1a) && (rand.Next(20) == 0))
                            {
                                color8 = new Color();
                                Dust.NewDust(new Vector2((float)(k * 0x10), (float)(i * 0x10)), 0x10, 0x10, 14, 0f, 0f, 100, color8, 1f);
                            }
                            else if (((tile[k, i].type == 0x47) || (tile[k, i].type == 0x48)) && (rand.Next(500) == 0))
                            {
                                color8 = new Color();
                                Dust.NewDust(new Vector2((float)(k * 0x10), (float)(i * 0x10)), 0x10, 0x10, 0x29, 0f, 0f, 250, color8, 0.8f);
                            }
                            else if ((((tile[k, i].type == 0x11) || (tile[k, i].type == 0x4d)) || (tile[k, i].type == 0x85)) && (rand.Next(40) == 0))
                            {
                                if ((tile[k, i].frameX == 0x12) & (tile[k, i].frameY == 0x12))
                                {
                                    color8 = new Color();
                                    Dust.NewDust(new Vector2((float)((k * 0x10) + 2), (float)(i * 0x10)), 8, 6, 6, 0f, 0f, 100, color8, 1f);
                                }
                            }
                            else if ((tile[k, i].type == 0x25) && (rand.Next(250) == 0))
                            {
                                color8 = new Color();
                                int num15 = Dust.NewDust(new Vector2((float)(k * 0x10), (float)(i * 0x10)), 0x10, 0x10, 6, 0f, 0f, 0, color8, (float)rand.Next(3));
                                if (dust[num15].scale > 1f)
                                {
                                    dust[num15].noGravity = true;
                                }
                            }
                            else if (((tile[k, i].type == 0x3a) || (tile[k, i].type == 0x4c)) && (rand.Next(250) == 0))
                            {
                                color8 = new Color();
                                int num16 = Dust.NewDust(new Vector2((float)(k * 0x10), (float)(i * 0x10)), 0x10, 0x10, 6, 0f, 0f, 0, color8, (float)rand.Next(3));
                                if (dust[num16].scale > 1f)
                                {
                                    dust[num16].noGravity = true;
                                }
                                dust[num16].noLight = true;
                            }
                            else if (tile[k, i].type == 0x3d)
                            {
                                if (tile[k, i].frameX == 0x90)
                                {
                                    if (rand.Next(60) == 0)
                                    {
                                        color8 = new Color();
                                        int num17 = Dust.NewDust(new Vector2((float)(k * 0x10), (float)(i * 0x10)), 0x10, 0x10, 0x2c, 0f, 0f, 250, color8, 0.4f);
                                        dust[num17].fadeIn = 0.7f;
                                    }
                                    color.A = (byte)(245f - (mouseTextColor * 1.5f));
                                    color.R = (byte)(245f - (mouseTextColor * 1.5f));
                                    color.B = (byte)(245f - (mouseTextColor * 1.5f));
                                    color.G = (byte)(245f - (mouseTextColor * 1.5f));
                                }
                            }
                            else if ((tileShine[tile[k, i].type] > 0) && (((color.R > 20) || (color.B > 20)) || (color.G > 20)))
                            {
                                int r = color.R;
                                if (color.G > r)
                                {
                                    r = color.G;
                                }
                                if (color.B > r)
                                {
                                    r = color.B;
                                }
                                r /= 30;
                                if ((rand.Next(tileShine[tile[k, i].type]) < r) && ((tile[k, i].type != 0x15) || ((tile[k, i].frameX >= 0x24) && (tile[k, i].frameX < 180))))
                                {
                                    color8 = new Color();
                                    int num19 = Dust.NewDust(new Vector2((float)(k * 0x10), (float)(i * 0x10)), 0x10, 0x10, 0x2b, 0f, 0f, 0xfe, color8, 0.5f);
                                    Dust dust2 = dust[num19];
                                    dust2.velocity = (Vector2)(dust2.velocity * 0f);
                                }
                            }
                        }
                        if ((tile[k, i].type == 0x80) && (tile[k, i].frameX >= 100))
                        {
                            numArray[index] = k;
                            numArray2[index] = i;
                            index++;
                        }
                        if (((tile[k, i].type == 5) && (tile[k, i].frameY >= 0xc6)) && (tile[k, i].frameX >= 0x16))
                        {
                            numArray[index] = k;
                            numArray2[index] = i;
                            index++;
                        }
                        if ((tile[k, i].type == 0x48) && (tile[k, i].frameX >= 0x24))
                        {
                            int num20 = 0;
                            if (tile[k, i].frameY == 0x12)
                            {
                                num20 = 1;
                            }
                            else if (tile[k, i].frameY == 0x24)
                            {
                                num20 = 2;
                            }
                            vector3 = new Vector2();
                            this.spriteBatch.Draw(shroomCapTexture, new Vector2((float)(((k * 0x10) - ((int)screenPosition.X)) - 0x16), (float)(((i * 0x10) - ((int)screenPosition.Y)) - 0x1a)) + vector, new Rectangle(num20 * 0x3e, 0, 60, 0x2a), Lighting.GetColor(k, i), 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                        }
                        if (((color.R > 1) || (color.G > 1)) || (color.B > 1))
                        {
                            if (tile[k - 1, i] == null)
                            {
                                tile[k - 1, i] = new Tile();
                            }
                            if (tile[k + 1, i] == null)
                            {
                                tile[k + 1, i] = new Tile();
                            }
                            if (tile[k, i - 1] == null)
                            {
                                tile[k, i - 1] = new Tile();
                            }
                            if (tile[k, i + 1] == null)
                            {
                                tile[k, i + 1] = new Tile();
                            }
                            if (((solidOnly && flag) && !tileSolidTop[tile[k, i].type]) && (((tile[k - 1, i].liquid > 0) || (tile[k + 1, i].liquid > 0)) || ((tile[k, i - 1].liquid > 0) || (tile[k, i + 1].liquid > 0))))
                            {
                                Color color2 = Lighting.GetColor(k, i);
                                int liquid = 0;
                                bool flag2 = false;
                                bool flag3 = false;
                                bool flag4 = false;
                                bool flag5 = false;
                                int num22 = 0;
                                bool flag6 = false;
                                if (tile[k - 1, i].liquid > liquid)
                                {
                                    liquid = tile[k - 1, i].liquid;
                                    flag2 = true;
                                }
                                else if (tile[k - 1, i].liquid > 0)
                                {
                                    flag2 = true;
                                }
                                if (tile[k + 1, i].liquid > liquid)
                                {
                                    liquid = tile[k + 1, i].liquid;
                                    flag3 = true;
                                }
                                else if (tile[k + 1, i].liquid > 0)
                                {
                                    liquid = tile[k + 1, i].liquid;
                                    flag3 = true;
                                }
                                if (tile[k, i - 1].liquid > 0)
                                {
                                    flag4 = true;
                                }
                                if (tile[k, i + 1].liquid > 240)
                                {
                                    flag5 = true;
                                }
                                if (tile[k - 1, i].liquid > 0)
                                {
                                    if (tile[k - 1, i].lava)
                                    {
                                        num22 = 1;
                                    }
                                    else
                                    {
                                        flag6 = true;
                                    }
                                }
                                if (tile[k + 1, i].liquid > 0)
                                {
                                    if (tile[k + 1, i].lava)
                                    {
                                        num22 = 1;
                                    }
                                    else
                                    {
                                        flag6 = true;
                                    }
                                }
                                if (tile[k, i - 1].liquid > 0)
                                {
                                    if (tile[k, i - 1].lava)
                                    {
                                        num22 = 1;
                                    }
                                    else
                                    {
                                        flag6 = true;
                                    }
                                }
                                if (tile[k, i + 1].liquid > 0)
                                {
                                    if (tile[k, i + 1].lava)
                                    {
                                        num22 = 1;
                                    }
                                    else
                                    {
                                        flag6 = true;
                                    }
                                }
                                if (!flag6 || (num22 != 1))
                                {
                                    float num23 = 0f;
                                    Vector2 vector2 = new Vector2((float)(k * 0x10), (float)(i * 0x10));
                                    Rectangle rectangle = new Rectangle(0, 4, 0x10, 0x10);
                                    if (flag5 && (flag2 || flag3))
                                    {
                                        flag2 = true;
                                        flag3 = true;
                                    }
                                    if ((!flag4 || (!flag2 && !flag3)) && (!flag5 || !flag4))
                                    {
                                        if (flag4)
                                        {
                                            rectangle = new Rectangle(0, 4, 0x10, 4);
                                        }
                                        else if ((flag5 && !flag2) && !flag3)
                                        {
                                            vector2 = new Vector2((float)(k * 0x10), (float)((i * 0x10) + 12));
                                            rectangle = new Rectangle(0, 4, 0x10, 4);
                                        }
                                        else
                                        {
                                            num23 = 0x100 - liquid;
                                            num23 /= 32f;
                                            if (flag2 && flag3)
                                            {
                                                vector2 = new Vector2((float)(k * 0x10), (float)((i * 0x10) + (((int)num23) * 2)));
                                                rectangle = new Rectangle(0, 4, 0x10, 0x10 - (((int)num23) * 2));
                                            }
                                            else if (flag2)
                                            {
                                                vector2 = new Vector2((float)(k * 0x10), (float)((i * 0x10) + (((int)num23) * 2)));
                                                rectangle = new Rectangle(0, 4, 4, 0x10 - (((int)num23) * 2));
                                            }
                                            else
                                            {
                                                vector2 = new Vector2((float)((k * 0x10) + 12), (float)((i * 0x10) + (((int)num23) * 2)));
                                                rectangle = new Rectangle(0, 4, 4, 0x10 - (((int)num23) * 2));
                                            }
                                        }
                                    }
                                    float num24 = 0.5f;
                                    if (num22 == 1)
                                    {
                                        num24 *= 1.6f;
                                    }
                                    if ((i < worldSurface) || (num24 > 1f))
                                    {
                                        num24 = 1f;
                                    }
                                    float num25 = color2.R * num24;
                                    float num26 = color2.G * num24;
                                    float num27 = color2.B * num24;
                                    float num28 = color2.A * num24;
                                    color2 = new Color((int)((byte)num25), (int)((byte)num26), (int)((byte)num27), (int)((byte)num28));
                                    vector3 = new Vector2();
                                    this.spriteBatch.Draw(liquidTexture[num22], (vector2 - screenPosition) + vector, new Rectangle?(rectangle), color2, 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                                }
                            }
                            if (tile[k, i].type == 0x33)
                            {
                                Color color3 = Lighting.GetColor(k, i);
                                float num29 = 0.5f;
                                float num30 = color3.R * num29;
                                float num31 = color3.G * num29;
                                float num32 = color3.B * num29;
                                float num33 = color3.A * num29;
                                color3 = new Color((int)((byte)num30), (int)((byte)num31), (int)((byte)num32), (int)((byte)num33));
                                vector3 = new Vector2();
                                this.spriteBatch.Draw(tileTexture[tile[k, i].type], new Vector2(((k * 0x10) - ((int)screenPosition.X)) - ((width - 16f) / 2f), (float)(((i * 0x10) - ((int)screenPosition.Y)) + num12)) + vector, new Rectangle(tile[k, i].frameX, tile[k, i].frameY, width, height), color3, 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                                continue;
                            }
                            if (tile[k, i].type == 0x81)
                            {
                                vector3 = new Vector2();
                                this.spriteBatch.Draw(tileTexture[tile[k, i].type], new Vector2(((k * 0x10) - ((int)screenPosition.X)) - ((width - 16f) / 2f), (float)(((i * 0x10) - ((int)screenPosition.Y)) + num12)) + vector, new Rectangle(tile[k, i].frameX, tile[k, i].frameY, width, height), new Color(200, 200, 200, 0), 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                                continue;
                            }
                            if (tileAlch[tile[k, i].type])
                            {
                                height = 20;
                                num12 = -1;
                                int num34 = tile[k, i].type;
                                int num35 = tile[k, i].frameX / 0x12;
                                if (num34 > 0x52)
                                {
                                    if ((num35 == 0) && dayTime)
                                    {
                                        num34 = 0x54;
                                    }
                                    if ((num35 == 1) && !dayTime)
                                    {
                                        num34 = 0x54;
                                    }
                                    if ((num35 == 3) && bloodMoon)
                                    {
                                        num34 = 0x54;
                                    }
                                }
                                if (num34 == 0x54)
                                {
                                    if ((num35 == 0) && (rand.Next(100) == 0))
                                    {
                                        color8 = new Color();
                                        int num36 = Dust.NewDust(new Vector2((float)(k * 0x10), (float)((i * 0x10) - 4)), 0x10, 0x10, 0x13, 0f, 0f, 160, color8, 0.1f);
                                        dust[num36].velocity.X /= 2f;
                                        dust[num36].velocity.Y /= 2f;
                                        dust[num36].noGravity = true;
                                        dust[num36].fadeIn = 1f;
                                    }
                                    if ((num35 == 1) && (rand.Next(100) == 0))
                                    {
                                        color8 = new Color();
                                        Dust.NewDust(new Vector2((float)(k * 0x10), (float)(i * 0x10)), 0x10, 0x10, 0x29, 0f, 0f, 250, color8, 0.8f);
                                    }
                                    if (num35 == 3)
                                    {
                                        if (rand.Next(200) == 0)
                                        {
                                            color8 = new Color();
                                            int num37 = Dust.NewDust(new Vector2((float)(k * 0x10), (float)(i * 0x10)), 0x10, 0x10, 14, 0f, 0f, 100, color8, 0.2f);
                                            dust[num37].fadeIn = 1.2f;
                                        }
                                        if (rand.Next(0x4b) == 0)
                                        {
                                            color8 = new Color();
                                            int num38 = Dust.NewDust(new Vector2((float)(k * 0x10), (float)(i * 0x10)), 0x10, 0x10, 0x1b, 0f, 0f, 100, color8, 1f);
                                            dust[num38].velocity.X /= 2f;
                                            dust[num38].velocity.Y /= 2f;
                                        }
                                    }
                                    if ((num35 == 4) && (rand.Next(150) == 0))
                                    {
                                        color8 = new Color();
                                        int num39 = Dust.NewDust(new Vector2((float)(k * 0x10), (float)(i * 0x10)), 0x10, 8, 0x10, 0f, 0f, 0, color8, 1f);
                                        dust[num39].velocity.X /= 3f;
                                        dust[num39].velocity.Y /= 3f;
                                        dust[num39].velocity.Y -= 0.7f;
                                        dust[num39].alpha = 50;
                                        Dust dust3 = dust[num39];
                                        dust3.scale *= 0.1f;
                                        dust[num39].fadeIn = 0.9f;
                                        dust[num39].noGravity = true;
                                    }
                                    if (num35 == 5)
                                    {
                                        if (rand.Next(40) == 0)
                                        {
                                            color8 = new Color();
                                            int num40 = Dust.NewDust(new Vector2((float)(k * 0x10), (float)((i * 0x10) - 6)), 0x10, 0x10, 6, 0f, 0f, 0, color8, 1.5f);
                                            dust[num40].velocity.Y -= 2f;
                                            dust[num40].noGravity = true;
                                        }
                                        color.A = (byte)(mouseTextColor / 2);
                                        color.G = mouseTextColor;
                                        color.B = mouseTextColor;
                                    }
                                }
                                vector3 = new Vector2();
                                this.spriteBatch.Draw(tileTexture[num34], new Vector2(((k * 0x10) - ((int)screenPosition.X)) - ((width - 16f) / 2f), (float)(((i * 0x10) - ((int)screenPosition.Y)) + num12)) + vector, new Rectangle(tile[k, i].frameX, tile[k, i].frameY, width, height), color, 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                                continue;
                            }
                            if (tile[k, i].type == 80)
                            {
                                bool flag7 = false;
                                bool flag8 = false;
                                int num41 = k;
                                if (tile[k, i].frameX == 0x24)
                                {
                                    num41--;
                                }
                                if (tile[k, i].frameX == 0x36)
                                {
                                    num41++;
                                }
                                if (tile[k, i].frameX == 0x6c)
                                {
                                    if (tile[k, i].frameY == 0x10)
                                    {
                                        num41--;
                                    }
                                    else
                                    {
                                        num41++;
                                    }
                                }
                                int num42 = i;
                                bool flag9 = false;
                                if ((tile[num41, num42].type == 80) && tile[num41, num42].active)
                                {
                                    flag9 = true;
                                }
                                while ((!tile[num41, num42].active || !tileSolid[tile[num41, num42].type]) || !flag9)
                                {
                                    if ((tile[num41, num42].type == 80) && tile[num41, num42].active)
                                    {
                                        flag9 = true;
                                    }
                                    num42++;
                                    if (num42 > (i + 20))
                                    {
                                        break;
                                    }
                                }
                                if (tile[num41, num42].type == 0x70)
                                {
                                    flag7 = true;
                                }
                                if (tile[num41, num42].type == 0x74)
                                {
                                    flag8 = true;
                                }
                                if (flag7)
                                {
                                    vector3 = new Vector2();
                                    this.spriteBatch.Draw(evilCactusTexture, new Vector2(((k * 0x10) - ((int)screenPosition.X)) - ((width - 16f) / 2f), (float)(((i * 0x10) - ((int)screenPosition.Y)) + num12)) + vector, new Rectangle(tile[k, i].frameX, tile[k, i].frameY, width, height), color, 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                                }
                                else if (flag8)
                                {
                                    vector3 = new Vector2();
                                    this.spriteBatch.Draw(goodCactusTexture, new Vector2(((k * 0x10) - ((int)screenPosition.X)) - ((width - 16f) / 2f), (float)(((i * 0x10) - ((int)screenPosition.Y)) + num12)) + vector, new Rectangle(tile[k, i].frameX, tile[k, i].frameY, width, height), color, 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                                }
                                else
                                {
                                    vector3 = new Vector2();
                                    this.spriteBatch.Draw(tileTexture[tile[k, i].type], new Vector2(((k * 0x10) - ((int)screenPosition.X)) - ((width - 16f) / 2f), (float)(((i * 0x10) - ((int)screenPosition.Y)) + num12)) + vector, new Rectangle(tile[k, i].frameX, tile[k, i].frameY, width, height), color, 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                                }
                                continue;
                            }
                            if (((Lighting.lightMode < 2) && tileSolid[tile[k, i].type]) && (tile[k, i].type != 0x89))
                            {
                                if (((color.R > num) || (color.G > (num * 1.1))) || (color.B > (num * 1.2)))
                                {
                                    for (int m = 0; m < 9; m++)
                                    {
                                        int num44 = 0;
                                        int num45 = 0;
                                        int num46 = 4;
                                        int num47 = 4;
                                        Color newColor = color;
                                        Color color5 = color;
                                        switch (m)
                                        {
                                            case 0:
                                                color5 = Lighting.GetColor(k - 1, i - 1);
                                                break;

                                            case 1:
                                                num46 = 8;
                                                num44 = 4;
                                                color5 = Lighting.GetColor(k, i - 1);
                                                break;

                                            case 2:
                                                color5 = Lighting.GetColor(k + 1, i - 1);
                                                num44 = 12;
                                                break;

                                            case 3:
                                                color5 = Lighting.GetColor(k - 1, i);
                                                num47 = 8;
                                                num45 = 4;
                                                break;

                                            case 4:
                                                num46 = 8;
                                                num47 = 8;
                                                num44 = 4;
                                                num45 = 4;
                                                break;

                                            case 5:
                                                num44 = 12;
                                                num45 = 4;
                                                num47 = 8;
                                                color5 = Lighting.GetColor(k + 1, i);
                                                break;

                                            case 6:
                                                color5 = Lighting.GetColor(k - 1, i + 1);
                                                num45 = 12;
                                                break;

                                            case 7:
                                                num46 = 8;
                                                num47 = 4;
                                                num44 = 4;
                                                num45 = 12;
                                                color5 = Lighting.GetColor(k, i + 1);
                                                break;

                                            case 8:
                                                color5 = Lighting.GetColor(k + 1, i + 1);
                                                num44 = 12;
                                                num45 = 12;
                                                break;
                                        }
                                        newColor.R = (byte)((color.R + color5.R) / 2);
                                        newColor.G = (byte)((color.G + color5.G) / 2);
                                        newColor.B = (byte)((color.B + color5.B) / 2);
                                        if (tileShine2[tile[k, i].type])
                                        {
                                            newColor = shine(newColor, tile[k, i].type);
                                        }
                                        vector3 = new Vector2();
                                        this.spriteBatch.Draw(tileTexture[tile[k, i].type], new Vector2((((k * 0x10) - ((int)screenPosition.X)) - ((width - 16f) / 2f)) + num44, (float)((((i * 0x10) - ((int)screenPosition.Y)) + num12) + num45)) + vector, new Rectangle(tile[k, i].frameX + num44, tile[k, i].frameY + num45, num46, num47), newColor, 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                                    }
                                }
                                else if (((color.R > num2) || (color.G > (num2 * 1.1))) || (color.B > (num2 * 1.2)))
                                {
                                    for (int n = 0; n < 4; n++)
                                    {
                                        int num49 = 0;
                                        int num50 = 0;
                                        Color color6 = color;
                                        Color color7 = color;
                                        switch (n)
                                        {
                                            case 0:
                                                if (Lighting.Brighter(k, i - 1, k - 1, i))
                                                {
                                                    color7 = Lighting.GetColor(k - 1, i);
                                                }
                                                else
                                                {
                                                    color7 = Lighting.GetColor(k, i - 1);
                                                }
                                                break;

                                            case 1:
                                                if (Lighting.Brighter(k, i - 1, k + 1, i))
                                                {
                                                    color7 = Lighting.GetColor(k + 1, i);
                                                }
                                                else
                                                {
                                                    color7 = Lighting.GetColor(k, i - 1);
                                                }
                                                num49 = 8;
                                                break;

                                            case 2:
                                                if (Lighting.Brighter(k, i + 1, k - 1, i))
                                                {
                                                    color7 = Lighting.GetColor(k - 1, i);
                                                }
                                                else
                                                {
                                                    color7 = Lighting.GetColor(k, i + 1);
                                                }
                                                num50 = 8;
                                                break;

                                            case 3:
                                                if (Lighting.Brighter(k, i + 1, k + 1, i))
                                                {
                                                    color7 = Lighting.GetColor(k + 1, i);
                                                }
                                                else
                                                {
                                                    color7 = Lighting.GetColor(k, i + 1);
                                                }
                                                num49 = 8;
                                                num50 = 8;
                                                break;
                                        }
                                        color6.R = (byte)((color.R + color7.R) / 2);
                                        color6.G = (byte)((color.G + color7.G) / 2);
                                        color6.B = (byte)((color.B + color7.B) / 2);
                                        if (tileShine2[tile[k, i].type])
                                        {
                                            color6 = shine(color6, tile[k, i].type);
                                        }
                                        vector3 = new Vector2();
                                        this.spriteBatch.Draw(tileTexture[tile[k, i].type], new Vector2((((k * 0x10) - ((int)screenPosition.X)) - ((width - 16f) / 2f)) + num49, (float)((((i * 0x10) - ((int)screenPosition.Y)) + num12) + num50)) + vector, new Rectangle(tile[k, i].frameX + num49, tile[k, i].frameY + num50, 8, 8), color6, 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                                    }
                                }
                                else
                                {
                                    if (tileShine2[tile[k, i].type])
                                    {
                                        color = shine(color, tile[k, i].type);
                                    }
                                    vector3 = new Vector2();
                                    this.spriteBatch.Draw(tileTexture[tile[k, i].type], new Vector2(((k * 0x10) - ((int)screenPosition.X)) - ((width - 16f) / 2f), (float)(((i * 0x10) - ((int)screenPosition.Y)) + num12)) + vector, new Rectangle(tile[k, i].frameX, tile[k, i].frameY, width, height), color, 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                                }
                            }
                            else
                            {
                                if ((Lighting.lightMode < 2) && tileShine2[tile[k, i].type])
                                {
                                    if (tile[k, i].type == 0x15)
                                    {
                                        if ((tile[k, i].frameX >= 0x24) && (tile[k, i].frameX < 0xb2))
                                        {
                                            color = shine(color, tile[k, i].type);
                                        }
                                    }
                                    else
                                    {
                                        color = shine(color, tile[k, i].type);
                                    }
                                }
                                if (tile[k, i].type == 0x80)
                                {
                                    int frameX = tile[k, i].frameX;
                                    while (frameX >= 100)
                                    {
                                        frameX -= 100;
                                    }
                                    vector3 = new Vector2();
                                    this.spriteBatch.Draw(tileTexture[tile[k, i].type], new Vector2(((k * 0x10) - ((int)screenPosition.X)) - ((width - 16f) / 2f), (float)(((i * 0x10) - ((int)screenPosition.Y)) + num12)) + vector, new Rectangle(frameX, tile[k, i].frameY, width, height), color, 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                                }
                                else
                                {
                                    vector3 = new Vector2();
                                    this.spriteBatch.Draw(tileTexture[tile[k, i].type], new Vector2(((k * 0x10) - ((int)screenPosition.X)) - ((width - 16f) / 2f), (float)(((i * 0x10) - ((int)screenPosition.Y)) + num12)) + vector, new Rectangle(tile[k, i].frameX, tile[k, i].frameY, width, height), color, 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                                    if (tile[k, i].type == 0x8b)
                                    {
                                        vector3 = new Vector2();
                                        this.spriteBatch.Draw(MusicBoxTexture, new Vector2(((k * 0x10) - ((int)screenPosition.X)) - ((width - 16f) / 2f), (float)(((i * 0x10) - ((int)screenPosition.Y)) + num12)) + vector, new Rectangle(tile[k, i].frameX, tile[k, i].frameY, width, height), new Color(200, 200, 200, 0), 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                                    }
                                    if (tile[k, i].type == 0x90)
                                    {
                                        vector3 = new Vector2();
                                        this.spriteBatch.Draw(timerTexture, new Vector2(((k * 0x10) - ((int)screenPosition.X)) - ((width - 16f) / 2f), (float)(((i * 0x10) - ((int)screenPosition.Y)) + num12)) + vector, new Rectangle(tile[k, i].frameX, tile[k, i].frameY, width, height), new Color(200, 200, 200, 0), 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            for (int j = 0; j < index; j++)
            {
                int x = numArray[j];
                int y = numArray2[j];
                if ((tile[x, y].type == 0x80) && (tile[x, y].frameX >= 100))
                {
                    int num55 = tile[x, y].frameY / 0x12;
                    int num56 = tile[x, y].frameX;
                    int num57 = 0;
                    while (num56 >= 100)
                    {
                        num57++;
                        num56 -= 100;
                    }
                    int num58 = -4;
                    SpriteEffects flipHorizontally = SpriteEffects.FlipHorizontally;
                    if (num56 >= 0x24)
                    {
                        flipHorizontally = SpriteEffects.None;
                        num58 = -4;
                    }
                    switch (num55)
                    {
                        case 0:
                            vector3 = new Vector2();
                            this.spriteBatch.Draw(armorHeadTexture[num57], new Vector2((float)(((x * 0x10) - ((int)screenPosition.X)) + num58), (float)(((y * 0x10) - ((int)screenPosition.Y)) - 12)) + vector, new Rectangle(0, 0, 40, 0x24), Lighting.GetColor(x, y), 0f, vector3, (float)1f, flipHorizontally, 0f);
                            break;

                        case 1:
                            vector3 = new Vector2();
                            this.spriteBatch.Draw(armorBodyTexture[num57], new Vector2((float)(((x * 0x10) - ((int)screenPosition.X)) + num58), (float)(((y * 0x10) - ((int)screenPosition.Y)) - 0x1c)) + vector, new Rectangle(0, 0, 40, 0x36), Lighting.GetColor(x, y), 0f, vector3, (float)1f, flipHorizontally, 0f);
                            break;

                        case 2:
                            vector3 = new Vector2();
                            this.spriteBatch.Draw(armorLegTexture[num57], new Vector2((float)(((x * 0x10) - ((int)screenPosition.X)) + num58), (float)(((y * 0x10) - ((int)screenPosition.Y)) - 0x2c)) + vector, new Rectangle(0, 0, 40, 0x36), Lighting.GetColor(x, y), 0f, vector3, (float)1f, flipHorizontally, 0f);
                            break;
                    }
                }
                if (((tile[x, y].type == 5) && (tile[x, y].frameY >= 0xc6)) && (tile[x, y].frameX >= 0x16))
                {
                    int num59 = 0;
                    if (tile[x, y].frameX == 0x16)
                    {
                        if (tile[x, y].frameY == 220)
                        {
                            num59 = 1;
                        }
                        else if (tile[x, y].frameY == 0xf2)
                        {
                            num59 = 2;
                        }
                        int num60 = 0;
                        int num61 = 80;
                        int num62 = 80;
                        int num63 = 0x20;
                        int num64 = 0;
                        for (int num65 = y; num65 < (y + 100); num65++)
                        {
                            if (tile[x, num65].type == 2)
                            {
                                num60 = 0;
                                break;
                            }
                            if (tile[x, num65].type == 0x17)
                            {
                                num60 = 1;
                                break;
                            }
                            if (tile[x, num65].type == 60)
                            {
                                num60 = 2;
                                num61 = 0x72;
                                num62 = 0x60;
                                num63 = 0x30;
                                break;
                            }
                            if (tile[x, num65].type == 0x93)
                            {
                                num60 = 4;
                                break;
                            }
                            if (tile[x, num65].type == 0x6d)
                            {
                                num60 = 3;
                                num62 = 140;
                                if ((x % 3) == 1)
                                {
                                    num59 += 3;
                                }
                                else if ((x % 3) == 2)
                                {
                                    num59 += 6;
                                }
                                break;
                            }
                        }
                        vector3 = new Vector2();
                        this.spriteBatch.Draw(treeTopTexture[num60], new Vector2((float)(((x * 0x10) - ((int)screenPosition.X)) - num63), (float)(((((y * 0x10) - ((int)screenPosition.Y)) - num62) + 0x10) + num64)) + vector, new Rectangle(num59 * (num61 + 2), 0, num61, num62), Lighting.GetColor(x, y), 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                        continue;
                    }
                    if (tile[x, y].frameX == 0x2c)
                    {
                        if (tile[x, y].frameY == 220)
                        {
                            num59 = 1;
                        }
                        else if (tile[x, y].frameY == 0xf2)
                        {
                            num59 = 2;
                        }
                        int num66 = 0;
                        for (int num67 = y; num67 < (y + 100); num67++)
                        {
                            if (tile[x + 1, num67].type == 2)
                            {
                                num66 = 0;
                                break;
                            }
                            if (tile[x + 1, num67].type == 0x17)
                            {
                                num66 = 1;
                                break;
                            }
                            if (tile[x + 1, num67].type == 60)
                            {
                                num66 = 2;
                                break;
                            }
                            if (tile[x + 1, num67].type == 0x93)
                            {
                                num66 = 4;
                                break;
                            }
                            if (tile[x + 1, num67].type == 0x6d)
                            {
                                num66 = 3;
                                if ((x % 3) == 1)
                                {
                                    num59 += 3;
                                }
                                else if ((x % 3) == 2)
                                {
                                    num59 += 6;
                                }
                                break;
                            }
                        }
                        vector3 = new Vector2();
                        this.spriteBatch.Draw(treeBranchTexture[num66], new Vector2((float)(((x * 0x10) - ((int)screenPosition.X)) - 0x18), (float)(((y * 0x10) - ((int)screenPosition.Y)) - 12)) + vector, new Rectangle(0, num59 * 0x2a, 40, 40), Lighting.GetColor(x, y), 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                        continue;
                    }
                    if (tile[x, y].frameX == 0x42)
                    {
                        if (tile[x, y].frameY == 220)
                        {
                            num59 = 1;
                        }
                        else if (tile[x, y].frameY == 0xf2)
                        {
                            num59 = 2;
                        }
                        int num68 = 0;
                        for (int num69 = y; num69 < (y + 100); num69++)
                        {
                            if (tile[x - 1, num69].type == 2)
                            {
                                num68 = 0;
                                break;
                            }
                            if (tile[x - 1, num69].type == 0x17)
                            {
                                num68 = 1;
                                break;
                            }
                            if (tile[x - 1, num69].type == 60)
                            {
                                num68 = 2;
                                break;
                            }
                            if (tile[x - 1, num69].type == 0x93)
                            {
                                num68 = 4;
                                break;
                            }
                            if (tile[x - 1, num69].type == 0x6d)
                            {
                                num68 = 3;
                                if ((x % 3) == 1)
                                {
                                    num59 += 3;
                                }
                                else if ((x % 3) == 2)
                                {
                                    num59 += 6;
                                }
                                break;
                            }
                        }
                        vector3 = new Vector2();
                        this.spriteBatch.Draw(treeBranchTexture[num68], new Vector2((float)((x * 0x10) - ((int)screenPosition.X)), (float)(((y * 0x10) - ((int)screenPosition.Y)) - 12)) + vector, new Rectangle(0x2a, num59 * 0x2a, 40, 40), Lighting.GetColor(x, y), 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                    }
                }
            }
            if (solidOnly)
            {
                renderTimer[0] = stopwatch.ElapsedMilliseconds;
            }
            else
            {
                renderTimer[1] = stopwatch.ElapsedMilliseconds;
            }
        }
Ejemplo n.º 31
0
 public static int GetTrackItem(Tile trackCache)
 {
     switch (Minecart._trackType[trackCache.frameX])
     {
         case 0:
         {
             return 2340;
         }
         case 1:
         {
             return 2492;
         }
         case 2:
         {
             return 2739;
         }
     }
     return 0;
 }
Ejemplo n.º 32
0
        protected void DrawWalls()
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            int num = (int)((255f * (1f - gfxQuality)) + (100f * gfxQuality));
            int num2 = (int)((120f * (1f - gfxQuality)) + (40f * gfxQuality));
            Vector2 vector = new Vector2((float)offScreenRange, (float)offScreenRange);
            if (drawToScreen)
            {
                vector = new Vector2();
            }
            int num3 = ((tileColor.R + tileColor.G) + tileColor.B) / 3;
            float num4 = ((float)(num3 * 0.53)) / 255f;
            if (Lighting.lightMode == 2)
            {
                num4 = ((float)(tileColor.R - 12)) / 255f;
            }
            if (Lighting.lightMode == 3)
            {
                num4 = ((float)(num3 - 12)) / 255f;
            }
            int num5 = (int)(((screenPosition.X - vector.X) / 16f) - 1f);
            int num6 = ((int)(((screenPosition.X + screenWidth) + vector.X) / 16f)) + 2;
            int num7 = (int)(((screenPosition.Y - vector.Y) / 16f) - 1f);
            int num8 = ((int)(((screenPosition.Y + screenHeight) + vector.Y) / 16f)) + 5;
            int num9 = offScreenRange / 0x10;
            int num10 = offScreenRange / 0x10;
            if ((num5 - num9) < 0)
            {
                num5 = num9;
            }
            if ((num6 + num9) > maxTilesX)
            {
                num6 = maxTilesX - num9;
            }
            if ((num7 - num10) < 0)
            {
                num7 = num10;
            }
            if ((num8 + num10) > maxTilesY)
            {
                num8 = maxTilesY - num10;
            }
            for (int i = num7 - num10; i < (num8 + num10); i++)
            {
                if (i <= worldSurface)
                {
                    for (int k = num5 - num9; k < (num6 + num9); k++)
                    {
                        if (tile[k, i] == null)
                        {
                            tile[k, i] = new Tile();
                        }
                        if ((Lighting.Brightness(k, i) < num4) && (((tile[k, i].liquid < 250) || WorldGen.SolidTile(k, i)) || ((tile[k, i].liquid > 250) && (Lighting.Brightness(k, i) == 0f))))
                        {
                            this.spriteBatch.Draw(blackTileTexture, new Vector2((float)((k * 0x10) - ((int)screenPosition.X)), (float)((i * 0x10) - ((int)screenPosition.Y))) + vector, Lighting.GetBlackness(k, i));
                        }
                    }
                }
            }
            for (int j = num7 - num10; j < (num8 + num10); j++)
            {
                for (int m = num5 - num9; m < (num6 + num9); m++)
                {
                    if (tile[m, j] == null)
                    {
                        tile[m, j] = new Tile();
                    }
                    if (((tile[m, j].wall > 0) && (Lighting.Brightness(m, j) > 0f)) && !this.FullTile(m, j))
                    {
                        Rectangle rectangle;
                        Color color = Lighting.GetColor(m, j);
                        if (((Lighting.lightMode < 2) && (tile[m, j].wall != 0x15)) && !WorldGen.SolidTile(m, j))
                        {
                            if (((color.R > num) || (color.G > (num * 1.1))) || (color.B > (num * 1.2)))
                            {
                                for (int n = 0; n < 9; n++)
                                {
                                    int num16 = 0;
                                    int num17 = 0;
                                    int width = 12;
                                    int height = 12;
                                    Color color2 = color;
                                    Color color3 = color;
                                    switch (n)
                                    {
                                        case 0:
                                            color3 = Lighting.GetColor(m - 1, j - 1);
                                            break;

                                        case 1:
                                            width = 8;
                                            num16 = 12;
                                            color3 = Lighting.GetColor(m, j - 1);
                                            break;

                                        case 2:
                                            color3 = Lighting.GetColor(m + 1, j - 1);
                                            num16 = 20;
                                            break;

                                        case 3:
                                            color3 = Lighting.GetColor(m - 1, j);
                                            height = 8;
                                            num17 = 12;
                                            break;

                                        case 4:
                                            width = 8;
                                            height = 8;
                                            num16 = 12;
                                            num17 = 12;
                                            break;

                                        case 5:
                                            num16 = 20;
                                            num17 = 12;
                                            height = 8;
                                            color3 = Lighting.GetColor(m + 1, j);
                                            break;

                                        case 6:
                                            color3 = Lighting.GetColor(m - 1, j + 1);
                                            num17 = 20;
                                            break;

                                        case 7:
                                            width = 12;
                                            num16 = 12;
                                            num17 = 20;
                                            color3 = Lighting.GetColor(m, j + 1);
                                            break;

                                        case 8:
                                            color3 = Lighting.GetColor(m + 1, j + 1);
                                            num16 = 20;
                                            num17 = 20;
                                            break;
                                    }
                                    color2.R = (byte)((color.R + color3.R) / 2);
                                    color2.G = (byte)((color.G + color3.G) / 2);
                                    color2.B = (byte)((color.B + color3.B) / 2);
                                    Vector2 origin = new Vector2();
                                    this.spriteBatch.Draw(wallTexture[tile[m, j].wall], new Vector2((float)((((m * 0x10) - ((int)screenPosition.X)) - 8) + num16), (float)((((j * 0x10) - ((int)screenPosition.Y)) - 8) + num17)) + vector, new Rectangle((tile[m, j].wallFrameX * 2) + num16, (tile[m, j].wallFrameY * 2) + num17, width, height), color2, 0f, origin, (float)1f, SpriteEffects.None, 0f);
                                }
                            }
                            else if (((color.R > num2) || (color.G > (num2 * 1.1))) || (color.B > (num2 * 1.2)))
                            {
                                for (int num20 = 0; num20 < 4; num20++)
                                {
                                    int num21 = 0;
                                    int num22 = 0;
                                    Color color4 = color;
                                    Color color5 = color;
                                    switch (num20)
                                    {
                                        case 0:
                                            if (Lighting.Brighter(m, j - 1, m - 1, j))
                                            {
                                                color5 = Lighting.GetColor(m - 1, j);
                                            }
                                            else
                                            {
                                                color5 = Lighting.GetColor(m, j - 1);
                                            }
                                            break;

                                        case 1:
                                            if (Lighting.Brighter(m, j - 1, m + 1, j))
                                            {
                                                color5 = Lighting.GetColor(m + 1, j);
                                            }
                                            else
                                            {
                                                color5 = Lighting.GetColor(m, j - 1);
                                            }
                                            num21 = 0x10;
                                            break;

                                        case 2:
                                            if (Lighting.Brighter(m, j + 1, m - 1, j))
                                            {
                                                color5 = Lighting.GetColor(m - 1, j);
                                            }
                                            else
                                            {
                                                color5 = Lighting.GetColor(m, j + 1);
                                            }
                                            num22 = 0x10;
                                            break;

                                        case 3:
                                            if (Lighting.Brighter(m, j + 1, m + 1, j))
                                            {
                                                color5 = Lighting.GetColor(m + 1, j);
                                            }
                                            else
                                            {
                                                color5 = Lighting.GetColor(m, j + 1);
                                            }
                                            num21 = 0x10;
                                            num22 = 0x10;
                                            break;
                                    }
                                    color4.R = (byte)((color.R + color5.R) / 2);
                                    color4.G = (byte)((color.G + color5.G) / 2);
                                    color4.B = (byte)((color.B + color5.B) / 2);
                                    Vector2 vector3 = new Vector2();
                                    this.spriteBatch.Draw(wallTexture[tile[m, j].wall], new Vector2((float)((((m * 0x10) - ((int)screenPosition.X)) - 8) + num21), (float)((((j * 0x10) - ((int)screenPosition.Y)) - 8) + num22)) + vector, new Rectangle((tile[m, j].wallFrameX * 2) + num21, (tile[m, j].wallFrameY * 2) + num22, 0x10, 0x10), color4, 0f, vector3, (float)1f, SpriteEffects.None, 0f);
                                }
                            }
                            else
                            {
                                rectangle = new Rectangle(tile[m, j].wallFrameX * 2, tile[m, j].wallFrameY * 2, 0x20, 0x20);
                                Vector2 vector4 = new Vector2();
                                this.spriteBatch.Draw(wallTexture[tile[m, j].wall], new Vector2((float)(((m * 0x10) - ((int)screenPosition.X)) - 8), (float)(((j * 0x10) - ((int)screenPosition.Y)) - 8)) + vector, new Rectangle?(rectangle), Lighting.GetColor(m, j), 0f, vector4, (float)1f, SpriteEffects.None, 0f);
                            }
                        }
                        else
                        {
                            rectangle = new Rectangle(tile[m, j].wallFrameX * 2, tile[m, j].wallFrameY * 2, 0x20, 0x20);
                            Vector2 vector5 = new Vector2();
                            this.spriteBatch.Draw(wallTexture[tile[m, j].wall], new Vector2((float)(((m * 0x10) - ((int)screenPosition.X)) - 8), (float)(((j * 0x10) - ((int)screenPosition.Y)) - 8)) + vector, new Rectangle?(rectangle), Lighting.GetColor(m, j), 0f, vector5, (float)1f, SpriteEffects.None, 0f);
                        }
                        if (((color.R > (num2 * 0.4)) || (color.G > (num2 * 0.35))) || (color.B > (num2 * 0.3)))
                        {
                            bool flag = false;
                            if ((tile[m - 1, j].wall > 0) && (wallBlend[tile[m - 1, j].wall] != wallBlend[tile[m, j].wall]))
                            {
                                flag = true;
                            }
                            bool flag2 = false;
                            if ((tile[m + 1, j].wall > 0) && (wallBlend[tile[m + 1, j].wall] != wallBlend[tile[m, j].wall]))
                            {
                                flag2 = true;
                            }
                            bool flag3 = false;
                            if ((tile[m, j - 1].wall > 0) && (wallBlend[tile[m, j - 1].wall] != wallBlend[tile[m, j].wall]))
                            {
                                flag3 = true;
                            }
                            bool flag4 = false;
                            if ((tile[m, j + 1].wall > 0) && (wallBlend[tile[m, j + 1].wall] != wallBlend[tile[m, j].wall]))
                            {
                                flag4 = true;
                            }
                            if (flag)
                            {
                                Vector2 vector6 = new Vector2();
                                this.spriteBatch.Draw(wallOutlineTexture, new Vector2((float)((m * 0x10) - ((int)screenPosition.X)), (float)((j * 0x10) - ((int)screenPosition.Y))) + vector, new Rectangle(0, 0, 2, 0x10), Lighting.GetColor(m, j), 0f, vector6, (float)1f, SpriteEffects.None, 0f);
                            }
                            if (flag2)
                            {
                                Vector2 vector7 = new Vector2();
                                this.spriteBatch.Draw(wallOutlineTexture, new Vector2((float)(((m * 0x10) - ((int)screenPosition.X)) + 14), (float)((j * 0x10) - ((int)screenPosition.Y))) + vector, new Rectangle(14, 0, 2, 0x10), Lighting.GetColor(m, j), 0f, vector7, (float)1f, SpriteEffects.None, 0f);
                            }
                            if (flag3)
                            {
                                Vector2 vector8 = new Vector2();
                                this.spriteBatch.Draw(wallOutlineTexture, new Vector2((float)((m * 0x10) - ((int)screenPosition.X)), (float)((j * 0x10) - ((int)screenPosition.Y))) + vector, new Rectangle(0, 0, 0x10, 2), Lighting.GetColor(m, j), 0f, vector8, (float)1f, SpriteEffects.None, 0f);
                            }
                            if (flag4)
                            {
                                Vector2 vector9 = new Vector2();
                                this.spriteBatch.Draw(wallOutlineTexture, new Vector2((float)((m * 0x10) - ((int)screenPosition.X)), (float)(((j * 0x10) - ((int)screenPosition.Y)) + 14)) + vector, new Rectangle(0, 14, 0x10, 2), Lighting.GetColor(m, j), 0f, vector9, (float)1f, SpriteEffects.None, 0f);
                            }
                        }
                    }
                }
            }
            renderTimer[2] = stopwatch.ElapsedMilliseconds;
        }
		public static void TileFrame(int i, int j, bool resetFrame = false, bool noBreak = false)
		{
			bool flag = false;
			try
			{
				if (i > 5 && j > 5 && i < Main.maxTilesX - 5 && j < Main.maxTilesY - 5 && Main.tile[i, j] != null)
				{
					if (Main.netMode != 2 && Main.mapEnabled && !WorldGen.noMapUpdate && !WorldGen.gen)
					{
						Map map = Main.map[i, j];
						if (map != null && map.light > 0)
						{
							map.setTile(i, j, map.light);
							if (map.changed)
							{
								flag = true;
								if (Map.numUpdateTile < Map.maxUpdateTile - 1)
								{
									Map.updateTileX[Map.numUpdateTile] = (short)i;
									Map.updateTileY[Map.numUpdateTile] = (short)j;
									Map.numUpdateTile++;
								}
								else
								{
									Main.refreshMap = true;
								}
							}
						}
					}
					Tile tile = Main.tile[i, j];
					if (!tile.active())
					{
						tile.halfBrick(false);
						tile.color(0);
						tile.slope(0);
					}
					if (tile.liquid > 0 && Main.netMode != 1 && !WorldGen.noLiquidCheck)
					{
						Liquid.AddWater(i, j);
					}
					if (tile.active())
					{
						if (noBreak && Main.tileFrameImportant[(int)tile.type] && tile.type != 4)
						{
							return;
						}
						int num = (int)tile.type;
						if (Main.tileStone[num])
						{
							num = 1;
						}
						int frameX = (int)tile.frameX;
						int frameY = (int)tile.frameY;
						Rectangle rectangle = new Rectangle(-1, -1, 0, 0);
						if (Main.tileFrameImportant[(int)tile.type])
						{
							if (num == 4)
							{
								Tile tile2 = Main.tile[i, j - 1];
								Tile tile3 = Main.tile[i, j + 1];
								Tile tile4 = Main.tile[i - 1, j];
								Tile tile5 = Main.tile[i + 1, j];
								Tile tile6 = Main.tile[i - 1, j + 1];
								Tile tile7 = Main.tile[i + 1, j + 1];
								Tile tile8 = Main.tile[i - 1, j - 1];
								Tile tile9 = Main.tile[i + 1, j - 1];
								short num2 = 0;
								if (tile.frameX >= 66)
								{
									num2 = 66;
								}
								int num3 = -1;
								int num4 = -1;
								int num5 = -1;
								int num6 = -1;
								int num7 = -1;
								int num8 = -1;
								int num9 = -1;
								if (tile2 != null && tile2.nactive() && !tile2.bottomSlope())
								{
									ushort arg_24A_0 = tile2.type;
								}
								if (tile3 != null && tile3.nactive() && !tile3.halfBrick() && !tile3.topSlope())
								{
									num3 = (int)tile3.type;
								}
								if (tile4 != null && tile4.nactive() && (tile4.slope() == 0 || tile4.slope() % 2 != 1))
								{
									num4 = (int)tile4.type;
								}
								if (tile5 != null && tile5.nactive() && (tile5.slope() == 0 || tile5.slope() % 2 != 0))
								{
									num5 = (int)tile5.type;
								}
								if (tile6 != null && tile6.nactive())
								{
									num6 = (int)tile6.type;
								}
								if (tile7 != null && tile7.nactive())
								{
									num7 = (int)tile7.type;
								}
								if (tile8 != null && tile8.nactive())
								{
									num8 = (int)tile8.type;
								}
								if (tile9 != null && tile9.nactive())
								{
									num9 = (int)tile9.type;
								}
								if (num3 >= 0 && Main.tileSolid[num3] && !Main.tileNoAttach[num3])
								{
									tile.frameX = num2;
								}
								else
								{
									if ((num4 >= 0 && Main.tileSolid[num4] && !Main.tileNoAttach[num4]) || num4 == 124 || (num4 == 5 && num8 == 5 && num6 == 5))
									{
										tile.frameX = (short)(22 + num2);
									}
									else
									{
										if ((num5 >= 0 && Main.tileSolid[num5] && !Main.tileNoAttach[num5]) || num5 == 124 || (num5 == 5 && num9 == 5 && num7 == 5))
										{
											tile.frameX = (short)(44 + num2);
										}
										else
										{
											if (tile.wall > 0)
											{
												tile.frameX = num2;
											}
											else
											{
												WorldGen.KillTile(i, j, false, false, false);
											}
										}
									}
								}
								return;
							}
							if (num == 136)
							{
								Tile tile2 = Main.tile[i, j - 1];
								Tile tile3 = Main.tile[i, j + 1];
								Tile tile4 = Main.tile[i - 1, j];
								Tile tile5 = Main.tile[i + 1, j];
								int num10 = -1;
								int num11 = -1;
								int num12 = -1;
								if (tile2 != null && tile2.nactive())
								{
									ushort arg_447_0 = tile2.type;
								}
								if (tile3 != null && tile3.nactive() && !tile3.halfBrick() && !tile3.topSlope())
								{
									num10 = (int)tile3.type;
								}
								if (tile4 != null && tile4.nactive())
								{
									num11 = (int)tile4.type;
								}
								if (tile5 != null && tile5.nactive())
								{
									num12 = (int)tile5.type;
								}
								if (num10 >= 0 && Main.tileSolid[num10] && !Main.tileNoAttach[num10])
								{
									tile.frameX = 0;
								}
								else
								{
									if ((num11 >= 0 && Main.tileSolid[num11] && !Main.tileNoAttach[num11]) || num11 == 124 || num11 == 5)
									{
										tile.frameX = 18;
									}
									else
									{
										if ((num12 >= 0 && Main.tileSolid[num12] && !Main.tileNoAttach[num12]) || num12 == 124 || num12 == 5)
										{
											tile.frameX = 36;
										}
										else
										{
											if (tile.wall > 0)
											{
												tile.frameX = 54;
											}
											else
											{
												WorldGen.KillTile(i, j, false, false, false);
											}
										}
									}
								}
								return;
							}
							if (num == 129 || num == 149)
							{
								Tile tile2 = Main.tile[i, j - 1];
								Tile tile3 = Main.tile[i, j + 1];
								Tile tile4 = Main.tile[i - 1, j];
								Tile tile5 = Main.tile[i + 1, j];
								int num13 = -1;
								int num14 = -1;
								int num15 = -1;
								int num16 = -1;
								if (tile2 != null && tile2.nactive() && !tile2.bottomSlope())
								{
									num14 = (int)tile2.type;
								}
								if (tile3 != null && tile3.nactive() && !tile3.halfBrick() && !tile3.topSlope())
								{
									num13 = (int)tile3.type;
								}
								if (tile4 != null && tile4.nactive())
								{
									num15 = (int)tile4.type;
								}
								if (tile5 != null && tile5.nactive())
								{
									num16 = (int)tile5.type;
								}
								if (num13 >= 0 && Main.tileSolid[num13] && !Main.tileSolidTop[num13])
								{
									tile.frameY = 0;
								}
								else
								{
									if (num15 >= 0 && Main.tileSolid[num15] && !Main.tileSolidTop[num15])
									{
										tile.frameY = 54;
									}
									else
									{
										if (num16 >= 0 && Main.tileSolid[num16] && !Main.tileSolidTop[num16])
										{
											tile.frameY = 36;
										}
										else
										{
											if (num14 >= 0 && Main.tileSolid[num14] && !Main.tileSolidTop[num14])
											{
												tile.frameY = 18;
											}
											else
											{
												WorldGen.KillTile(i, j, false, false, false);
											}
										}
									}
								}
							}
							else
							{
								if (num == 178)
								{
									Tile tile2 = Main.tile[i, j - 1];
									Tile tile3 = Main.tile[i, j + 1];
									Tile tile4 = Main.tile[i - 1, j];
									Tile tile5 = Main.tile[i + 1, j];
									int num17 = -1;
									int num18 = -1;
									int num19 = -1;
									int num20 = -1;
									if (tile2 != null && tile2.active() && !tile2.bottomSlope())
									{
										num18 = (int)tile2.type;
									}
									if (tile3 != null && tile3.active() && !tile3.halfBrick() && !tile3.topSlope())
									{
										num17 = (int)tile3.type;
									}
									if (tile4 != null && tile4.active())
									{
										num19 = (int)tile4.type;
									}
									if (tile5 != null && tile5.active())
									{
										num20 = (int)tile5.type;
									}
									short num21 = (short)(WorldGen.genRand.Next(3) * 18);
									if (num17 >= 0 && Main.tileSolid[num17] && !Main.tileSolidTop[num17])
									{
										if (tile.frameY < 0 || tile.frameY > 36)
										{
											tile.frameY = num21;
										}
									}
									else
									{
										if (num19 >= 0 && Main.tileSolid[num19] && !Main.tileSolidTop[num19])
										{
											if (tile.frameY < 108 || tile.frameY > 54)
											{
												tile.frameY = (short)(108 + num21);
											}
										}
										else
										{
											if (num20 >= 0 && Main.tileSolid[num20] && !Main.tileSolidTop[num20])
											{
												if (tile.frameY < 162 || tile.frameY > 198)
												{
													tile.frameY = (short)(162 + num21);
												}
											}
											else
											{
												if (num18 >= 0 && Main.tileSolid[num18] && !Main.tileSolidTop[num18])
												{
													if (tile.frameY < 54 || tile.frameY > 90)
													{
														tile.frameY = (short)(54 + num21);
													}
												}
												else
												{
													WorldGen.KillTile(i, j, false, false, false);
												}
											}
										}
									}
								}
								else
								{
									if (num == 184)
									{
										Tile tile2 = Main.tile[i, j - 1];
										Tile tile3 = Main.tile[i, j + 1];
										Tile tile4 = Main.tile[i - 1, j];
										Tile tile5 = Main.tile[i + 1, j];
										int num22 = -1;
										int num23 = -1;
										int num24 = -1;
										int num25 = -1;
										if (tile2 != null && tile2.active() && !tile2.bottomSlope())
										{
											num23 = (int)tile2.type;
										}
										if (tile3 != null && tile3.active() && !tile3.halfBrick() && !tile3.topSlope())
										{
											num22 = (int)tile3.type;
										}
										if (tile4 != null && tile4.active())
										{
											num24 = (int)tile4.type;
										}
										if (tile5 != null && tile5.active())
										{
											num25 = (int)tile5.type;
										}
										short num26 = (short)(WorldGen.genRand.Next(3) * 18);
										if (num22 >= 0 && Main.tileMoss[num22])
										{
											tile.frameX = (short)(22 * (num22 - 179));
											if (tile.frameY < 0 || tile.frameY > 36)
											{
												tile.frameY = num26;
											}
										}
										else
										{
											if (num23 >= 0 && Main.tileMoss[num23])
											{
												tile.frameX = (short)(22 * (num23 - 179));
												if (tile.frameY < 54 || tile.frameY > 90)
												{
													tile.frameY = (short)(54 + num26);
												}
											}
											else
											{
												if (num24 >= 0 && Main.tileMoss[num24])
												{
													tile.frameX = (short)(22 * (num24 - 179));
													if (tile.frameY < 108 || tile.frameY > 54)
													{
														tile.frameY = (short)(108 + num26);
													}
												}
												else
												{
													if (num25 >= 0 && Main.tileMoss[num25])
													{
														tile.frameX = (short)(22 * (num25 - 179));
														if (tile.frameY < 162 || tile.frameY > 198)
														{
															tile.frameY = (short)(162 + num26);
														}
													}
													else
													{
														WorldGen.KillTile(i, j, false, false, false);
													}
												}
											}
										}
									}
									else
									{
										if (num == 3 || num == 24 || num == 61 || num == 71 || num == 73 || num == 74 || num == 110 || num == 113 || num == 201)
										{
											WorldGen.PlantCheck(i, j);
										}
										else
										{
											if (num == 227)
											{
												WorldGen.CheckDye(i, j);
											}
											else
											{
												if (num == 12 || num == 31)
												{
													WorldGen.CheckOrb(i, j, num);
												}
												else
												{
													if (num == 165)
													{
														WorldGen.CheckTight(i, j);
													}
													else
													{
														if (num == 235)
														{
															WorldGen.Check3x1(i, j, num);
														}
														else
														{
															if (num == 185)
															{
																WorldGen.CheckPile(i, j);
															}
															else
															{
																if ((num >= 275 && num <= 281) || num == 296 || num == 297 || num == 309)
																{
																	WorldGen.Check6x3(i, j, num);
																}
																else
																{
																	if (num == 10)
																	{
																		if (!WorldGen.destroyObject)
																		{
																			bool flag2 = false;
																			int frameY2 = (int)tile.frameY;
																			int num27 = frameY2 / 54;
																			int num28 = j - frameY2 % 54 / 18;
																			Tile tile10 = Main.tile[i, num28 - 1];
																			Tile tile11 = Main.tile[i, num28];
																			Tile tile12 = Main.tile[i, num28 + 1];
																			Tile tile13 = Main.tile[i, num28 + 2];
																			Tile tile14 = Main.tile[i, num28 + 3];
																			if (tile10 == null)
																			{
																				tile10 = new Tile();
																				Main.tile[i, num28 - 1] = tile10;
																			}
																			if (tile11 == null)
																			{
																				tile11 = new Tile();
																				Main.tile[i, num28] = tile11;
																			}
																			if (tile12 == null)
																			{
																				tile12 = new Tile();
																				Main.tile[i, num28 + 1] = tile12;
																			}
																			if (tile13 == null)
																			{
																				tile13 = new Tile();
																				Main.tile[i, num28 + 2] = tile13;
																			}
																			if (tile14 == null)
																			{
																				tile14 = new Tile();
																				Main.tile[i, num28 + 3] = tile14;
																			}
																			if (!tile10.active() || !Main.tileSolid[(int)tile10.type])
																			{
																				flag2 = true;
																			}
																			if (!WorldGen.SolidTile(tile14))
																			{
																				flag2 = true;
																			}
																			if (!tile11.active() || (int)tile11.type != num)
																			{
																				flag2 = true;
																			}
																			if (!tile12.active() || (int)tile12.type != num)
																			{
																				flag2 = true;
																			}
																			if (!tile13.active() || (int)tile13.type != num)
																			{
																				flag2 = true;
																			}
																			if (flag2)
																			{
																				WorldGen.destroyObject = true;
																				WorldGen.KillTile(i, num28, false, false, false);
																				WorldGen.KillTile(i, num28 + 1, false, false, false);
																				WorldGen.KillTile(i, num28 + 2, false, false, false);
																				if (num27 == 0)
																				{
																					Item.NewItem(i * 16, j * 16, 16, 16, 25, 1, false, 0, false);
																				}
																				else
																				{
																					if (num27 == 9)
																					{
																						Item.NewItem(i * 16, j * 16, 16, 16, 837, 1, false, 0, false);
																					}
																					else
																					{
																						if (num27 == 10)
																						{
																							Item.NewItem(i * 16, j * 16, 16, 16, 912, 1, false, 0, false);
																						}
																						else
																						{
																							if (num27 == 12)
																							{
																								Item.NewItem(i * 16, j * 16, 16, 16, 1137, 1, false, 0, false);
																							}
																							else
																							{
																								if (num27 == 13)
																								{
																									Item.NewItem(i * 16, j * 16, 16, 16, 1138, 1, false, 0, false);
																								}
																								else
																								{
																									if (num27 == 14)
																									{
																										Item.NewItem(i * 16, j * 16, 16, 16, 1139, 1, false, 0, false);
																									}
																									else
																									{
																										if (num27 == 15)
																										{
																											Item.NewItem(i * 16, j * 16, 16, 16, 1140, 1, false, 0, false);
																										}
																										else
																										{
																											if (num27 == 16)
																											{
																												Item.NewItem(i * 16, j * 16, 16, 16, 1411, 1, false, 0, false);
																											}
																											else
																											{
																												if (num27 == 17)
																												{
																													Item.NewItem(i * 16, j * 16, 16, 16, 1412, 1, false, 0, false);
																												}
																												else
																												{
																													if (num27 == 18)
																													{
																														Item.NewItem(i * 16, j * 16, 16, 16, 1413, 1, false, 0, false);
																													}
																													else
																													{
																														if (num27 == 19)
																														{
																															Item.NewItem(i * 16, j * 16, 16, 16, 1458, 1, false, 0, false);
																														}
																														else
																														{
																															if (num27 >= 20 && num27 <= 23)
																															{
																																Item.NewItem(i * 16, j * 16, 16, 16, 1709 + num27 - 20, 1, false, 0, false);
																															}
																															else
																															{
																																if (num27 == 24)
																																{
																																	Item.NewItem(i * 16, j * 16, 16, 16, 1793, 1, false, 0, false);
																																}
																																else
																																{
																																	if (num27 == 25)
																																	{
																																		Item.NewItem(i * 16, j * 16, 16, 16, 1815, 1, false, 0, false);
																																	}
																																	else
																																	{
																																		if (num27 == 26)
																																		{
																																			Item.NewItem(i * 16, j * 16, 16, 16, 1924, 1, false, 0, false);
																																		}
																																		else
																																		{
																																			if (num27 == 27)
																																			{
																																				Item.NewItem(i * 16, j * 16, 16, 16, 2044, 1, false, 0, false);
																																			}
																																			else
																																			{
																																				if (num27 == 28)
																																				{
																																					Item.NewItem(i * 16, j * 16, 16, 16, 2265, 1, false, 0, false);
																																				}
																																				else
																																				{
																																					if (num27 >= 4 && num27 <= 8)
																																					{
																																						Item.NewItem(i * 16, j * 16, 16, 16, 812 + num27, 1, false, 0, false);
																																					}
																																					else
																																					{
																																						if (num27 != 11)
																																						{
																																							Item.NewItem(i * 16, j * 16, 16, 16, 649 + num27, 1, false, 0, false);
																																						}
																																					}
																																				}
																																			}
																																		}
																																	}
																																}
																															}
																														}
																													}
																												}
																											}
																										}
																									}
																								}
																							}
																						}
																					}
																				}
																			}
																			WorldGen.destroyObject = false;
																		}
																	}
																	else
																	{
																		if (num == 11)
																		{
																			if (!WorldGen.destroyObject)
																			{
																				int num29 = 0;
																				int num30 = i;
																				int frameX2 = (int)tile.frameX;
																				int frameY3 = (int)tile.frameY;
																				int num31 = frameY3 / 54;
																				int num32 = j - frameY3 % 54 / 18;
																				bool flag3 = false;
																				if (frameX2 == 0)
																				{
																					num30 = i;
																					num29 = 1;
																				}
																				else
																				{
																					if (frameX2 == 18)
																					{
																						num30 = i - 1;
																						num29 = 1;
																					}
																					else
																					{
																						if (frameX2 == 36)
																						{
																							num30 = i + 1;
																							num29 = -1;
																						}
																						else
																						{
																							if (frameX2 == 54)
																							{
																								num30 = i;
																								num29 = -1;
																							}
																						}
																					}
																				}
																				Tile tile15 = Main.tile[num30, num32 - 1];
																				Tile tile16 = Main.tile[num30, num32 + 3];
																				if (tile15 == null)
																				{
																					tile15 = new Tile();
																					Main.tile[num30, num32 - 1] = tile15;
																				}
																				if (tile16 == null)
																				{
																					tile16 = new Tile();
																					Main.tile[num30, num32 + 3] = tile16;
																				}
																				if (!tile15.active() || !Main.tileSolid[(int)tile15.type] || !WorldGen.SolidTile(tile16))
																				{
																					flag3 = true;
																					WorldGen.destroyObject = true;
																					if (num31 == 0)
																					{
																						Item.NewItem(i * 16, j * 16, 16, 16, 25, 1, false, 0, false);
																					}
																					else
																					{
																						if (num31 == 9)
																						{
																							Item.NewItem(i * 16, j * 16, 16, 16, 837, 1, false, 0, false);
																						}
																						else
																						{
																							if (num31 == 10)
																							{
																								Item.NewItem(i * 16, j * 16, 16, 16, 912, 1, false, 0, false);
																							}
																							else
																							{
																								if (num31 == 11 || num31 == 12)
																								{
																									Item.NewItem(i * 16, j * 16, 16, 16, 1137, 1, false, 0, false);
																								}
																								else
																								{
																									if (num31 == 13)
																									{
																										Item.NewItem(i * 16, j * 16, 16, 16, 1138, 1, false, 0, false);
																									}
																									else
																									{
																										if (num31 == 14)
																										{
																											Item.NewItem(i * 16, j * 16, 16, 16, 1139, 1, false, 0, false);
																										}
																										else
																										{
																											if (num31 == 15)
																											{
																												Item.NewItem(i * 16, j * 16, 16, 16, 1140, 1, false, 0, false);
																											}
																											else
																											{
																												if (num31 == 16)
																												{
																													Item.NewItem(i * 16, j * 16, 16, 16, 1411, 1, false, 0, false);
																												}
																												else
																												{
																													if (num31 == 17)
																													{
																														Item.NewItem(i * 16, j * 16, 16, 16, 1412, 1, false, 0, false);
																													}
																													else
																													{
																														if (num31 == 18)
																														{
																															Item.NewItem(i * 16, j * 16, 16, 16, 1413, 1, false, 0, false);
																														}
																														else
																														{
																															if (num31 == 19)
																															{
																																Item.NewItem(i * 16, j * 16, 16, 16, 1458, 1, false, 0, false);
																															}
																															else
																															{
																																if (num31 >= 20 && num31 <= 23)
																																{
																																	Item.NewItem(i * 16, j * 16, 16, 16, 1709 + num31 - 20, 1, false, 0, false);
																																}
																																else
																																{
																																	if (num31 == 24)
																																	{
																																		Item.NewItem(i * 16, j * 16, 16, 16, 1793, 1, false, 0, false);
																																	}
																																	else
																																	{
																																		if (num31 == 25)
																																		{
																																			Item.NewItem(i * 16, j * 16, 16, 16, 1815, 1, false, 0, false);
																																		}
																																		else
																																		{
																																			if (num31 == 26)
																																			{
																																				Item.NewItem(i * 16, j * 16, 16, 16, 1924, 1, false, 0, false);
																																			}
																																			else
																																			{
																																				if (num31 == 27)
																																				{
																																					Item.NewItem(i * 16, j * 16, 16, 16, 2044, 1, false, 0, false);
																																				}
																																				else
																																				{
																																					if (num31 == 28)
																																					{
																																						Item.NewItem(i * 16, j * 16, 16, 16, 2265, 1, false, 0, false);
																																					}
																																					else
																																					{
																																						if (num31 >= 4 && num31 <= 8)
																																						{
																																							Item.NewItem(i * 16, j * 16, 16, 16, 812 + num31, 1, false, 0, false);
																																						}
																																						else
																																						{
																																							Item.NewItem(i * 16, j * 16, 16, 16, 649 + num31, 1, false, 0, false);
																																						}
																																					}
																																				}
																																			}
																																		}
																																	}
																																}
																															}
																														}
																													}
																												}
																											}
																										}
																									}
																								}
																							}
																						}
																					}
																				}
																				int num33 = num30;
																				if (num29 == -1)
																				{
																					num33 = num30 - 1;
																				}
																				for (int k = num33; k < num33 + 2; k++)
																				{
																					for (int l = num32; l < num32 + 3; l++)
																					{
																						if (!flag3)
																						{
																							Tile tile17 = Main.tile[k, l];
																							if (!tile17.active() || tile17.type != 11)
																							{
																								WorldGen.destroyObject = true;
																								if (num31 == 0)
																								{
																									Item.NewItem(i * 16, j * 16, 16, 16, 25, 1, false, 0, false);
																								}
																								else
																								{
																									if (num31 == 9)
																									{
																										Item.NewItem(i * 16, j * 16, 16, 16, 837, 1, false, 0, false);
																									}
																									else
																									{
																										if (num31 == 10)
																										{
																											Item.NewItem(i * 16, j * 16, 16, 16, 912, 1, false, 0, false);
																										}
																										else
																										{
																											if (num31 == 11 || num31 == 12)
																											{
																												Item.NewItem(i * 16, j * 16, 16, 16, 1137, 1, false, 0, false);
																											}
																											else
																											{
																												if (num31 == 13)
																												{
																													Item.NewItem(i * 16, j * 16, 16, 16, 1138, 1, false, 0, false);
																												}
																												else
																												{
																													if (num31 == 14)
																													{
																														Item.NewItem(i * 16, j * 16, 16, 16, 1139, 1, false, 0, false);
																													}
																													else
																													{
																														if (num31 == 15)
																														{
																															Item.NewItem(i * 16, j * 16, 16, 16, 1140, 1, false, 0, false);
																														}
																														else
																														{
																															if (num31 == 16)
																															{
																																Item.NewItem(i * 16, j * 16, 16, 16, 1411, 1, false, 0, false);
																															}
																															else
																															{
																																if (num31 == 17)
																																{
																																	Item.NewItem(i * 16, j * 16, 16, 16, 1412, 1, false, 0, false);
																																}
																																else
																																{
																																	if (num31 == 18)
																																	{
																																		Item.NewItem(i * 16, j * 16, 16, 16, 1413, 1, false, 0, false);
																																	}
																																	else
																																	{
																																		if (num31 == 19)
																																		{
																																			Item.NewItem(i * 16, j * 16, 16, 16, 1458, 1, false, 0, false);
																																		}
																																		else
																																		{
																																			if (num31 >= 20 && num31 <= 23)
																																			{
																																				Item.NewItem(i * 16, j * 16, 16, 16, 1709 + num31 - 20, 1, false, 0, false);
																																			}
																																			else
																																			{
																																				if (num31 == 24)
																																				{
																																					Item.NewItem(i * 16, j * 16, 16, 16, 1793, 1, false, 0, false);
																																				}
																																				else
																																				{
																																					if (num31 == 25)
																																					{
																																						Item.NewItem(i * 16, j * 16, 16, 16, 1815, 1, false, 0, false);
																																					}
																																					else
																																					{
																																						if (num31 == 26)
																																						{
																																							Item.NewItem(i * 16, j * 16, 16, 16, 1924, 1, false, 0, false);
																																						}
																																						else
																																						{
																																							if (num31 == 27)
																																							{
																																								Item.NewItem(i * 16, j * 16, 16, 16, 2044, 1, false, 0, false);
																																							}
																																							else
																																							{
																																								if (num31 == 28)
																																								{
																																									Item.NewItem(i * 16, j * 16, 16, 16, 2265, 1, false, 0, false);
																																								}
																																								else
																																								{
																																									if (num31 >= 4 && num31 <= 8)
																																									{
																																										Item.NewItem(i * 16, j * 16, 16, 16, 812 + num31, 1, false, 0, false);
																																									}
																																									else
																																									{
																																										Item.NewItem(i * 16, j * 16, 16, 16, 649 + num31, 1, false, 0, false);
																																									}
																																								}
																																							}
																																						}
																																					}
																																				}
																																			}
																																		}
																																	}
																																}
																															}
																														}
																													}
																												}
																											}
																										}
																									}
																								}
																								flag3 = true;
																								k = num33;
																								l = num32;
																							}
																						}
																						if (flag3)
																						{
																							WorldGen.KillTile(k, l, false, false, false);
																						}
																					}
																				}
																				WorldGen.destroyObject = false;
																			}
																		}
																		else
																		{
																			if (num == 19)
																			{
																				Tile tile4 = Main.tile[i - 1, j];
																				Tile tile5 = Main.tile[i + 1, j];
																				Tile tile6 = Main.tile[i - 1, j + 1];
																				Tile tile7 = Main.tile[i + 1, j + 1];
																				Tile tile8 = Main.tile[i - 1, j - 1];
																				Tile tile9 = Main.tile[i + 1, j - 1];
																				int num34 = -1;
																				int num35 = -1;
																				if (tile4 != null && tile4.active())
																				{
																					if (Main.tileStone[(int)tile4.type])
																					{
																						num35 = 1;
																					}
																					else
																					{
																						num35 = (int)tile4.type;
																					}
																				}
																				if (tile5 != null && tile5.active())
																				{
																					if (Main.tileStone[(int)tile5.type])
																					{
																						num34 = 1;
																					}
																					else
																					{
																						num34 = (int)tile5.type;
																					}
																				}
																				if (num34 >= 0 && !Main.tileSolid[num34])
																				{
																					num34 = -1;
																				}
																				if (num35 >= 0 && !Main.tileSolid[num35])
																				{
																					num35 = -1;
																				}
																				if (num35 == num && tile4.halfBrick() != tile.halfBrick())
																				{
																					num35 = -1;
																				}
																				if (num34 == num && tile5.halfBrick() != tile.halfBrick())
																				{
																					num34 = -1;
																				}
																				if (num35 != -1 && num35 != num && tile.halfBrick())
																				{
																					num35 = -1;
																				}
																				if (num34 != -1 && num34 != num && tile.halfBrick())
																				{
																					num34 = -1;
																				}
																				if (num35 == -1 && tile8.active() && (int)tile8.type == num && tile8.slope() == 1)
																				{
																					num35 = num;
																				}
																				if (num34 == -1 && tile9.active() && (int)tile9.type == num && tile9.slope() == 2)
																				{
																					num34 = num;
																				}
																				if (num35 == num && tile4.slope() == 2 && num34 != num)
																				{
																					num34 = -1;
																				}
																				if (num34 == num && tile5.slope() == 1 && num35 != num)
																				{
																					num35 = -1;
																				}
																				if (tile.slope() == 1)
																				{
																					if (tile5.type == 19 && tile5.slope() == 0)
																					{
																						rectangle.X = 468;
																					}
																					else
																					{
																						if (!tile7.active() && (tile7.type != 19 || tile7.slope() == 2))
																						{
																							if (!tile4.active() && (tile8.type != 19 || tile8.slope() != 1))
																							{
																								rectangle.X = 432;
																							}
																							else
																							{
																								rectangle.X = 360;
																							}
																						}
																						else
																						{
																							if (!tile4.active() && (tile8.type != 19 || tile8.slope() != 1))
																							{
																								rectangle.X = 396;
																							}
																							else
																							{
																								rectangle.X = 180;
																							}
																						}
																					}
																				}
																				else
																				{
																					if (tile.slope() == 2)
																					{
																						if (tile4.type == 19 && tile4.slope() == 0)
																						{
																							rectangle.X = 450;
																						}
																						else
																						{
																							if (!tile6.active() && (tile6.type != 19 || tile6.slope() == 1))
																							{
																								if (!tile5.active() && (tile9.type != 19 || tile9.slope() != 2))
																								{
																									rectangle.X = 414;
																								}
																								else
																								{
																									rectangle.X = 342;
																								}
																							}
																							else
																							{
																								if (!tile5.active() && (tile9.type != 19 || tile9.slope() != 2))
																								{
																									rectangle.X = 378;
																								}
																								else
																								{
																									rectangle.X = 144;
																								}
																							}
																						}
																					}
																					else
																					{
																						if (num35 == num && num34 == num)
																						{
																							if (tile4.slope() == 2 && tile5.slope() == 1)
																							{
																								rectangle.X = 252;
																							}
																							else
																							{
																								if (tile4.slope() == 2)
																								{
																									rectangle.X = 216;
																								}
																								else
																								{
																									if (tile5.slope() == 1)
																									{
																										rectangle.X = 234;
																									}
																									else
																									{
																										rectangle.X = 0;
																									}
																								}
																							}
																						}
																						else
																						{
																							if (num35 == num && num34 == -1)
																							{
																								if (tile4.slope() == 2)
																								{
																									rectangle.X = 270;
																								}
																								else
																								{
																									rectangle.X = 18;
																								}
																							}
																							else
																							{
																								if (num35 == -1 && num34 == num)
																								{
																									if (tile5.slope() == 1)
																									{
																										rectangle.X = 288;
																									}
																									else
																									{
																										rectangle.X = 36;
																									}
																								}
																								else
																								{
																									if (num35 != num && num34 == num)
																									{
																										rectangle.X = 54;
																									}
																									else
																									{
																										if (num35 == num && num34 != num)
																										{
																											rectangle.X = 72;
																										}
																										else
																										{
																											if (num35 != num && num35 != -1 && num34 == -1)
																											{
																												rectangle.X = 108;
																											}
																											else
																											{
																												if (num35 == -1 && num34 != num && num34 != -1)
																												{
																													rectangle.X = 126;
																												}
																												else
																												{
																													rectangle.X = 90;
																												}
																											}
																										}
																									}
																								}
																							}
																						}
																					}
																				}
																				tile.frameX = (short)rectangle.X;
																			}
																			else
																			{
																				if (num == 233 || num == 236 || num == 238)
																				{
																					WorldGen.CheckJunglePlant(i, j, num);
																				}
																				else
																				{
																					if (num == 240)
																					{
																						WorldGen.Check3x3Wall(i, j);
																					}
																					else
																					{
																						if (num == 245)
																						{
																							WorldGen.Check2x3Wall(i, j);
																						}
																						else
																						{
																							if (num == 246)
																							{
																								WorldGen.Check3x2Wall(i, j);
																							}
																							else
																							{
																								if (num == 241)
																								{
																									WorldGen.Check4x3Wall(i, j);
																								}
																								else
																								{
																									if (num == 242)
																									{
																										WorldGen.Check6x4Wall(i, j);
																									}
																									else
																									{
																										if (num == 34)
																										{
																											WorldGen.CheckChand(i, j, num);
																										}
																										else
																										{
																											if (num == 106 || num == 212 || num == 219 || num == 220 || num == 228 || num == 231 || num == 243 || num == 247 || num == 283 || (num >= 300 && num <= 308))
																											{
																												WorldGen.Check3x3(i, j, (int)((ushort)num));
																											}
																											else
																											{
																												if (num == 15 || num == 20 || num == 216)
																												{
																													WorldGen.Check1x2(i, j, (byte)num);
																												}
																												else
																												{
																													if (num == 14 || num == 17 || num == 26 || num == 77 || num == 86 || num == 87 || num == 88 || num == 89 || num == 114 || num == 133 || num == 186 || num == 187 || num == 215 || num == 217 || num == 218 || num == 237 || num == 244 || num == 285 || num == 286 || num == 298 || num == 299 || num == 310)
																													{
																														WorldGen.Check3x2(i, j, (int)((ushort)num));
																													}
																													else
																													{
																														if (num == 135 || num == 144 || num == 141 || num == 210 || num == 239 || num == 36)
																														{
																															WorldGen.Check1x1(i, j, num);
																														}
																														else
																														{
																															if (num == 16 || num == 18 || num == 29 || num == 103 || num == 134)
																															{
																																WorldGen.Check2x1(i, j, (ushort)((byte)num));
																															}
																															else
																															{
																																if (num == 13 || num == 33 || num == 50 || num == 78 || num == 174)
																																{
																																	WorldGen.CheckOnTable1x1(i, j, (int)((byte)num));
																																}
																																else
																																{
																																	if (num == 21)
																																	{
																																		WorldGen.CheckChest(i, j, (int)((byte)num));
																																	}
																																	else
																																	{
																																		if (num == 128)
																																		{
																																			WorldGen.CheckMan(i, j);
																																		}
																																		else
																																		{
																																			if (num == 269)
																																			{
																																				WorldGen.CheckWoman(i, j);
																																			}
																																			else
																																			{
																																				if (num == 27)
																																				{
																																					WorldGen.CheckSunflower(i, j, 27);
																																				}
																																				else
																																				{
																																					if (num == 28)
																																					{
																																						WorldGen.CheckPot(i, j, 28);
																																					}
																																					else
																																					{
																																						if (num == 171)
																																						{
																																							WorldGen.CheckXmasTree(i, j);
																																						}
																																						else
																																						{
																																							if (num == 254)
																																							{
																																								WorldGen.Check2x2Style(i, j, num);
																																							}
																																							else
																																							{
																																								if (num == 132 || num == 138 || num == 142 || num == 143 || (num >= 288 && num <= 295))
																																								{
																																									WorldGen.Check2x2(i, j, num);
																																								}
																																								else
																																								{
																																									if (num == 91)
																																									{
																																										WorldGen.CheckBanner(i, j, (byte)num);
																																									}
																																									else
																																									{
																																										if (num == 139 || num == 35)
																																										{
																																											WorldGen.CheckMB(i, j, (int)((byte)num));
																																										}
																																										else
																																										{
																																											if (num == 92 || num == 93)
																																											{
																																												WorldGen.Check1xX(i, j, (byte)num);
																																											}
																																											else
																																											{
																																												if (num == 104 || num == 105 || num == 207)
																																												{
																																													WorldGen.Check2xX(i, j, (byte)num);
																																												}
																																												else
																																												{
																																													if (num == 101 || num == 102)
																																													{
																																														WorldGen.Check3x4(i, j, (int)((byte)num));
																																													}
																																													else
																																													{
																																														if (num == 42 || num == 270 || num == 271)
																																														{
																																															WorldGen.Check1x2Top(i, j, (ushort)num);
																																														}
																																														else
																																														{
																																															if (num == 55 || num == 85)
																																															{
																																																WorldGen.CheckSign(i, j, (ushort)num);
																																															}
																																															else
																																															{
																																																if (num == 209)
																																																{
																																																	WorldGen.CheckCannon(i, j, num);
																																																}
																																																else
																																																{
																																																	if (num == 79 || num == 90)
																																																	{
																																																		WorldGen.Check4x2(i, j, num);
																																																	}
																																																	else
																																																	{
																																																		if (num == 94 || num == 95 || num == 97 || num == 98 || num == 99 || num == 100 || num == 125 || num == 126 || num == 173 || num == 282 || num == 287)
																																																		{
																																																			WorldGen.Check2x2(i, j, num);
																																																		}
																																																		else
																																																		{
																																																			if (num == 96)
																																																			{
																																																				WorldGen.Check2x2Style(i, j, num);
																																																			}
																																																			else
																																																			{
																																																				if (num == 81)
																																																				{
																																																					Tile tile2 = Main.tile[i, j - 1];
																																																					Tile tile3 = Main.tile[i, j + 1];
																																																					Tile tile4 = Main.tile[i - 1, j];
																																																					Tile tile5 = Main.tile[i + 1, j];
																																																					int num36 = -1;
																																																					int num37 = -1;
																																																					int num38 = -1;
																																																					int num39 = -1;
																																																					if (tile2 != null && tile2.active())
																																																					{
																																																						num37 = (int)tile2.type;
																																																					}
																																																					if (tile3 != null && tile3.active())
																																																					{
																																																						num36 = (int)tile3.type;
																																																					}
																																																					if (tile4 != null && tile4.active())
																																																					{
																																																						num38 = (int)tile4.type;
																																																					}
																																																					if (tile5 != null && tile5.active())
																																																					{
																																																						num39 = (int)tile5.type;
																																																					}
																																																					if (num38 != -1 || num37 != -1 || num39 != -1)
																																																					{
																																																						WorldGen.KillTile(i, j, false, false, false);
																																																					}
																																																					else
																																																					{
																																																						if (num36 < 0 || !Main.tileSolid[num36] || tile3.halfBrick() || tile3.topSlope())
																																																						{
																																																							WorldGen.KillTile(i, j, false, false, false);
																																																						}
																																																					}
																																																				}
																																																				else
																																																				{
																																																					if (Main.tileAlch[num])
																																																					{
																																																						WorldGen.CheckAlch(i, j);
																																																					}
																																																					else
																																																					{
																																																						if (num == 72)
																																																						{
																																																							Tile tile2 = Main.tile[i, j - 1];
																																																							Tile tile3 = Main.tile[i, j + 1];
																																																							int num40 = -1;
																																																							int num41 = -1;
																																																							if (tile2 != null && tile2.active())
																																																							{
																																																								num41 = (int)tile2.type;
																																																							}
																																																							if (tile3 != null && tile3.active())
																																																							{
																																																								num40 = (int)tile3.type;
																																																							}
																																																							if (num40 != num && num40 != 70)
																																																							{
																																																								WorldGen.KillTile(i, j, false, false, false);
																																																							}
																																																							else
																																																							{
																																																								if (num41 != num && tile.frameX == 0)
																																																								{
																																																									tile.frameNumber((byte)WorldGen.genRand.Next(3));
																																																									if (tile.frameNumber() == 0)
																																																									{
																																																										tile.frameX = 18;
																																																										tile.frameY = 0;
																																																									}
																																																									if (tile.frameNumber() == 1)
																																																									{
																																																										tile.frameX = 18;
																																																										tile.frameY = 18;
																																																									}
																																																									if (tile.frameNumber() == 2)
																																																									{
																																																										tile.frameX = 18;
																																																										tile.frameY = 36;
																																																									}
																																																								}
																																																							}
																																																						}
																																																						else
																																																						{
																																																							if (num == 5)
																																																							{
																																																								WorldGen.CheckTree(i, j);
																																																							}
																																																						}
																																																					}
																																																				}
																																																			}
																																																		}
																																																	}
																																																}
																																															}
																																														}
																																													}
																																												}
																																											}
																																										}
																																									}
																																								}
																																							}
																																						}
																																					}
																																				}
																																			}
																																		}
																																	}
																																}
																															}
																														}
																													}
																												}
																											}
																										}
																									}
																								}
																							}
																						}
																					}
																				}
																			}
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
							return;
						}
						else
						{
							Tile tile2 = Main.tile[i, j - 1];
							Tile tile3 = Main.tile[i, j + 1];
							Tile tile4 = Main.tile[i - 1, j];
							Tile tile5 = Main.tile[i + 1, j];
							Tile tile6 = Main.tile[i - 1, j + 1];
							Tile tile7 = Main.tile[i + 1, j + 1];
							Tile tile8 = Main.tile[i - 1, j - 1];
							Tile tile9 = Main.tile[i + 1, j - 1];
							int num42 = -1;
							int num43 = -1;
							int num44 = -1;
							int num45 = -1;
							int num46 = -1;
							int num47 = -1;
							int num48 = -1;
							int num49 = -1;
							if (tile4 != null && tile4.active())
							{
								if (Main.tileStone[(int)tile4.type])
								{
									num45 = 1;
								}
								else
								{
									num45 = (int)tile4.type;
								}
								if (tile4.slope() == 1 || tile4.slope() == 3)
								{
									num45 = -1;
								}
							}
							if (tile5 != null && tile5.active())
							{
								if (Main.tileStone[(int)tile5.type])
								{
									num46 = 1;
								}
								else
								{
									num46 = (int)tile5.type;
								}
								if (tile5.slope() == 2 || tile5.slope() == 4)
								{
									num46 = -1;
								}
							}
							if (tile2 != null && tile2.active())
							{
								if (Main.tileStone[(int)tile2.type])
								{
									num43 = 1;
								}
								else
								{
									num43 = (int)tile2.type;
								}
								if (tile2.slope() == 3 || tile2.slope() == 4)
								{
									num43 = -1;
								}
							}
							if (tile3 != null && tile3.active())
							{
								if (Main.tileStone[(int)tile3.type])
								{
									num48 = 1;
								}
								else
								{
									num48 = (int)tile3.type;
								}
								if (tile3.slope() == 1 || tile3.slope() == 2)
								{
									num48 = -1;
								}
							}
							if (tile8 != null && tile8.active())
							{
								if (Main.tileStone[(int)tile8.type])
								{
									num42 = 1;
								}
								else
								{
									num42 = (int)tile8.type;
								}
							}
							if (tile9 != null && tile9.active())
							{
								if (Main.tileStone[(int)tile9.type])
								{
									num44 = 1;
								}
								else
								{
									num44 = (int)tile9.type;
								}
							}
							if (tile6 != null && tile6.active())
							{
								if (Main.tileStone[(int)tile6.type])
								{
									num47 = 1;
								}
								else
								{
									num47 = (int)tile6.type;
								}
							}
							if (tile7 != null && tile7.active())
							{
								if (Main.tileStone[(int)tile7.type])
								{
									num49 = 1;
								}
								else
								{
									num49 = (int)tile7.type;
								}
							}
							if (tile.slope() == 2)
							{
								num43 = -1;
								num45 = -1;
							}
							if (tile.slope() == 1)
							{
								num43 = -1;
								num46 = -1;
							}
							if (tile.slope() == 4)
							{
								num48 = -1;
								num45 = -1;
							}
							if (tile.slope() == 3)
							{
								num48 = -1;
								num46 = -1;
							}
							if (num == 147)
							{
								if (num43 > -1 && Main.tileBrick[num43] && num43 != 161 && num43 != 163 && num43 != 164 && num43 != 200)
								{
									num43 = num;
								}
								if (num48 > -1 && Main.tileBrick[num48] && num48 != 161 && num48 != 163 && num48 != 164 && num48 != 200)
								{
									num48 = num;
								}
								if (num45 > -1 && Main.tileBrick[num45] && num45 != 161 && num45 != 163 && num45 != 164 && num45 != 200)
								{
									num45 = num;
								}
								if (num46 > -1 && Main.tileBrick[num46] && num46 != 161 && num46 != 163 && num46 != 164 && num46 != 200)
								{
									num46 = num;
								}
								if (num42 > -1 && Main.tileBrick[num42] && num42 != 161 && num42 != 163 && num42 != 164 && num42 != 200)
								{
									num42 = num;
								}
								if (num44 > -1 && Main.tileBrick[num44] && num44 != 161 && num44 != 163 && num44 != 164 && num44 != 200)
								{
									num44 = num;
								}
								if (num47 > -1 && Main.tileBrick[num47] && num47 != 161 && num47 != 163 && num47 != 164 && num47 != 200)
								{
									num47 = num;
								}
								if (num49 > -1 && Main.tileBrick[num49] && num49 != 161 && num49 != 163 && num49 != 164 && num49 != 200)
								{
									num49 = num;
								}
							}
							else
							{
								if (num == 161 || num == 163 || num == 164 || num == 200)
								{
									if (num43 > -1 && Main.tileBrick[num43] && num43 != 147)
									{
										num43 = num;
									}
									if (num48 > -1 && Main.tileBrick[num48] && num48 != 147)
									{
										num48 = num;
									}
									if (num45 > -1 && Main.tileBrick[num45] && num45 != 147)
									{
										num45 = num;
									}
									if (num46 > -1 && Main.tileBrick[num46] && num46 != 147)
									{
										num46 = num;
									}
									if (num42 > -1 && Main.tileBrick[num42] && num42 != 147)
									{
										num42 = num;
									}
									if (num44 > -1 && Main.tileBrick[num44] && num44 != 147)
									{
										num44 = num;
									}
									if (num47 > -1 && Main.tileBrick[num47] && num47 != 147)
									{
										num47 = num;
									}
									if (num49 > -1 && Main.tileBrick[num49] && num49 != 147)
									{
										num49 = num;
									}
								}
								else
								{
									if (Main.tileBrick[num])
									{
										if (num == 60 || num == 70)
										{
											if (num43 > -1 && num43 != 59 && Main.tileBrick[num43])
											{
												num43 = num;
											}
											if (num48 > -1 && num48 != 59 && Main.tileBrick[num48])
											{
												num48 = num;
											}
											if (num45 > -1 && num45 != 59 && Main.tileBrick[num45])
											{
												num45 = num;
											}
											if (num46 > -1 && num46 != 59 && Main.tileBrick[num46])
											{
												num46 = num;
											}
											if (num42 > -1 && num42 != 59 && Main.tileBrick[num42])
											{
												num42 = num;
											}
											if (num44 > -1 && num44 != 59 && Main.tileBrick[num44])
											{
												num44 = num;
											}
											if (num47 > -1 && num47 != 59 && Main.tileBrick[num47])
											{
												num47 = num;
											}
											if (num49 > -1 && num49 != 59 && Main.tileBrick[num49])
											{
												num49 = num;
											}
										}
										else
										{
											if (num43 > -1 && Main.tileBrick[num43])
											{
												num43 = num;
											}
											if (num48 > -1 && Main.tileBrick[num48])
											{
												num48 = num;
											}
											if (num45 > -1 && Main.tileBrick[num45])
											{
												num45 = num;
											}
											if (num46 > -1 && Main.tileBrick[num46])
											{
												num46 = num;
											}
											if (num42 > -1 && Main.tileBrick[num42])
											{
												num42 = num;
											}
											if (num44 > -1 && Main.tileBrick[num44])
											{
												num44 = num;
											}
											if (num47 > -1 && Main.tileBrick[num47])
											{
												num47 = num;
											}
											if (num49 > -1 && Main.tileBrick[num49])
											{
												num49 = num;
											}
										}
									}
								}
							}
							if ((num == 1 || Main.tileMoss[num] || num == 117 || num == 25 || num == 203) && num48 == 165)
							{
								if (tile3.frameY == 72)
								{
									num48 = num;
								}
								else
								{
									if (tile3.frameY == 0)
									{
										num48 = num;
									}
								}
							}
							if ((num == 1 || Main.tileMoss[num] || num == 117 || num == 25 || num == 203) && num43 == 165)
							{
								if (tile2.frameY == 90)
								{
									num43 = num;
								}
								else
								{
									if (tile2.frameY == 54)
									{
										num43 = num;
									}
								}
							}
							if (num == 225)
							{
								if (num48 == 165)
								{
									num48 = num;
								}
								if (num43 == 165)
								{
									num43 = num;
								}
							}
							if (num == 200 && num48 == 165)
							{
								num48 = 200;
							}
							if (num == 161 && num48 == 165)
							{
								num48 = 161;
							}
							if (num == 163 && num48 == 165)
							{
								num48 = 163;
							}
							if (num == 164 && num48 == 165)
							{
								num48 = 164;
							}
							if ((tile.slope() == 1 || tile.slope() == 2) && num48 > -1)
							{
								num48 = num;
							}
							if (num43 > -1 && (tile2.slope() == 1 || tile2.slope() == 2))
							{
								num43 = num;
							}
							if ((tile.slope() == 3 || tile.slope() == 4) && num43 > -1)
							{
								num43 = num;
							}
							if (num48 > -1 && (tile3.slope() == 3 || tile3.slope() == 4))
							{
								num48 = num;
							}
							if (num == 124)
							{
								if (num43 > -1 && Main.tileSolid[num43])
								{
									num43 = num;
								}
								if (num48 > -1 && Main.tileSolid[num48])
								{
									num48 = num;
								}
							}
							if (num43 > -1 && tile2.halfBrick())
							{
								num43 = num;
							}
							if (num45 > -1 && tile4.halfBrick())
							{
								if (tile.halfBrick())
								{
									num45 = num;
								}
								else
								{
									if ((int)tile4.type != num)
									{
										num45 = -1;
									}
								}
							}
							if (num46 > -1 && tile5.halfBrick())
							{
								if (tile.halfBrick())
								{
									num46 = num;
								}
								else
								{
									if ((int)tile5.type != num)
									{
										num46 = -1;
									}
								}
							}
							if (tile.halfBrick())
							{
								if (num45 != num)
								{
									num45 = -1;
								}
								if (num46 != num)
								{
									num46 = -1;
								}
								num43 = -1;
							}
							if (tile3 != null && tile3.halfBrick())
							{
								num48 = -1;
							}
							if (!Main.tileSolid[num])
							{
								if (num == 49)
								{
									WorldGen.CheckOnTable1x1(i, j, (int)((byte)num));
									return;
								}
								if (num == 80)
								{
									WorldGen.CactusFrame(i, j);
									return;
								}
							}
							WorldGen.mergeUp = false;
							WorldGen.mergeDown = false;
							WorldGen.mergeLeft = false;
							WorldGen.mergeRight = false;
							int num50;
							if (resetFrame)
							{
								num50 = WorldGen.genRand.Next(0, 3);
								tile.frameNumber((byte)num50);
							}
							else
							{
								num50 = (int)tile.frameNumber();
							}
							if (Main.tileLargeFrames[num] == 1)
							{
								int num51 = j % 4;
								int num52 = i % 3;
								int[,] array = new int[,]
								{

									{
										2,
										4,
										2
									},

									{
										1,
										3,
										1
									},

									{
										2,
										2,
										4
									},

									{
										1,
										1,
										3
									}
								};
								num50 = array[num51, num52] - 1;
							}
							if (num == 0)
							{
								if (num43 > -1 && Main.tileMergeDirt[num43])
								{
									WorldGen.TileFrame(i, j - 1, false, false);
									if (WorldGen.mergeDown)
									{
										num43 = num;
									}
								}
								else
								{
									if (num43 == 147)
									{
										WorldGen.TileFrame(i, j - 1, false, false);
										if (WorldGen.mergeDown)
										{
											num43 = num;
										}
									}
								}
								if (num48 > -1 && Main.tileMergeDirt[num48])
								{
									WorldGen.TileFrame(i, j + 1, false, false);
									if (WorldGen.mergeUp)
									{
										num48 = num;
									}
								}
								else
								{
									if (num48 == 147)
									{
										WorldGen.TileFrame(i, j + 1, false, false);
										if (WorldGen.mergeUp)
										{
											num48 = num;
										}
									}
								}
								if (num45 > -1 && Main.tileMergeDirt[num45])
								{
									WorldGen.TileFrame(i - 1, j, false, false);
									if (WorldGen.mergeRight)
									{
										num45 = num;
									}
								}
								else
								{
									if (num45 == 147)
									{
										WorldGen.TileFrame(i - 1, j, false, false);
										if (WorldGen.mergeRight)
										{
											num45 = num;
										}
									}
								}
								if (num46 > -1 && Main.tileMergeDirt[num46])
								{
									WorldGen.TileFrame(i + 1, j, false, false);
									if (WorldGen.mergeLeft)
									{
										num46 = num;
									}
								}
								else
								{
									if (num46 == 147)
									{
										WorldGen.TileFrame(i + 1, j, false, false);
										if (WorldGen.mergeLeft)
										{
											num46 = num;
										}
									}
								}
								if (num43 == 2 || num43 == 23 || num43 == 109 || num43 == 199)
								{
									num43 = num;
								}
								if (num48 == 2 || num48 == 23 || num48 == 109 || num48 == 199)
								{
									num48 = num;
								}
								if (num45 == 2 || num45 == 23 || num45 == 109 || num45 == 199)
								{
									num45 = num;
								}
								if (num46 == 2 || num46 == 23 || num46 == 109 || num46 == 199)
								{
									num46 = num;
								}
								if (num42 > -1 && Main.tileMergeDirt[num42])
								{
									num42 = num;
								}
								else
								{
									if (num42 == 2 || num42 == 23 || num42 == 109 || num42 == 199)
									{
										num42 = num;
									}
								}
								if (num44 > -1 && Main.tileMergeDirt[num44])
								{
									num44 = num;
								}
								else
								{
									if (num44 == 2 || num44 == 23 || num44 == 109 || num44 == 199)
									{
										num44 = num;
									}
								}
								if (num47 > -1 && Main.tileMergeDirt[num47])
								{
									num47 = num;
								}
								else
								{
									if (num47 == 2 || num47 == 23 || num47 == 109 || num47 == 199)
									{
										num47 = num;
									}
								}
								if (num49 > -1 && Main.tileMergeDirt[num49])
								{
									num49 = num;
								}
								else
								{
									if (num49 == 2 || num49 == 23 || num49 == 109 || num49 == 199)
									{
										num49 = num;
									}
								}
								double arg_2F6E_0 = Main.rockLayer;
								if (num43 == 59)
								{
									num43 = -2;
								}
								if (num48 == 59)
								{
									num48 = -2;
								}
								if (num45 == 59)
								{
									num45 = -2;
								}
								if (num46 == 59)
								{
									num46 = -2;
								}
								if (num42 == 59)
								{
									num42 = -2;
								}
								if (num44 == 59)
								{
									num44 = -2;
								}
								if (num47 == 59)
								{
									num47 = -2;
								}
								if (num49 == 59)
								{
									num49 = -2;
								}
								if (num43 == 191)
								{
									num43 = num;
								}
								if (num48 == 191)
								{
									num48 = num;
								}
								if (num45 == 191)
								{
									num45 = num;
								}
								if (num46 == 191)
								{
									num46 = num;
								}
								if (num42 == 191)
								{
									num42 = num;
								}
								if (num44 == 191)
								{
									num44 = num;
								}
								if (num47 == 191)
								{
									num47 = num;
								}
								if (num49 == 191)
								{
									num49 = num;
								}
							}
							else
							{
								if (num == 213)
								{
									if (num43 > -1 && Main.tileSolid[num43] && !Main.tileSolidTop[num43])
									{
										num43 = num;
									}
									if (num48 > -1 && Main.tileSolid[num48])
									{
										num48 = num;
									}
									if (num43 != num)
									{
										if (num45 > -1 && Main.tileSolid[num45])
										{
											num45 = num;
										}
										if (num46 > -1 && Main.tileSolid[num46])
										{
											num46 = num;
										}
									}
								}
								if (Main.tileMergeDirt[num])
								{
									if (num43 == 0)
									{
										num43 = -2;
									}
									if (num48 == 0)
									{
										num48 = -2;
									}
									if (num45 == 0)
									{
										num45 = -2;
									}
									if (num46 == 0)
									{
										num46 = -2;
									}
									if (num42 == 0)
									{
										num42 = -2;
									}
									if (num44 == 0)
									{
										num44 = -2;
									}
									if (num47 == 0)
									{
										num47 = -2;
									}
									if (num49 == 0)
									{
										num49 = -2;
									}
									if (num == 1)
									{
										if ((double)j > Main.rockLayer)
										{
											if (num43 == 59)
											{
												WorldGen.TileFrame(i, j - 1, false, false);
												if (WorldGen.mergeDown)
												{
													num43 = num;
												}
											}
											if (num48 == 59)
											{
												WorldGen.TileFrame(i, j + 1, false, false);
												if (WorldGen.mergeUp)
												{
													num48 = num;
												}
											}
											if (num45 == 59)
											{
												WorldGen.TileFrame(i - 1, j, false, false);
												if (WorldGen.mergeRight)
												{
													num45 = num;
												}
											}
											if (num46 == 59)
											{
												WorldGen.TileFrame(i + 1, j, false, false);
												if (WorldGen.mergeLeft)
												{
													num46 = num;
												}
											}
											if (num42 == 59)
											{
												num42 = num;
											}
											if (num44 == 59)
											{
												num44 = num;
											}
											if (num47 == 59)
											{
												num47 = num;
											}
											if (num49 == 59)
											{
												num49 = num;
											}
										}
										if (num43 == 57)
										{
											WorldGen.TileFrame(i, j - 1, false, false);
											if (WorldGen.mergeDown)
											{
												num43 = num;
											}
										}
										if (num48 == 57)
										{
											WorldGen.TileFrame(i, j + 1, false, false);
											if (WorldGen.mergeUp)
											{
												num48 = num;
											}
										}
										if (num45 == 57)
										{
											WorldGen.TileFrame(i - 1, j, false, false);
											if (WorldGen.mergeRight)
											{
												num45 = num;
											}
										}
										if (num46 == 57)
										{
											WorldGen.TileFrame(i + 1, j, false, false);
											if (WorldGen.mergeLeft)
											{
												num46 = num;
											}
										}
										if (num42 == 57)
										{
											num42 = num;
										}
										if (num44 == 57)
										{
											num44 = num;
										}
										if (num47 == 57)
										{
											num47 = num;
										}
										if (num49 == 57)
										{
											num49 = num;
										}
									}
								}
								else
								{
									if (num == 58 || num == 76 || num == 75)
									{
										if (num43 == 57)
										{
											num43 = -2;
										}
										if (num48 == 57)
										{
											num48 = -2;
										}
										if (num45 == 57)
										{
											num45 = -2;
										}
										if (num46 == 57)
										{
											num46 = -2;
										}
										if (num42 == 57)
										{
											num42 = -2;
										}
										if (num44 == 57)
										{
											num44 = -2;
										}
										if (num47 == 57)
										{
											num47 = -2;
										}
										if (num49 == 57)
										{
											num49 = -2;
										}
									}
									else
									{
										if (num == 211)
										{
											if (num43 == 60)
											{
												num43 = 59;
											}
											if (num48 == 60)
											{
												num48 = 59;
											}
											if (num45 == 60)
											{
												num45 = 59;
											}
											if (num46 == 60)
											{
												num46 = 59;
											}
											if (num43 == 59)
											{
												num43 = -2;
											}
											if (num48 == 59)
											{
												num48 = -2;
											}
											if (num45 == 59)
											{
												num45 = -2;
											}
											if (num46 == 59)
											{
												num46 = -2;
											}
											if (num42 == 59)
											{
												num42 = -2;
											}
											if (num44 == 59)
											{
												num44 = -2;
											}
											if (num47 == 59)
											{
												num47 = -2;
											}
											if (num49 == 59)
											{
												num49 = -2;
											}
										}
										else
										{
											if (num == 225 || num == 226)
											{
												if (num43 == 59)
												{
													num43 = -2;
												}
												if (num48 == 59)
												{
													num48 = -2;
												}
												if (num45 == 59)
												{
													num45 = -2;
												}
												if (num46 == 59)
												{
													num46 = -2;
												}
												if (num42 == 59)
												{
													num42 = -2;
												}
												if (num44 == 59)
												{
													num44 = -2;
												}
												if (num47 == 59)
												{
													num47 = -2;
												}
												if (num49 == 59)
												{
													num49 = -2;
												}
											}
											else
											{
												if (num == 59)
												{
													if ((double)j > Main.rockLayer)
													{
														if (num43 == 1)
														{
															num43 = -2;
														}
														if (num48 == 1)
														{
															num48 = -2;
														}
														if (num45 == 1)
														{
															num45 = -2;
														}
														if (num46 == 1)
														{
															num46 = -2;
														}
														if (num42 == 1)
														{
															num42 = -2;
														}
														if (num44 == 1)
														{
															num44 = -2;
														}
														if (num47 == 1)
														{
															num47 = -2;
														}
														if (num49 == 1)
														{
															num49 = -2;
														}
													}
													if (num43 == 60)
													{
														num43 = num;
													}
													if (num48 == 60)
													{
														num48 = num;
													}
													if (num45 == 60)
													{
														num45 = num;
													}
													if (num46 == 60)
													{
														num46 = num;
													}
													if (num42 == 60)
													{
														num42 = num;
													}
													if (num44 == 60)
													{
														num44 = num;
													}
													if (num47 == 60)
													{
														num47 = num;
													}
													if (num49 == 60)
													{
														num49 = num;
													}
													if (num43 == 70)
													{
														num43 = num;
													}
													if (num48 == 70)
													{
														num48 = num;
													}
													if (num45 == 70)
													{
														num45 = num;
													}
													if (num46 == 70)
													{
														num46 = num;
													}
													if (num42 == 70)
													{
														num42 = num;
													}
													if (num44 == 70)
													{
														num44 = num;
													}
													if (num47 == 70)
													{
														num47 = num;
													}
													if (num49 == 70)
													{
														num49 = num;
													}
													if (num43 == 211 || num43 == 226 || num43 == 225)
													{
														WorldGen.TileFrame(i, j - 1, false, false);
														if (WorldGen.mergeDown)
														{
															num43 = num;
														}
													}
													if (num48 == 211 || num48 == 226 || num48 == 225)
													{
														WorldGen.TileFrame(i, j + 1, false, false);
														if (WorldGen.mergeUp)
														{
															num48 = num;
														}
													}
													if (num45 == 211 || num45 == 226 || num45 == 225)
													{
														WorldGen.TileFrame(i - 1, j, false, false);
														if (WorldGen.mergeRight)
														{
															num45 = num;
														}
													}
													if (num46 == 211 || num46 == 226 || num46 == 225)
													{
														WorldGen.TileFrame(i + 1, j, false, false);
														if (WorldGen.mergeLeft)
														{
															num46 = num;
														}
													}
													if (num42 == 211 || num42 == 225 || num42 == 226)
													{
														num42 = num;
													}
													if (num44 == 211 || num44 == 225 || num44 == 226)
													{
														num44 = num;
													}
													if (num47 == 211 || num47 == 225 || num47 == 226)
													{
														num47 = num;
													}
													if (num49 == 211 || num49 == 225 || num49 == 226)
													{
														num49 = num;
													}
													if ((double)j < Main.rockLayer)
													{
														if (num43 == 0)
														{
															WorldGen.TileFrame(i, j - 1, false, false);
															if (WorldGen.mergeDown)
															{
																num43 = num;
															}
														}
														if (num48 == 0)
														{
															WorldGen.TileFrame(i, j + 1, false, false);
															if (WorldGen.mergeUp)
															{
																num48 = num;
															}
														}
														if (num45 == 0)
														{
															WorldGen.TileFrame(i - 1, j, false, false);
															if (WorldGen.mergeRight)
															{
																num45 = num;
															}
														}
														if (num46 == 0)
														{
															WorldGen.TileFrame(i + 1, j, false, false);
															if (WorldGen.mergeLeft)
															{
																num46 = num;
															}
														}
														if (num42 == 0)
														{
															num42 = num;
														}
														if (num44 == 0)
														{
															num44 = num;
														}
														if (num47 == 0)
														{
															num47 = num;
														}
														if (num49 == 0)
														{
															num49 = num;
														}
													}
													else
													{
														if (num43 == 0)
														{
															num43 = num;
														}
														if (num45 == 0)
														{
															num45 = num;
														}
														if (num46 == 0)
														{
															num46 = num;
														}
														if (num48 == 0)
														{
															num48 = num;
														}
													}
												}
												else
												{
													if (num == 57)
													{
														if (num43 == 1)
														{
															num43 = -2;
														}
														if (num48 == 1)
														{
															num48 = -2;
														}
														if (num45 == 1)
														{
															num45 = -2;
														}
														if (num46 == 1)
														{
															num46 = -2;
														}
														if (num42 == 1)
														{
															num42 = -2;
														}
														if (num44 == 1)
														{
															num44 = -2;
														}
														if (num47 == 1)
														{
															num47 = -2;
														}
														if (num49 == 1)
														{
															num49 = -2;
														}
														if (num43 == 58 || num43 == 76 || num43 == 75)
														{
															WorldGen.TileFrame(i, j - 1, false, false);
															if (WorldGen.mergeDown)
															{
																num43 = num;
															}
														}
														if (num48 == 58 || num48 == 76 || num48 == 75)
														{
															WorldGen.TileFrame(i, j + 1, false, false);
															if (WorldGen.mergeUp)
															{
																num48 = num;
															}
														}
														if (num45 == 58 || num45 == 76 || num45 == 75)
														{
															WorldGen.TileFrame(i - 1, j, false, false);
															if (WorldGen.mergeRight)
															{
																num45 = num;
															}
														}
														if (num46 == 58 || num46 == 76 || num46 == 75)
														{
															WorldGen.TileFrame(i + 1, j, false, false);
															if (WorldGen.mergeLeft)
															{
																num46 = num;
															}
														}
														if (num42 == 58 || num42 == 76 || num42 == 75)
														{
															num42 = num;
														}
														if (num44 == 58 || num44 == 76 || num44 == 75)
														{
															num44 = num;
														}
														if (num47 == 58 || num47 == 76 || num47 == 75)
														{
															num47 = num;
														}
														if (num49 == 58 || num49 == 76 || num49 == 75)
														{
															num49 = num;
														}
													}
													else
													{
														if (num == 189)
														{
															if (num43 == 196)
															{
																WorldGen.TileFrame(i, j - 1, false, false);
																if (WorldGen.mergeDown)
																{
																	num43 = num;
																}
															}
															if (num48 == 196)
															{
																WorldGen.TileFrame(i, j + 1, false, false);
																if (WorldGen.mergeUp)
																{
																	num48 = num;
																}
															}
															if (num45 == 196)
															{
																WorldGen.TileFrame(i - 1, j, false, false);
																if (WorldGen.mergeRight)
																{
																	num45 = num;
																}
															}
															if (num46 == 196)
															{
																WorldGen.TileFrame(i + 1, j, false, false);
																if (WorldGen.mergeLeft)
																{
																	num46 = num;
																}
															}
															if (num42 == 196)
															{
																num42 = num;
															}
															if (num44 == 196)
															{
																num44 = num;
															}
															if (num47 == 196)
															{
																num47 = num;
															}
															if (num49 == 196)
															{
																num49 = num;
															}
														}
														else
														{
															if (num == 196)
															{
																if (num43 == 189)
																{
																	num43 = -2;
																}
																if (num48 == 189)
																{
																	num48 = -2;
																}
																if (num45 == 189)
																{
																	num45 = -2;
																}
																if (num46 == 189)
																{
																	num46 = -2;
																}
																if (num42 == 189)
																{
																	num42 = -2;
																}
																if (num44 == 189)
																{
																	num44 = -2;
																}
																if (num47 == 189)
																{
																	num47 = -2;
																}
																if (num49 == 189)
																{
																	num49 = -2;
																}
															}
															else
															{
																if (num == 147)
																{
																	if (num43 == 0)
																	{
																		num43 = -2;
																	}
																	if (num48 == 0)
																	{
																		num48 = -2;
																	}
																	if (num45 == 0)
																	{
																		num45 = -2;
																	}
																	if (num46 == 0)
																	{
																		num46 = -2;
																	}
																	if (num42 == 0)
																	{
																		num42 = -2;
																	}
																	if (num44 == 0)
																	{
																		num44 = -2;
																	}
																	if (num47 == 0)
																	{
																		num47 = -2;
																	}
																	if (num49 == 0)
																	{
																		num49 = -2;
																	}
																	if (num43 == 161 || num43 == 163 || num43 == 164 || num43 == 200 || num43 == 224)
																	{
																		WorldGen.TileFrame(i, j - 1, false, false);
																		if (WorldGen.mergeDown)
																		{
																			num43 = num;
																		}
																	}
																	if (num48 == 161 || num48 == 163 || num48 == 164 || num48 == 200 || num48 == 224)
																	{
																		WorldGen.TileFrame(i, j + 1, false, false);
																		if (WorldGen.mergeUp)
																		{
																			num48 = num;
																		}
																	}
																	if (num45 == 161 || num45 == 163 || num45 == 164 || num45 == 200 || num45 == 224)
																	{
																		WorldGen.TileFrame(i - 1, j, false, false);
																		if (WorldGen.mergeRight)
																		{
																			num45 = num;
																		}
																	}
																	if (num46 == 161 || num46 == 163 || num46 == 164 || num46 == 200 || num46 == 224)
																	{
																		WorldGen.TileFrame(i + 1, j, false, false);
																		if (WorldGen.mergeLeft)
																		{
																			num46 = num;
																		}
																	}
																	if (num42 == 161 || num42 == 163 || num42 == 164 || num42 == 200 || num42 == 224)
																	{
																		num42 = num;
																	}
																	if (num44 == 161 || num44 == 163 || num44 == 164 || num44 == 200 || num44 == 224)
																	{
																		num44 = num;
																	}
																	if (num47 == 161 || num47 == 163 || num47 == 164 || num47 == 200 || num47 == 224)
																	{
																		num47 = num;
																	}
																	if (num49 == 161 || num49 == 163 || num49 == 164 || num49 == 200 || num49 == 224)
																	{
																		num49 = num;
																	}
																}
																else
																{
																	if (num == 161 || num == 163 || num == 164 || num == 200 || num == 224)
																	{
																		if (num43 == 147)
																		{
																			num43 = -2;
																		}
																		if (num48 == 147)
																		{
																			num48 = -2;
																		}
																		if (num45 == 147)
																		{
																			num45 = -2;
																		}
																		if (num46 == 147)
																		{
																			num46 = -2;
																		}
																		if (num42 == 147)
																		{
																			num42 = -2;
																		}
																		if (num44 == 147)
																		{
																			num44 = -2;
																		}
																		if (num47 == 147)
																		{
																			num47 = -2;
																		}
																		if (num49 == 147)
																		{
																			num49 = -2;
																		}
																	}
																	else
																	{
																		if (num == 32)
																		{
																			if (num48 == 23)
																			{
																				num48 = num;
																			}
																		}
																		else
																		{
																			if (num == 69)
																			{
																				if (num48 == 60)
																				{
																					num48 = num;
																				}
																			}
																			else
																			{
																				if (num == 51)
																				{
																					if (num43 > -1 && !Main.tileNoAttach[num43])
																					{
																						num43 = num;
																					}
																					if (num48 > -1 && !Main.tileNoAttach[num48])
																					{
																						num48 = num;
																					}
																					if (num45 > -1 && !Main.tileNoAttach[num45])
																					{
																						num45 = num;
																					}
																					if (num46 > -1 && !Main.tileNoAttach[num46])
																					{
																						num46 = num;
																					}
																					if (num42 > -1 && !Main.tileNoAttach[num42])
																					{
																						num42 = num;
																					}
																					if (num44 > -1 && !Main.tileNoAttach[num44])
																					{
																						num44 = num;
																					}
																					if (num47 > -1 && !Main.tileNoAttach[num47])
																					{
																						num47 = num;
																					}
																					if (num49 > -1 && !Main.tileNoAttach[num49])
																					{
																						num49 = num;
																					}
																				}
																				else
																				{
																					if (num == 192)
																					{
																						if (num43 == 191)
																						{
																							WorldGen.TileFrame(i, j - 1, false, false);
																							if (WorldGen.mergeDown)
																							{
																								num43 = num;
																							}
																						}
																						if (num48 == 191)
																						{
																							WorldGen.TileFrame(i, j + 1, false, false);
																							if (WorldGen.mergeUp)
																							{
																								num48 = num;
																							}
																						}
																						if (num45 == 191)
																						{
																							WorldGen.TileFrame(i - 1, j, false, false);
																							if (WorldGen.mergeRight)
																							{
																								num45 = num;
																							}
																						}
																						if (num46 == 191)
																						{
																							WorldGen.TileFrame(i + 1, j, false, false);
																							if (WorldGen.mergeLeft)
																							{
																								num46 = num;
																							}
																						}
																						if (num42 == 191)
																						{
																							num42 = num;
																						}
																						if (num44 == 191)
																						{
																							num44 = num;
																						}
																						if (num47 == 191)
																						{
																							num47 = num;
																						}
																						if (num49 == 191)
																						{
																							num49 = num;
																						}
																					}
																					else
																					{
																						if (num == 191)
																						{
																							if (num43 == 192)
																							{
																								num43 = -2;
																							}
																							if (num48 == 192)
																							{
																								num48 = -2;
																							}
																							if (num45 == 192)
																							{
																								num45 = -2;
																							}
																							if (num46 == 192)
																							{
																								num46 = -2;
																							}
																							if (num42 == 192)
																							{
																								num42 = -2;
																							}
																							if (num44 == 192)
																							{
																								num44 = -2;
																							}
																							if (num47 == 192)
																							{
																								num47 = -2;
																							}
																							if (num49 == 192)
																							{
																								num49 = -2;
																							}
																							if (num43 == 0)
																							{
																								num43 = num;
																							}
																							if (num48 == 0)
																							{
																								num48 = num;
																							}
																							if (num45 == 0)
																							{
																								num45 = num;
																							}
																							if (num46 == 0)
																							{
																								num46 = num;
																							}
																							if (num42 == 0)
																							{
																								num42 = num;
																							}
																							if (num44 == 0)
																							{
																								num44 = num;
																							}
																							if (num47 == 0)
																							{
																								num47 = num;
																							}
																							if (num49 == 0)
																							{
																								num49 = num;
																							}
																						}
																						else
																						{
																							if (num == 60)
																							{
																								if (num43 == 211)
																								{
																									num43 = 59;
																								}
																								if (num48 == 211)
																								{
																									num48 = 59;
																								}
																								if (num45 == 211)
																								{
																									num45 = 59;
																								}
																								if (num46 == 211)
																								{
																									num46 = 59;
																								}
																							}
																						}
																					}
																				}
																			}
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
							if (Main.tileStone[num] || num == 1)
							{
								if (num43 > -1 && Main.tileMoss[num43])
								{
									num43 = num;
								}
								if (num48 > -1 && Main.tileMoss[num48])
								{
									num48 = num;
								}
								if (num45 > -1 && Main.tileMoss[num45])
								{
									num45 = num;
								}
								if (num46 > -1 && Main.tileMoss[num46])
								{
									num46 = num;
								}
								if (num42 > -1 && Main.tileMoss[num42])
								{
									num42 = num;
								}
								if (num44 > -1 && Main.tileMoss[num44])
								{
									num44 = num;
								}
								if (num47 > -1 && Main.tileMoss[num47])
								{
									num47 = num;
								}
								if (num49 > -1 && Main.tileMoss[num49])
								{
									num49 = num;
								}
							}
							bool flag4 = false;
							if (num43 == -2 && tile.color() != tile2.color())
							{
								num43 = num;
								WorldGen.mergeUp = true;
							}
							if (num48 == -2 && tile.color() != tile3.color())
							{
								num48 = num;
								WorldGen.mergeDown = true;
							}
							if (num45 == -2 && tile.color() != tile4.color())
							{
								num45 = num;
								WorldGen.mergeLeft = true;
							}
							if (num46 == -2 && tile.color() != tile5.color())
							{
								num46 = num;
								WorldGen.mergeRight = true;
							}
							if (num == 2 || num == 23 || num == 60 || num == 70 || num == 109 || num == 199 || Main.tileMoss[num])
							{
								flag4 = true;
								if (num43 > -1 && !Main.tileSolid[num43] && num43 != num)
								{
									num43 = -1;
								}
								if (num48 > -1 && !Main.tileSolid[num48] && num48 != num)
								{
									num48 = -1;
								}
								if (num45 > -1 && !Main.tileSolid[num45] && num45 != num)
								{
									num45 = -1;
								}
								if (num46 > -1 && !Main.tileSolid[num46] && num46 != num)
								{
									num46 = -1;
								}
								if (num42 > -1 && !Main.tileSolid[num42] && num42 != num)
								{
									num42 = -1;
								}
								if (num44 > -1 && !Main.tileSolid[num44] && num44 != num)
								{
									num44 = -1;
								}
								if (num47 > -1 && !Main.tileSolid[num47] && num47 != num)
								{
									num47 = -1;
								}
								if (num49 > -1 && !Main.tileSolid[num49] && num49 != num)
								{
									num49 = -1;
								}
								int num53 = 0;
								if (num == 60 || num == 70)
								{
									num53 = 59;
								}
								else
								{
									if (Main.tileMoss[num])
									{
										num53 = 1;
									}
									else
									{
										if (num == 2)
										{
											if (num43 == 23)
											{
												num43 = num53;
											}
											if (num48 == 23)
											{
												num48 = num53;
											}
											if (num45 == 23)
											{
												num45 = num53;
											}
											if (num46 == 23)
											{
												num46 = num53;
											}
											if (num42 == 23)
											{
												num42 = num53;
											}
											if (num44 == 23)
											{
												num44 = num53;
											}
											if (num47 == 23)
											{
												num47 = num53;
											}
											if (num49 == 23)
											{
												num49 = num53;
											}
										}
										else
										{
											if (num == 23)
											{
												if (num43 == 2)
												{
													num43 = num53;
												}
												if (num48 == 2)
												{
													num48 = num53;
												}
												if (num45 == 2)
												{
													num45 = num53;
												}
												if (num46 == 2)
												{
													num46 = num53;
												}
												if (num42 == 2)
												{
													num42 = num53;
												}
												if (num44 == 2)
												{
													num44 = num53;
												}
												if (num47 == 2)
												{
													num47 = num53;
												}
												if (num49 == 2)
												{
													num49 = num53;
												}
											}
										}
									}
								}
								if (num43 != num && num43 != num53 && (num48 == num || num48 == num53))
								{
									if (num45 == num53 && num46 == num)
									{
										if (num50 == 0)
										{
											rectangle.X = 0;
											rectangle.Y = 198;
										}
										else
										{
											if (num50 == 1)
											{
												rectangle.X = 18;
												rectangle.Y = 198;
											}
											else
											{
												rectangle.X = 36;
												rectangle.Y = 198;
											}
										}
									}
									else
									{
										if (num45 == num && num46 == num53)
										{
											if (num50 == 0)
											{
												rectangle.X = 54;
												rectangle.Y = 198;
											}
											else
											{
												if (num50 == 1)
												{
													rectangle.X = 72;
													rectangle.Y = 198;
												}
												else
												{
													rectangle.X = 90;
													rectangle.Y = 198;
												}
											}
										}
									}
								}
								else
								{
									if (num48 != num && num48 != num53 && (num43 == num || num43 == num53))
									{
										if (num45 == num53 && num46 == num)
										{
											if (num50 == 0)
											{
												rectangle.X = 0;
												rectangle.Y = 216;
											}
											else
											{
												if (num50 == 1)
												{
													rectangle.X = 18;
													rectangle.Y = 216;
												}
												else
												{
													rectangle.X = 36;
													rectangle.Y = 216;
												}
											}
										}
										else
										{
											if (num45 == num && num46 == num53)
											{
												if (num50 == 0)
												{
													rectangle.X = 54;
													rectangle.Y = 216;
												}
												else
												{
													if (num50 == 1)
													{
														rectangle.X = 72;
														rectangle.Y = 216;
													}
													else
													{
														rectangle.X = 90;
														rectangle.Y = 216;
													}
												}
											}
										}
									}
									else
									{
										if (num45 != num && num45 != num53 && (num46 == num || num46 == num53))
										{
											if (num43 == num53 && num48 == num)
											{
												if (num50 == 0)
												{
													rectangle.X = 72;
													rectangle.Y = 144;
												}
												else
												{
													if (num50 == 1)
													{
														rectangle.X = 72;
														rectangle.Y = 162;
													}
													else
													{
														rectangle.X = 72;
														rectangle.Y = 180;
													}
												}
											}
											else
											{
												if (num48 == num && num46 == num43)
												{
													if (num50 == 0)
													{
														rectangle.X = 72;
														rectangle.Y = 90;
													}
													else
													{
														if (num50 == 1)
														{
															rectangle.X = 72;
															rectangle.Y = 108;
														}
														else
														{
															rectangle.X = 72;
															rectangle.Y = 126;
														}
													}
												}
											}
										}
										else
										{
											if (num46 != num && num46 != num53 && (num45 == num || num45 == num53))
											{
												if (num43 == num53 && num48 == num)
												{
													if (num50 == 0)
													{
														rectangle.X = 90;
														rectangle.Y = 144;
													}
													else
													{
														if (num50 == 1)
														{
															rectangle.X = 90;
															rectangle.Y = 162;
														}
														else
														{
															rectangle.X = 90;
															rectangle.Y = 180;
														}
													}
												}
												else
												{
													if (num48 == num && num46 == num43)
													{
														if (num50 == 0)
														{
															rectangle.X = 90;
															rectangle.Y = 90;
														}
														else
														{
															if (num50 == 1)
															{
																rectangle.X = 90;
																rectangle.Y = 108;
															}
															else
															{
																rectangle.X = 90;
																rectangle.Y = 126;
															}
														}
													}
												}
											}
											else
											{
												if (num43 == num && num48 == num && num45 == num && num46 == num)
												{
													if (num42 != num && num44 != num && num47 != num && num49 != num)
													{
														if (num49 == num53)
														{
															if (num50 == 0)
															{
																rectangle.X = 108;
																rectangle.Y = 324;
															}
															else
															{
																if (num50 == 1)
																{
																	rectangle.X = 126;
																	rectangle.Y = 324;
																}
																else
																{
																	rectangle.X = 144;
																	rectangle.Y = 324;
																}
															}
														}
														else
														{
															if (num44 == num53)
															{
																if (num50 == 0)
																{
																	rectangle.X = 108;
																	rectangle.Y = 342;
																}
																else
																{
																	if (num50 == 1)
																	{
																		rectangle.X = 126;
																		rectangle.Y = 342;
																	}
																	else
																	{
																		rectangle.X = 144;
																		rectangle.Y = 342;
																	}
																}
															}
															else
															{
																if (num47 == num53)
																{
																	if (num50 == 0)
																	{
																		rectangle.X = 108;
																		rectangle.Y = 360;
																	}
																	else
																	{
																		if (num50 == 1)
																		{
																			rectangle.X = 126;
																			rectangle.Y = 360;
																		}
																		else
																		{
																			rectangle.X = 144;
																			rectangle.Y = 360;
																		}
																	}
																}
																else
																{
																	if (num42 == num53)
																	{
																		if (num50 == 0)
																		{
																			rectangle.X = 108;
																			rectangle.Y = 378;
																		}
																		else
																		{
																			if (num50 == 1)
																			{
																				rectangle.X = 126;
																				rectangle.Y = 378;
																			}
																			else
																			{
																				rectangle.X = 144;
																				rectangle.Y = 378;
																			}
																		}
																	}
																	else
																	{
																		if (num50 == 0)
																		{
																			rectangle.X = 144;
																			rectangle.Y = 234;
																		}
																		else
																		{
																			if (num50 == 1)
																			{
																				rectangle.X = 198;
																				rectangle.Y = 234;
																			}
																			else
																			{
																				rectangle.X = 252;
																				rectangle.Y = 234;
																			}
																		}
																	}
																}
															}
														}
													}
													else
													{
														if (num42 != num && num49 != num)
														{
															if (num50 == 0)
															{
																rectangle.X = 36;
																rectangle.Y = 306;
															}
															else
															{
																if (num50 == 1)
																{
																	rectangle.X = 54;
																	rectangle.Y = 306;
																}
																else
																{
																	rectangle.X = 72;
																	rectangle.Y = 306;
																}
															}
														}
														else
														{
															if (num44 != num && num47 != num)
															{
																if (num50 == 0)
																{
																	rectangle.X = 90;
																	rectangle.Y = 306;
																}
																else
																{
																	if (num50 == 1)
																	{
																		rectangle.X = 108;
																		rectangle.Y = 306;
																	}
																	else
																	{
																		rectangle.X = 126;
																		rectangle.Y = 306;
																	}
																}
															}
															else
															{
																if (num42 != num && num44 == num && num47 == num && num49 == num)
																{
																	if (num50 == 0)
																	{
																		rectangle.X = 54;
																		rectangle.Y = 108;
																	}
																	else
																	{
																		if (num50 == 1)
																		{
																			rectangle.X = 54;
																			rectangle.Y = 144;
																		}
																		else
																		{
																			rectangle.X = 54;
																			rectangle.Y = 180;
																		}
																	}
																}
																else
																{
																	if (num42 == num && num44 != num && num47 == num && num49 == num)
																	{
																		if (num50 == 0)
																		{
																			rectangle.X = 36;
																			rectangle.Y = 108;
																		}
																		else
																		{
																			if (num50 == 1)
																			{
																				rectangle.X = 36;
																				rectangle.Y = 144;
																			}
																			else
																			{
																				rectangle.X = 36;
																				rectangle.Y = 180;
																			}
																		}
																	}
																	else
																	{
																		if (num42 == num && num44 == num && num47 != num && num49 == num)
																		{
																			if (num50 == 0)
																			{
																				rectangle.X = 54;
																				rectangle.Y = 90;
																			}
																			else
																			{
																				if (num50 == 1)
																				{
																					rectangle.X = 54;
																					rectangle.Y = 126;
																				}
																				else
																				{
																					rectangle.X = 54;
																					rectangle.Y = 162;
																				}
																			}
																		}
																		else
																		{
																			if (num42 == num && num44 == num && num47 == num && num49 != num)
																			{
																				if (num50 == 0)
																				{
																					rectangle.X = 36;
																					rectangle.Y = 90;
																				}
																				else
																				{
																					if (num50 == 1)
																					{
																						rectangle.X = 36;
																						rectangle.Y = 126;
																					}
																					else
																					{
																						rectangle.X = 36;
																						rectangle.Y = 162;
																					}
																				}
																			}
																		}
																	}
																}
															}
														}
													}
												}
												else
												{
													if (num43 == num && num48 == num53 && num45 == num && num46 == num && num42 == -1 && num44 == -1)
													{
														if (num50 == 0)
														{
															rectangle.X = 108;
															rectangle.Y = 18;
														}
														else
														{
															if (num50 == 1)
															{
																rectangle.X = 126;
																rectangle.Y = 18;
															}
															else
															{
																rectangle.X = 144;
																rectangle.Y = 18;
															}
														}
													}
													else
													{
														if (num43 == num53 && num48 == num && num45 == num && num46 == num && num47 == -1 && num49 == -1)
														{
															if (num50 == 0)
															{
																rectangle.X = 108;
																rectangle.Y = 36;
															}
															else
															{
																if (num50 == 1)
																{
																	rectangle.X = 126;
																	rectangle.Y = 36;
																}
																else
																{
																	rectangle.X = 144;
																	rectangle.Y = 36;
																}
															}
														}
														else
														{
															if (num43 == num && num48 == num && num45 == num53 && num46 == num && num44 == -1 && num49 == -1)
															{
																if (num50 == 0)
																{
																	rectangle.X = 198;
																	rectangle.Y = 0;
																}
																else
																{
																	if (num50 == 1)
																	{
																		rectangle.X = 198;
																		rectangle.Y = 18;
																	}
																	else
																	{
																		rectangle.X = 198;
																		rectangle.Y = 36;
																	}
																}
															}
															else
															{
																if (num43 == num && num48 == num && num45 == num && num46 == num53 && num42 == -1 && num47 == -1)
																{
																	if (num50 == 0)
																	{
																		rectangle.X = 180;
																		rectangle.Y = 0;
																	}
																	else
																	{
																		if (num50 == 1)
																		{
																			rectangle.X = 180;
																			rectangle.Y = 18;
																		}
																		else
																		{
																			rectangle.X = 180;
																			rectangle.Y = 36;
																		}
																	}
																}
																else
																{
																	if (num43 == num && num48 == num53 && num45 == num && num46 == num)
																	{
																		if (num44 != -1)
																		{
																			if (num50 == 0)
																			{
																				rectangle.X = 54;
																				rectangle.Y = 108;
																			}
																			else
																			{
																				if (num50 == 1)
																				{
																					rectangle.X = 54;
																					rectangle.Y = 144;
																				}
																				else
																				{
																					rectangle.X = 54;
																					rectangle.Y = 180;
																				}
																			}
																		}
																		else
																		{
																			if (num42 != -1)
																			{
																				if (num50 == 0)
																				{
																					rectangle.X = 36;
																					rectangle.Y = 108;
																				}
																				else
																				{
																					if (num50 == 1)
																					{
																						rectangle.X = 36;
																						rectangle.Y = 144;
																					}
																					else
																					{
																						rectangle.X = 36;
																						rectangle.Y = 180;
																					}
																				}
																			}
																		}
																	}
																	else
																	{
																		if (num43 == num53 && num48 == num && num45 == num && num46 == num)
																		{
																			if (num49 != -1)
																			{
																				if (num50 == 0)
																				{
																					rectangle.X = 54;
																					rectangle.Y = 90;
																				}
																				else
																				{
																					if (num50 == 1)
																					{
																						rectangle.X = 54;
																						rectangle.Y = 126;
																					}
																					else
																					{
																						rectangle.X = 54;
																						rectangle.Y = 162;
																					}
																				}
																			}
																			else
																			{
																				if (num47 != -1)
																				{
																					if (num50 == 0)
																					{
																						rectangle.X = 36;
																						rectangle.Y = 90;
																					}
																					else
																					{
																						if (num50 == 1)
																						{
																							rectangle.X = 36;
																							rectangle.Y = 126;
																						}
																						else
																						{
																							rectangle.X = 36;
																							rectangle.Y = 162;
																						}
																					}
																				}
																			}
																		}
																		else
																		{
																			if (num43 == num && num48 == num && num45 == num && num46 == num53)
																			{
																				if (num42 != -1)
																				{
																					if (num50 == 0)
																					{
																						rectangle.X = 54;
																						rectangle.Y = 90;
																					}
																					else
																					{
																						if (num50 == 1)
																						{
																							rectangle.X = 54;
																							rectangle.Y = 126;
																						}
																						else
																						{
																							rectangle.X = 54;
																							rectangle.Y = 162;
																						}
																					}
																				}
																				else
																				{
																					if (num47 != -1)
																					{
																						if (num50 == 0)
																						{
																							rectangle.X = 54;
																							rectangle.Y = 108;
																						}
																						else
																						{
																							if (num50 == 1)
																							{
																								rectangle.X = 54;
																								rectangle.Y = 144;
																							}
																							else
																							{
																								rectangle.X = 54;
																								rectangle.Y = 180;
																							}
																						}
																					}
																				}
																			}
																			else
																			{
																				if (num43 == num && num48 == num && num45 == num53 && num46 == num)
																				{
																					if (num44 != -1)
																					{
																						if (num50 == 0)
																						{
																							rectangle.X = 36;
																							rectangle.Y = 90;
																						}
																						else
																						{
																							if (num50 == 1)
																							{
																								rectangle.X = 36;
																								rectangle.Y = 126;
																							}
																							else
																							{
																								rectangle.X = 36;
																								rectangle.Y = 162;
																							}
																						}
																					}
																					else
																					{
																						if (num49 != -1)
																						{
																							if (num50 == 0)
																							{
																								rectangle.X = 36;
																								rectangle.Y = 108;
																							}
																							else
																							{
																								if (num50 == 1)
																								{
																									rectangle.X = 36;
																									rectangle.Y = 144;
																								}
																								else
																								{
																									rectangle.X = 36;
																									rectangle.Y = 180;
																								}
																							}
																						}
																					}
																				}
																				else
																				{
																					if ((num43 == num53 && num48 == num && num45 == num && num46 == num) || (num43 == num && num48 == num53 && num45 == num && num46 == num) || (num43 == num && num48 == num && num45 == num53 && num46 == num) || (num43 == num && num48 == num && num45 == num && num46 == num53))
																					{
																						if (num50 == 0)
																						{
																							rectangle.X = 18;
																							rectangle.Y = 18;
																						}
																						else
																						{
																							if (num50 == 1)
																							{
																								rectangle.X = 36;
																								rectangle.Y = 18;
																							}
																							else
																							{
																								rectangle.X = 54;
																								rectangle.Y = 18;
																							}
																						}
																					}
																				}
																			}
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
								if ((num43 == num || num43 == num53) && (num48 == num || num48 == num53) && (num45 == num || num45 == num53) && (num46 == num || num46 == num53))
								{
									if (num42 != num && num42 != num53 && (num44 == num || num44 == num53) && (num47 == num || num47 == num53) && (num49 == num || num49 == num53))
									{
										if (num50 == 0)
										{
											rectangle.X = 54;
											rectangle.Y = 108;
										}
										else
										{
											if (num50 == 1)
											{
												rectangle.X = 54;
												rectangle.Y = 144;
											}
											else
											{
												rectangle.X = 54;
												rectangle.Y = 180;
											}
										}
									}
									else
									{
										if (num44 != num && num44 != num53 && (num42 == num || num42 == num53) && (num47 == num || num47 == num53) && (num49 == num || num49 == num53))
										{
											if (num50 == 0)
											{
												rectangle.X = 36;
												rectangle.Y = 108;
											}
											else
											{
												if (num50 == 1)
												{
													rectangle.X = 36;
													rectangle.Y = 144;
												}
												else
												{
													rectangle.X = 36;
													rectangle.Y = 180;
												}
											}
										}
										else
										{
											if (num47 != num && num47 != num53 && (num42 == num || num42 == num53) && (num44 == num || num44 == num53) && (num49 == num || num49 == num53))
											{
												if (num50 == 0)
												{
													rectangle.X = 54;
													rectangle.Y = 90;
												}
												else
												{
													if (num50 == 1)
													{
														rectangle.X = 54;
														rectangle.Y = 126;
													}
													else
													{
														rectangle.X = 54;
														rectangle.Y = 162;
													}
												}
											}
											else
											{
												if (num49 != num && num49 != num53 && (num42 == num || num42 == num53) && (num47 == num || num47 == num53) && (num44 == num || num44 == num53))
												{
													if (num50 == 0)
													{
														rectangle.X = 36;
														rectangle.Y = 90;
													}
													else
													{
														if (num50 == 1)
														{
															rectangle.X = 36;
															rectangle.Y = 126;
														}
														else
														{
															rectangle.X = 36;
															rectangle.Y = 162;
														}
													}
												}
											}
										}
									}
								}
								if (num43 != num53 && num43 != num && num48 == num && num45 != num53 && num45 != num && num46 == num && num49 != num53 && num49 != num)
								{
									if (num50 == 0)
									{
										rectangle.X = 90;
										rectangle.Y = 270;
									}
									else
									{
										if (num50 == 1)
										{
											rectangle.X = 108;
											rectangle.Y = 270;
										}
										else
										{
											rectangle.X = 126;
											rectangle.Y = 270;
										}
									}
								}
								else
								{
									if (num43 != num53 && num43 != num && num48 == num && num45 == num && num46 != num53 && num46 != num && num47 != num53 && num47 != num)
									{
										if (num50 == 0)
										{
											rectangle.X = 144;
											rectangle.Y = 270;
										}
										else
										{
											if (num50 == 1)
											{
												rectangle.X = 162;
												rectangle.Y = 270;
											}
											else
											{
												rectangle.X = 180;
												rectangle.Y = 270;
											}
										}
									}
									else
									{
										if (num48 != num53 && num48 != num && num43 == num && num45 != num53 && num45 != num && num46 == num && num44 != num53 && num44 != num)
										{
											if (num50 == 0)
											{
												rectangle.X = 90;
												rectangle.Y = 288;
											}
											else
											{
												if (num50 == 1)
												{
													rectangle.X = 108;
													rectangle.Y = 288;
												}
												else
												{
													rectangle.X = 126;
													rectangle.Y = 288;
												}
											}
										}
										else
										{
											if (num48 != num53 && num48 != num && num43 == num && num45 == num && num46 != num53 && num46 != num && num42 != num53 && num42 != num)
											{
												if (num50 == 0)
												{
													rectangle.X = 144;
													rectangle.Y = 288;
												}
												else
												{
													if (num50 == 1)
													{
														rectangle.X = 162;
														rectangle.Y = 288;
													}
													else
													{
														rectangle.X = 180;
														rectangle.Y = 288;
													}
												}
											}
											else
											{
												if (num43 != num && num43 != num53 && num48 == num && num45 == num && num46 == num && num47 != num && num47 != num53 && num49 != num && num49 != num53)
												{
													if (num50 == 0)
													{
														rectangle.X = 144;
														rectangle.Y = 216;
													}
													else
													{
														if (num50 == 1)
														{
															rectangle.X = 198;
															rectangle.Y = 216;
														}
														else
														{
															rectangle.X = 252;
															rectangle.Y = 216;
														}
													}
												}
												else
												{
													if (num48 != num && num48 != num53 && num43 == num && num45 == num && num46 == num && num42 != num && num42 != num53 && num44 != num && num44 != num53)
													{
														if (num50 == 0)
														{
															rectangle.X = 144;
															rectangle.Y = 252;
														}
														else
														{
															if (num50 == 1)
															{
																rectangle.X = 198;
																rectangle.Y = 252;
															}
															else
															{
																rectangle.X = 252;
																rectangle.Y = 252;
															}
														}
													}
													else
													{
														if (num45 != num && num45 != num53 && num48 == num && num43 == num && num46 == num && num44 != num && num44 != num53 && num49 != num && num49 != num53)
														{
															if (num50 == 0)
															{
																rectangle.X = 126;
																rectangle.Y = 234;
															}
															else
															{
																if (num50 == 1)
																{
																	rectangle.X = 180;
																	rectangle.Y = 234;
																}
																else
																{
																	rectangle.X = 234;
																	rectangle.Y = 234;
																}
															}
														}
														else
														{
															if (num46 != num && num46 != num53 && num48 == num && num43 == num && num45 == num && num42 != num && num42 != num53 && num47 != num && num47 != num53)
															{
																if (num50 == 0)
																{
																	rectangle.X = 162;
																	rectangle.Y = 234;
																}
																else
																{
																	if (num50 == 1)
																	{
																		rectangle.X = 216;
																		rectangle.Y = 234;
																	}
																	else
																	{
																		rectangle.X = 270;
																		rectangle.Y = 234;
																	}
																}
															}
															else
															{
																if (num43 != num53 && num43 != num && (num48 == num53 || num48 == num) && num45 == num53 && num46 == num53)
																{
																	if (num50 == 0)
																	{
																		rectangle.X = 36;
																		rectangle.Y = 270;
																	}
																	else
																	{
																		if (num50 == 1)
																		{
																			rectangle.X = 54;
																			rectangle.Y = 270;
																		}
																		else
																		{
																			rectangle.X = 72;
																			rectangle.Y = 270;
																		}
																	}
																}
																else
																{
																	if (num48 != num53 && num48 != num && (num43 == num53 || num43 == num) && num45 == num53 && num46 == num53)
																	{
																		if (num50 == 0)
																		{
																			rectangle.X = 36;
																			rectangle.Y = 288;
																		}
																		else
																		{
																			if (num50 == 1)
																			{
																				rectangle.X = 54;
																				rectangle.Y = 288;
																			}
																			else
																			{
																				rectangle.X = 72;
																				rectangle.Y = 288;
																			}
																		}
																	}
																	else
																	{
																		if (num45 != num53 && num45 != num && (num46 == num53 || num46 == num) && num43 == num53 && num48 == num53)
																		{
																			if (num50 == 0)
																			{
																				rectangle.X = 0;
																				rectangle.Y = 270;
																			}
																			else
																			{
																				if (num50 == 1)
																				{
																					rectangle.X = 0;
																					rectangle.Y = 288;
																				}
																				else
																				{
																					rectangle.X = 0;
																					rectangle.Y = 306;
																				}
																			}
																		}
																		else
																		{
																			if (num46 != num53 && num46 != num && (num45 == num53 || num45 == num) && num43 == num53 && num48 == num53)
																			{
																				if (num50 == 0)
																				{
																					rectangle.X = 18;
																					rectangle.Y = 270;
																				}
																				else
																				{
																					if (num50 == 1)
																					{
																						rectangle.X = 18;
																						rectangle.Y = 288;
																					}
																					else
																					{
																						rectangle.X = 18;
																						rectangle.Y = 306;
																					}
																				}
																			}
																			else
																			{
																				if (num43 == num && num48 == num53 && num45 == num53 && num46 == num53)
																				{
																					if (num50 == 0)
																					{
																						rectangle.X = 198;
																						rectangle.Y = 288;
																					}
																					else
																					{
																						if (num50 == 1)
																						{
																							rectangle.X = 216;
																							rectangle.Y = 288;
																						}
																						else
																						{
																							rectangle.X = 234;
																							rectangle.Y = 288;
																						}
																					}
																				}
																				else
																				{
																					if (num43 == num53 && num48 == num && num45 == num53 && num46 == num53)
																					{
																						if (num50 == 0)
																						{
																							rectangle.X = 198;
																							rectangle.Y = 270;
																						}
																						else
																						{
																							if (num50 == 1)
																							{
																								rectangle.X = 216;
																								rectangle.Y = 270;
																							}
																							else
																							{
																								rectangle.X = 234;
																								rectangle.Y = 270;
																							}
																						}
																					}
																					else
																					{
																						if (num43 == num53 && num48 == num53 && num45 == num && num46 == num53)
																						{
																							if (num50 == 0)
																							{
																								rectangle.X = 198;
																								rectangle.Y = 306;
																							}
																							else
																							{
																								if (num50 == 1)
																								{
																									rectangle.X = 216;
																									rectangle.Y = 306;
																								}
																								else
																								{
																									rectangle.X = 234;
																									rectangle.Y = 306;
																								}
																							}
																						}
																						else
																						{
																							if (num43 == num53 && num48 == num53 && num45 == num53 && num46 == num)
																							{
																								if (num50 == 0)
																								{
																									rectangle.X = 144;
																									rectangle.Y = 306;
																								}
																								else
																								{
																									if (num50 == 1)
																									{
																										rectangle.X = 162;
																										rectangle.Y = 306;
																									}
																									else
																									{
																										rectangle.X = 180;
																										rectangle.Y = 306;
																									}
																								}
																							}
																						}
																					}
																				}
																			}
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
								if (num43 != num && num43 != num53 && num48 == num && num45 == num && num46 == num)
								{
									if ((num47 == num53 || num47 == num) && num49 != num53 && num49 != num)
									{
										if (num50 == 0)
										{
											rectangle.X = 0;
											rectangle.Y = 324;
										}
										else
										{
											if (num50 == 1)
											{
												rectangle.X = 18;
												rectangle.Y = 324;
											}
											else
											{
												rectangle.X = 36;
												rectangle.Y = 324;
											}
										}
									}
									else
									{
										if ((num49 == num53 || num49 == num) && num47 != num53 && num47 != num)
										{
											if (num50 == 0)
											{
												rectangle.X = 54;
												rectangle.Y = 324;
											}
											else
											{
												if (num50 == 1)
												{
													rectangle.X = 72;
													rectangle.Y = 324;
												}
												else
												{
													rectangle.X = 90;
													rectangle.Y = 324;
												}
											}
										}
									}
								}
								else
								{
									if (num48 != num && num48 != num53 && num43 == num && num45 == num && num46 == num)
									{
										if ((num42 == num53 || num42 == num) && num44 != num53 && num44 != num)
										{
											if (num50 == 0)
											{
												rectangle.X = 0;
												rectangle.Y = 342;
											}
											else
											{
												if (num50 == 1)
												{
													rectangle.X = 18;
													rectangle.Y = 342;
												}
												else
												{
													rectangle.X = 36;
													rectangle.Y = 342;
												}
											}
										}
										else
										{
											if ((num44 == num53 || num44 == num) && num42 != num53 && num42 != num)
											{
												if (num50 == 0)
												{
													rectangle.X = 54;
													rectangle.Y = 342;
												}
												else
												{
													if (num50 == 1)
													{
														rectangle.X = 72;
														rectangle.Y = 342;
													}
													else
													{
														rectangle.X = 90;
														rectangle.Y = 342;
													}
												}
											}
										}
									}
									else
									{
										if (num45 != num && num45 != num53 && num43 == num && num48 == num && num46 == num)
										{
											if ((num44 == num53 || num44 == num) && num49 != num53 && num49 != num)
											{
												if (num50 == 0)
												{
													rectangle.X = 54;
													rectangle.Y = 360;
												}
												else
												{
													if (num50 == 1)
													{
														rectangle.X = 72;
														rectangle.Y = 360;
													}
													else
													{
														rectangle.X = 90;
														rectangle.Y = 360;
													}
												}
											}
											else
											{
												if ((num49 == num53 || num49 == num) && num44 != num53 && num44 != num)
												{
													if (num50 == 0)
													{
														rectangle.X = 0;
														rectangle.Y = 360;
													}
													else
													{
														if (num50 == 1)
														{
															rectangle.X = 18;
															rectangle.Y = 360;
														}
														else
														{
															rectangle.X = 36;
															rectangle.Y = 360;
														}
													}
												}
											}
										}
										else
										{
											if (num46 != num && num46 != num53 && num43 == num && num48 == num && num45 == num)
											{
												if ((num42 == num53 || num42 == num) && num47 != num53 && num47 != num)
												{
													if (num50 == 0)
													{
														rectangle.X = 0;
														rectangle.Y = 378;
													}
													else
													{
														if (num50 == 1)
														{
															rectangle.X = 18;
															rectangle.Y = 378;
														}
														else
														{
															rectangle.X = 36;
															rectangle.Y = 378;
														}
													}
												}
												else
												{
													if ((num47 == num53 || num47 == num) && num42 != num53 && num42 != num)
													{
														if (num50 == 0)
														{
															rectangle.X = 54;
															rectangle.Y = 378;
														}
														else
														{
															if (num50 == 1)
															{
																rectangle.X = 72;
																rectangle.Y = 378;
															}
															else
															{
																rectangle.X = 90;
																rectangle.Y = 378;
															}
														}
													}
												}
											}
										}
									}
								}
								if ((num43 == num || num43 == num53) && (num48 == num || num48 == num53) && (num45 == num || num45 == num53) && (num46 == num || num46 == num53) && num42 != -1 && num44 != -1 && num47 != -1 && num49 != -1)
								{
									if (num50 == 0)
									{
										rectangle.X = 18;
										rectangle.Y = 18;
									}
									else
									{
										if (num50 == 1)
										{
											rectangle.X = 36;
											rectangle.Y = 18;
										}
										else
										{
											rectangle.X = 54;
											rectangle.Y = 18;
										}
									}
								}
								if (num43 == num53)
								{
									num43 = -2;
								}
								if (num48 == num53)
								{
									num48 = -2;
								}
								if (num45 == num53)
								{
									num45 = -2;
								}
								if (num46 == num53)
								{
									num46 = -2;
								}
								if (num42 == num53)
								{
									num42 = -2;
								}
								if (num44 == num53)
								{
									num44 = -2;
								}
								if (num47 == num53)
								{
									num47 = -2;
								}
								if (num49 == num53)
								{
									num49 = -2;
								}
							}
							if (rectangle.X == -1 && rectangle.Y == -1 && (Main.tileMergeDirt[num] || num == 0 || num == 2 || num == 57 || num == 58 || num == 59 || num == 60 || num == 70 || num == 109 || num == 76 || num == 75 || num == 147 || num == 161 || num == 163 || num == 164 || num == 189 || num == 196 || num == 191 || num == 199 || num == 200 || num == 211 || num == 224 || num == 226 || num == 225))
							{
								if (!flag4)
								{
									flag4 = true;
									if (num43 > -1 && !Main.tileSolid[num43] && num43 != num)
									{
										num43 = -1;
									}
									if (num48 > -1 && !Main.tileSolid[num48] && num48 != num)
									{
										num48 = -1;
									}
									if (num45 > -1 && !Main.tileSolid[num45] && num45 != num)
									{
										num45 = -1;
									}
									if (num46 > -1 && !Main.tileSolid[num46] && num46 != num)
									{
										num46 = -1;
									}
									if (num42 > -1 && !Main.tileSolid[num42] && num42 != num)
									{
										num42 = -1;
									}
									if (num44 > -1 && !Main.tileSolid[num44] && num44 != num)
									{
										num44 = -1;
									}
									if (num47 > -1 && !Main.tileSolid[num47] && num47 != num)
									{
										num47 = -1;
									}
									if (num49 > -1 && !Main.tileSolid[num49] && num49 != num)
									{
										num49 = -1;
									}
								}
								if (num43 > -1 && num43 != num)
								{
									num43 = -1;
								}
								if (num48 > -1 && num48 != num)
								{
									num48 = -1;
								}
								if (num45 > -1 && num45 != num)
								{
									num45 = -1;
								}
								if (num46 > -1 && num46 != num)
								{
									num46 = -1;
								}
								if (num43 != -1 && num48 != -1 && num45 != -1 && num46 != -1)
								{
									if (num43 == -2 && num48 == num && num45 == num && num46 == num)
									{
										if (num50 == 0)
										{
											rectangle.X = 144;
											rectangle.Y = 108;
										}
										else
										{
											if (num50 == 1)
											{
												rectangle.X = 162;
												rectangle.Y = 108;
											}
											else
											{
												rectangle.X = 180;
												rectangle.Y = 108;
											}
										}
										WorldGen.mergeUp = true;
									}
									else
									{
										if (num43 == num && num48 == -2 && num45 == num && num46 == num)
										{
											if (num50 == 0)
											{
												rectangle.X = 144;
												rectangle.Y = 90;
											}
											else
											{
												if (num50 == 1)
												{
													rectangle.X = 162;
													rectangle.Y = 90;
												}
												else
												{
													rectangle.X = 180;
													rectangle.Y = 90;
												}
											}
											WorldGen.mergeDown = true;
										}
										else
										{
											if (num43 == num && num48 == num && num45 == -2 && num46 == num)
											{
												if (num50 == 0)
												{
													rectangle.X = 162;
													rectangle.Y = 126;
												}
												else
												{
													if (num50 == 1)
													{
														rectangle.X = 162;
														rectangle.Y = 144;
													}
													else
													{
														rectangle.X = 162;
														rectangle.Y = 162;
													}
												}
												WorldGen.mergeLeft = true;
											}
											else
											{
												if (num43 == num && num48 == num && num45 == num && num46 == -2)
												{
													if (num50 == 0)
													{
														rectangle.X = 144;
														rectangle.Y = 126;
													}
													else
													{
														if (num50 == 1)
														{
															rectangle.X = 144;
															rectangle.Y = 144;
														}
														else
														{
															rectangle.X = 144;
															rectangle.Y = 162;
														}
													}
													WorldGen.mergeRight = true;
												}
												else
												{
													if (num43 == -2 && num48 == num && num45 == -2 && num46 == num)
													{
														if (num50 == 0)
														{
															rectangle.X = 36;
															rectangle.Y = 90;
														}
														else
														{
															if (num50 == 1)
															{
																rectangle.X = 36;
																rectangle.Y = 126;
															}
															else
															{
																rectangle.X = 36;
																rectangle.Y = 162;
															}
														}
														WorldGen.mergeUp = true;
														WorldGen.mergeLeft = true;
													}
													else
													{
														if (num43 == -2 && num48 == num && num45 == num && num46 == -2)
														{
															if (num50 == 0)
															{
																rectangle.X = 54;
																rectangle.Y = 90;
															}
															else
															{
																if (num50 == 1)
																{
																	rectangle.X = 54;
																	rectangle.Y = 126;
																}
																else
																{
																	rectangle.X = 54;
																	rectangle.Y = 162;
																}
															}
															WorldGen.mergeUp = true;
															WorldGen.mergeRight = true;
														}
														else
														{
															if (num43 == num && num48 == -2 && num45 == -2 && num46 == num)
															{
																if (num50 == 0)
																{
																	rectangle.X = 36;
																	rectangle.Y = 108;
																}
																else
																{
																	if (num50 == 1)
																	{
																		rectangle.X = 36;
																		rectangle.Y = 144;
																	}
																	else
																	{
																		rectangle.X = 36;
																		rectangle.Y = 180;
																	}
																}
																WorldGen.mergeDown = true;
																WorldGen.mergeLeft = true;
															}
															else
															{
																if (num43 == num && num48 == -2 && num45 == num && num46 == -2)
																{
																	if (num50 == 0)
																	{
																		rectangle.X = 54;
																		rectangle.Y = 108;
																	}
																	else
																	{
																		if (num50 == 1)
																		{
																			rectangle.X = 54;
																			rectangle.Y = 144;
																		}
																		else
																		{
																			rectangle.X = 54;
																			rectangle.Y = 180;
																		}
																	}
																	WorldGen.mergeDown = true;
																	WorldGen.mergeRight = true;
																}
																else
																{
																	if (num43 == num && num48 == num && num45 == -2 && num46 == -2)
																	{
																		if (num50 == 0)
																		{
																			rectangle.X = 180;
																			rectangle.Y = 126;
																		}
																		else
																		{
																			if (num50 == 1)
																			{
																				rectangle.X = 180;
																				rectangle.Y = 144;
																			}
																			else
																			{
																				rectangle.X = 180;
																				rectangle.Y = 162;
																			}
																		}
																		WorldGen.mergeLeft = true;
																		WorldGen.mergeRight = true;
																	}
																	else
																	{
																		if (num43 == -2 && num48 == -2 && num45 == num && num46 == num)
																		{
																			if (num50 == 0)
																			{
																				rectangle.X = 144;
																				rectangle.Y = 180;
																			}
																			else
																			{
																				if (num50 == 1)
																				{
																					rectangle.X = 162;
																					rectangle.Y = 180;
																				}
																				else
																				{
																					rectangle.X = 180;
																					rectangle.Y = 180;
																				}
																			}
																			WorldGen.mergeUp = true;
																			WorldGen.mergeDown = true;
																		}
																		else
																		{
																			if (num43 == -2 && num48 == num && num45 == -2 && num46 == -2)
																			{
																				if (num50 == 0)
																				{
																					rectangle.X = 198;
																					rectangle.Y = 90;
																				}
																				else
																				{
																					if (num50 == 1)
																					{
																						rectangle.X = 198;
																						rectangle.Y = 108;
																					}
																					else
																					{
																						rectangle.X = 198;
																						rectangle.Y = 126;
																					}
																				}
																				WorldGen.mergeUp = true;
																				WorldGen.mergeLeft = true;
																				WorldGen.mergeRight = true;
																			}
																			else
																			{
																				if (num43 == num && num48 == -2 && num45 == -2 && num46 == -2)
																				{
																					if (num50 == 0)
																					{
																						rectangle.X = 198;
																						rectangle.Y = 144;
																					}
																					else
																					{
																						if (num50 == 1)
																						{
																							rectangle.X = 198;
																							rectangle.Y = 162;
																						}
																						else
																						{
																							rectangle.X = 198;
																							rectangle.Y = 180;
																						}
																					}
																					WorldGen.mergeDown = true;
																					WorldGen.mergeLeft = true;
																					WorldGen.mergeRight = true;
																				}
																				else
																				{
																					if (num43 == -2 && num48 == -2 && num45 == num && num46 == -2)
																					{
																						if (num50 == 0)
																						{
																							rectangle.X = 216;
																							rectangle.Y = 144;
																						}
																						else
																						{
																							if (num50 == 1)
																							{
																								rectangle.X = 216;
																								rectangle.Y = 162;
																							}
																							else
																							{
																								rectangle.X = 216;
																								rectangle.Y = 180;
																							}
																						}
																						WorldGen.mergeUp = true;
																						WorldGen.mergeDown = true;
																						WorldGen.mergeRight = true;
																					}
																					else
																					{
																						if (num43 == -2 && num48 == -2 && num45 == -2 && num46 == num)
																						{
																							if (num50 == 0)
																							{
																								rectangle.X = 216;
																								rectangle.Y = 90;
																							}
																							else
																							{
																								if (num50 == 1)
																								{
																									rectangle.X = 216;
																									rectangle.Y = 108;
																								}
																								else
																								{
																									rectangle.X = 216;
																									rectangle.Y = 126;
																								}
																							}
																							WorldGen.mergeUp = true;
																							WorldGen.mergeDown = true;
																							WorldGen.mergeLeft = true;
																						}
																						else
																						{
																							if (num43 == -2 && num48 == -2 && num45 == -2 && num46 == -2)
																							{
																								if (num50 == 0)
																								{
																									rectangle.X = 108;
																									rectangle.Y = 198;
																								}
																								else
																								{
																									if (num50 == 1)
																									{
																										rectangle.X = 126;
																										rectangle.Y = 198;
																									}
																									else
																									{
																										rectangle.X = 144;
																										rectangle.Y = 198;
																									}
																								}
																								WorldGen.mergeUp = true;
																								WorldGen.mergeDown = true;
																								WorldGen.mergeLeft = true;
																								WorldGen.mergeRight = true;
																							}
																							else
																							{
																								if (num43 == num && num48 == num && num45 == num && num46 == num)
																								{
																									if (num42 == -2)
																									{
																										if (num50 == 0)
																										{
																											rectangle.X = 18;
																											rectangle.Y = 108;
																										}
																										else
																										{
																											if (num50 == 1)
																											{
																												rectangle.X = 18;
																												rectangle.Y = 144;
																											}
																											else
																											{
																												rectangle.X = 18;
																												rectangle.Y = 180;
																											}
																										}
																									}
																									if (num44 == -2)
																									{
																										if (num50 == 0)
																										{
																											rectangle.X = 0;
																											rectangle.Y = 108;
																										}
																										else
																										{
																											if (num50 == 1)
																											{
																												rectangle.X = 0;
																												rectangle.Y = 144;
																											}
																											else
																											{
																												rectangle.X = 0;
																												rectangle.Y = 180;
																											}
																										}
																									}
																									if (num47 == -2)
																									{
																										if (num50 == 0)
																										{
																											rectangle.X = 18;
																											rectangle.Y = 90;
																										}
																										else
																										{
																											if (num50 == 1)
																											{
																												rectangle.X = 18;
																												rectangle.Y = 126;
																											}
																											else
																											{
																												rectangle.X = 18;
																												rectangle.Y = 162;
																											}
																										}
																									}
																									if (num49 == -2)
																									{
																										if (num50 == 0)
																										{
																											rectangle.X = 0;
																											rectangle.Y = 90;
																										}
																										else
																										{
																											if (num50 == 1)
																											{
																												rectangle.X = 0;
																												rectangle.Y = 126;
																											}
																											else
																											{
																												rectangle.X = 0;
																												rectangle.Y = 162;
																											}
																										}
																									}
																								}
																							}
																						}
																					}
																				}
																			}
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
								else
								{
									if (num != 2 && num != 23 && num != 60 && num != 70 && num != 109 && num != 199)
									{
										if (num43 == -1 && num48 == -2 && num45 == num && num46 == num)
										{
											if (num50 == 0)
											{
												rectangle.X = 234;
												rectangle.Y = 0;
											}
											else
											{
												if (num50 == 1)
												{
													rectangle.X = 252;
													rectangle.Y = 0;
												}
												else
												{
													rectangle.X = 270;
													rectangle.Y = 0;
												}
											}
											WorldGen.mergeDown = true;
										}
										else
										{
											if (num43 == -2 && num48 == -1 && num45 == num && num46 == num)
											{
												if (num50 == 0)
												{
													rectangle.X = 234;
													rectangle.Y = 18;
												}
												else
												{
													if (num50 == 1)
													{
														rectangle.X = 252;
														rectangle.Y = 18;
													}
													else
													{
														rectangle.X = 270;
														rectangle.Y = 18;
													}
												}
												WorldGen.mergeUp = true;
											}
											else
											{
												if (num43 == num && num48 == num && num45 == -1 && num46 == -2)
												{
													if (num50 == 0)
													{
														rectangle.X = 234;
														rectangle.Y = 36;
													}
													else
													{
														if (num50 == 1)
														{
															rectangle.X = 252;
															rectangle.Y = 36;
														}
														else
														{
															rectangle.X = 270;
															rectangle.Y = 36;
														}
													}
													WorldGen.mergeRight = true;
												}
												else
												{
													if (num43 == num && num48 == num && num45 == -2 && num46 == -1)
													{
														if (num50 == 0)
														{
															rectangle.X = 234;
															rectangle.Y = 54;
														}
														else
														{
															if (num50 == 1)
															{
																rectangle.X = 252;
																rectangle.Y = 54;
															}
															else
															{
																rectangle.X = 270;
																rectangle.Y = 54;
															}
														}
														WorldGen.mergeLeft = true;
													}
												}
											}
										}
									}
									if (num43 != -1 && num48 != -1 && num45 == -1 && num46 == num)
									{
										if (num43 == -2 && num48 == num)
										{
											if (num50 == 0)
											{
												rectangle.X = 72;
												rectangle.Y = 144;
											}
											else
											{
												if (num50 == 1)
												{
													rectangle.X = 72;
													rectangle.Y = 162;
												}
												else
												{
													rectangle.X = 72;
													rectangle.Y = 180;
												}
											}
											WorldGen.mergeUp = true;
										}
										else
										{
											if (num48 == -2 && num43 == num)
											{
												if (num50 == 0)
												{
													rectangle.X = 72;
													rectangle.Y = 90;
												}
												else
												{
													if (num50 == 1)
													{
														rectangle.X = 72;
														rectangle.Y = 108;
													}
													else
													{
														rectangle.X = 72;
														rectangle.Y = 126;
													}
												}
												WorldGen.mergeDown = true;
											}
										}
									}
									else
									{
										if (num43 != -1 && num48 != -1 && num45 == num && num46 == -1)
										{
											if (num43 == -2 && num48 == num)
											{
												if (num50 == 0)
												{
													rectangle.X = 90;
													rectangle.Y = 144;
												}
												else
												{
													if (num50 == 1)
													{
														rectangle.X = 90;
														rectangle.Y = 162;
													}
													else
													{
														rectangle.X = 90;
														rectangle.Y = 180;
													}
												}
												WorldGen.mergeUp = true;
											}
											else
											{
												if (num48 == -2 && num43 == num)
												{
													if (num50 == 0)
													{
														rectangle.X = 90;
														rectangle.Y = 90;
													}
													else
													{
														if (num50 == 1)
														{
															rectangle.X = 90;
															rectangle.Y = 108;
														}
														else
														{
															rectangle.X = 90;
															rectangle.Y = 126;
														}
													}
													WorldGen.mergeDown = true;
												}
											}
										}
										else
										{
											if (num43 == -1 && num48 == num && num45 != -1 && num46 != -1)
											{
												if (num45 == -2 && num46 == num)
												{
													if (num50 == 0)
													{
														rectangle.X = 0;
														rectangle.Y = 198;
													}
													else
													{
														if (num50 == 1)
														{
															rectangle.X = 18;
															rectangle.Y = 198;
														}
														else
														{
															rectangle.X = 36;
															rectangle.Y = 198;
														}
													}
													WorldGen.mergeLeft = true;
												}
												else
												{
													if (num46 == -2 && num45 == num)
													{
														if (num50 == 0)
														{
															rectangle.X = 54;
															rectangle.Y = 198;
														}
														else
														{
															if (num50 == 1)
															{
																rectangle.X = 72;
																rectangle.Y = 198;
															}
															else
															{
																rectangle.X = 90;
																rectangle.Y = 198;
															}
														}
														WorldGen.mergeRight = true;
													}
												}
											}
											else
											{
												if (num43 == num && num48 == -1 && num45 != -1 && num46 != -1)
												{
													if (num45 == -2 && num46 == num)
													{
														if (num50 == 0)
														{
															rectangle.X = 0;
															rectangle.Y = 216;
														}
														else
														{
															if (num50 == 1)
															{
																rectangle.X = 18;
																rectangle.Y = 216;
															}
															else
															{
																rectangle.X = 36;
																rectangle.Y = 216;
															}
														}
														WorldGen.mergeLeft = true;
													}
													else
													{
														if (num46 == -2 && num45 == num)
														{
															if (num50 == 0)
															{
																rectangle.X = 54;
																rectangle.Y = 216;
															}
															else
															{
																if (num50 == 1)
																{
																	rectangle.X = 72;
																	rectangle.Y = 216;
																}
																else
																{
																	rectangle.X = 90;
																	rectangle.Y = 216;
																}
															}
															WorldGen.mergeRight = true;
														}
													}
												}
												else
												{
													if (num43 != -1 && num48 != -1 && num45 == -1 && num46 == -1)
													{
														if (num43 == -2 && num48 == -2)
														{
															if (num50 == 0)
															{
																rectangle.X = 108;
																rectangle.Y = 216;
															}
															else
															{
																if (num50 == 1)
																{
																	rectangle.X = 108;
																	rectangle.Y = 234;
																}
																else
																{
																	rectangle.X = 108;
																	rectangle.Y = 252;
																}
															}
															WorldGen.mergeUp = true;
															WorldGen.mergeDown = true;
														}
														else
														{
															if (num43 == -2)
															{
																if (num50 == 0)
																{
																	rectangle.X = 126;
																	rectangle.Y = 144;
																}
																else
																{
																	if (num50 == 1)
																	{
																		rectangle.X = 126;
																		rectangle.Y = 162;
																	}
																	else
																	{
																		rectangle.X = 126;
																		rectangle.Y = 180;
																	}
																}
																WorldGen.mergeUp = true;
															}
															else
															{
																if (num48 == -2)
																{
																	if (num50 == 0)
																	{
																		rectangle.X = 126;
																		rectangle.Y = 90;
																	}
																	else
																	{
																		if (num50 == 1)
																		{
																			rectangle.X = 126;
																			rectangle.Y = 108;
																		}
																		else
																		{
																			rectangle.X = 126;
																			rectangle.Y = 126;
																		}
																	}
																	WorldGen.mergeDown = true;
																}
															}
														}
													}
													else
													{
														if (num43 == -1 && num48 == -1 && num45 != -1 && num46 != -1)
														{
															if (num45 == -2 && num46 == -2)
															{
																if (num50 == 0)
																{
																	rectangle.X = 162;
																	rectangle.Y = 198;
																}
																else
																{
																	if (num50 == 1)
																	{
																		rectangle.X = 180;
																		rectangle.Y = 198;
																	}
																	else
																	{
																		rectangle.X = 198;
																		rectangle.Y = 198;
																	}
																}
																WorldGen.mergeLeft = true;
																WorldGen.mergeRight = true;
															}
															else
															{
																if (num45 == -2)
																{
																	if (num50 == 0)
																	{
																		rectangle.X = 0;
																		rectangle.Y = 252;
																	}
																	else
																	{
																		if (num50 == 1)
																		{
																			rectangle.X = 18;
																			rectangle.Y = 252;
																		}
																		else
																		{
																			rectangle.X = 36;
																			rectangle.Y = 252;
																		}
																	}
																	WorldGen.mergeLeft = true;
																}
																else
																{
																	if (num46 == -2)
																	{
																		if (num50 == 0)
																		{
																			rectangle.X = 54;
																			rectangle.Y = 252;
																		}
																		else
																		{
																			if (num50 == 1)
																			{
																				rectangle.X = 72;
																				rectangle.Y = 252;
																			}
																			else
																			{
																				rectangle.X = 90;
																				rectangle.Y = 252;
																			}
																		}
																		WorldGen.mergeRight = true;
																	}
																}
															}
														}
														else
														{
															if (num43 == -2 && num48 == -1 && num45 == -1 && num46 == -1)
															{
																if (num50 == 0)
																{
																	rectangle.X = 108;
																	rectangle.Y = 144;
																}
																else
																{
																	if (num50 == 1)
																	{
																		rectangle.X = 108;
																		rectangle.Y = 162;
																	}
																	else
																	{
																		rectangle.X = 108;
																		rectangle.Y = 180;
																	}
																}
																WorldGen.mergeUp = true;
															}
															else
															{
																if (num43 == -1 && num48 == -2 && num45 == -1 && num46 == -1)
																{
																	if (num50 == 0)
																	{
																		rectangle.X = 108;
																		rectangle.Y = 90;
																	}
																	else
																	{
																		if (num50 == 1)
																		{
																			rectangle.X = 108;
																			rectangle.Y = 108;
																		}
																		else
																		{
																			rectangle.X = 108;
																			rectangle.Y = 126;
																		}
																	}
																	WorldGen.mergeDown = true;
																}
																else
																{
																	if (num43 == -1 && num48 == -1 && num45 == -2 && num46 == -1)
																	{
																		if (num50 == 0)
																		{
																			rectangle.X = 0;
																			rectangle.Y = 234;
																		}
																		else
																		{
																			if (num50 == 1)
																			{
																				rectangle.X = 18;
																				rectangle.Y = 234;
																			}
																			else
																			{
																				rectangle.X = 36;
																				rectangle.Y = 234;
																			}
																		}
																		WorldGen.mergeLeft = true;
																	}
																	else
																	{
																		if (num43 == -1 && num48 == -1 && num45 == -1 && num46 == -2)
																		{
																			if (num50 == 0)
																			{
																				rectangle.X = 54;
																				rectangle.Y = 234;
																			}
																			else
																			{
																				if (num50 == 1)
																				{
																					rectangle.X = 72;
																					rectangle.Y = 234;
																				}
																				else
																				{
																					rectangle.X = 90;
																					rectangle.Y = 234;
																				}
																			}
																			WorldGen.mergeRight = true;
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
							if (rectangle.X < 0 || rectangle.Y < 0)
							{
								if (!flag4)
								{
									if (num43 > -1 && !Main.tileSolid[num43] && num43 != num)
									{
										num43 = -1;
									}
									if (num48 > -1 && !Main.tileSolid[num48] && num48 != num)
									{
										num48 = -1;
									}
									if (num45 > -1 && !Main.tileSolid[num45] && num45 != num)
									{
										num45 = -1;
									}
									if (num46 > -1 && !Main.tileSolid[num46] && num46 != num)
									{
										num46 = -1;
									}
									if (num42 > -1 && !Main.tileSolid[num42] && num42 != num)
									{
										num42 = -1;
									}
									if (num44 > -1 && !Main.tileSolid[num44] && num44 != num)
									{
										num44 = -1;
									}
									if (num47 > -1 && !Main.tileSolid[num47] && num47 != num)
									{
										num47 = -1;
									}
									if (num49 > -1 && !Main.tileSolid[num49] && num49 != num)
									{
										num49 = -1;
									}
								}
								if (num == 2 || num == 23 || num == 60 || num == 70 || num == 109 || num == 199 || Main.tileMoss[num])
								{
									if (num43 == -2)
									{
										num43 = num;
									}
									if (num48 == -2)
									{
										num48 = num;
									}
									if (num45 == -2)
									{
										num45 = num;
									}
									if (num46 == -2)
									{
										num46 = num;
									}
									if (num42 == -2)
									{
										num42 = num;
									}
									if (num44 == -2)
									{
										num44 = num;
									}
									if (num47 == -2)
									{
										num47 = num;
									}
									if (num49 == -2)
									{
										num49 = num;
									}
								}
								if (num43 == num && num48 == num && (num45 == num & num46 == num))
								{
									if (num42 != num && num44 != num)
									{
										if (num50 == 0)
										{
											rectangle.X = 108;
											rectangle.Y = 18;
										}
										else
										{
											if (num50 == 1)
											{
												rectangle.X = 126;
												rectangle.Y = 18;
											}
											else
											{
												rectangle.X = 144;
												rectangle.Y = 18;
											}
										}
									}
									else
									{
										if (num47 != num && num49 != num)
										{
											if (num50 == 0)
											{
												rectangle.X = 108;
												rectangle.Y = 36;
											}
											else
											{
												if (num50 == 1)
												{
													rectangle.X = 126;
													rectangle.Y = 36;
												}
												else
												{
													rectangle.X = 144;
													rectangle.Y = 36;
												}
											}
										}
										else
										{
											if (num42 != num && num47 != num)
											{
												if (num50 == 0)
												{
													rectangle.X = 180;
													rectangle.Y = 0;
												}
												else
												{
													if (num50 == 1)
													{
														rectangle.X = 180;
														rectangle.Y = 18;
													}
													else
													{
														rectangle.X = 180;
														rectangle.Y = 36;
													}
												}
											}
											else
											{
												if (num44 != num && num49 != num)
												{
													if (num50 == 0)
													{
														rectangle.X = 198;
														rectangle.Y = 0;
													}
													else
													{
														if (num50 == 1)
														{
															rectangle.X = 198;
															rectangle.Y = 18;
														}
														else
														{
															rectangle.X = 198;
															rectangle.Y = 36;
														}
													}
												}
												else
												{
													if (num50 == 0)
													{
														rectangle.X = 18;
														rectangle.Y = 18;
													}
													else
													{
														if (num50 == 1)
														{
															rectangle.X = 36;
															rectangle.Y = 18;
														}
														else
														{
															rectangle.X = 54;
															rectangle.Y = 18;
														}
													}
												}
											}
										}
									}
								}
								else
								{
									if (num43 != num && num48 == num && (num45 == num & num46 == num))
									{
										if (num50 == 0)
										{
											rectangle.X = 18;
											rectangle.Y = 0;
										}
										else
										{
											if (num50 == 1)
											{
												rectangle.X = 36;
												rectangle.Y = 0;
											}
											else
											{
												rectangle.X = 54;
												rectangle.Y = 0;
											}
										}
									}
									else
									{
										if (num43 == num && num48 != num && (num45 == num & num46 == num))
										{
											if (num50 == 0)
											{
												rectangle.X = 18;
												rectangle.Y = 36;
											}
											else
											{
												if (num50 == 1)
												{
													rectangle.X = 36;
													rectangle.Y = 36;
												}
												else
												{
													rectangle.X = 54;
													rectangle.Y = 36;
												}
											}
										}
										else
										{
											if (num43 == num && num48 == num && (num45 != num & num46 == num))
											{
												if (num50 == 0)
												{
													rectangle.X = 0;
													rectangle.Y = 0;
												}
												else
												{
													if (num50 == 1)
													{
														rectangle.X = 0;
														rectangle.Y = 18;
													}
													else
													{
														rectangle.X = 0;
														rectangle.Y = 36;
													}
												}
											}
											else
											{
												if (num43 == num && num48 == num && (num45 == num & num46 != num))
												{
													if (num50 == 0)
													{
														rectangle.X = 72;
														rectangle.Y = 0;
													}
													else
													{
														if (num50 == 1)
														{
															rectangle.X = 72;
															rectangle.Y = 18;
														}
														else
														{
															rectangle.X = 72;
															rectangle.Y = 36;
														}
													}
												}
												else
												{
													if (num43 != num && num48 == num && (num45 != num & num46 == num))
													{
														if (num50 == 0)
														{
															rectangle.X = 0;
															rectangle.Y = 54;
														}
														else
														{
															if (num50 == 1)
															{
																rectangle.X = 36;
																rectangle.Y = 54;
															}
															else
															{
																rectangle.X = 72;
																rectangle.Y = 54;
															}
														}
													}
													else
													{
														if (num43 != num && num48 == num && (num45 == num & num46 != num))
														{
															if (num50 == 0)
															{
																rectangle.X = 18;
																rectangle.Y = 54;
															}
															else
															{
																if (num50 == 1)
																{
																	rectangle.X = 54;
																	rectangle.Y = 54;
																}
																else
																{
																	rectangle.X = 90;
																	rectangle.Y = 54;
																}
															}
														}
														else
														{
															if (num43 == num && num48 != num && (num45 != num & num46 == num))
															{
																if (num50 == 0)
																{
																	rectangle.X = 0;
																	rectangle.Y = 72;
																}
																else
																{
																	if (num50 == 1)
																	{
																		rectangle.X = 36;
																		rectangle.Y = 72;
																	}
																	else
																	{
																		rectangle.X = 72;
																		rectangle.Y = 72;
																	}
																}
															}
															else
															{
																if (num43 == num && num48 != num && (num45 == num & num46 != num))
																{
																	if (num50 == 0)
																	{
																		rectangle.X = 18;
																		rectangle.Y = 72;
																	}
																	else
																	{
																		if (num50 == 1)
																		{
																			rectangle.X = 54;
																			rectangle.Y = 72;
																		}
																		else
																		{
																			rectangle.X = 90;
																			rectangle.Y = 72;
																		}
																	}
																}
																else
																{
																	if (num43 == num && num48 == num && (num45 != num & num46 != num))
																	{
																		if (num50 == 0)
																		{
																			rectangle.X = 90;
																			rectangle.Y = 0;
																		}
																		else
																		{
																			if (num50 == 1)
																			{
																				rectangle.X = 90;
																				rectangle.Y = 18;
																			}
																			else
																			{
																				rectangle.X = 90;
																				rectangle.Y = 36;
																			}
																		}
																	}
																	else
																	{
																		if (num43 != num && num48 != num && (num45 == num & num46 == num))
																		{
																			if (num50 == 0)
																			{
																				rectangle.X = 108;
																				rectangle.Y = 72;
																			}
																			else
																			{
																				if (num50 == 1)
																				{
																					rectangle.X = 126;
																					rectangle.Y = 72;
																				}
																				else
																				{
																					rectangle.X = 144;
																					rectangle.Y = 72;
																				}
																			}
																		}
																		else
																		{
																			if (num43 != num && num48 == num && (num45 != num & num46 != num))
																			{
																				if (num50 == 0)
																				{
																					rectangle.X = 108;
																					rectangle.Y = 0;
																				}
																				else
																				{
																					if (num50 == 1)
																					{
																						rectangle.X = 126;
																						rectangle.Y = 0;
																					}
																					else
																					{
																						rectangle.X = 144;
																						rectangle.Y = 0;
																					}
																				}
																			}
																			else
																			{
																				if (num43 == num && num48 != num && (num45 != num & num46 != num))
																				{
																					if (num50 == 0)
																					{
																						rectangle.X = 108;
																						rectangle.Y = 54;
																					}
																					else
																					{
																						if (num50 == 1)
																						{
																							rectangle.X = 126;
																							rectangle.Y = 54;
																						}
																						else
																						{
																							rectangle.X = 144;
																							rectangle.Y = 54;
																						}
																					}
																				}
																				else
																				{
																					if (num43 != num && num48 != num && (num45 != num & num46 == num))
																					{
																						if (num50 == 0)
																						{
																							rectangle.X = 162;
																							rectangle.Y = 0;
																						}
																						else
																						{
																							if (num50 == 1)
																							{
																								rectangle.X = 162;
																								rectangle.Y = 18;
																							}
																							else
																							{
																								rectangle.X = 162;
																								rectangle.Y = 36;
																							}
																						}
																					}
																					else
																					{
																						if (num43 != num && num48 != num && (num45 == num & num46 != num))
																						{
																							if (num50 == 0)
																							{
																								rectangle.X = 216;
																								rectangle.Y = 0;
																							}
																							else
																							{
																								if (num50 == 1)
																								{
																									rectangle.X = 216;
																									rectangle.Y = 18;
																								}
																								else
																								{
																									rectangle.X = 216;
																									rectangle.Y = 36;
																								}
																							}
																						}
																						else
																						{
																							if (num43 != num && num48 != num && (num45 != num & num46 != num))
																							{
																								if (num50 == 0)
																								{
																									rectangle.X = 162;
																									rectangle.Y = 54;
																								}
																								else
																								{
																									if (num50 == 1)
																									{
																										rectangle.X = 180;
																										rectangle.Y = 54;
																									}
																									else
																									{
																										rectangle.X = 198;
																										rectangle.Y = 54;
																									}
																								}
																							}
																						}
																					}
																				}
																			}
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
							if (rectangle.X <= -1 || rectangle.Y <= -1)
							{
								if (num50 <= 0)
								{
									rectangle.X = 18;
									rectangle.Y = 18;
								}
								else
								{
									if (num50 == 1)
									{
										rectangle.X = 36;
										rectangle.Y = 18;
									}
								}
								if (num50 >= 2)
								{
									rectangle.X = 54;
									rectangle.Y = 18;
								}
							}
							if (Main.tileLargeFrames[num] == 1 && num50 == 3)
							{
								rectangle.Y += 90;
							}
							tile.frameX = (short)rectangle.X;
							tile.frameY = (short)rectangle.Y;
							if (num == 52 || num == 62 || num == 115 || num == 205)
							{
								if (tile2 != null)
								{
									if (!tile2.active())
									{
										num43 = -1;
									}
									else
									{
										if (tile2.bottomSlope())
										{
											num43 = -1;
										}
										else
										{
											num43 = (int)tile2.type;
										}
									}
								}
								else
								{
									num43 = num;
								}
								if ((num == 52 || num == 205) && (num43 == 109 || num43 == 115))
								{
									tile.type = 115;
									WorldGen.SquareTileFrame(i, j, true);
									return;
								}
								if ((num == 115 || num == 205) && (num43 == 2 || num43 == 52))
								{
									tile.type = 52;
									WorldGen.SquareTileFrame(i, j, true);
									return;
								}
								if ((num == 52 || num == 115) && (num43 == 199 || num43 == 205))
								{
									tile.type = 205;
									WorldGen.SquareTileFrame(i, j, true);
									return;
								}
								if (num43 != num)
								{
									bool flag5 = false;
									if (num43 == -1)
									{
										flag5 = true;
									}
									if (num == 52 && num43 != 2 && num43 != 192)
									{
										flag5 = true;
									}
									if (num == 62 && num43 != 60)
									{
										flag5 = true;
									}
									if (num == 115 && num43 != 109)
									{
										flag5 = true;
									}
									if (num == 205 && num43 != 199)
									{
										flag5 = true;
									}
									if (flag5)
									{
										WorldGen.KillTile(i, j, false, false, false);
									}
								}
							}
							if (!WorldGen.noTileActions && (num == 53 || num == 112 || num == 116 || num == 123 || num == 234 || num == 224))
							{
								if (Main.netMode == 0)
								{
									if (tile3 != null && !tile3.active())
									{
										bool flag6 = true;
										if (tile2.active() && tile2.type == 21)
										{
											flag6 = false;
										}
										if (flag6)
										{
											int type;
											if (num == 112)
											{
												type = 56;
											}
											else
											{
												if (num == 116)
												{
													type = 67;
												}
												else
												{
													if (num == 123)
													{
														type = 71;
													}
													else
													{
														if (num == 224)
														{
															type = 179;
														}
														else
														{
															if (num == 234)
															{
																type = 241;
															}
															else
															{
																type = 31;
															}
														}
													}
												}
											}
											tile.active(false);
											int num54 = Projectile.NewProjectile((float)(i * 16 + 8), (float)(j * 16 + 8), 0f, 0.41f, type, 10, 0f, Main.myPlayer, 0f, 0f);
											Main.projectile[num54].ai[0] = 1f;
											WorldGen.SquareTileFrame(i, j, true);
										}
									}
								}
								else
								{
									if (Main.netMode == 2 && tile3 != null && !tile3.active())
									{
										bool flag7 = true;
										if (tile2.active() && tile2.type == 21)
										{
											flag7 = false;
										}
										if (flag7)
										{
											int type2;
											if (num == 112)
											{
												type2 = 56;
											}
											else
											{
												if (num == 116)
												{
													type2 = 67;
												}
												else
												{
													if (num == 123)
													{
														type2 = 71;
													}
													else
													{
														if (num == 224)
														{
															type2 = 179;
														}
														else
														{
															if (num == 234)
															{
																type2 = 241;
															}
															else
															{
																type2 = 31;
															}
														}
													}
												}
											}
											tile.active(false);
											int num55 = Projectile.NewProjectile((float)(i * 16 + 8), (float)(j * 16 + 8), 0f, 2.5f, type2, 10, 0f, Main.myPlayer, 0f, 0f);
											Main.projectile[num55].velocity.Y = 0.5f;
											Projectile expr_80DD_cp_0 = Main.projectile[num55];
											expr_80DD_cp_0.position.Y = expr_80DD_cp_0.position.Y + 2f;
											Main.projectile[num55].netUpdate = true;
											NetMessage.SendTileSquare(-1, i, j, 1);
											WorldGen.SquareTileFrame(i, j, true);
										}
									}
								}
							}
							if (rectangle.X != frameX && rectangle.Y != frameY && frameX >= 0 && frameY >= 0)
							{
								WorldGen.tileReframeCount++;
								if (WorldGen.tileReframeCount < 100)
								{
									bool flag8 = WorldGen.mergeUp;
									bool flag9 = WorldGen.mergeDown;
									bool flag10 = WorldGen.mergeLeft;
									bool flag11 = WorldGen.mergeRight;
									WorldGen.TileFrame(i - 1, j, false, false);
									WorldGen.TileFrame(i + 1, j, false, false);
									WorldGen.TileFrame(i, j - 1, false, false);
									WorldGen.TileFrame(i, j + 1, false, false);
									WorldGen.mergeUp = flag8;
									WorldGen.mergeDown = flag9;
									WorldGen.mergeLeft = flag10;
									WorldGen.mergeRight = flag11;
								}
								WorldGen.tileReframeCount--;
							}
						}
					}
				}
			}
			catch
			{
			}
			if (Main.netMode != 2 && Main.mapEnabled && !WorldGen.noMapUpdate && !WorldGen.gen && i > 0 && j > 0)
			{
				Map map2 = Main.map[i, j];
				if (map2 != null && map2.light > 0)
				{
					map2.setTile(i, j, map2.light);
					if (map2.changed && !flag)
					{
						if (Map.numUpdateTile < Map.maxUpdateTile - 1)
						{
							Map.updateTileX[Map.numUpdateTile] = (short)i;
							Map.updateTileY[Map.numUpdateTile] = (short)j;
							Map.numUpdateTile++;
							return;
						}
						Main.refreshMap = true;
					}
				}
			}
		}
Ejemplo n.º 34
0
        protected void DrawWater(bool bg = false)
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            Vector2 vector = new Vector2((float)offScreenRange, (float)offScreenRange);
            if (drawToScreen)
            {
                vector = new Vector2();
            }
            int num = (int)((255f * (1f - gfxQuality)) + (40f * gfxQuality));
            int num2 = (int)((255f * (1f - gfxQuality)) + (140f * gfxQuality));
            float num3 = ((float)evilTiles) / 350f;
            if (num3 > 1f)
            {
                num3 = 1f;
            }
            if (num3 < 0f)
            {
                num3 = 0f;
            }
            float num4 = (255f - (100f * num3)) / 255f;
            float num5 = (255f - (50f * num3)) / 255f;
            int num6 = (int)(((screenPosition.X - vector.X) / 16f) - 1f);
            int num7 = ((int)(((screenPosition.X + screenWidth) + vector.X) / 16f)) + 2;
            int num8 = (int)(((screenPosition.Y - vector.Y) / 16f) - 1f);
            int num9 = ((int)(((screenPosition.Y + screenHeight) + vector.Y) / 16f)) + 5;
            if (num6 < 5)
            {
                num6 = 5;
            }
            if (num7 > (maxTilesX - 5))
            {
                num7 = maxTilesX - 5;
            }
            if (num8 < 5)
            {
                num8 = 5;
            }
            if (num9 > (maxTilesY - 5))
            {
                num9 = maxTilesY - 5;
            }
            for (int i = num8; i < (num9 + 4); i++)
            {
                for (int j = num6 - 2; j < (num7 + 2); j++)
                {
                    if (tile[j, i] == null)
                    {
                        tile[j, i] = new Tile();
                    }
                    if (((tile[j, i].liquid > 0) && ((!tile[j, i].active || !tileSolid[tile[j, i].type]) || tileSolidTop[tile[j, i].type])) && ((Lighting.Brightness(j, i) > 0f) || bg))
                    {
                        Color color = Lighting.GetColor(j, i);
                        float num12 = 0x100 - tile[j, i].liquid;
                        num12 /= 32f;
                        int index = 0;
                        if (tile[j, i].lava)
                        {
                            index = 1;
                        }
                        float num14 = 0.5f;
                        if (bg)
                        {
                            num14 = 1f;
                        }
                        Vector2 vector2 = new Vector2((float)(j * 0x10), (float)((i * 0x10) + (((int)num12) * 2)));
                        Rectangle rectangle = new Rectangle(0, 0, 0x10, 0x10 - (((int)num12) * 2));
                        if ((tile[j, i + 1].liquid < 0xf5) && ((!tile[j, i + 1].active || !tileSolid[tile[j, i + 1].type]) || tileSolidTop[tile[j, i + 1].type]))
                        {
                            float num15 = 0x100 - tile[j, i + 1].liquid;
                            num15 /= 32f;
                            num14 = (0.5f * (8f - num12)) / 4f;
                            if (num14 > 0.55)
                            {
                                num14 = 0.55f;
                            }
                            if (num14 < 0.35)
                            {
                                num14 = 0.35f;
                            }
                            float num16 = num12 / 2f;
                            if (tile[j, i + 1].liquid < 200)
                            {
                                if (bg)
                                {
                                    continue;
                                }
                                if ((tile[j, i - 1].liquid > 0) && (tile[j, i - 1].liquid > 0))
                                {
                                    rectangle = new Rectangle(0, 4, 0x10, 0x10);
                                    num14 = 0.5f;
                                }
                                else if (tile[j, i - 1].liquid > 0)
                                {
                                    vector2 = new Vector2((float)(j * 0x10), (float)((i * 0x10) + 4));
                                    rectangle = new Rectangle(0, 4, 0x10, 12);
                                    num14 = 0.5f;
                                }
                                else if (tile[j, i + 1].liquid > 0)
                                {
                                    vector2 = new Vector2((float)(j * 0x10), (float)(((i * 0x10) + (((int)num12) * 2)) + (((int)num15) * 2)));
                                    rectangle = new Rectangle(0, 4, 0x10, 0x10 - (((int)num12) * 2));
                                }
                                else
                                {
                                    vector2 = new Vector2((float)((j * 0x10) + ((int)num16)), (float)(((i * 0x10) + (((int)num16) * 2)) + (((int)num15) * 2)));
                                    rectangle = new Rectangle(0, 4, 0x10 - (((int)num16) * 2), 0x10 - (((int)num16) * 2));
                                }
                            }
                            else
                            {
                                num14 = 0.5f;
                                rectangle = new Rectangle(0, 4, 0x10, (0x10 - (((int)num12) * 2)) + (((int)num15) * 2));
                            }
                        }
                        else if (tile[j, i - 1].liquid > 0x20)
                        {
                            rectangle = new Rectangle(0, 4, rectangle.Width, rectangle.Height);
                        }
                        else if (((num12 < 1f) && tile[j, i - 1].active) && (tileSolid[tile[j, i - 1].type] && !tileSolidTop[tile[j, i - 1].type]))
                        {
                            vector2 = new Vector2((float)(j * 0x10), (float)(i * 0x10));
                            rectangle = new Rectangle(0, 4, 0x10, 0x10);
                        }
                        else
                        {
                            bool flag = true;
                            for (int k = i + 1; k < (i + 6); k++)
                            {
                                if ((tile[j, k].active && tileSolid[tile[j, k].type]) && !tileSolidTop[tile[j, k].type])
                                {
                                    break;
                                }
                                if (tile[j, k].liquid < 200)
                                {
                                    flag = false;
                                    break;
                                }
                            }
                            if (!flag)
                            {
                                num14 = 0.5f;
                                rectangle = new Rectangle(0, 4, 0x10, 0x10);
                            }
                            else if (tile[j, i - 1].liquid > 0)
                            {
                                rectangle = new Rectangle(0, 2, rectangle.Width, rectangle.Height);
                            }
                        }
                        if (tile[j, i].lava)
                        {
                            num14 *= 1.8f;
                            if (num14 > 1f)
                            {
                                num14 = 1f;
                            }
                            if ((base.IsActive && !gamePaused) && (Dust.lavaBubbles < 200))
                            {
                                if ((tile[j, i].liquid > 200) && (rand.Next(700) == 0))
                                {
                                    Color newColor = new Color();
                                    Dust.NewDust(new Vector2((float)(j * 0x10), (float)(i * 0x10)), 0x10, 0x10, 0x23, 0f, 0f, 0, newColor, 1f);
                                }
                                if ((rectangle.Y == 0) && (rand.Next(350) == 0))
                                {
                                    Color color6 = new Color();
                                    int num18 = Dust.NewDust(new Vector2((float)(j * 0x10), ((i * 0x10) + (num12 * 2f)) - 8f), 0x10, 8, 0x23, 0f, 0f, 50, color6, 1.5f);
                                    Dust dust1 = dust[num18];
                                    dust1.velocity = (Vector2)(dust1.velocity * 0.8f);
                                    dust[num18].velocity.X *= 2f;
                                    dust[num18].velocity.Y -= rand.Next(1, 7) * 0.1f;
                                    if (rand.Next(10) == 0)
                                    {
                                        dust[num18].velocity.Y *= rand.Next(2, 5);
                                    }
                                    dust[num18].noGravity = true;
                                }
                            }
                        }
                        float num19 = color.R * num14;
                        float num20 = color.G * num14;
                        float num21 = color.B * num14;
                        float num22 = color.A * num14;
                        if (index == 0)
                        {
                            num21 *= num4;
                        }
                        else
                        {
                            num19 *= num5;
                        }
                        color = new Color((int)((byte)num19), (int)((byte)num20), (int)((byte)num21), (int)((byte)num22));
                        if ((Lighting.lightMode < 2) && !bg)
                        {
                            Color color2 = color;
                            if (((index == 0) && (((color2.R > num) || (color2.G > (num * 1.1))) || (color2.B > (num * 1.2)))) || (((color2.R > num2) || (color2.G > (num2 * 1.1))) || (color2.B > (num2 * 1.2))))
                            {
                                for (int m = 0; m < 4; m++)
                                {
                                    int num24 = 0;
                                    int num25 = 0;
                                    int width = 8;
                                    int height = 8;
                                    Color color3 = color2;
                                    Color color4 = Lighting.GetColor(j, i);
                                    switch (m)
                                    {
                                        case 0:
                                            if (Lighting.Brighter(j, i - 1, j - 1, i))
                                            {
                                                if (!tile[j - 1, i].active)
                                                {
                                                    color4 = Lighting.GetColor(j - 1, i);
                                                }
                                                else if (!tile[j, i - 1].active)
                                                {
                                                    color4 = Lighting.GetColor(j, i - 1);
                                                }
                                            }
                                            if (rectangle.Height < 8)
                                            {
                                                height = rectangle.Height;
                                            }
                                            break;

                                        case 1:
                                            if (Lighting.Brighter(j, i - 1, j + 1, i))
                                            {
                                                if (!tile[j + 1, i].active)
                                                {
                                                    color4 = Lighting.GetColor(j + 1, i);
                                                }
                                                else if (!tile[j, i - 1].active)
                                                {
                                                    color4 = Lighting.GetColor(j, i - 1);
                                                }
                                            }
                                            num24 = 8;
                                            if (rectangle.Height < 8)
                                            {
                                                height = rectangle.Height;
                                            }
                                            break;

                                        case 2:
                                            if (Lighting.Brighter(j, i + 1, j - 1, i))
                                            {
                                                if (!tile[j - 1, i].active)
                                                {
                                                    color4 = Lighting.GetColor(j - 1, i);
                                                }
                                                else if (!tile[j, i + 1].active)
                                                {
                                                    color4 = Lighting.GetColor(j, i + 1);
                                                }
                                            }
                                            num25 = 8;
                                            height = 8 - (0x10 - rectangle.Height);
                                            break;

                                        case 3:
                                            if (Lighting.Brighter(j, i + 1, j + 1, i))
                                            {
                                                if (!tile[j + 1, i].active)
                                                {
                                                    color4 = Lighting.GetColor(j + 1, i);
                                                }
                                                else if (!tile[j, i + 1].active)
                                                {
                                                    color4 = Lighting.GetColor(j, i + 1);
                                                }
                                            }
                                            num24 = 8;
                                            num25 = 8;
                                            height = 8 - (0x10 - rectangle.Height);
                                            break;
                                    }
                                    num19 = color4.R * num14;
                                    num20 = color4.G * num14;
                                    num21 = color4.B * num14;
                                    num22 = color4.A * num14;
                                    color4 = new Color((int)((byte)num19), (int)((byte)num20), (int)((byte)num21), (int)((byte)num22));
                                    color3.R = (byte)((color2.R + color4.R) / 2);
                                    color3.G = (byte)((color2.G + color4.G) / 2);
                                    color3.B = (byte)((color2.B + color4.B) / 2);
                                    color3.A = (byte)((color2.A + color4.A) / 2);
                                    Vector2 origin = new Vector2();
                                    this.spriteBatch.Draw(liquidTexture[index], ((vector2 - screenPosition) + new Vector2((float)num24, (float)num25)) + vector, new Rectangle(rectangle.X + num24, rectangle.Y + num25, width, height), color3, 0f, origin, (float)1f, SpriteEffects.None, 0f);
                                }
                            }
                            else
                            {
                                Vector2 vector4 = new Vector2();
                                this.spriteBatch.Draw(liquidTexture[index], (vector2 - screenPosition) + vector, new Rectangle?(rectangle), color, 0f, vector4, (float)1f, SpriteEffects.None, 0f);
                            }
                        }
                        else
                        {
                            Vector2 vector5 = new Vector2();
                            this.spriteBatch.Draw(liquidTexture[index], (vector2 - screenPosition) + vector, new Rectangle?(rectangle), color, 0f, vector5, (float)1f, SpriteEffects.None, 0f);
                        }
                    }
                }
            }
            if (!bg)
            {
                renderTimer[4] = stopwatch.ElapsedMilliseconds;
            }
        }
		public void FindWaterfalls()
		{
			this.findWaterfallCount++;
			if (this.findWaterfallCount < 30)
			{
				return;
			}
			this.findWaterfallCount = 0;
			this.waterfallDist = (int)(75f * Main.gfxQuality) + 25;
			this.qualityMax = (int)(175f * Main.gfxQuality) + 25;
			this.currentMax = 0;
			int num = (int)(Main.screenPosition.X / 16f - 1f);
			int num2 = (int)((Main.screenPosition.X + (float)Main.screenWidth) / 16f) + 2;
			int num3 = (int)(Main.screenPosition.Y / 16f - 1f);
			int num4 = (int)((Main.screenPosition.Y + (float)Main.screenHeight) / 16f) + 2;
			num -= this.waterfallDist;
			num2 += this.waterfallDist;
			num3 -= this.waterfallDist;
			num4 += 20;
			if (num < 0)
			{
				num = 0;
			}
			if (num2 > Main.maxTilesX)
			{
				num2 = Main.maxTilesX;
			}
			if (num3 < 0)
			{
				num3 = 0;
			}
			if (num4 > Main.maxTilesY)
			{
				num4 = Main.maxTilesY;
			}
			for (int i = num; i < num2; i++)
			{
				for (int j = num3; j < num4; j++)
				{
					Tile tile = Main.tile[i, j];
					if (tile == null)
					{
						tile = new Tile();
						Main.tile[i, j] = tile;
					}
					if (tile.active())
					{
						if (tile.halfBrick())
						{
							Tile tile2 = Main.tile[i, j - 1];
							if (tile2 == null)
							{
								tile2 = new Tile();
								Main.tile[i, j - 1] = tile2;
							}
							if (tile2.liquid < 16 || WorldGen.SolidTile(tile2))
							{
								Tile tile3 = Main.tile[i + 1, j];
								if (tile3 == null)
								{
									tile3 = new Tile();
									Main.tile[i - 1, j] = tile3;
								}
								Tile tile4 = Main.tile[i - 1, j];
								if (tile4 == null)
								{
									tile4 = new Tile();
									Main.tile[i + 1, j] = tile4;
								}
								if ((tile3.liquid > 160 || tile4.liquid > 160) && ((tile3.liquid == 0 && !WorldGen.SolidTile(tile3) && tile3.slope() == 0) || (tile4.liquid == 0 && !WorldGen.SolidTile(tile4) && tile4.slope() == 0)) && this.currentMax < this.qualityMax)
								{
									this.waterfalls[this.currentMax].type = 0;
									if (tile2.lava() || tile4.lava() || tile3.lava())
									{
										this.waterfalls[this.currentMax].type = 1;
									}
									else
									{
										if (tile2.honey() || tile4.honey() || tile3.honey())
										{
											this.waterfalls[this.currentMax].type = 14;
										}
										else
										{
											this.waterfalls[this.currentMax].type = 0;
										}
									}
									this.waterfalls[this.currentMax].x = i;
									this.waterfalls[this.currentMax].y = j;
									this.currentMax++;
								}
							}
						}
						if (tile.type == 196)
						{
							Tile tile5 = Main.tile[i, j + 1];
							if (tile5 == null)
							{
								tile5 = new Tile();
								Main.tile[i, j + 1] = tile5;
							}
							if (!WorldGen.SolidTile(tile5) && tile5.slope() == 0 && this.currentMax < this.qualityMax)
							{
								this.waterfalls[this.currentMax].type = 11;
								this.waterfalls[this.currentMax].x = i;
								this.waterfalls[this.currentMax].y = j + 1;
								this.currentMax++;
							}
						}
					}
				}
			}
		}
Ejemplo n.º 36
0
 public bool HasSameSlope(Tile tile)
 {
     return(((int)this.sTileHeader & 29696) == ((int)tile.sTileHeader & 29696));
 }