Beispiel #1
0
        public static bool Place(TileObject toBePlaced)
        {
            TileObjectData tileData = TileObjectData.GetTileData(toBePlaced.type, toBePlaced.style, toBePlaced.alternate);

            if (tileData == null)
            {
                return(false);
            }
            if (tileData.HookPlaceOverride.hook != null)
            {
                int num1;
                int num2;
                if (tileData.HookPlaceOverride.processedCoordinates)
                {
                    num1 = toBePlaced.xCoord;
                    num2 = toBePlaced.yCoord;
                }
                else
                {
                    num1 = toBePlaced.xCoord + (int)tileData.Origin.X;
                    num2 = toBePlaced.yCoord + (int)tileData.Origin.Y;
                }
                if (tileData.HookPlaceOverride.hook(num1, num2, toBePlaced.type, toBePlaced.style, 1) == tileData.HookPlaceOverride.badReturn)
                {
                    return(false);
                }
            }
            else
            {
                ushort num1 = (ushort)toBePlaced.type;
                int    num2 = tileData.CalculatePlacementStyle(toBePlaced.style, toBePlaced.alternate, toBePlaced.random);
                int    num3 = 0;
                if (tileData.StyleWrapLimit > 0)
                {
                    num3  = num2 / tileData.StyleWrapLimit;
                    num2 %= tileData.StyleWrapLimit;
                }
                int num4;
                int num5;
                if (tileData.StyleHorizontal)
                {
                    num4 = tileData.CoordinateFullWidth * num2;
                    num5 = tileData.CoordinateFullHeight * num3;
                }
                else
                {
                    num4 = tileData.CoordinateFullWidth * num3;
                    num5 = tileData.CoordinateFullHeight * num2;
                }
                int num6 = toBePlaced.xCoord;
                int num7 = toBePlaced.yCoord;
                for (int index1 = 0; index1 < tileData.Width; ++index1)
                {
                    for (int index2 = 0; index2 < tileData.Height; ++index2)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num6 + index1, num7 + index2);
                        if (tileSafely.active() && Main.tileCut[(int)tileSafely.type])
                        {
                            WorldGen.KillTile(num6 + index1, num7 + index2, false, false, false);
                        }
                    }
                }
                for (int index1 = 0; index1 < tileData.Width; ++index1)
                {
                    int num8 = num4 + index1 * (tileData.CoordinateWidth + tileData.CoordinatePadding);
                    int num9 = num5;
                    for (int index2 = 0; index2 < tileData.Height; ++index2)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num6 + index1, num7 + index2);
                        if (!tileSafely.active())
                        {
                            tileSafely.active(true);
                            tileSafely.frameX = (short)num8;
                            tileSafely.frameY = (short)num9;
                            tileSafely.type   = num1;
                        }
                        num9 += tileData.CoordinateHeights[index2] + tileData.CoordinatePadding;
                    }
                }
            }
            if (tileData.FlattenAnchors)
            {
                AnchorData anchorData = tileData.AnchorBottom;
                if (anchorData.tileCount != 0 && (anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int num = toBePlaced.xCoord + anchorData.checkStart;
                    int j   = toBePlaced.yCoord + tileData.Height;
                    for (int index = 0; index < anchorData.tileCount; ++index)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num + index, j);
                        if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                        {
                            WorldGen.SlopeTile(num + index, j, 0);
                        }
                    }
                }
                anchorData = tileData.AnchorTop;
                if (anchorData.tileCount != 0 && (anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int num = toBePlaced.xCoord + anchorData.checkStart;
                    int j   = toBePlaced.yCoord - 1;
                    for (int index = 0; index < anchorData.tileCount; ++index)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num + index, j);
                        if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                        {
                            WorldGen.SlopeTile(num + index, j, 0);
                        }
                    }
                }
                anchorData = tileData.AnchorRight;
                if (anchorData.tileCount != 0 && (anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int i   = toBePlaced.xCoord + tileData.Width;
                    int num = toBePlaced.yCoord + anchorData.checkStart;
                    for (int index = 0; index < anchorData.tileCount; ++index)
                    {
                        Tile tileSafely = Framing.GetTileSafely(i, num + index);
                        if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                        {
                            WorldGen.SlopeTile(i, num + index, 0);
                        }
                    }
                }
                anchorData = tileData.AnchorLeft;
                if (anchorData.tileCount != 0 && (anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int i   = toBePlaced.xCoord - 1;
                    int num = toBePlaced.yCoord + anchorData.checkStart;
                    for (int index = 0; index < anchorData.tileCount; ++index)
                    {
                        Tile tileSafely = Framing.GetTileSafely(i, num + index);
                        if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                        {
                            WorldGen.SlopeTile(i, num + index, 0);
                        }
                    }
                }
            }
            return(true);
        }
Beispiel #2
0
 public static bool CallPostPlacementPlayerHook(int tileX, int tileY, int type, int style, int dir, TileObject data)
 {
     TileObjectData tileData = TileObjectData.GetTileData(type, style, data.alternate);
     if (tileData == null || tileData._placementHooks == null || tileData._placementHooks.postPlaceMyPlayer.hook == null)
     {
         return false;
     }
     PlacementHook placementHook = tileData._placementHooks.postPlaceMyPlayer;
     if (placementHook.processedCoordinates)
     {
         tileX = tileX - tileData.Origin.X;
         tileY = tileY - tileData.Origin.Y;
     }
     return placementHook.hook(tileX, tileY, type, style, dir) == placementHook.badReturn;
 }
Beispiel #3
0
        public static bool CanPlace(int x, int y, int type, int style, int dir, out TileObject objectData, bool onlyCheck = false)
        {
            TileObjectData tileData1 = TileObjectData.GetTileData(type, style, 0);

            objectData = TileObject.Empty;
            if (tileData1 == null)
            {
                return(false);
            }
            int num1 = x - (int)tileData1.Origin.X;
            int num2 = y - (int)tileData1.Origin.Y;

            if (num1 < 0 || num1 + tileData1.Width >= Main.maxTilesX || (num2 < 0 || num2 + tileData1.Height >= Main.maxTilesY))
            {
                return(false);
            }
            bool flag1 = tileData1.RandomStyleRange > 0;

            if (TileObjectPreviewData.placementCache == null)
            {
                TileObjectPreviewData.placementCache = new TileObjectPreviewData();
            }
            TileObjectPreviewData.placementCache.Reset();
            int num3 = 0;
            int num4 = 0;

            if (tileData1.AlternatesCount != 0)
            {
                num4 = tileData1.AlternatesCount;
            }
            float          num5           = -1f;
            float          num6           = -1f;
            int            num7           = 0;
            TileObjectData tileObjectData = (TileObjectData)null;
            int            num8           = 1;
            int            alternate      = num3 - num8;

            while (alternate < num4)
            {
                ++alternate;
                TileObjectData tileData2 = TileObjectData.GetTileData(type, style, alternate);
                if (tileData2.Direction == TileObjectDirection.None || (tileData2.Direction != TileObjectDirection.PlaceLeft || dir != 1) && (tileData2.Direction != TileObjectDirection.PlaceRight || dir != -1))
                {
                    int num9  = x - (int)tileData2.Origin.X;
                    int num10 = y - (int)tileData2.Origin.Y;
                    if (num9 < 5 || num9 + tileData2.Width > Main.maxTilesX - 5 || (num10 < 5 || num10 + tileData2.Height > Main.maxTilesY - 5))
                    {
                        return(false);
                    }
                    Rectangle rectangle;
                    // ISSUE: explicit reference operation
                    ((Rectangle)@rectangle).\u002Ector(0, 0, tileData2.Width, tileData2.Height);
                    int X = 0;
                    int Y = 0;
                    if (tileData2.AnchorTop.tileCount != 0)
                    {
                        if (rectangle.Y == null)
                        {
                            rectangle.Y = (__Null) - 1;
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            __Null& local = @rectangle.Height;
                            // ISSUE: cast to a reference type
                            // ISSUE: explicit reference operation
                            int num11 = ^ (int&)local + 1;
 static TileObject()
 {
     TileObject.Empty = new TileObject();
     TileObject.objectPreview = new TileObjectPreviewData();
 }
Beispiel #5
0
        public static bool CanPlace(int x, int y, int type, int style, int dir, out TileObject objectData, bool onlyCheck = false)
        {
            TileObjectData tileData = TileObjectData.GetTileData(type, style);

            objectData = Empty;
            if (tileData == null)
            {
                return(false);
            }
            int num  = x - tileData.Origin.X;
            int num2 = y - tileData.Origin.Y;

            if (num < 0 || num + tileData.Width >= Main.maxTilesX || num2 < 0 || num2 + tileData.Height >= Main.maxTilesY)
            {
                return(false);
            }
            bool flag = tileData.RandomStyleRange > 0;

            if (TileObjectPreviewData.placementCache == null)
            {
                TileObjectPreviewData.placementCache = new TileObjectPreviewData();
            }
            TileObjectPreviewData.placementCache.Reset();
            int num3 = 0;
            int num4 = 0;

            if (tileData.AlternatesCount != 0)
            {
                num4 = tileData.AlternatesCount;
            }
            float          num5           = -1f;
            float          num6           = -1f;
            int            num7           = 0;
            TileObjectData tileObjectData = null;
            int            num8           = num3 - 1;

            while (num8 < num4)
            {
                num8++;
                TileObjectData tileData2 = TileObjectData.GetTileData(type, style, num8);
                if (tileData2.Direction != 0 && ((tileData2.Direction == TileObjectDirection.PlaceLeft && dir == 1) || (tileData2.Direction == TileObjectDirection.PlaceRight && dir == -1)))
                {
                    continue;
                }
                int num9  = x - tileData2.Origin.X;
                int num10 = y - tileData2.Origin.Y;
                if (num9 < 5 || num9 + tileData2.Width > Main.maxTilesX - 5 || num10 < 5 || num10 + tileData2.Height > Main.maxTilesY - 5)
                {
                    return(false);
                }
                Rectangle rectangle = new Rectangle(0, 0, tileData2.Width, tileData2.Height);
                int       num11     = 0;
                int       num12     = 0;
                if (tileData2.AnchorTop.tileCount != 0)
                {
                    if (rectangle.Y == 0)
                    {
                        rectangle.Y = -1;
                        rectangle.Height++;
                        num12++;
                    }
                    int checkStart = tileData2.AnchorTop.checkStart;
                    if (checkStart < rectangle.X)
                    {
                        rectangle.Width += rectangle.X - checkStart;
                        num11           += rectangle.X - checkStart;
                        rectangle.X      = checkStart;
                    }
                    int num13 = checkStart + tileData2.AnchorTop.tileCount - 1;
                    int num14 = rectangle.X + rectangle.Width - 1;
                    if (num13 > num14)
                    {
                        rectangle.Width += num13 - num14;
                    }
                }
                if (tileData2.AnchorBottom.tileCount != 0)
                {
                    if (rectangle.Y + rectangle.Height == tileData2.Height)
                    {
                        rectangle.Height++;
                    }
                    int checkStart2 = tileData2.AnchorBottom.checkStart;
                    if (checkStart2 < rectangle.X)
                    {
                        rectangle.Width += rectangle.X - checkStart2;
                        num11           += rectangle.X - checkStart2;
                        rectangle.X      = checkStart2;
                    }
                    int num15 = checkStart2 + tileData2.AnchorBottom.tileCount - 1;
                    int num16 = rectangle.X + rectangle.Width - 1;
                    if (num15 > num16)
                    {
                        rectangle.Width += num15 - num16;
                    }
                }
                if (tileData2.AnchorLeft.tileCount != 0)
                {
                    if (rectangle.X == 0)
                    {
                        rectangle.X = -1;
                        rectangle.Width++;
                        num11++;
                    }
                    int num17 = tileData2.AnchorLeft.checkStart;
                    if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                    {
                        num17--;
                    }
                    if (num17 < rectangle.Y)
                    {
                        rectangle.Width += rectangle.Y - num17;
                        num12           += rectangle.Y - num17;
                        rectangle.Y      = num17;
                    }
                    int num18 = num17 + tileData2.AnchorLeft.tileCount - 1;
                    if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                    {
                        num18 += 2;
                    }
                    int num19 = rectangle.Y + rectangle.Height - 1;
                    if (num18 > num19)
                    {
                        rectangle.Height += num18 - num19;
                    }
                }
                if (tileData2.AnchorRight.tileCount != 0)
                {
                    if (rectangle.X + rectangle.Width == tileData2.Width)
                    {
                        rectangle.Width++;
                    }
                    int num20 = tileData2.AnchorLeft.checkStart;
                    if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                    {
                        num20--;
                    }
                    if (num20 < rectangle.Y)
                    {
                        rectangle.Width += rectangle.Y - num20;
                        num12           += rectangle.Y - num20;
                        rectangle.Y      = num20;
                    }
                    int num21 = num20 + tileData2.AnchorRight.tileCount - 1;
                    if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                    {
                        num21 += 2;
                    }
                    int num22 = rectangle.Y + rectangle.Height - 1;
                    if (num21 > num22)
                    {
                        rectangle.Height += num21 - num22;
                    }
                }
                if (onlyCheck)
                {
                    objectPreview.Reset();
                    objectPreview.Active      = true;
                    objectPreview.Type        = (ushort)type;
                    objectPreview.Style       = (short)style;
                    objectPreview.Alternate   = num8;
                    objectPreview.Size        = new Point16(rectangle.Width, rectangle.Height);
                    objectPreview.ObjectStart = new Point16(num11, num12);
                    objectPreview.Coordinates = new Point16(num9 - num11, num10 - num12);
                }
                float num23 = 0f;
                float num24 = tileData2.Width * tileData2.Height;
                float num25 = 0f;
                float num26 = 0f;
                for (int i = 0; i < tileData2.Width; i++)
                {
                    for (int j = 0; j < tileData2.Height; j++)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num9 + i, num10 + j);
                        bool flag2      = !tileData2.LiquidPlace(tileSafely);
                        bool flag3      = false;
                        if (tileData2.AnchorWall)
                        {
                            num26 += 1f;
                            if (!tileData2.isValidWallAnchor(tileSafely.wall))
                            {
                                flag3 = true;
                            }
                            else
                            {
                                num25 += 1f;
                            }
                        }
                        bool flag4 = false;
                        if (tileSafely.active() && !Main.tileCut[tileSafely.type])
                        {
                            flag4 = true;
                        }
                        if (flag4 || flag2 || flag3)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[i + num11, j + num12] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[i + num11, j + num12] = 1;
                        }
                        num23 += 1f;
                    }
                }
                AnchorData anchorBottom = tileData2.AnchorBottom;
                if (anchorBottom.tileCount != 0)
                {
                    num26 += (float)anchorBottom.tileCount;
                    int height = tileData2.Height;
                    for (int k = 0; k < anchorBottom.tileCount; k++)
                    {
                        int  num27      = anchorBottom.checkStart + k;
                        Tile tileSafely = Framing.GetTileSafely(num9 + num27, num10 + height);
                        bool flag5      = false;
                        if (tileSafely.nactive())
                        {
                            if ((anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                            {
                                flag5 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag5 && ((anchorBottom.type & AnchorType.SolidWithTop) == AnchorType.SolidWithTop || (anchorBottom.type & AnchorType.Table) == AnchorType.Table))
                            {
                                if (tileSafely.type == 19)
                                {
                                    int num28 = tileSafely.frameX / TileObjectData.PlatformFrameWidth();
                                    if ((!tileSafely.halfBrick() && num28 >= 0 && num28 <= 7) || (num28 >= 12 && num28 <= 16) || (num28 >= 25 && num28 <= 26))
                                    {
                                        flag5 = true;
                                    }
                                }
                                else if (Main.tileSolid[tileSafely.type] && Main.tileSolidTop[tileSafely.type])
                                {
                                    flag5 = true;
                                }
                            }
                            if (!flag5 && (anchorBottom.type & AnchorType.Table) == AnchorType.Table && tileSafely.type != 19 && Main.tileTable[tileSafely.type] && tileSafely.blockType() == 0)
                            {
                                flag5 = true;
                            }
                            if (!flag5 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                            {
                                switch (tileSafely.blockType())
                                {
                                case 4:
                                case 5:
                                    flag5 = tileData2.isValidTileAnchor(tileSafely.type);
                                    break;
                                }
                            }
                            if (!flag5 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
                            {
                                flag5 = true;
                            }
                        }
                        else if (!flag5 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                        {
                            flag5 = true;
                        }
                        if (!flag5)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[num27 + num11, height + num12] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[num27 + num11, height + num12] = 1;
                        }
                        num25 += 1f;
                    }
                }
                anchorBottom = tileData2.AnchorTop;
                if (anchorBottom.tileCount != 0)
                {
                    num26 += (float)anchorBottom.tileCount;
                    int num29 = -1;
                    for (int l = 0; l < anchorBottom.tileCount; l++)
                    {
                        int  num30      = anchorBottom.checkStart + l;
                        Tile tileSafely = Framing.GetTileSafely(num9 + num30, num10 + num29);
                        bool flag6      = false;
                        if (tileSafely.nactive())
                        {
                            if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                            {
                                flag6 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag6 && (anchorBottom.type & AnchorType.SolidBottom) == AnchorType.SolidBottom && ((Main.tileSolid[tileSafely.type] && (!Main.tileSolidTop[tileSafely.type] || (tileSafely.type == 19 && (tileSafely.halfBrick() || tileSafely.topSlope())))) || tileSafely.halfBrick() || tileSafely.topSlope()) && !TileID.Sets.NotReallySolid[tileSafely.type] && !tileSafely.bottomSlope())
                            {
                                flag6 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag6 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                            {
                                switch (tileSafely.blockType())
                                {
                                case 2:
                                case 3:
                                    flag6 = tileData2.isValidTileAnchor(tileSafely.type);
                                    break;
                                }
                            }
                            if (!flag6 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
                            {
                                flag6 = true;
                            }
                        }
                        else if (!flag6 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                        {
                            flag6 = true;
                        }
                        if (!flag6)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[num30 + num11, num29 + num12] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[num30 + num11, num29 + num12] = 1;
                        }
                        num25 += 1f;
                    }
                }
                anchorBottom = tileData2.AnchorRight;
                if (anchorBottom.tileCount != 0)
                {
                    num26 += (float)anchorBottom.tileCount;
                    int width = tileData2.Width;
                    for (int m = 0; m < anchorBottom.tileCount; m++)
                    {
                        int  num31      = anchorBottom.checkStart + m;
                        Tile tileSafely = Framing.GetTileSafely(num9 + width, num10 + num31);
                        bool flag7      = false;
                        if (tileSafely.nactive())
                        {
                            if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                            {
                                flag7 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag7 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                            {
                                switch (tileSafely.blockType())
                                {
                                case 2:
                                case 4:
                                    flag7 = tileData2.isValidTileAnchor(tileSafely.type);
                                    break;
                                }
                            }
                            if (!flag7 && (anchorBottom.type & AnchorType.Tree) == AnchorType.Tree && tileSafely.type == 5)
                            {
                                flag7 = true;
                                if (m == 0)
                                {
                                    num26 += 1f;
                                    Tile tileSafely2 = Framing.GetTileSafely(num9 + width, num10 + num31 - 1);
                                    if (tileSafely2.nactive() && tileSafely2.type == 5)
                                    {
                                        num25 += 1f;
                                        if (onlyCheck)
                                        {
                                            objectPreview[width + num11, num31 + num12 - 1] = 1;
                                        }
                                    }
                                    else if (onlyCheck)
                                    {
                                        objectPreview[width + num11, num31 + num12 - 1] = 2;
                                    }
                                }
                                if (m == anchorBottom.tileCount - 1)
                                {
                                    num26 += 1f;
                                    Tile tileSafely3 = Framing.GetTileSafely(num9 + width, num10 + num31 + 1);
                                    if (tileSafely3.nactive() && tileSafely3.type == 5)
                                    {
                                        num25 += 1f;
                                        if (onlyCheck)
                                        {
                                            objectPreview[width + num11, num31 + num12 + 1] = 1;
                                        }
                                    }
                                    else if (onlyCheck)
                                    {
                                        objectPreview[width + num11, num31 + num12 + 1] = 2;
                                    }
                                }
                            }
                            if (!flag7 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
                            {
                                flag7 = true;
                            }
                        }
                        else if (!flag7 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                        {
                            flag7 = true;
                        }
                        if (!flag7)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[width + num11, num31 + num12] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[width + num11, num31 + num12] = 1;
                        }
                        num25 += 1f;
                    }
                }
                anchorBottom = tileData2.AnchorLeft;
                if (anchorBottom.tileCount != 0)
                {
                    num26 += (float)anchorBottom.tileCount;
                    int num32 = -1;
                    for (int n = 0; n < anchorBottom.tileCount; n++)
                    {
                        int  num33      = anchorBottom.checkStart + n;
                        Tile tileSafely = Framing.GetTileSafely(num9 + num32, num10 + num33);
                        bool flag8      = false;
                        if (tileSafely.nactive())
                        {
                            if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                            {
                                flag8 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag8 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                            {
                                switch (tileSafely.blockType())
                                {
                                case 3:
                                case 5:
                                    flag8 = tileData2.isValidTileAnchor(tileSafely.type);
                                    break;
                                }
                            }
                            if (!flag8 && (anchorBottom.type & AnchorType.Tree) == AnchorType.Tree && tileSafely.type == 5)
                            {
                                flag8 = true;
                                if (n == 0)
                                {
                                    num26 += 1f;
                                    Tile tileSafely4 = Framing.GetTileSafely(num9 + num32, num10 + num33 - 1);
                                    if (tileSafely4.nactive() && tileSafely4.type == 5)
                                    {
                                        num25 += 1f;
                                        if (onlyCheck)
                                        {
                                            objectPreview[num32 + num11, num33 + num12 - 1] = 1;
                                        }
                                    }
                                    else if (onlyCheck)
                                    {
                                        objectPreview[num32 + num11, num33 + num12 - 1] = 2;
                                    }
                                }
                                if (n == anchorBottom.tileCount - 1)
                                {
                                    num26 += 1f;
                                    Tile tileSafely5 = Framing.GetTileSafely(num9 + num32, num10 + num33 + 1);
                                    if (tileSafely5.nactive() && tileSafely5.type == 5)
                                    {
                                        num25 += 1f;
                                        if (onlyCheck)
                                        {
                                            objectPreview[num32 + num11, num33 + num12 + 1] = 1;
                                        }
                                    }
                                    else if (onlyCheck)
                                    {
                                        objectPreview[num32 + num11, num33 + num12 + 1] = 2;
                                    }
                                }
                            }
                            if (!flag8 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
                            {
                                flag8 = true;
                            }
                        }
                        else if (!flag8 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                        {
                            flag8 = true;
                        }
                        if (!flag8)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[num32 + num11, num33 + num12] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[num32 + num11, num33 + num12] = 1;
                        }
                        num25 += 1f;
                    }
                }
                if (tileData2.HookCheck.hook != null)
                {
                    if (tileData2.HookCheck.processedCoordinates)
                    {
                        short x2 = tileData2.Origin.X;
                        short y2 = tileData2.Origin.Y;
                    }
                    if (tileData2.HookCheck.hook(x, y, type, style, dir) == tileData2.HookCheck.badReturn && tileData2.HookCheck.badResponse == 0)
                    {
                        num25 = 0f;
                        num23 = 0f;
                        objectPreview.AllInvalid();
                    }
                }
                float num34 = num25 / num26;
                float num35 = num23 / num24;
                if (num34 == 1f && num35 == 1f)
                {
                    num5           = 1f;
                    num6           = 1f;
                    num7           = num8;
                    tileObjectData = tileData2;
                    break;
                }
                if (num34 > num5 || (num34 == num5 && num35 > num6))
                {
                    TileObjectPreviewData.placementCache.CopyFrom(objectPreview);
                    num5           = num34;
                    num6           = num35;
                    tileObjectData = tileData2;
                    num7           = num8;
                }
            }
            int num36 = -1;

            if (flag)
            {
                if (TileObjectPreviewData.randomCache == null)
                {
                    TileObjectPreviewData.randomCache = new TileObjectPreviewData();
                }
                bool flag9 = false;
                if (TileObjectPreviewData.randomCache.Type == type)
                {
                    Point16 coordinates = TileObjectPreviewData.randomCache.Coordinates;
                    Point16 objectStart = TileObjectPreviewData.randomCache.ObjectStart;
                    int     num37       = coordinates.X + objectStart.X;
                    int     num38       = coordinates.Y + objectStart.Y;
                    int     num39       = x - tileData.Origin.X;
                    int     num40       = y - tileData.Origin.Y;
                    if (num37 != num39 || num38 != num40)
                    {
                        flag9 = true;
                    }
                }
                else
                {
                    flag9 = true;
                }
                num36 = ((!flag9) ? TileObjectPreviewData.randomCache.Random : Main.rand.Next(tileData.RandomStyleRange));
            }
            if (onlyCheck)
            {
                if (num5 != 1f || num6 != 1f)
                {
                    objectPreview.CopyFrom(TileObjectPreviewData.placementCache);
                    num8 = num7;
                }
                objectPreview.Random = num36;
                if (tileData.RandomStyleRange > 0)
                {
                    TileObjectPreviewData.randomCache.CopyFrom(objectPreview);
                }
            }
            if (!onlyCheck)
            {
                objectData.xCoord    = x - tileObjectData.Origin.X;
                objectData.yCoord    = y - tileObjectData.Origin.Y;
                objectData.type      = type;
                objectData.style     = style;
                objectData.alternate = num8;
                objectData.random    = num36;
            }
            if (num5 == 1f)
            {
                return(num6 == 1f);
            }
            return(false);
        }
Beispiel #6
0
        public static bool CanPlace(int x, int y, int type, int style, int dir, out TileObject objectData, bool onlyCheck = false)
        {
            TileObjectData tileData = TileObjectData.GetTileData(type, style);

            objectData = Empty;
            if (tileData == null)
            {
                return(false);
            }
            int num  = x - tileData.Origin.X;
            int num2 = y - tileData.Origin.Y;

            if (num < 0 || num + tileData.Width >= Main.maxTilesX || num2 < 0 || num2 + tileData.Height >= Main.maxTilesY)
            {
                return(false);
            }
            bool flag = tileData.RandomStyleRange > 0;

            if (TileObjectPreviewData.placementCache == null)
            {
                TileObjectPreviewData.placementCache = new TileObjectPreviewData();
            }
            TileObjectPreviewData.placementCache.Reset();
            int num3 = 0;

            if (tileData.AlternatesCount != 0)
            {
                num3 = tileData.AlternatesCount;
            }
            float          num4           = -1f;
            float          num5           = -1f;
            int            num6           = 0;
            TileObjectData tileObjectData = null;
            int            num7           = -1;

            while (num7 < num3)
            {
                num7++;
                TileObjectData tileData2 = TileObjectData.GetTileData(type, style, num7);
                if (tileData2.Direction != 0 && ((tileData2.Direction == TileObjectDirection.PlaceLeft && dir == 1) || (tileData2.Direction == TileObjectDirection.PlaceRight && dir == -1)))
                {
                    continue;
                }
                int num8 = x - tileData2.Origin.X;
                int num9 = y - tileData2.Origin.Y;
                if (num8 < 5 || num8 + tileData2.Width > Main.maxTilesX - 5 || num9 < 5 || num9 + tileData2.Height > Main.maxTilesY - 5)
                {
                    return(false);
                }
                Rectangle rectangle = new Rectangle(0, 0, tileData2.Width, tileData2.Height);
                int       num10     = 0;
                int       num11     = 0;
                if (tileData2.AnchorTop.tileCount != 0)
                {
                    if (rectangle.Y == 0)
                    {
                        rectangle.Y = -1;
                        rectangle.Height++;
                        num11++;
                    }
                    int checkStart = tileData2.AnchorTop.checkStart;
                    if (checkStart < rectangle.X)
                    {
                        rectangle.Width += rectangle.X - checkStart;
                        num10           += rectangle.X - checkStart;
                        rectangle.X      = checkStart;
                    }
                    int num12 = checkStart + tileData2.AnchorTop.tileCount - 1;
                    int num13 = rectangle.X + rectangle.Width - 1;
                    if (num12 > num13)
                    {
                        rectangle.Width += num12 - num13;
                    }
                }
                if (tileData2.AnchorBottom.tileCount != 0)
                {
                    if (rectangle.Y + rectangle.Height == tileData2.Height)
                    {
                        rectangle.Height++;
                    }
                    int checkStart2 = tileData2.AnchorBottom.checkStart;
                    if (checkStart2 < rectangle.X)
                    {
                        rectangle.Width += rectangle.X - checkStart2;
                        num10           += rectangle.X - checkStart2;
                        rectangle.X      = checkStart2;
                    }
                    int num14 = checkStart2 + tileData2.AnchorBottom.tileCount - 1;
                    int num15 = rectangle.X + rectangle.Width - 1;
                    if (num14 > num15)
                    {
                        rectangle.Width += num14 - num15;
                    }
                }
                if (tileData2.AnchorLeft.tileCount != 0)
                {
                    if (rectangle.X == 0)
                    {
                        rectangle.X = -1;
                        rectangle.Width++;
                        num10++;
                    }
                    int num16 = tileData2.AnchorLeft.checkStart;
                    if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                    {
                        num16--;
                    }
                    if (num16 < rectangle.Y)
                    {
                        rectangle.Width += rectangle.Y - num16;
                        num11           += rectangle.Y - num16;
                        rectangle.Y      = num16;
                    }
                    int num17 = num16 + tileData2.AnchorLeft.tileCount - 1;
                    if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                    {
                        num17 += 2;
                    }
                    int num18 = rectangle.Y + rectangle.Height - 1;
                    if (num17 > num18)
                    {
                        rectangle.Height += num17 - num18;
                    }
                }
                if (tileData2.AnchorRight.tileCount != 0)
                {
                    if (rectangle.X + rectangle.Width == tileData2.Width)
                    {
                        rectangle.Width++;
                    }
                    int num19 = tileData2.AnchorLeft.checkStart;
                    if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                    {
                        num19--;
                    }
                    if (num19 < rectangle.Y)
                    {
                        rectangle.Width += rectangle.Y - num19;
                        num11           += rectangle.Y - num19;
                        rectangle.Y      = num19;
                    }
                    int num20 = num19 + tileData2.AnchorRight.tileCount - 1;
                    if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                    {
                        num20 += 2;
                    }
                    int num21 = rectangle.Y + rectangle.Height - 1;
                    if (num20 > num21)
                    {
                        rectangle.Height += num20 - num21;
                    }
                }
                if (onlyCheck)
                {
                    objectPreview.Reset();
                    objectPreview.Active      = true;
                    objectPreview.Type        = (ushort)type;
                    objectPreview.Style       = (short)style;
                    objectPreview.Alternate   = num7;
                    objectPreview.Size        = new Point16(rectangle.Width, rectangle.Height);
                    objectPreview.ObjectStart = new Point16(num10, num11);
                    objectPreview.Coordinates = new Point16(num8 - num10, num9 - num11);
                }
                float num22 = 0f;
                float num23 = tileData2.Width * tileData2.Height;
                float num24 = 0f;
                float num25 = 0f;
                for (int i = 0; i < tileData2.Width; i++)
                {
                    for (int j = 0; j < tileData2.Height; j++)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num8 + i, num9 + j);
                        bool flag2      = !tileData2.LiquidPlace(tileSafely);
                        bool flag3      = false;
                        if (tileData2.AnchorWall)
                        {
                            num25 += 1f;
                            if (!tileData2.isValidWallAnchor(tileSafely.wall))
                            {
                                flag3 = true;
                            }
                            else
                            {
                                num24 += 1f;
                            }
                        }
                        bool flag4 = false;
                        if (tileSafely.active() && (!Main.tileCut[tileSafely.type] || tileSafely.type == 484) && !TileID.Sets.BreakableWhenPlacing[tileSafely.type])
                        {
                            flag4 = true;
                        }
                        if (flag4 | flag2 | flag3)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[i + num10, j + num11] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[i + num10, j + num11] = 1;
                        }
                        num22 += 1f;
                    }
                }
                AnchorData anchorBottom = tileData2.AnchorBottom;
                if (anchorBottom.tileCount != 0)
                {
                    num25 += (float)anchorBottom.tileCount;
                    int height = tileData2.Height;
                    for (int k = 0; k < anchorBottom.tileCount; k++)
                    {
                        int  num26      = anchorBottom.checkStart + k;
                        Tile tileSafely = Framing.GetTileSafely(num8 + num26, num9 + height);
                        bool flag5      = false;
                        if (tileSafely.nactive())
                        {
                            if ((anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                            {
                                flag5 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag5 && ((anchorBottom.type & AnchorType.SolidWithTop) == AnchorType.SolidWithTop || (anchorBottom.type & AnchorType.Table) == AnchorType.Table))
                            {
                                if (TileID.Sets.Platforms[tileSafely.type])
                                {
                                    _ = tileSafely.frameX / TileObjectData.PlatformFrameWidth();
                                    if (!tileSafely.halfBrick() && WorldGen.PlatformProperTopFrame(tileSafely.frameX))
                                    {
                                        flag5 = true;
                                    }
                                }
                                else if (Main.tileSolid[tileSafely.type] && Main.tileSolidTop[tileSafely.type])
                                {
                                    flag5 = true;
                                }
                            }
                            if (!flag5 && (anchorBottom.type & AnchorType.Table) == AnchorType.Table && !TileID.Sets.Platforms[tileSafely.type] && Main.tileTable[tileSafely.type] && tileSafely.blockType() == 0)
                            {
                                flag5 = true;
                            }
                            if (!flag5 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                            {
                                int num27 = tileSafely.blockType();
                                if ((uint)(num27 - 4) <= 1u)
                                {
                                    flag5 = tileData2.isValidTileAnchor(tileSafely.type);
                                }
                            }
                            if (!flag5 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
                            {
                                flag5 = true;
                            }
                        }
                        else if (!flag5 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                        {
                            flag5 = true;
                        }
                        if (!flag5)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[num26 + num10, height + num11] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[num26 + num10, height + num11] = 1;
                        }
                        num24 += 1f;
                    }
                }
                anchorBottom = tileData2.AnchorTop;
                if (anchorBottom.tileCount != 0)
                {
                    num25 += (float)anchorBottom.tileCount;
                    int num28 = -1;
                    for (int l = 0; l < anchorBottom.tileCount; l++)
                    {
                        int  num29      = anchorBottom.checkStart + l;
                        Tile tileSafely = Framing.GetTileSafely(num8 + num29, num9 + num28);
                        bool flag6      = false;
                        if (tileSafely.nactive())
                        {
                            if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                            {
                                flag6 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag6 && (anchorBottom.type & AnchorType.SolidBottom) == AnchorType.SolidBottom && ((Main.tileSolid[tileSafely.type] && (!Main.tileSolidTop[tileSafely.type] || (TileID.Sets.Platforms[tileSafely.type] && (tileSafely.halfBrick() || tileSafely.topSlope())))) || tileSafely.halfBrick() || tileSafely.topSlope()) && !TileID.Sets.NotReallySolid[tileSafely.type] && !tileSafely.bottomSlope())
                            {
                                flag6 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag6 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                            {
                                int num27 = tileSafely.blockType();
                                if ((uint)(num27 - 2) <= 1u)
                                {
                                    flag6 = tileData2.isValidTileAnchor(tileSafely.type);
                                }
                            }
                            if (!flag6 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
                            {
                                flag6 = true;
                            }
                        }
                        else if (!flag6 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                        {
                            flag6 = true;
                        }
                        if (!flag6)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[num29 + num10, num28 + num11] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[num29 + num10, num28 + num11] = 1;
                        }
                        num24 += 1f;
                    }
                }
                anchorBottom = tileData2.AnchorRight;
                if (anchorBottom.tileCount != 0)
                {
                    num25 += (float)anchorBottom.tileCount;
                    int width = tileData2.Width;
                    for (int m = 0; m < anchorBottom.tileCount; m++)
                    {
                        int  num30      = anchorBottom.checkStart + m;
                        Tile tileSafely = Framing.GetTileSafely(num8 + width, num9 + num30);
                        bool flag7      = false;
                        if (tileSafely.nactive())
                        {
                            if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                            {
                                flag7 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag7 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                            {
                                int num27 = tileSafely.blockType();
                                if (num27 == 2 || num27 == 4)
                                {
                                    flag7 = tileData2.isValidTileAnchor(tileSafely.type);
                                }
                            }
                            if (!flag7 && (anchorBottom.type & AnchorType.Tree) == AnchorType.Tree && TileID.Sets.IsATreeTrunk[tileSafely.type])
                            {
                                flag7 = true;
                                if (m == 0)
                                {
                                    num25 += 1f;
                                    Tile tileSafely2 = Framing.GetTileSafely(num8 + width, num9 + num30 - 1);
                                    if (tileSafely2.nactive() && TileID.Sets.IsATreeTrunk[tileSafely2.type])
                                    {
                                        num24 += 1f;
                                        if (onlyCheck)
                                        {
                                            objectPreview[width + num10, num30 + num11 - 1] = 1;
                                        }
                                    }
                                    else if (onlyCheck)
                                    {
                                        objectPreview[width + num10, num30 + num11 - 1] = 2;
                                    }
                                }
                                if (m == anchorBottom.tileCount - 1)
                                {
                                    num25 += 1f;
                                    Tile tileSafely3 = Framing.GetTileSafely(num8 + width, num9 + num30 + 1);
                                    if (tileSafely3.nactive() && TileID.Sets.IsATreeTrunk[tileSafely3.type])
                                    {
                                        num24 += 1f;
                                        if (onlyCheck)
                                        {
                                            objectPreview[width + num10, num30 + num11 + 1] = 1;
                                        }
                                    }
                                    else if (onlyCheck)
                                    {
                                        objectPreview[width + num10, num30 + num11 + 1] = 2;
                                    }
                                }
                            }
                            if (!flag7 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
                            {
                                flag7 = true;
                            }
                        }
                        else if (!flag7 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                        {
                            flag7 = true;
                        }
                        if (!flag7)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[width + num10, num30 + num11] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[width + num10, num30 + num11] = 1;
                        }
                        num24 += 1f;
                    }
                }
                anchorBottom = tileData2.AnchorLeft;
                if (anchorBottom.tileCount != 0)
                {
                    num25 += (float)anchorBottom.tileCount;
                    int num31 = -1;
                    for (int n = 0; n < anchorBottom.tileCount; n++)
                    {
                        int  num32      = anchorBottom.checkStart + n;
                        Tile tileSafely = Framing.GetTileSafely(num8 + num31, num9 + num32);
                        bool flag8      = false;
                        if (tileSafely.nactive())
                        {
                            if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                            {
                                flag8 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag8 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                            {
                                int num27 = tileSafely.blockType();
                                if (num27 == 3 || num27 == 5)
                                {
                                    flag8 = tileData2.isValidTileAnchor(tileSafely.type);
                                }
                            }
                            if (!flag8 && (anchorBottom.type & AnchorType.Tree) == AnchorType.Tree && TileID.Sets.IsATreeTrunk[tileSafely.type])
                            {
                                flag8 = true;
                                if (n == 0)
                                {
                                    num25 += 1f;
                                    Tile tileSafely4 = Framing.GetTileSafely(num8 + num31, num9 + num32 - 1);
                                    if (tileSafely4.nactive() && TileID.Sets.IsATreeTrunk[tileSafely4.type])
                                    {
                                        num24 += 1f;
                                        if (onlyCheck)
                                        {
                                            objectPreview[num31 + num10, num32 + num11 - 1] = 1;
                                        }
                                    }
                                    else if (onlyCheck)
                                    {
                                        objectPreview[num31 + num10, num32 + num11 - 1] = 2;
                                    }
                                }
                                if (n == anchorBottom.tileCount - 1)
                                {
                                    num25 += 1f;
                                    Tile tileSafely5 = Framing.GetTileSafely(num8 + num31, num9 + num32 + 1);
                                    if (tileSafely5.nactive() && TileID.Sets.IsATreeTrunk[tileSafely5.type])
                                    {
                                        num24 += 1f;
                                        if (onlyCheck)
                                        {
                                            objectPreview[num31 + num10, num32 + num11 + 1] = 1;
                                        }
                                    }
                                    else if (onlyCheck)
                                    {
                                        objectPreview[num31 + num10, num32 + num11 + 1] = 2;
                                    }
                                }
                            }
                            if (!flag8 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
                            {
                                flag8 = true;
                            }
                        }
                        else if (!flag8 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                        {
                            flag8 = true;
                        }
                        if (!flag8)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[num31 + num10, num32 + num11] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[num31 + num10, num32 + num11] = 1;
                        }
                        num24 += 1f;
                    }
                }
                if (tileData2.HookCheckIfCanPlace.hook != null)
                {
                    if (tileData2.HookCheckIfCanPlace.processedCoordinates)
                    {
                        _ = tileData2.Origin;
                        _ = tileData2.Origin;
                    }
                    if (tileData2.HookCheckIfCanPlace.hook(x, y, type, style, dir, num7) == tileData2.HookCheckIfCanPlace.badReturn && tileData2.HookCheckIfCanPlace.badResponse == 0)
                    {
                        num24 = 0f;
                        num22 = 0f;
                        objectPreview.AllInvalid();
                    }
                }
                float num33 = num24 / num25;
                float num34 = num22 / num23;
                if (num34 == 1f && num25 == 0f)
                {
                    num23 = 1f;
                    num25 = 1f;
                    num33 = 1f;
                    num34 = 1f;
                }
                if (num33 == 1f && num34 == 1f)
                {
                    num4           = 1f;
                    num5           = 1f;
                    num6           = num7;
                    tileObjectData = tileData2;
                    break;
                }
                if (num33 > num4 || (num33 == num4 && num34 > num5))
                {
                    TileObjectPreviewData.placementCache.CopyFrom(objectPreview);
                    num4           = num33;
                    num5           = num34;
                    tileObjectData = tileData2;
                    num6           = num7;
                }
            }
            int num35 = -1;

            if (flag)
            {
                if (TileObjectPreviewData.randomCache == null)
                {
                    TileObjectPreviewData.randomCache = new TileObjectPreviewData();
                }
                bool flag9 = false;
                if (TileObjectPreviewData.randomCache.Type == type)
                {
                    Point16 coordinates = TileObjectPreviewData.randomCache.Coordinates;
                    Point16 objectStart = TileObjectPreviewData.randomCache.ObjectStart;
                    int     num36       = coordinates.X + objectStart.X;
                    int     num37       = coordinates.Y + objectStart.Y;
                    int     num38       = x - tileData.Origin.X;
                    int     num39       = y - tileData.Origin.Y;
                    if (num36 != num38 || num37 != num39)
                    {
                        flag9 = true;
                    }
                }
                else
                {
                    flag9 = true;
                }
                num35 = ((!flag9) ? TileObjectPreviewData.randomCache.Random : Main.rand.Next(tileData.RandomStyleRange));
            }
            if (onlyCheck)
            {
                if (num4 != 1f || num5 != 1f)
                {
                    objectPreview.CopyFrom(TileObjectPreviewData.placementCache);
                    num7 = num6;
                }
                objectPreview.Random = num35;
                if (tileData.RandomStyleRange > 0)
                {
                    TileObjectPreviewData.randomCache.CopyFrom(objectPreview);
                }
            }
            if (!onlyCheck)
            {
                objectData.xCoord    = x - tileObjectData.Origin.X;
                objectData.yCoord    = y - tileObjectData.Origin.Y;
                objectData.type      = type;
                objectData.style     = style;
                objectData.alternate = num7;
                objectData.random    = num35;
            }
            if (num4 == 1f)
            {
                return(num5 == 1f);
            }
            return(false);
        }
Beispiel #7
0
        public static bool CanPlace(
            int x,
            int y,
            int type,
            int style,
            int dir,
            out TileObject objectData,
            bool onlyCheck = false)
        {
            TileObjectData tileData1 = TileObjectData.GetTileData(type, style, 0);

            objectData = TileObject.Empty;
            if (tileData1 == null)
            {
                return(false);
            }
            int num1 = x - (int)tileData1.Origin.X;
            int num2 = y - (int)tileData1.Origin.Y;

            if (num1 < 0 || num1 + tileData1.Width >= Main.maxTilesX || (num2 < 0 || num2 + tileData1.Height >= Main.maxTilesY))
            {
                return(false);
            }
            bool flag1 = tileData1.RandomStyleRange > 0;

            if (TileObjectPreviewData.placementCache == null)
            {
                TileObjectPreviewData.placementCache = new TileObjectPreviewData();
            }
            TileObjectPreviewData.placementCache.Reset();
            int num3 = 0;

            if (tileData1.AlternatesCount != 0)
            {
                num3 = tileData1.AlternatesCount;
            }
            float          num4           = -1f;
            float          num5           = -1f;
            int            num6           = 0;
            TileObjectData tileObjectData = (TileObjectData)null;
            int            alternate      = 0 - 1;

            while (alternate < num3)
            {
                ++alternate;
                TileObjectData tileData2 = TileObjectData.GetTileData(type, style, alternate);
                if (tileData2.Direction == TileObjectDirection.None || (tileData2.Direction != TileObjectDirection.PlaceLeft || dir != 1) && (tileData2.Direction != TileObjectDirection.PlaceRight || dir != -1))
                {
                    int num7 = x - (int)tileData2.Origin.X;
                    int num8 = y - (int)tileData2.Origin.Y;
                    if (num7 < 5 || num7 + tileData2.Width > Main.maxTilesX - 5 || (num8 < 5 || num8 + tileData2.Height > Main.maxTilesY - 5))
                    {
                        return(false);
                    }
                    Rectangle rectangle = new Rectangle(0, 0, tileData2.Width, tileData2.Height);
                    int       X         = 0;
                    int       Y         = 0;
                    if (tileData2.AnchorTop.tileCount != 0)
                    {
                        if (rectangle.Y == 0)
                        {
                            rectangle.Y = -1;
                            ++rectangle.Height;
                            ++Y;
                        }
                        int checkStart = tileData2.AnchorTop.checkStart;
                        if (checkStart < rectangle.X)
                        {
                            rectangle.Width += rectangle.X - checkStart;
                            X          += rectangle.X - checkStart;
                            rectangle.X = checkStart;
                        }
                        int num9  = checkStart + tileData2.AnchorTop.tileCount - 1;
                        int num10 = rectangle.X + rectangle.Width - 1;
                        if (num9 > num10)
                        {
                            rectangle.Width += num9 - num10;
                        }
                    }
                    if (tileData2.AnchorBottom.tileCount != 0)
                    {
                        if (rectangle.Y + rectangle.Height == tileData2.Height)
                        {
                            ++rectangle.Height;
                        }
                        int checkStart = tileData2.AnchorBottom.checkStart;
                        if (checkStart < rectangle.X)
                        {
                            rectangle.Width += rectangle.X - checkStart;
                            X          += rectangle.X - checkStart;
                            rectangle.X = checkStart;
                        }
                        int num9  = checkStart + tileData2.AnchorBottom.tileCount - 1;
                        int num10 = rectangle.X + rectangle.Width - 1;
                        if (num9 > num10)
                        {
                            rectangle.Width += num9 - num10;
                        }
                    }
                    if (tileData2.AnchorLeft.tileCount != 0)
                    {
                        if (rectangle.X == 0)
                        {
                            rectangle.X = -1;
                            ++rectangle.Width;
                            ++X;
                        }
                        int checkStart = tileData2.AnchorLeft.checkStart;
                        if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            --checkStart;
                        }
                        if (checkStart < rectangle.Y)
                        {
                            rectangle.Width += rectangle.Y - checkStart;
                            Y          += rectangle.Y - checkStart;
                            rectangle.Y = checkStart;
                        }
                        int num9 = checkStart + tileData2.AnchorLeft.tileCount - 1;
                        if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            num9 += 2;
                        }
                        int num10 = rectangle.Y + rectangle.Height - 1;
                        if (num9 > num10)
                        {
                            rectangle.Height += num9 - num10;
                        }
                    }
                    if (tileData2.AnchorRight.tileCount != 0)
                    {
                        if (rectangle.X + rectangle.Width == tileData2.Width)
                        {
                            ++rectangle.Width;
                        }
                        int checkStart = tileData2.AnchorLeft.checkStart;
                        if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            --checkStart;
                        }
                        if (checkStart < rectangle.Y)
                        {
                            rectangle.Width += rectangle.Y - checkStart;
                            Y          += rectangle.Y - checkStart;
                            rectangle.Y = checkStart;
                        }
                        int num9 = checkStart + tileData2.AnchorRight.tileCount - 1;
                        if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            num9 += 2;
                        }
                        int num10 = rectangle.Y + rectangle.Height - 1;
                        if (num9 > num10)
                        {
                            rectangle.Height += num9 - num10;
                        }
                    }
                    if (onlyCheck)
                    {
                        TileObject.objectPreview.Reset();
                        TileObject.objectPreview.Active      = true;
                        TileObject.objectPreview.Type        = (ushort)type;
                        TileObject.objectPreview.Style       = (short)style;
                        TileObject.objectPreview.Alternate   = alternate;
                        TileObject.objectPreview.Size        = new Point16(rectangle.Width, rectangle.Height);
                        TileObject.objectPreview.ObjectStart = new Point16(X, Y);
                        TileObject.objectPreview.Coordinates = new Point16(num7 - X, num8 - Y);
                    }
                    float num11 = 0.0f;
                    float num12 = (float)(tileData2.Width * tileData2.Height);
                    float num13 = 0.0f;
                    float num14 = 0.0f;
                    for (int index1 = 0; index1 < tileData2.Width; ++index1)
                    {
                        for (int index2 = 0; index2 < tileData2.Height; ++index2)
                        {
                            Tile tileSafely = Framing.GetTileSafely(num7 + index1, num8 + index2);
                            bool flag2      = !tileData2.LiquidPlace(tileSafely);
                            bool flag3      = false;
                            if (tileData2.AnchorWall)
                            {
                                ++num14;
                                if (!tileData2.isValidWallAnchor((int)tileSafely.wall))
                                {
                                    flag3 = true;
                                }
                                else
                                {
                                    ++num13;
                                }
                            }
                            bool flag4 = false;
                            if (tileSafely.active() && (!Main.tileCut[(int)tileSafely.type] || tileSafely.type == (ushort)484) && !TileID.Sets.BreakableWhenPlacing[(int)tileSafely.type])
                            {
                                flag4 = true;
                            }
                            if (flag4 | flag2 | flag3)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[index1 + X, index2 + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[index1 + X, index2 + Y] = 1;
                                }
                                ++num11;
                            }
                        }
                    }
                    AnchorData anchorBottom = tileData2.AnchorBottom;
                    if (anchorBottom.tileCount != 0)
                    {
                        num14 += (float)anchorBottom.tileCount;
                        int height = tileData2.Height;
                        for (int index = 0; index < anchorBottom.tileCount; ++index)
                        {
                            int  num9       = anchorBottom.checkStart + index;
                            Tile tileSafely = Framing.GetTileSafely(num7 + num9, num8 + height);
                            bool flag2      = false;
                            if (tileSafely.nactive())
                            {
                                if ((anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile && Main.tileSolid[(int)tileSafely.type] && (!Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type]) && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag2 && ((anchorBottom.type & AnchorType.SolidWithTop) == AnchorType.SolidWithTop || (anchorBottom.type & AnchorType.Table) == AnchorType.Table))
                                {
                                    if (TileID.Sets.Platforms[(int)tileSafely.type])
                                    {
                                        int num10 = (int)tileSafely.frameX / TileObjectData.PlatformFrameWidth();
                                        if (!tileSafely.halfBrick() && WorldGen.PlatformProperTopFrame(tileSafely.frameX))
                                        {
                                            flag2 = true;
                                        }
                                    }
                                    else if (Main.tileSolid[(int)tileSafely.type] && Main.tileSolidTop[(int)tileSafely.type])
                                    {
                                        flag2 = true;
                                    }
                                }
                                if (!flag2 && (anchorBottom.type & AnchorType.Table) == AnchorType.Table && (!TileID.Sets.Platforms[(int)tileSafely.type] && Main.tileTable[(int)tileSafely.type]) && tileSafely.blockType() == 0)
                                {
                                    flag2 = true;
                                }
                                if (!flag2 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type]))
                                {
                                    switch (tileSafely.blockType())
                                    {
                                    case 4:
                                    case 5:
                                        flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                        break;
                                    }
                                }
                                if (!flag2 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
                                {
                                    flag2 = true;
                                }
                            }
                            else if (!flag2 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag2 = true;
                            }
                            if (!flag2)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num9 + X, height + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num9 + X, height + Y] = 1;
                                }
                                ++num13;
                            }
                        }
                    }
                    AnchorData anchorTop = tileData2.AnchorTop;
                    if (anchorTop.tileCount != 0)
                    {
                        num14 += (float)anchorTop.tileCount;
                        int num9 = -1;
                        for (int index = 0; index < anchorTop.tileCount; ++index)
                        {
                            int  num10      = anchorTop.checkStart + index;
                            Tile tileSafely = Framing.GetTileSafely(num7 + num10, num8 + num9);
                            bool flag2      = false;
                            if (tileSafely.nactive())
                            {
                                if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag2 && (anchorTop.type & AnchorType.SolidBottom) == AnchorType.SolidBottom && (Main.tileSolid[(int)tileSafely.type] && (!Main.tileSolidTop[(int)tileSafely.type] || TileID.Sets.Platforms[(int)tileSafely.type] && (tileSafely.halfBrick() || tileSafely.topSlope())) || (tileSafely.halfBrick() || tileSafely.topSlope())) && (!TileID.Sets.NotReallySolid[(int)tileSafely.type] && !tileSafely.bottomSlope()))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag2 && (anchorTop.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type]))
                                {
                                    switch (tileSafely.blockType())
                                    {
                                    case 2:
                                    case 3:
                                        flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                        break;
                                    }
                                }
                                if (!flag2 && (anchorTop.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
                                {
                                    flag2 = true;
                                }
                            }
                            else if (!flag2 && (anchorTop.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag2 = true;
                            }
                            if (!flag2)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num10 + X, num9 + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num10 + X, num9 + Y] = 1;
                                }
                                ++num13;
                            }
                        }
                    }
                    AnchorData anchorRight = tileData2.AnchorRight;
                    if (anchorRight.tileCount != 0)
                    {
                        num14 += (float)anchorRight.tileCount;
                        int width = tileData2.Width;
                        for (int index = 0; index < anchorRight.tileCount; ++index)
                        {
                            int  num9        = anchorRight.checkStart + index;
                            Tile tileSafely1 = Framing.GetTileSafely(num7 + width, num8 + num9);
                            bool flag2       = false;
                            if (tileSafely1.nactive())
                            {
                                if (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type] && !Main.tileNoAttach[(int)tileSafely1.type] && (tileData2.FlattenAnchors || tileSafely1.blockType() == 0))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                                }
                                if (!flag2 && (anchorRight.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type]))
                                {
                                    switch (tileSafely1.blockType())
                                    {
                                    case 2:
                                    case 4:
                                        flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                                        break;
                                    }
                                }
                                if (!flag2 && (anchorRight.type & AnchorType.Tree) == AnchorType.Tree && TileID.Sets.IsATreeTrunk[(int)tileSafely1.type])
                                {
                                    flag2 = true;
                                    if (index == 0)
                                    {
                                        ++num14;
                                        Tile tileSafely2 = Framing.GetTileSafely(num7 + width, num8 + num9 - 1);
                                        if (tileSafely2.nactive() && TileID.Sets.IsATreeTrunk[(int)tileSafely2.type])
                                        {
                                            ++num13;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[width + X, num9 + Y - 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[width + X, num9 + Y - 1] = 2;
                                        }
                                    }
                                    if (index == anchorRight.tileCount - 1)
                                    {
                                        ++num14;
                                        Tile tileSafely2 = Framing.GetTileSafely(num7 + width, num8 + num9 + 1);
                                        if (tileSafely2.nactive() && TileID.Sets.IsATreeTrunk[(int)tileSafely2.type])
                                        {
                                            ++num13;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[width + X, num9 + Y + 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[width + X, num9 + Y + 1] = 2;
                                        }
                                    }
                                }
                                if (!flag2 && (anchorRight.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely1.type))
                                {
                                    flag2 = true;
                                }
                            }
                            else if (!flag2 && (anchorRight.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag2 = true;
                            }
                            if (!flag2)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[width + X, num9 + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[width + X, num9 + Y] = 1;
                                }
                                ++num13;
                            }
                        }
                    }
                    AnchorData anchorLeft = tileData2.AnchorLeft;
                    if (anchorLeft.tileCount != 0)
                    {
                        num14 += (float)anchorLeft.tileCount;
                        int num9 = -1;
                        for (int index = 0; index < anchorLeft.tileCount; ++index)
                        {
                            int  num10       = anchorLeft.checkStart + index;
                            Tile tileSafely1 = Framing.GetTileSafely(num7 + num9, num8 + num10);
                            bool flag2       = false;
                            if (tileSafely1.nactive())
                            {
                                if (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type] && !Main.tileNoAttach[(int)tileSafely1.type] && (tileData2.FlattenAnchors || tileSafely1.blockType() == 0))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                                }
                                if (!flag2 && (anchorLeft.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type]))
                                {
                                    switch (tileSafely1.blockType())
                                    {
                                    case 3:
                                    case 5:
                                        flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                                        break;
                                    }
                                }
                                if (!flag2 && (anchorLeft.type & AnchorType.Tree) == AnchorType.Tree && TileID.Sets.IsATreeTrunk[(int)tileSafely1.type])
                                {
                                    flag2 = true;
                                    if (index == 0)
                                    {
                                        ++num14;
                                        Tile tileSafely2 = Framing.GetTileSafely(num7 + num9, num8 + num10 - 1);
                                        if (tileSafely2.nactive() && TileID.Sets.IsATreeTrunk[(int)tileSafely2.type])
                                        {
                                            ++num13;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[num9 + X, num10 + Y - 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[num9 + X, num10 + Y - 1] = 2;
                                        }
                                    }
                                    if (index == anchorLeft.tileCount - 1)
                                    {
                                        ++num14;
                                        Tile tileSafely2 = Framing.GetTileSafely(num7 + num9, num8 + num10 + 1);
                                        if (tileSafely2.nactive() && TileID.Sets.IsATreeTrunk[(int)tileSafely2.type])
                                        {
                                            ++num13;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[num9 + X, num10 + Y + 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[num9 + X, num10 + Y + 1] = 2;
                                        }
                                    }
                                }
                                if (!flag2 && (anchorLeft.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely1.type))
                                {
                                    flag2 = true;
                                }
                            }
                            else if (!flag2 && (anchorLeft.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag2 = true;
                            }
                            if (!flag2)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num9 + X, num10 + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num9 + X, num10 + Y] = 1;
                                }
                                ++num13;
                            }
                        }
                    }
                    if (tileData2.HookCheckIfCanPlace.hook != null)
                    {
                        if (tileData2.HookCheckIfCanPlace.processedCoordinates)
                        {
                            Point16 origin1 = tileData2.Origin;
                            Point16 origin2 = tileData2.Origin;
                        }
                        if (tileData2.HookCheckIfCanPlace.hook(x, y, type, style, dir, alternate) == tileData2.HookCheckIfCanPlace.badReturn && tileData2.HookCheckIfCanPlace.badResponse == 0)
                        {
                            num13 = 0.0f;
                            num11 = 0.0f;
                            TileObject.objectPreview.AllInvalid();
                        }
                    }
                    float num15 = num13 / num14;
                    float num16 = num11 / num12;
                    if ((double)num16 == 1.0 && (double)num14 == 0.0)
                    {
                        num15 = 1f;
                        num16 = 1f;
                    }
                    if ((double)num15 == 1.0 && (double)num16 == 1.0)
                    {
                        num4           = 1f;
                        num5           = 1f;
                        num6           = alternate;
                        tileObjectData = tileData2;
                        break;
                    }
                    if ((double)num15 > (double)num4 || (double)num15 == (double)num4 && (double)num16 > (double)num5)
                    {
                        TileObjectPreviewData.placementCache.CopyFrom(TileObject.objectPreview);
                        num4           = num15;
                        num5           = num16;
                        tileObjectData = tileData2;
                        num6           = alternate;
                    }
                }
            }
            int num17 = -1;

            if (flag1)
            {
                if (TileObjectPreviewData.randomCache == null)
                {
                    TileObjectPreviewData.randomCache = new TileObjectPreviewData();
                }
                bool flag2 = false;
                if ((int)TileObjectPreviewData.randomCache.Type == type)
                {
                    Point16 coordinates = TileObjectPreviewData.randomCache.Coordinates;
                    Point16 objectStart = TileObjectPreviewData.randomCache.ObjectStart;
                    int     num7        = (int)coordinates.X + (int)objectStart.X;
                    int     num8        = (int)coordinates.Y + (int)objectStart.Y;
                    int     num9        = x - (int)tileData1.Origin.X;
                    int     num10       = y - (int)tileData1.Origin.Y;
                    if (num7 != num9 || num8 != num10)
                    {
                        flag2 = true;
                    }
                }
                else
                {
                    flag2 = true;
                }
                num17 = !flag2 ? TileObjectPreviewData.randomCache.Random : Main.rand.Next(tileData1.RandomStyleRange);
            }
            if (onlyCheck)
            {
                if ((double)num4 != 1.0 || (double)num5 != 1.0)
                {
                    TileObject.objectPreview.CopyFrom(TileObjectPreviewData.placementCache);
                    alternate = num6;
                }
                TileObject.objectPreview.Random = num17;
                if (tileData1.RandomStyleRange > 0)
                {
                    TileObjectPreviewData.randomCache.CopyFrom(TileObject.objectPreview);
                }
            }
            if (!onlyCheck)
            {
                objectData.xCoord    = x - (int)tileObjectData.Origin.X;
                objectData.yCoord    = y - (int)tileObjectData.Origin.Y;
                objectData.type      = type;
                objectData.style     = style;
                objectData.alternate = alternate;
                objectData.random    = num17;
            }
            return((double)num4 == 1.0 && (double)num5 == 1.0);
        }
Beispiel #8
0
 public static bool Place(TileObject toBePlaced)
 {
     TileObjectData tileData = TileObjectData.GetTileData(toBePlaced.type, toBePlaced.style, toBePlaced.alternate);
     if (tileData == null)
         return false;
     if (tileData.HookPlaceOverride.hook != null)
     {
         int num1;
         int num2;
         if (tileData.HookPlaceOverride.processedCoordinates)
         {
             num1 = toBePlaced.xCoord;
             num2 = toBePlaced.yCoord;
         }
         else
         {
             num1 = toBePlaced.xCoord + (int)tileData.Origin.X;
             num2 = toBePlaced.yCoord + (int)tileData.Origin.Y;
         }
         if (tileData.HookPlaceOverride.hook(num1, num2, toBePlaced.type, toBePlaced.style, 1) == tileData.HookPlaceOverride.badReturn)
             return false;
     }
     else
     {
         ushort num1 = (ushort)toBePlaced.type;
         int num2 = tileData.CalculatePlacementStyle(toBePlaced.style, toBePlaced.alternate, toBePlaced.random);
         int num3 = 0;
         if (tileData.StyleWrapLimit > 0)
         {
             num3 = num2 / tileData.StyleWrapLimit;
             num2 %= tileData.StyleWrapLimit;
         }
         int num4;
         int num5;
         if (tileData.StyleHorizontal)
         {
             num4 = tileData.CoordinateFullWidth * num2;
             num5 = tileData.CoordinateFullHeight * num3;
         }
         else
         {
             num4 = tileData.CoordinateFullWidth * num3;
             num5 = tileData.CoordinateFullHeight * num2;
         }
         int num6 = toBePlaced.xCoord;
         int num7 = toBePlaced.yCoord;
         for (int index1 = 0; index1 < tileData.Width; ++index1)
         {
             for (int index2 = 0; index2 < tileData.Height; ++index2)
             {
                 Tile tileSafely = Framing.GetTileSafely(num6 + index1, num7 + index2);
                 if (tileSafely.active() && Main.tileCut[(int)tileSafely.type])
                     WorldGen.KillTile(num6 + index1, num7 + index2, false, false, false);
             }
         }
         for (int index1 = 0; index1 < tileData.Width; ++index1)
         {
             int num8 = num4 + index1 * (tileData.CoordinateWidth + tileData.CoordinatePadding);
             int num9 = num5;
             for (int index2 = 0; index2 < tileData.Height; ++index2)
             {
                 Tile tileSafely = Framing.GetTileSafely(num6 + index1, num7 + index2);
                 if (!tileSafely.active())
                 {
                     tileSafely.active(true);
                     tileSafely.frameX = (short)num8;
                     tileSafely.frameY = (short)num9;
                     tileSafely.type = num1;
                 }
                 num9 += tileData.CoordinateHeights[index2] + tileData.CoordinatePadding;
             }
         }
     }
     if (tileData.FlattenAnchors)
     {
         AnchorData anchorData = tileData.AnchorBottom;
         if (anchorData.tileCount != 0 && (anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile)
         {
             int num = toBePlaced.xCoord + anchorData.checkStart;
             int j = toBePlaced.yCoord + tileData.Height;
             for (int index = 0; index < anchorData.tileCount; ++index)
             {
                 Tile tileSafely = Framing.GetTileSafely(num + index, j);
                 if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                     WorldGen.SlopeTile(num + index, j, 0);
             }
         }
         anchorData = tileData.AnchorTop;
         if (anchorData.tileCount != 0 && (anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile)
         {
             int num = toBePlaced.xCoord + anchorData.checkStart;
             int j = toBePlaced.yCoord - 1;
             for (int index = 0; index < anchorData.tileCount; ++index)
             {
                 Tile tileSafely = Framing.GetTileSafely(num + index, j);
                 if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                     WorldGen.SlopeTile(num + index, j, 0);
             }
         }
         anchorData = tileData.AnchorRight;
         if (anchorData.tileCount != 0 && (anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile)
         {
             int i = toBePlaced.xCoord + tileData.Width;
             int num = toBePlaced.yCoord + anchorData.checkStart;
             for (int index = 0; index < anchorData.tileCount; ++index)
             {
                 Tile tileSafely = Framing.GetTileSafely(i, num + index);
                 if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                     WorldGen.SlopeTile(i, num + index, 0);
             }
         }
         anchorData = tileData.AnchorLeft;
         if (anchorData.tileCount != 0 && (anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile)
         {
             int i = toBePlaced.xCoord - 1;
             int num = toBePlaced.yCoord + anchorData.checkStart;
             for (int index = 0; index < anchorData.tileCount; ++index)
             {
                 Tile tileSafely = Framing.GetTileSafely(i, num + index);
                 if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                     WorldGen.SlopeTile(i, num + index, 0);
             }
         }
     }
     return true;
 }
Beispiel #9
0
        // Token: 0x060001A6 RID: 422 RVA: 0x0002ECC8 File Offset: 0x0002CEC8
        public static bool CanPlace(int x, int y, int type, int style, int dir, out TileObject objectData, bool onlyCheck = false)
        {
            TileObjectData tileData = TileObjectData.GetTileData(type, style, 0);

            objectData = TileObject.Empty;
            if (tileData == null)
            {
                return(false);
            }
            int num  = x - (int)tileData.Origin.X;
            int num2 = y - (int)tileData.Origin.Y;

            if (num < 0 || num + tileData.Width >= Main.maxTilesX || num2 < 0 || num2 + tileData.Height >= Main.maxTilesY)
            {
                return(false);
            }
            bool flag = tileData.RandomStyleRange > 0;

            if (TileObjectPreviewData.placementCache == null)
            {
                TileObjectPreviewData.placementCache = new TileObjectPreviewData();
            }
            TileObjectPreviewData.placementCache.Reset();
            int arg_AF_0 = 0;
            int num3     = 0;

            if (tileData.AlternatesCount != 0)
            {
                num3 = tileData.AlternatesCount;
            }
            float          num4           = -1f;
            float          num5           = -1f;
            int            num6           = 0;
            TileObjectData tileObjectData = null;
            int            i = arg_AF_0 - 1;

            while (i < num3)
            {
                i++;
                TileObjectData tileData2 = TileObjectData.GetTileData(type, style, i);
                if (tileData2.Direction == TileObjectDirection.None || ((tileData2.Direction != TileObjectDirection.PlaceLeft || dir != 1) && (tileData2.Direction != TileObjectDirection.PlaceRight || dir != -1)))
                {
                    int num7 = x - (int)tileData2.Origin.X;
                    int num8 = y - (int)tileData2.Origin.Y;
                    if (num7 < 5 || num7 + tileData2.Width > Main.maxTilesX - 5 || num8 < 5 || num8 + tileData2.Height > Main.maxTilesY - 5)
                    {
                        return(false);
                    }
                    Rectangle rectangle = new Rectangle(0, 0, tileData2.Width, tileData2.Height);
                    int       num9      = 0;
                    int       num10     = 0;
                    if (tileData2.AnchorTop.tileCount != 0)
                    {
                        if (rectangle.Y == 0)
                        {
                            rectangle.Y = -1;
                            rectangle.Height++;
                            num10++;
                        }
                        int checkStart = tileData2.AnchorTop.checkStart;
                        if (checkStart < rectangle.X)
                        {
                            rectangle.Width += rectangle.X - checkStart;
                            num9            += rectangle.X - checkStart;
                            rectangle.X      = checkStart;
                        }
                        int num11 = checkStart + tileData2.AnchorTop.tileCount - 1;
                        int num12 = rectangle.X + rectangle.Width - 1;
                        if (num11 > num12)
                        {
                            rectangle.Width += num11 - num12;
                        }
                    }
                    if (tileData2.AnchorBottom.tileCount != 0)
                    {
                        if (rectangle.Y + rectangle.Height == tileData2.Height)
                        {
                            rectangle.Height++;
                        }
                        int checkStart2 = tileData2.AnchorBottom.checkStart;
                        if (checkStart2 < rectangle.X)
                        {
                            rectangle.Width += rectangle.X - checkStart2;
                            num9            += rectangle.X - checkStart2;
                            rectangle.X      = checkStart2;
                        }
                        int num13 = checkStart2 + tileData2.AnchorBottom.tileCount - 1;
                        int num14 = rectangle.X + rectangle.Width - 1;
                        if (num13 > num14)
                        {
                            rectangle.Width += num13 - num14;
                        }
                    }
                    if (tileData2.AnchorLeft.tileCount != 0)
                    {
                        if (rectangle.X == 0)
                        {
                            rectangle.X = -1;
                            rectangle.Width++;
                            num9++;
                        }
                        int num15 = tileData2.AnchorLeft.checkStart;
                        if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            num15--;
                        }
                        if (num15 < rectangle.Y)
                        {
                            rectangle.Width += rectangle.Y - num15;
                            num10           += rectangle.Y - num15;
                            rectangle.Y      = num15;
                        }
                        int num16 = num15 + tileData2.AnchorLeft.tileCount - 1;
                        if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            num16 += 2;
                        }
                        int num17 = rectangle.Y + rectangle.Height - 1;
                        if (num16 > num17)
                        {
                            rectangle.Height += num16 - num17;
                        }
                    }
                    if (tileData2.AnchorRight.tileCount != 0)
                    {
                        if (rectangle.X + rectangle.Width == tileData2.Width)
                        {
                            rectangle.Width++;
                        }
                        int num18 = tileData2.AnchorLeft.checkStart;
                        if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            num18--;
                        }
                        if (num18 < rectangle.Y)
                        {
                            rectangle.Width += rectangle.Y - num18;
                            num10           += rectangle.Y - num18;
                            rectangle.Y      = num18;
                        }
                        int num19 = num18 + tileData2.AnchorRight.tileCount - 1;
                        if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            num19 += 2;
                        }
                        int num20 = rectangle.Y + rectangle.Height - 1;
                        if (num19 > num20)
                        {
                            rectangle.Height += num19 - num20;
                        }
                    }
                    if (onlyCheck)
                    {
                        TileObject.objectPreview.Reset();
                        TileObject.objectPreview.Active      = true;
                        TileObject.objectPreview.Type        = (ushort)type;
                        TileObject.objectPreview.Style       = (short)style;
                        TileObject.objectPreview.Alternate   = i;
                        TileObject.objectPreview.Size        = new Point16(rectangle.Width, rectangle.Height);
                        TileObject.objectPreview.ObjectStart = new Point16(num9, num10);
                        TileObject.objectPreview.Coordinates = new Point16(num7 - num9, num8 - num10);
                    }
                    float num21 = 0f;
                    float num22 = (float)(tileData2.Width * tileData2.Height);
                    float num23 = 0f;
                    float num24 = 0f;
                    for (int j = 0; j < tileData2.Width; j++)
                    {
                        for (int k = 0; k < tileData2.Height; k++)
                        {
                            Tile tileSafely = Framing.GetTileSafely(num7 + j, num8 + k);
                            bool flag2      = !tileData2.LiquidPlace(tileSafely);
                            bool flag3      = false;
                            if (tileData2.AnchorWall)
                            {
                                num24 += 1f;
                                if (!tileData2.isValidWallAnchor((int)tileSafely.wall))
                                {
                                    flag3 = true;
                                }
                                else
                                {
                                    num23 += 1f;
                                }
                            }
                            bool flag4 = false;
                            if (tileSafely.active() && !Main.tileCut[(int)tileSafely.type])
                            {
                                flag4 = true;
                            }
                            if (flag4 | flag2 | flag3)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[j + num9, k + num10] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[j + num9, k + num10] = 1;
                                }
                                num21 += 1f;
                            }
                        }
                    }
                    AnchorData anchorData = tileData2.AnchorBottom;
                    if (anchorData.tileCount != 0)
                    {
                        num24 += (float)anchorData.tileCount;
                        int height = tileData2.Height;
                        for (int l = 0; l < anchorData.tileCount; l++)
                        {
                            int  num25      = anchorData.checkStart + l;
                            Tile tileSafely = Framing.GetTileSafely(num7 + num25, num8 + height);
                            bool flag5      = false;
                            if (tileSafely.nactive())
                            {
                                if ((anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile && Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                                {
                                    flag5 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag5 && ((anchorData.type & AnchorType.SolidWithTop) == AnchorType.SolidWithTop || (anchorData.type & AnchorType.Table) == AnchorType.Table))
                                {
                                    if (TileID.Sets.Platforms[(int)tileSafely.type])
                                    {
                                        int num26 = (int)tileSafely.frameX / TileObjectData.PlatformFrameWidth();
                                        if ((!tileSafely.halfBrick() && num26 >= 0 && num26 <= 7) || (num26 >= 12 && num26 <= 16) || (num26 >= 25 && num26 <= 26))
                                        {
                                            flag5 = true;
                                        }
                                    }
                                    else if (Main.tileSolid[(int)tileSafely.type] && Main.tileSolidTop[(int)tileSafely.type])
                                    {
                                        flag5 = true;
                                    }
                                }
                                if (!flag5 && (anchorData.type & AnchorType.Table) == AnchorType.Table && !TileID.Sets.Platforms[(int)tileSafely.type] && Main.tileTable[(int)tileSafely.type] && tileSafely.blockType() == 0)
                                {
                                    flag5 = true;
                                }
                                if (!flag5 && (anchorData.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type])
                                {
                                    int num27 = tileSafely.blockType();
                                    if (num27 - 4 <= 1)
                                    {
                                        flag5 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                    }
                                }
                                if (!flag5 && (anchorData.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
                                {
                                    flag5 = true;
                                }
                            }
                            else if (!flag5 && (anchorData.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag5 = true;
                            }
                            if (!flag5)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num25 + num9, height + num10] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num25 + num9, height + num10] = 1;
                                }
                                num23 += 1f;
                            }
                        }
                    }
                    anchorData = tileData2.AnchorTop;
                    if (anchorData.tileCount != 0)
                    {
                        num24 += (float)anchorData.tileCount;
                        int num28 = -1;
                        for (int m = 0; m < anchorData.tileCount; m++)
                        {
                            int  num29      = anchorData.checkStart + m;
                            Tile tileSafely = Framing.GetTileSafely(num7 + num29, num8 + num28);
                            bool flag6      = false;
                            if (tileSafely.nactive())
                            {
                                if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                                {
                                    flag6 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag6 && (anchorData.type & AnchorType.SolidBottom) == AnchorType.SolidBottom && ((Main.tileSolid[(int)tileSafely.type] && (!Main.tileSolidTop[(int)tileSafely.type] || (TileID.Sets.Platforms[(int)tileSafely.type] && (tileSafely.halfBrick() || tileSafely.topSlope())))) || tileSafely.halfBrick() || tileSafely.topSlope()) && !TileID.Sets.NotReallySolid[(int)tileSafely.type] && !tileSafely.bottomSlope())
                                {
                                    flag6 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag6 && (anchorData.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type])
                                {
                                    int num27 = tileSafely.blockType();
                                    if (num27 - 2 <= 1)
                                    {
                                        flag6 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                    }
                                }
                                if (!flag6 && (anchorData.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
                                {
                                    flag6 = true;
                                }
                            }
                            else if (!flag6 && (anchorData.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag6 = true;
                            }
                            if (!flag6)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num29 + num9, num28 + num10] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num29 + num9, num28 + num10] = 1;
                                }
                                num23 += 1f;
                            }
                        }
                    }
                    anchorData = tileData2.AnchorRight;
                    if (anchorData.tileCount != 0)
                    {
                        num24 += (float)anchorData.tileCount;
                        int width = tileData2.Width;
                        for (int n = 0; n < anchorData.tileCount; n++)
                        {
                            int  num30      = anchorData.checkStart + n;
                            Tile tileSafely = Framing.GetTileSafely(num7 + width, num8 + num30);
                            bool flag7      = false;
                            if (tileSafely.nactive())
                            {
                                if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                                {
                                    flag7 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag7 && (anchorData.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type])
                                {
                                    int num27 = tileSafely.blockType();
                                    if (num27 == 2 || num27 == 4)
                                    {
                                        flag7 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                    }
                                }
                                if (!flag7 && (anchorData.type & AnchorType.Tree) == AnchorType.Tree && tileSafely.type == 5)
                                {
                                    flag7 = true;
                                    if (n == 0)
                                    {
                                        num24 += 1f;
                                        Tile tileSafely2 = Framing.GetTileSafely(num7 + width, num8 + num30 - 1);
                                        if (tileSafely2.nactive() && tileSafely2.type == 5)
                                        {
                                            num23 += 1f;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[width + num9, num30 + num10 - 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[width + num9, num30 + num10 - 1] = 2;
                                        }
                                    }
                                    if (n == anchorData.tileCount - 1)
                                    {
                                        num24 += 1f;
                                        Tile tileSafely3 = Framing.GetTileSafely(num7 + width, num8 + num30 + 1);
                                        if (tileSafely3.nactive() && tileSafely3.type == 5)
                                        {
                                            num23 += 1f;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[width + num9, num30 + num10 + 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[width + num9, num30 + num10 + 1] = 2;
                                        }
                                    }
                                }
                                if (!flag7 && (anchorData.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
                                {
                                    flag7 = true;
                                }
                            }
                            else if (!flag7 && (anchorData.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag7 = true;
                            }
                            if (!flag7)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[width + num9, num30 + num10] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[width + num9, num30 + num10] = 1;
                                }
                                num23 += 1f;
                            }
                        }
                    }
                    anchorData = tileData2.AnchorLeft;
                    if (anchorData.tileCount != 0)
                    {
                        num24 += (float)anchorData.tileCount;
                        int num31 = -1;
                        for (int num32 = 0; num32 < anchorData.tileCount; num32++)
                        {
                            int  num33      = anchorData.checkStart + num32;
                            Tile tileSafely = Framing.GetTileSafely(num7 + num31, num8 + num33);
                            bool flag8      = false;
                            if (tileSafely.nactive())
                            {
                                if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                                {
                                    flag8 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag8 && (anchorData.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type])
                                {
                                    int num27 = tileSafely.blockType();
                                    if (num27 == 3 || num27 == 5)
                                    {
                                        flag8 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                    }
                                }
                                if (!flag8 && (anchorData.type & AnchorType.Tree) == AnchorType.Tree && tileSafely.type == 5)
                                {
                                    flag8 = true;
                                    if (num32 == 0)
                                    {
                                        num24 += 1f;
                                        Tile tileSafely4 = Framing.GetTileSafely(num7 + num31, num8 + num33 - 1);
                                        if (tileSafely4.nactive() && tileSafely4.type == 5)
                                        {
                                            num23 += 1f;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[num31 + num9, num33 + num10 - 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[num31 + num9, num33 + num10 - 1] = 2;
                                        }
                                    }
                                    if (num32 == anchorData.tileCount - 1)
                                    {
                                        num24 += 1f;
                                        Tile tileSafely5 = Framing.GetTileSafely(num7 + num31, num8 + num33 + 1);
                                        if (tileSafely5.nactive() && tileSafely5.type == 5)
                                        {
                                            num23 += 1f;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[num31 + num9, num33 + num10 + 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[num31 + num9, num33 + num10 + 1] = 2;
                                        }
                                    }
                                }
                                if (!flag8 && (anchorData.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
                                {
                                    flag8 = true;
                                }
                            }
                            else if (!flag8 && (anchorData.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag8 = true;
                            }
                            if (!flag8)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num31 + num9, num33 + num10] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num31 + num9, num33 + num10] = 1;
                                }
                                num23 += 1f;
                            }
                        }
                    }
                    if (tileData2.HookCheck.hook != null)
                    {
                        if (tileData2.HookCheck.processedCoordinates)
                        {
                            Point16 arg_103B_0 = tileData2.Origin;
                            Point16 arg_1043_0 = tileData2.Origin;
                        }
                        if (tileData2.HookCheck.hook(x, y, type, style, dir) == tileData2.HookCheck.badReturn && tileData2.HookCheck.badResponse == 0)
                        {
                            num23 = 0f;
                            num21 = 0f;
                            TileObject.objectPreview.AllInvalid();
                        }
                    }
                    float num34 = num23 / num24;
                    float num35 = num21 / num22;
                    if (num35 == 1f && num24 == 0f)
                    {
                        num34 = 1f;
                        num35 = 1f;
                    }
                    if (num34 == 1f && num35 == 1f)
                    {
                        num4           = 1f;
                        num5           = 1f;
                        num6           = i;
                        tileObjectData = tileData2;
                        break;
                    }
                    if (num34 > num4 || (num34 == num4 && num35 > num5))
                    {
                        TileObjectPreviewData.placementCache.CopyFrom(TileObject.objectPreview);
                        num4           = num34;
                        num5           = num35;
                        tileObjectData = tileData2;
                        num6           = i;
                    }
                }
            }
            int num36 = -1;

            if (flag)
            {
                if (TileObjectPreviewData.randomCache == null)
                {
                    TileObjectPreviewData.randomCache = new TileObjectPreviewData();
                }
                bool flag9 = false;
                if ((int)TileObjectPreviewData.randomCache.Type == type)
                {
                    Point16 arg_116E_0  = TileObjectPreviewData.randomCache.Coordinates;
                    Point16 objectStart = TileObjectPreviewData.randomCache.ObjectStart;
                    int     num37       = (int)(arg_116E_0.X + objectStart.X);
                    int     num38       = (int)(arg_116E_0.Y + objectStart.Y);
                    int     num39       = x - (int)tileData.Origin.X;
                    int     num40       = y - (int)tileData.Origin.Y;
                    if (num37 != num39 || num38 != num40)
                    {
                        flag9 = true;
                    }
                }
                else
                {
                    flag9 = true;
                }
                if (flag9)
                {
                    num36 = Main.rand.Next(tileData.RandomStyleRange);
                }
                else
                {
                    num36 = TileObjectPreviewData.randomCache.Random;
                }
            }
            if (onlyCheck)
            {
                if (num4 != 1f || num5 != 1f)
                {
                    TileObject.objectPreview.CopyFrom(TileObjectPreviewData.placementCache);
                    i = num6;
                }
                TileObject.objectPreview.Random = num36;
                if (tileData.RandomStyleRange > 0)
                {
                    TileObjectPreviewData.randomCache.CopyFrom(TileObject.objectPreview);
                }
            }
            if (!onlyCheck)
            {
                objectData.xCoord    = x - (int)tileObjectData.Origin.X;
                objectData.yCoord    = y - (int)tileObjectData.Origin.Y;
                objectData.type      = type;
                objectData.style     = style;
                objectData.alternate = i;
                objectData.random    = num36;
            }
            return(num4 == 1f && num5 == 1f);
        }
		public static bool Place(TileObject toBePlaced)
		{
			TileObjectData tileData = TileObjectData.GetTileData(toBePlaced.type, toBePlaced.style, toBePlaced.alternate);
			if (tileData == null)
			{
				return false;
			}
			if (tileData.HookPlaceOverride.hook != null)
			{
				int arg;
				int arg2;
				if (tileData.HookPlaceOverride.processedCoordinates)
				{
					arg = toBePlaced.xCoord;
					arg2 = toBePlaced.yCoord;
				}
				else
				{
					arg = toBePlaced.xCoord + (int)tileData.Origin.X;
					arg2 = toBePlaced.yCoord + (int)tileData.Origin.Y;
				}
				if (tileData.HookPlaceOverride.hook(arg, arg2, toBePlaced.type, toBePlaced.style, 1) == tileData.HookPlaceOverride.badReturn)
				{
					return false;
				}
			}
			else
			{
				ushort num = (ushort)toBePlaced.type;
				int num2 = tileData.CalculatePlacementStyle(toBePlaced.style, toBePlaced.alternate, toBePlaced.random);
				int num3 = 0;
				if (tileData.StyleWrapLimit > 0)
				{
					num3 = num2 / tileData.StyleWrapLimit;
					num2 %= tileData.StyleWrapLimit;
				}
				int num4;
				int num5;
				if (tileData.StyleHorizontal)
				{
					num4 = tileData.CoordinateFullWidth * num2;
					num5 = tileData.CoordinateFullHeight * num3;
				}
				else
				{
					num4 = tileData.CoordinateFullWidth * num3;
					num5 = tileData.CoordinateFullHeight * num2;
				}
				int num6 = toBePlaced.xCoord;
				int num7 = toBePlaced.yCoord;
				for (int i = 0; i < tileData.Width; i++)
				{
					for (int j = 0; j < tileData.Height; j++)
					{
						Tile tileSafely = Framing.GetTileSafely(num6 + i, num7 + j);
						if (tileSafely.active() && Main.tileCut[(int)tileSafely.type])
						{
							WorldGen.KillTile(num6 + i, num7 + j, false, false, false);
						}
					}
				}
				for (int k = 0; k < tileData.Width; k++)//36 x, 144 y
				{
					int num8 = num4 + k * (tileData.CoordinateWidth + tileData.CoordinatePadding);
                    int num9 = num5;
					for (int l = 0; l < tileData.Height; l++)
					{
						Tile tileSafely2 = Framing.GetTileSafely(num6 + k, num7 + l);
						if (!tileSafely2.active())
						{
							tileSafely2.active(true);
							tileSafely2.frameX = (short)num8;
							tileSafely2.frameY = (short)num9;
							tileSafely2.type = num;
                            Main.NewText(tileSafely2.frameY.ToString());
						}
						num9 += tileData.CoordinateHeights[l] + tileData.CoordinatePadding;
					}
				}
			}
			if (tileData.FlattenAnchors)
			{
				AnchorData anchorData = tileData.AnchorBottom;
				if (anchorData.tileCount != 0 && (anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile)
				{
					int num10 = toBePlaced.xCoord + anchorData.checkStart;
					int j2 = toBePlaced.yCoord + tileData.Height;
					for (int m = 0; m < anchorData.tileCount; m++)
					{
						Tile tileSafely3 = Framing.GetTileSafely(num10 + m, j2);
						if (Main.tileSolid[(int)tileSafely3.type] && !Main.tileSolidTop[(int)tileSafely3.type] && tileSafely3.blockType() != 0)
						{
							WorldGen.SlopeTile(num10 + m, j2, 0);
						}
					}
				}
				anchorData = tileData.AnchorTop;
				if (anchorData.tileCount != 0 && (anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile)
				{
					int num11 = toBePlaced.xCoord + anchorData.checkStart;
					int j3 = toBePlaced.yCoord - 1;
					for (int n = 0; n < anchorData.tileCount; n++)
					{
						Tile tileSafely4 = Framing.GetTileSafely(num11 + n, j3);
						if (Main.tileSolid[(int)tileSafely4.type] && !Main.tileSolidTop[(int)tileSafely4.type] && tileSafely4.blockType() != 0)
						{
							WorldGen.SlopeTile(num11 + n, j3, 0);
						}
					}
				}
				anchorData = tileData.AnchorRight;
				if (anchorData.tileCount != 0 && (anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile)
				{
					int i2 = toBePlaced.xCoord + tileData.Width;
					int num12 = toBePlaced.yCoord + anchorData.checkStart;
					for (int num13 = 0; num13 < anchorData.tileCount; num13++)
					{
						Tile tileSafely5 = Framing.GetTileSafely(i2, num12 + num13);
						if (Main.tileSolid[(int)tileSafely5.type] && !Main.tileSolidTop[(int)tileSafely5.type] && tileSafely5.blockType() != 0)
						{
							WorldGen.SlopeTile(i2, num12 + num13, 0);
						}
					}
				}
				anchorData = tileData.AnchorLeft;
				if (anchorData.tileCount != 0 && (anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile)
				{
					int i3 = toBePlaced.xCoord - 1;
					int num14 = toBePlaced.yCoord + anchorData.checkStart;
					for (int num15 = 0; num15 < anchorData.tileCount; num15++)
					{
						Tile tileSafely6 = Framing.GetTileSafely(i3, num14 + num15);
						if (Main.tileSolid[(int)tileSafely6.type] && !Main.tileSolidTop[(int)tileSafely6.type] && tileSafely6.blockType() != 0)
						{
							WorldGen.SlopeTile(i3, num14 + num15, 0);
						}
					}
				}
			}
			return true;
		}
Beispiel #11
0
 public static bool CanPlace(int x, int y, int type, int style, int dir, out TileObject objectData, bool onlyCheck = false)
 {
     TileObjectData tileData1 = TileObjectData.GetTileData(type, style, 0);
     objectData = TileObject.Empty;
     if (tileData1 == null)
         return false;
     int num1 = x - (int)tileData1.Origin.X;
     int num2 = y - (int)tileData1.Origin.Y;
     if (num1 < 0 || num1 + tileData1.Width >= Main.maxTilesX || (num2 < 0 || num2 + tileData1.Height >= Main.maxTilesY))
         return false;
     bool flag1 = tileData1.RandomStyleRange > 0;
     if (TileObjectPreviewData.placementCache == null)
         TileObjectPreviewData.placementCache = new TileObjectPreviewData();
     TileObjectPreviewData.placementCache.Reset();
     int num3 = 0;
     int num4 = 0;
     if (tileData1.AlternatesCount != 0)
         num4 = tileData1.AlternatesCount;
     float num5 = -1f;
     float num6 = -1f;
     int num7 = 0;
     TileObjectData tileObjectData = (TileObjectData)null;
     int alternate = num3 - 1;
     while (alternate < num4)
     {
         ++alternate;
         TileObjectData tileData2 = TileObjectData.GetTileData(type, style, alternate);
         if (tileData2.Direction == TileObjectDirection.None || (tileData2.Direction != TileObjectDirection.PlaceLeft || dir != 1) && (tileData2.Direction != TileObjectDirection.PlaceRight || dir != -1))
         {
             int num8 = x - (int)tileData2.Origin.X;
             int num9 = y - (int)tileData2.Origin.Y;
             if (num8 < 5 || num8 + tileData2.Width > Main.maxTilesX - 5 || (num9 < 5 || num9 + tileData2.Height > Main.maxTilesY - 5))
                 return false;
             Rectangle rectangle = new Rectangle(0, 0, tileData2.Width, tileData2.Height);
             int X = 0;
             int Y = 0;
             if (tileData2.AnchorTop.tileCount != 0)
             {
                 if (rectangle.Y == 0)
                 {
                     rectangle.Y = -1;
                     ++rectangle.Height;
                     ++Y;
                 }
                 int num10 = tileData2.AnchorTop.checkStart;
                 if (num10 < rectangle.X)
                 {
                     rectangle.Width += rectangle.X - num10;
                     X += rectangle.X - num10;
                     rectangle.X = num10;
                 }
                 int num11 = num10 + tileData2.AnchorTop.tileCount - 1;
                 int num12 = rectangle.X + rectangle.Width - 1;
                 if (num11 > num12)
                     rectangle.Width += num11 - num12;
             }
             if (tileData2.AnchorBottom.tileCount != 0)
             {
                 if (rectangle.Y + rectangle.Height == tileData2.Height)
                     ++rectangle.Height;
                 int num10 = tileData2.AnchorBottom.checkStart;
                 if (num10 < rectangle.X)
                 {
                     rectangle.Width += rectangle.X - num10;
                     X += rectangle.X - num10;
                     rectangle.X = num10;
                 }
                 int num11 = num10 + tileData2.AnchorBottom.tileCount - 1;
                 int num12 = rectangle.X + rectangle.Width - 1;
                 if (num11 > num12)
                     rectangle.Width += num11 - num12;
             }
             if (tileData2.AnchorLeft.tileCount != 0)
             {
                 if (rectangle.X == 0)
                 {
                     rectangle.X = -1;
                     ++rectangle.Width;
                     ++X;
                 }
                 int num10 = tileData2.AnchorLeft.checkStart;
                 if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                     --num10;
                 if (num10 < rectangle.Y)
                 {
                     rectangle.Width += rectangle.Y - num10;
                     Y += rectangle.Y - num10;
                     rectangle.Y = num10;
                 }
                 int num11 = num10 + tileData2.AnchorLeft.tileCount - 1;
                 if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                     num11 += 2;
                 int num12 = rectangle.Y + rectangle.Height - 1;
                 if (num11 > num12)
                     rectangle.Height += num11 - num12;
             }
             if (tileData2.AnchorRight.tileCount != 0)
             {
                 if (rectangle.X + rectangle.Width == tileData2.Width)
                     ++rectangle.Width;
                 int num10 = tileData2.AnchorLeft.checkStart;
                 if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                     --num10;
                 if (num10 < rectangle.Y)
                 {
                     rectangle.Width += rectangle.Y - num10;
                     Y += rectangle.Y - num10;
                     rectangle.Y = num10;
                 }
                 int num11 = num10 + tileData2.AnchorRight.tileCount - 1;
                 if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                     num11 += 2;
                 int num12 = rectangle.Y + rectangle.Height - 1;
                 if (num11 > num12)
                     rectangle.Height += num11 - num12;
             }
             if (onlyCheck)
             {
                 TileObject.objectPreview.Reset();
                 TileObject.objectPreview.Active = true;
                 TileObject.objectPreview.Type = (ushort)type;
                 TileObject.objectPreview.Style = (short)style;
                 TileObject.objectPreview.Alternate = alternate;
                 TileObject.objectPreview.Size = new Point16(rectangle.Width, rectangle.Height);
                 TileObject.objectPreview.ObjectStart = new Point16(X, Y);
                 TileObject.objectPreview.Coordinates = new Point16(num8 - X, num9 - Y);
             }
             float num13 = 0.0f;
             float num14 = (float)(tileData2.Width * tileData2.Height);
             float num15 = 0.0f;
             float num16 = 0.0f;
             for (int index1 = 0; index1 < tileData2.Width; ++index1)
             {
                 for (int index2 = 0; index2 < tileData2.Height; ++index2)
                 {
                     Tile tileSafely = Framing.GetTileSafely(num8 + index1, num9 + index2);
                     bool flag2 = !tileData2.LiquidPlace(tileSafely);
                     bool flag3 = false;
                     if (tileData2.AnchorWall)
                     {
                         ++num16;
                         if (!tileData2.isValidWallAnchor((int)tileSafely.wall))
                             flag3 = true;
                         else
                             ++num15;
                     }
                     bool flag4 = false;
                     if (tileSafely.active() && !Main.tileCut[(int)tileSafely.type])
                         flag4 = true;
                     if (flag4 || flag2 || flag3)
                     {
                         if (onlyCheck)
                             TileObject.objectPreview[index1 + X, index2 + Y] = 2;
                     }
                     else
                     {
                         if (onlyCheck)
                             TileObject.objectPreview[index1 + X, index2 + Y] = 1;
                         ++num13;
                     }
                 }
             }
             AnchorData anchorBottom = tileData2.AnchorBottom;
             if (anchorBottom.tileCount != 0)
             {
                 num16 += (float)anchorBottom.tileCount;
                 int height = tileData2.Height;
                 for (int index = 0; index < anchorBottom.tileCount; ++index)
                 {
                     int num10 = anchorBottom.checkStart + index;
                     Tile tileSafely = Framing.GetTileSafely(num8 + num10, num9 + height);
                     bool flag2 = false;
                     if (tileSafely.nactive())
                     {
                         if ((anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile && Main.tileSolid[(int)tileSafely.type] && (!Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type]) && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                             flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                         if (!flag2 && ((anchorBottom.type & AnchorType.SolidWithTop) == AnchorType.SolidWithTop || (anchorBottom.type & AnchorType.Table) == AnchorType.Table))
                         {
                             if ((int)tileSafely.type == 19)
                             {
                                 int num11 = (int)tileSafely.frameX / TileObjectData.PlatformFrameWidth();
                                 if (!tileSafely.halfBrick() && num11 >= 0 && num11 <= 7 || (num11 >= 12 && num11 <= 16 || num11 >= 25 && num11 <= 26))
                                     flag2 = true;
                             }
                             else if (Main.tileSolid[(int)tileSafely.type] && Main.tileSolidTop[(int)tileSafely.type])
                                 flag2 = true;
                         }
                         if (!flag2 && (anchorBottom.type & AnchorType.Table) == AnchorType.Table && ((int)tileSafely.type != 19 && Main.tileTable[(int)tileSafely.type]) && tileSafely.blockType() == 0)
                             flag2 = true;
                         if (!flag2 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type]))
                         {
                             switch (tileSafely.blockType())
                             {
                                 case 4:
                                 case 5:
                                     flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                     break;
                             }
                         }
                         if (!flag2 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
                             flag2 = true;
                     }
                     else if (!flag2 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                         flag2 = true;
                     if (!flag2)
                     {
                         if (onlyCheck)
                             TileObject.objectPreview[num10 + X, height + Y] = 2;
                     }
                     else
                     {
                         if (onlyCheck)
                             TileObject.objectPreview[num10 + X, height + Y] = 1;
                         ++num15;
                     }
                 }
             }
             AnchorData anchorTop = tileData2.AnchorTop;
             if (anchorTop.tileCount != 0)
             {
                 num16 += (float)anchorTop.tileCount;
                 int num10 = -1;
                 for (int index = 0; index < anchorTop.tileCount; ++index)
                 {
                     int num11 = anchorTop.checkStart + index;
                     Tile tileSafely = Framing.GetTileSafely(num8 + num11, num9 + num10);
                     bool flag2 = false;
                     if (tileSafely.nactive())
                     {
                         if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                             flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                         if (!flag2 && (anchorTop.type & AnchorType.SolidBottom) == AnchorType.SolidBottom && (Main.tileSolid[(int)tileSafely.type] && (!Main.tileSolidTop[(int)tileSafely.type] || (int)tileSafely.type == 19 && (tileSafely.halfBrick() || tileSafely.topSlope())) || (tileSafely.halfBrick() || tileSafely.topSlope())) && (!TileID.Sets.NotReallySolid[(int)tileSafely.type] && !tileSafely.bottomSlope()))
                             flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                         if (!flag2 && (anchorTop.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type]))
                         {
                             switch (tileSafely.blockType())
                             {
                                 case 2:
                                 case 3:
                                     flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                     break;
                             }
                         }
                         if (!flag2 && (anchorTop.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
                             flag2 = true;
                     }
                     else if (!flag2 && (anchorTop.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                         flag2 = true;
                     if (!flag2)
                     {
                         if (onlyCheck)
                             TileObject.objectPreview[num11 + X, num10 + Y] = 2;
                     }
                     else
                     {
                         if (onlyCheck)
                             TileObject.objectPreview[num11 + X, num10 + Y] = 1;
                         ++num15;
                     }
                 }
             }
             AnchorData anchorRight = tileData2.AnchorRight;
             if (anchorRight.tileCount != 0)
             {
                 num16 += (float)anchorRight.tileCount;
                 int width = tileData2.Width;
                 for (int index = 0; index < anchorRight.tileCount; ++index)
                 {
                     int num10 = anchorRight.checkStart + index;
                     Tile tileSafely1 = Framing.GetTileSafely(num8 + width, num9 + num10);
                     bool flag2 = false;
                     if (tileSafely1.nactive())
                     {
                         if (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type] && !Main.tileNoAttach[(int)tileSafely1.type] && (tileData2.FlattenAnchors || tileSafely1.blockType() == 0))
                             flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                         if (!flag2 && (anchorRight.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type]))
                         {
                             switch (tileSafely1.blockType())
                             {
                                 case 2:
                                 case 4:
                                     flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                                     break;
                             }
                         }
                         if (!flag2 && (anchorRight.type & AnchorType.Tree) == AnchorType.Tree && (int)tileSafely1.type == 5)
                         {
                             flag2 = true;
                             if (index == 0)
                             {
                                 ++num16;
                                 Tile tileSafely2 = Framing.GetTileSafely(num8 + width, num9 + num10 - 1);
                                 if (tileSafely2.nactive() && (int)tileSafely2.type == 5)
                                 {
                                     ++num15;
                                     if (onlyCheck)
                                         TileObject.objectPreview[width + X, num10 + Y - 1] = 1;
                                 }
                                 else if (onlyCheck)
                                     TileObject.objectPreview[width + X, num10 + Y - 1] = 2;
                             }
                             if (index == anchorRight.tileCount - 1)
                             {
                                 ++num16;
                                 Tile tileSafely2 = Framing.GetTileSafely(num8 + width, num9 + num10 + 1);
                                 if (tileSafely2.nactive() && (int)tileSafely2.type == 5)
                                 {
                                     ++num15;
                                     if (onlyCheck)
                                         TileObject.objectPreview[width + X, num10 + Y + 1] = 1;
                                 }
                                 else if (onlyCheck)
                                     TileObject.objectPreview[width + X, num10 + Y + 1] = 2;
                             }
                         }
                         if (!flag2 && (anchorRight.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely1.type))
                             flag2 = true;
                     }
                     else if (!flag2 && (anchorRight.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                         flag2 = true;
                     if (!flag2)
                     {
                         if (onlyCheck)
                             TileObject.objectPreview[width + X, num10 + Y] = 2;
                     }
                     else
                     {
                         if (onlyCheck)
                             TileObject.objectPreview[width + X, num10 + Y] = 1;
                         ++num15;
                     }
                 }
             }
             AnchorData anchorLeft = tileData2.AnchorLeft;
             if (anchorLeft.tileCount != 0)
             {
                 num16 += (float)anchorLeft.tileCount;
                 int num10 = -1;
                 for (int index = 0; index < anchorLeft.tileCount; ++index)
                 {
                     int num11 = anchorLeft.checkStart + index;
                     Tile tileSafely1 = Framing.GetTileSafely(num8 + num10, num9 + num11);
                     bool flag2 = false;
                     if (tileSafely1.nactive())
                     {
                         if (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type] && !Main.tileNoAttach[(int)tileSafely1.type] && (tileData2.FlattenAnchors || tileSafely1.blockType() == 0))
                             flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                         if (!flag2 && (anchorLeft.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type]))
                         {
                             switch (tileSafely1.blockType())
                             {
                                 case 3:
                                 case 5:
                                     flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                                     break;
                             }
                         }
                         if (!flag2 && (anchorLeft.type & AnchorType.Tree) == AnchorType.Tree && (int)tileSafely1.type == 5)
                         {
                             flag2 = true;
                             if (index == 0)
                             {
                                 ++num16;
                                 Tile tileSafely2 = Framing.GetTileSafely(num8 + num10, num9 + num11 - 1);
                                 if (tileSafely2.nactive() && (int)tileSafely2.type == 5)
                                 {
                                     ++num15;
                                     if (onlyCheck)
                                         TileObject.objectPreview[num10 + X, num11 + Y - 1] = 1;
                                 }
                                 else if (onlyCheck)
                                     TileObject.objectPreview[num10 + X, num11 + Y - 1] = 2;
                             }
                             if (index == anchorLeft.tileCount - 1)
                             {
                                 ++num16;
                                 Tile tileSafely2 = Framing.GetTileSafely(num8 + num10, num9 + num11 + 1);
                                 if (tileSafely2.nactive() && (int)tileSafely2.type == 5)
                                 {
                                     ++num15;
                                     if (onlyCheck)
                                         TileObject.objectPreview[num10 + X, num11 + Y + 1] = 1;
                                 }
                                 else if (onlyCheck)
                                     TileObject.objectPreview[num10 + X, num11 + Y + 1] = 2;
                             }
                         }
                         if (!flag2 && (anchorLeft.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely1.type))
                             flag2 = true;
                     }
                     else if (!flag2 && (anchorLeft.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                         flag2 = true;
                     if (!flag2)
                     {
                         if (onlyCheck)
                             TileObject.objectPreview[num10 + X, num11 + Y] = 2;
                     }
                     else
                     {
                         if (onlyCheck)
                             TileObject.objectPreview[num10 + X, num11 + Y] = 1;
                         ++num15;
                     }
                 }
             }
             if (tileData2.HookCheck.hook != null)
             {
                 if (tileData2.HookCheck.processedCoordinates)
                 {
                     int num10 = (int)tileData2.Origin.X;
                     int num11 = (int)tileData2.Origin.Y;
                 }
                 if (tileData2.HookCheck.hook(x, y, type, style, dir) == tileData2.HookCheck.badReturn && tileData2.HookCheck.badResponse == 0)
                 {
                     num15 = 0.0f;
                     num13 = 0.0f;
                     TileObject.objectPreview.AllInvalid();
                 }
             }
             float num17 = num15 / num16;
             float num18 = num13 / num14;
             if ((double)num17 == 1.0 && (double)num18 == 1.0)
             {
                 num5 = 1f;
                 num6 = 1f;
                 num7 = alternate;
                 tileObjectData = tileData2;
                 break;
             }
             if ((double)num17 > (double)num5 || (double)num17 == (double)num5 && (double)num18 > (double)num6)
             {
                 TileObjectPreviewData.placementCache.CopyFrom(TileObject.objectPreview);
                 num5 = num17;
                 num6 = num18;
                 tileObjectData = tileData2;
                 num7 = alternate;
             }
         }
     }
     int num19 = -1;
     if (flag1)
     {
         if (TileObjectPreviewData.randomCache == null)
             TileObjectPreviewData.randomCache = new TileObjectPreviewData();
         bool flag2 = false;
         if ((int)TileObjectPreviewData.randomCache.Type == type)
         {
             Point16 coordinates = TileObjectPreviewData.randomCache.Coordinates;
             Point16 objectStart = TileObjectPreviewData.randomCache.ObjectStart;
             int num8 = (int)coordinates.X + (int)objectStart.X;
             int num9 = (int)coordinates.Y + (int)objectStart.Y;
             int num10 = x - (int)tileData1.Origin.X;
             int num11 = y - (int)tileData1.Origin.Y;
             if (num8 != num10 || num9 != num11)
                 flag2 = true;
         }
         else
             flag2 = true;
         num19 = !flag2 ? TileObjectPreviewData.randomCache.Random : Main.rand.Next(tileData1.RandomStyleRange);
     }
     if (onlyCheck)
     {
         if ((double)num5 != 1.0 || (double)num6 != 1.0)
         {
             TileObject.objectPreview.CopyFrom(TileObjectPreviewData.placementCache);
             alternate = num7;
         }
         TileObject.objectPreview.Random = num19;
         if (tileData1.RandomStyleRange > 0)
             TileObjectPreviewData.randomCache.CopyFrom(TileObject.objectPreview);
     }
     if (!onlyCheck)
     {
         objectData.xCoord = x - (int)tileObjectData.Origin.X;
         objectData.yCoord = y - (int)tileObjectData.Origin.Y;
         objectData.type = type;
         objectData.style = style;
         objectData.alternate = alternate;
         objectData.random = num19;
     }
     if ((double)num5 == 1.0)
         return (double)num6 == 1.0;
     return false;
 }
        public static bool CanPlace(int x, int y, int type, int style, int dir, out TileObject objectData, bool onlyCheck = false, bool checkStay = false)//
		{
			TileObjectData tileData = TileObjectData.GetTileData(type, style, 0);
			objectData = TileObject.Empty;
			if (tileData == null)
			{
				return false;
			}
			int num = x - (int)tileData.Origin.X;
			int num2 = y - (int)tileData.Origin.Y;
			if (num < 0 || num + tileData.Width >= Main.maxTilesX || num2 < 0 || num2 + tileData.Height >= Main.maxTilesY)
			{
				return false;
			}
			bool flag = tileData.RandomStyleRange > 0;
			if (TileObjectPreviewData.placementCache == null)
			{
				TileObjectPreviewData.placementCache = new TileObjectPreviewData();
			}
			TileObjectPreviewData.placementCache.Reset();
			int num3 = 0;
			int num4 = 0;
			if (tileData.AlternatesCount != 0)
			{
				num4 = tileData.AlternatesCount;
			}
			float num5 = -1f;
			float num6 = -1f;
			int num7 = 0;
			TileObjectData tileObjectData = null;
			int i = num3 - 1;
			while (i < num4)
			{
				i++;
				TileObjectData tileData2 = TileObjectData.GetTileData(type, style, i);
				if (tileData2.Direction == TileObjectDirection.None || ((tileData2.Direction != TileObjectDirection.PlaceLeft || dir != 1) && (tileData2.Direction != TileObjectDirection.PlaceRight || dir != -1)))
				{
					int num8 = x - (int)tileData2.Origin.X;
					int num9 = y - (int)tileData2.Origin.Y;
					if (num8 < 5 || num8 + tileData2.Width > Main.maxTilesX - 5 || num9 < 5 || num9 + tileData2.Height > Main.maxTilesY - 5)
					{
						return false;
					}
					Rectangle rectangle = new Rectangle(0, 0, tileData2.Width, tileData2.Height);
					int num10 = 0;
					int num11 = 0;
					if (tileData2.AnchorTop.tileCount != 0)
					{
						if (rectangle.Y == 0)
						{
							rectangle.Y = -1;
							rectangle.Height++;
							num11++;
						}
						int checkStart = tileData2.AnchorTop.checkStart;
						if (checkStart < rectangle.X)
						{
							rectangle.Width += rectangle.X - checkStart;
							num10 += rectangle.X - checkStart;
							rectangle.X = checkStart;
						}
						int num12 = checkStart + tileData2.AnchorTop.tileCount - 1;
						int num13 = rectangle.X + rectangle.Width - 1;
						if (num12 > num13)
						{
							rectangle.Width += num12 - num13;
						}
					}
					if (tileData2.AnchorBottom.tileCount != 0)
					{
						if (rectangle.Y + rectangle.Height == tileData2.Height)
						{
							rectangle.Height++;
						}
						int checkStart2 = tileData2.AnchorBottom.checkStart;
						if (checkStart2 < rectangle.X)
						{
							rectangle.Width += rectangle.X - checkStart2;
							num10 += rectangle.X - checkStart2;
							rectangle.X = checkStart2;
						}
						int num14 = checkStart2 + tileData2.AnchorBottom.tileCount - 1;
						int num15 = rectangle.X + rectangle.Width - 1;
						if (num14 > num15)
						{
							rectangle.Width += num14 - num15;
						}
					}
					if (tileData2.AnchorLeft.tileCount != 0)
					{
						if (rectangle.X == 0)
						{
							rectangle.X = -1;
							rectangle.Width++;
							num10++;
						}
						int num16 = tileData2.AnchorLeft.checkStart;
						if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
						{
							num16--;
						}
						if (num16 < rectangle.Y)
						{
							rectangle.Width += rectangle.Y - num16;
							num11 += rectangle.Y - num16;
							rectangle.Y = num16;
						}
						int num17 = num16 + tileData2.AnchorLeft.tileCount - 1;
						if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
						{
							num17 += 2;
						}
						int num18 = rectangle.Y + rectangle.Height - 1;
						if (num17 > num18)
						{
							rectangle.Height += num17 - num18;
						}
					}
					if (tileData2.AnchorRight.tileCount != 0)
					{
						if (rectangle.X + rectangle.Width == tileData2.Width)
						{
							rectangle.Width++;
						}
						int num19 = tileData2.AnchorLeft.checkStart;
						if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
						{
							num19--;
						}
						if (num19 < rectangle.Y)
						{
							rectangle.Width += rectangle.Y - num19;
							num11 += rectangle.Y - num19;
							rectangle.Y = num19;
						}
						int num20 = num19 + tileData2.AnchorRight.tileCount - 1;
						if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
						{
							num20 += 2;
						}
						int num21 = rectangle.Y + rectangle.Height - 1;
						if (num20 > num21)
						{
							rectangle.Height += num20 - num21;
						}
					}
					if (onlyCheck)
					{
						TileObject.objectPreview.Reset();
						TileObject.objectPreview.Active = true;
						TileObject.objectPreview.Type = (ushort)type;
						TileObject.objectPreview.Style = (short)style;
						TileObject.objectPreview.Alternate = i;
						TileObject.objectPreview.Size = new Point16(rectangle.Width, rectangle.Height);
						TileObject.objectPreview.ObjectStart = new Point16(num10, num11);
						TileObject.objectPreview.Coordinates = new Point16(num8 - num10, num9 - num11);
					}
					float num22 = 0f;
					float num23 = (float)(tileData2.Width * tileData2.Height);
					float num24 = 0f;
					float num25 = 0f;
					for (int j = 0; j < tileData2.Width; j++)
					{
						for (int k = 0; k < tileData2.Height; k++)
						{
							Tile tileSafely = Framing.GetTileSafely(num8 + j, num9 + k);
							bool flag2 = !tileData2.LiquidPlace(tileSafely);
							bool flag3 = false;
							if (tileData2.AnchorWall)
							{
								num25 += 1f;
								if (!tileData2.isValidWallAnchor((int)tileSafely.wall))
								{
									flag3 = true;
								}
								else
								{
									num24 += 1f;
								}
							}
							bool flag4 = false;
							if (!checkStay && tileSafely.active() && !Main.tileCut[(int)tileSafely.type])
							{
								flag4 = true;
							}
							if (flag4 || flag2 || flag3)
							{
								if (onlyCheck)
								{
									TileObject.objectPreview[j + num10, k + num11] = 2;
								}
							}
							else
							{
								if (onlyCheck)
								{
									TileObject.objectPreview[j + num10, k + num11] = 1;
								}
								num22 += 1f;
							}
						}
					}
					AnchorData anchorData = tileData2.AnchorBottom;
					if (anchorData.tileCount != 0)
					{
						num25 += (float)anchorData.tileCount;
						int height = tileData2.Height;
						for (int l = 0; l < anchorData.tileCount; l++)
						{
							int num26 = anchorData.checkStart + l;
							Tile tileSafely = Framing.GetTileSafely(num8 + num26, num9 + height);
							bool flag5 = false;
							if (tileSafely.nactive())
							{
								if ((anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile && Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
								{
									flag5 = tileData2.isValidTileAnchor((int)tileSafely.type);
								}
								if (!flag5 && ((anchorData.type & AnchorType.SolidWithTop) == AnchorType.SolidWithTop || (anchorData.type & AnchorType.Table) == AnchorType.Table))
								{
									if (tileSafely.type == 19)
									{
										int num27 = (int)tileSafely.frameX / TileObjectData.PlatformFrameWidth();
										if ((!tileSafely.halfBrick() && num27 >= 0 && num27 <= 7) || (num27 >= 12 && num27 <= 16) || (num27 >= 25 && num27 <= 26))
										{
											flag5 = true;
										}
									}
									else if (Main.tileSolid[(int)tileSafely.type] && Main.tileSolidTop[(int)tileSafely.type])
									{
										flag5 = true;
									}
								}
								if (!flag5 && (anchorData.type & AnchorType.Table) == AnchorType.Table && tileSafely.type != 19 && Main.tileTable[(int)tileSafely.type] && tileSafely.blockType() == 0)
								{
									flag5 = true;
								}
								if (!flag5 && (anchorData.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type])
								{
									switch (tileSafely.blockType())
									{
									case 4:
									case 5:
										flag5 = tileData2.isValidTileAnchor((int)tileSafely.type);
										break;
									}
								}
								if (!flag5 && (anchorData.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
								{
									flag5 = true;
								}
							}
							else if (!flag5 && (anchorData.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
							{
								flag5 = true;
							}
							if (!flag5)
							{
								if (onlyCheck)
								{
									TileObject.objectPreview[num26 + num10, height + num11] = 2;
								}
							}
							else
							{
								if (onlyCheck)
								{
									TileObject.objectPreview[num26 + num10, height + num11] = 1;
								}
								num24 += 1f;
							}
						}
					}
					anchorData = tileData2.AnchorTop;
					if (anchorData.tileCount != 0)
					{
						num25 += (float)anchorData.tileCount;
						int num28 = -1;
						for (int m = 0; m < anchorData.tileCount; m++)
						{
							int num29 = anchorData.checkStart + m;
							Tile tileSafely = Framing.GetTileSafely(num8 + num29, num9 + num28);
							bool flag6 = false;
							if (tileSafely.nactive())
							{
								if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
								{
									flag6 = tileData2.isValidTileAnchor((int)tileSafely.type);
								}
								if (!flag6 && (anchorData.type & AnchorType.SolidBottom) == AnchorType.SolidBottom && ((Main.tileSolid[(int)tileSafely.type] && (!Main.tileSolidTop[(int)tileSafely.type] || (tileSafely.type == 19 && (tileSafely.halfBrick() || tileSafely.topSlope())))) || tileSafely.halfBrick() || tileSafely.topSlope()) && !TileID.Sets.NotReallySolid[(int)tileSafely.type] && !tileSafely.bottomSlope())
								{
									flag6 = tileData2.isValidTileAnchor((int)tileSafely.type);
								}
								if (!flag6 && (anchorData.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type])
								{
									switch (tileSafely.blockType())
									{
									case 2:
									case 3:
										flag6 = tileData2.isValidTileAnchor((int)tileSafely.type);
										break;
									}
								}
								if (!flag6 && (anchorData.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
								{
									flag6 = true;
								}
							}
							else if (!flag6 && (anchorData.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
							{
								flag6 = true;
							}
							if (!flag6)
							{
								if (onlyCheck)
								{
									TileObject.objectPreview[num29 + num10, num28 + num11] = 2;
								}
							}
							else
							{
								if (onlyCheck)
								{
									TileObject.objectPreview[num29 + num10, num28 + num11] = 1;
								}
								num24 += 1f;
							}
						}
					}
					anchorData = tileData2.AnchorRight;
					if (anchorData.tileCount != 0)
					{
						num25 += (float)anchorData.tileCount;
						int width = tileData2.Width;
						for (int n = 0; n < anchorData.tileCount; n++)
						{
							int num30 = anchorData.checkStart + n;
							Tile tileSafely = Framing.GetTileSafely(num8 + width, num9 + num30);
							bool flag7 = false;
							if (tileSafely.nactive())
							{
								if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
								{
									flag7 = tileData2.isValidTileAnchor((int)tileSafely.type);
								}
								if (!flag7 && (anchorData.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type])
								{
									switch (tileSafely.blockType())
									{
									case 2:
									case 4:
										flag7 = tileData2.isValidTileAnchor((int)tileSafely.type);
										break;
									}
								}
								if (!flag7 && (anchorData.type & AnchorType.Tree) == AnchorType.Tree && tileSafely.type == 5)
								{
									flag7 = true;
									if (n == 0)
									{
										num25 += 1f;
										Tile tileSafely2 = Framing.GetTileSafely(num8 + width, num9 + num30 - 1);
										if (tileSafely2.nactive() && tileSafely2.type == 5)
										{
											num24 += 1f;
											if (onlyCheck)
											{
												TileObject.objectPreview[width + num10, num30 + num11 - 1] = 1;
											}
										}
										else if (onlyCheck)
										{
											TileObject.objectPreview[width + num10, num30 + num11 - 1] = 2;
										}
									}
									if (n == anchorData.tileCount - 1)
									{
										num25 += 1f;
										Tile tileSafely3 = Framing.GetTileSafely(num8 + width, num9 + num30 + 1);
										if (tileSafely3.nactive() && tileSafely3.type == 5)
										{
											num24 += 1f;
											if (onlyCheck)
											{
												TileObject.objectPreview[width + num10, num30 + num11 + 1] = 1;
											}
										}
										else if (onlyCheck)
										{
											TileObject.objectPreview[width + num10, num30 + num11 + 1] = 2;
										}
									}
								}
								if (!flag7 && (anchorData.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
								{
									flag7 = true;
								}
							}
							else if (!flag7 && (anchorData.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
							{
								flag7 = true;
							}
							if (!flag7)
							{
								if (onlyCheck)
								{
									TileObject.objectPreview[width + num10, num30 + num11] = 2;
								}
							}
							else
							{
								if (onlyCheck)
								{
									TileObject.objectPreview[width + num10, num30 + num11] = 1;
								}
								num24 += 1f;
							}
						}
					}
					anchorData = tileData2.AnchorLeft;
					if (anchorData.tileCount != 0)
					{
						num25 += (float)anchorData.tileCount;
						int num31 = -1;
						for (int num32 = 0; num32 < anchorData.tileCount; num32++)
						{
							int num33 = anchorData.checkStart + num32;
							Tile tileSafely = Framing.GetTileSafely(num8 + num31, num9 + num33);
							bool flag8 = false;
							if (tileSafely.nactive())
							{
								if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
								{
									flag8 = tileData2.isValidTileAnchor((int)tileSafely.type);
								}
								if (!flag8 && (anchorData.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type])
								{
									switch (tileSafely.blockType())
									{
									case 3:
									case 5:
										flag8 = tileData2.isValidTileAnchor((int)tileSafely.type);
										break;
									}
								}
								if (!flag8 && (anchorData.type & AnchorType.Tree) == AnchorType.Tree && tileSafely.type == 5)
								{
									flag8 = true;
									if (num32 == 0)
									{
										num25 += 1f;
										Tile tileSafely4 = Framing.GetTileSafely(num8 + num31, num9 + num33 - 1);
										if (tileSafely4.nactive() && tileSafely4.type == 5)
										{
											num24 += 1f;
											if (onlyCheck)
											{
												TileObject.objectPreview[num31 + num10, num33 + num11 - 1] = 1;
											}
										}
										else if (onlyCheck)
										{
											TileObject.objectPreview[num31 + num10, num33 + num11 - 1] = 2;
										}
									}
									if (num32 == anchorData.tileCount - 1)
									{
										num25 += 1f;
										Tile tileSafely5 = Framing.GetTileSafely(num8 + num31, num9 + num33 + 1);
										if (tileSafely5.nactive() && tileSafely5.type == 5)
										{
											num24 += 1f;
											if (onlyCheck)
											{
												TileObject.objectPreview[num31 + num10, num33 + num11 + 1] = 1;
											}
										}
										else if (onlyCheck)
										{
											TileObject.objectPreview[num31 + num10, num33 + num11 + 1] = 2;
										}
									}
								}
								if (!flag8 && (anchorData.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
								{
									flag8 = true;
								}
							}
							else if (!flag8 && (anchorData.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
							{
								flag8 = true;
							}
							if (!flag8)
							{
								if (onlyCheck)
								{
									TileObject.objectPreview[num31 + num10, num33 + num11] = 2;
								}
							}
							else
							{
								if (onlyCheck)
								{
									TileObject.objectPreview[num31 + num10, num33 + num11] = 1;
								}
								num24 += 1f;
							}
						}
					}
					if (tileData2.HookCheck.hook != null)
					{
						if (tileData2.HookCheck.processedCoordinates)
						{
							short arg_1091_0 = tileData2.Origin.X;
							short arg_109E_0 = tileData2.Origin.Y;
						}
						if (tileData2.HookCheck.hook(x, y, type, style, dir) == tileData2.HookCheck.badReturn)
						{
							int badResponse = tileData2.HookCheck.badResponse;
							if (badResponse == 0)
							{
								num24 = 0f;
								num22 = 0f;
								TileObject.objectPreview.AllInvalid();
							}
						}
					}
					float num34 = num24 / num25;
					float num35 = num22 / num23;
					if (num34 == 1f && num35 == 1f)
					{
						num5 = 1f;
						num6 = 1f;
						num7 = i;
						tileObjectData = tileData2;
						break;
					}
					if (num34 > num5 || (num34 == num5 && num35 > num6))
					{
						TileObjectPreviewData.placementCache.CopyFrom(TileObject.objectPreview);
						num5 = num34;
						num6 = num35;
						tileObjectData = tileData2;
						num7 = i;
					}
				}
			}
			int num36 = -1;
			if (flag)
			{
				if (TileObjectPreviewData.randomCache == null)
				{
					TileObjectPreviewData.randomCache = new TileObjectPreviewData();
				}
				bool flag9 = false;
				if ((int)TileObjectPreviewData.randomCache.Type == type)
				{
					Point16 coordinates = TileObjectPreviewData.randomCache.Coordinates;
					Point16 objectStart = TileObjectPreviewData.randomCache.ObjectStart;
					int num37 = (int)(coordinates.X + objectStart.X);
					int num38 = (int)(coordinates.Y + objectStart.Y);
					int num39 = x - (int)tileData.Origin.X;
					int num40 = y - (int)tileData.Origin.Y;
					if (num37 != num39 || num38 != num40)
					{
						flag9 = true;
					}
				}
				else
				{
					flag9 = true;
				}
				if (flag9)
				{
					num36 = Main.rand.Next(tileData.RandomStyleRange);
				}
				else
				{
					num36 = TileObjectPreviewData.randomCache.Random;
				}
			}
			if (onlyCheck)
			{
				if (num5 != 1f || num6 != 1f)
				{
					TileObject.objectPreview.CopyFrom(TileObjectPreviewData.placementCache);
					i = num7;
				}
				TileObject.objectPreview.Random = num36;
				if (tileData.RandomStyleRange > 0)
				{
					TileObjectPreviewData.randomCache.CopyFrom(TileObject.objectPreview);
				}
			}
			if (!onlyCheck)
			{
				objectData.xCoord = x - (int)tileObjectData.Origin.X;
				objectData.yCoord = y - (int)tileObjectData.Origin.Y;
				objectData.type = type;
				objectData.style = style;
				objectData.alternate = i;
				objectData.random = num36;
			}
			return num5 == 1f && num6 == 1f;
		}
Beispiel #13
0
 public static bool Place(TileObject toBePlaced)
 {
     int num;
     int num1;
     TileObjectData tileData = TileObjectData.GetTileData(toBePlaced.type, toBePlaced.style, toBePlaced.alternate);
     if (tileData == null)
     {
         return false;
     }
     if (tileData.HookPlaceOverride.hook == null)
     {
         ushort num2 = (ushort)toBePlaced.type;
         int coordinateFullWidth = 0;
         int coordinateFullHeight = 0;
         int styleWrapLimit = tileData.CalculatePlacementStyle(toBePlaced.style, toBePlaced.alternate, toBePlaced.random);
         int styleWrapLimit1 = 0;
         if (tileData.StyleWrapLimit > 0)
         {
             styleWrapLimit1 = styleWrapLimit / tileData.StyleWrapLimit;
             styleWrapLimit = styleWrapLimit % tileData.StyleWrapLimit;
         }
         if (!tileData.StyleHorizontal)
         {
             coordinateFullWidth = tileData.CoordinateFullWidth * styleWrapLimit1;
             coordinateFullHeight = tileData.CoordinateFullHeight * styleWrapLimit;
         }
         else
         {
             coordinateFullWidth = tileData.CoordinateFullWidth * styleWrapLimit;
             coordinateFullHeight = tileData.CoordinateFullHeight * styleWrapLimit1;
         }
         int num3 = toBePlaced.xCoord;
         int num4 = toBePlaced.yCoord;
         for (int i = 0; i < tileData.Width; i++)
         {
             for (int j = 0; j < tileData.Height; j++)
             {
                 Tile tileSafely = Framing.GetTileSafely(num3 + i, num4 + j);
                 if (tileSafely.active() && Main.tileCut[tileSafely.type])
                 {
                     WorldGen.KillTile(num3 + i, num4 + j, false, false, false);
                 }
             }
         }
         for (int k = 0; k < tileData.Width; k++)
         {
             int coordinateWidth = coordinateFullWidth + k * (tileData.CoordinateWidth + tileData.CoordinatePadding);
             int coordinateHeights = coordinateFullHeight;
             for (int l = 0; l < tileData.Height; l++)
             {
                 Tile tile = Framing.GetTileSafely(num3 + k, num4 + l);
                 if (!tile.active())
                 {
                     tile.active(true);
                     tile.frameX = (short)coordinateWidth;
                     tile.frameY = (short)coordinateHeights;
                     tile.type = num2;
                 }
                 coordinateHeights = coordinateHeights + tileData.CoordinateHeights[l] + tileData.CoordinatePadding;
             }
         }
     }
     else
     {
         if (!tileData.HookPlaceOverride.processedCoordinates)
         {
             num = toBePlaced.xCoord + tileData.Origin.X;
             num1 = toBePlaced.yCoord + tileData.Origin.Y;
         }
         else
         {
             num = toBePlaced.xCoord;
             num1 = toBePlaced.yCoord;
         }
         if (tileData.HookPlaceOverride.hook(num, num1, toBePlaced.type, toBePlaced.style, 1) == tileData.HookPlaceOverride.badReturn)
         {
             return false;
         }
     }
     if (tileData.FlattenAnchors)
     {
         AnchorData anchorBottom = tileData.AnchorBottom;
         if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
         {
             int num5 = toBePlaced.xCoord + anchorBottom.checkStart;
             int num6 = toBePlaced.yCoord + tileData.Height;
             for (int m = 0; m < anchorBottom.tileCount; m++)
             {
                 Tile tileSafely1 = Framing.GetTileSafely(num5 + m, num6);
                 if (Main.tileSolid[tileSafely1.type] && !Main.tileSolidTop[tileSafely1.type] && tileSafely1.blockType() != 0)
                 {
                     WorldGen.SlopeTile(num5 + m, num6, 0);
                 }
             }
         }
         anchorBottom = tileData.AnchorTop;
         if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
         {
             int num7 = toBePlaced.xCoord + anchorBottom.checkStart;
             int num8 = toBePlaced.yCoord - 1;
             for (int n = 0; n < anchorBottom.tileCount; n++)
             {
                 Tile tile1 = Framing.GetTileSafely(num7 + n, num8);
                 if (Main.tileSolid[tile1.type] && !Main.tileSolidTop[tile1.type] && tile1.blockType() != 0)
                 {
                     WorldGen.SlopeTile(num7 + n, num8, 0);
                 }
             }
         }
         anchorBottom = tileData.AnchorRight;
         if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
         {
             int num9 = toBePlaced.xCoord + tileData.Width;
             int num10 = toBePlaced.yCoord + anchorBottom.checkStart;
             for (int o = 0; o < anchorBottom.tileCount; o++)
             {
                 Tile tileSafely2 = Framing.GetTileSafely(num9, num10 + o);
                 if (Main.tileSolid[tileSafely2.type] && !Main.tileSolidTop[tileSafely2.type] && tileSafely2.blockType() != 0)
                 {
                     WorldGen.SlopeTile(num9, num10 + o, 0);
                 }
             }
         }
         anchorBottom = tileData.AnchorLeft;
         if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
         {
             int num11 = toBePlaced.xCoord - 1;
             int num12 = toBePlaced.yCoord + anchorBottom.checkStart;
             for (int p = 0; p < anchorBottom.tileCount; p++)
             {
                 Tile tile2 = Framing.GetTileSafely(num11, num12 + p);
                 if (Main.tileSolid[tile2.type] && !Main.tileSolidTop[tile2.type] && tile2.blockType() != 0)
                 {
                     WorldGen.SlopeTile(num11, num12 + p, 0);
                 }
             }
         }
     }
     return true;
 }
Beispiel #14
0
 public static bool CanPlace(int x, int y, int type, int style, int dir, out TileObject objectData, bool onlyCheck = false)
 {
     Tile tileSafely;
     TileObjectData tileData = TileObjectData.GetTileData(type, style, 0);
     objectData = TileObject.Empty;
     if (tileData == null)
     {
         return false;
     }
     int num = x - tileData.Origin.X;
     int num1 = y - tileData.Origin.Y;
     if (num < 0 || num + tileData.Width >= Main.maxTilesX || num1 < 0 || num1 + tileData.Height >= Main.maxTilesY)
     {
         return false;
     }
     bool randomStyleRange = tileData.RandomStyleRange > 0;
     if (TileObjectPreviewData.placementCache == null)
     {
         TileObjectPreviewData.placementCache = new TileObjectPreviewData();
     }
     TileObjectPreviewData.placementCache.Reset();
     int num2 = 0;
     int alternatesCount = 0;
     if (tileData.AlternatesCount != 0)
     {
         alternatesCount = tileData.AlternatesCount;
     }
     float single = -1f;
     float single1 = -1f;
     int num3 = 0;
     TileObjectData tileObjectDatum = null;
     int num4 = num2 - 1;
     while (num4 < alternatesCount)
     {
         num4++;
         TileObjectData tileData1 = TileObjectData.GetTileData(type, style, num4);
         if (tileData1.Direction != TileObjectDirection.None && (tileData1.Direction == TileObjectDirection.PlaceLeft && dir == 1 || tileData1.Direction == TileObjectDirection.PlaceRight && dir == -1))
         {
             continue;
         }
         int num5 = x - tileData1.Origin.X;
         int num6 = y - tileData1.Origin.Y;
         if (num5 < 5 || num5 + tileData1.Width > Main.maxTilesX - 5 || num6 < 5 || num6 + tileData1.Height > Main.maxTilesY - 5)
         {
             return false;
         }
         Rectangle rectangle = new Rectangle(0, 0, tileData1.Width, tileData1.Height);
         int num7 = 0;
         int num8 = 0;
         if (tileData1.AnchorTop.tileCount != 0)
         {
             if (rectangle.Y == 0)
             {
                 rectangle.Y = -1;
                 rectangle.Height = rectangle.Height + 1;
                 num8++;
             }
             int anchorTop = tileData1.AnchorTop.checkStart;
             if (anchorTop < rectangle.X)
             {
                 rectangle.Width = rectangle.Width + (rectangle.X - anchorTop);
                 num7 = num7 + (rectangle.X - anchorTop);
                 rectangle.X = anchorTop;
             }
             int anchorTop1 = anchorTop + tileData1.AnchorTop.tileCount - 1;
             int num9 = rectangle.X + rectangle.Width - 1;
             if (anchorTop1 > num9)
             {
                 rectangle.Width = rectangle.Width + (anchorTop1 - num9);
             }
         }
         if (tileData1.AnchorBottom.tileCount != 0)
         {
             if (rectangle.Y + rectangle.Height == tileData1.Height)
             {
                 rectangle.Height = rectangle.Height + 1;
             }
             int anchorBottom = tileData1.AnchorBottom.checkStart;
             if (anchorBottom < rectangle.X)
             {
                 rectangle.Width = rectangle.Width + (rectangle.X - anchorBottom);
                 num7 = num7 + (rectangle.X - anchorBottom);
                 rectangle.X = anchorBottom;
             }
             int anchorBottom1 = anchorBottom + tileData1.AnchorBottom.tileCount - 1;
             int num10 = rectangle.X + rectangle.Width - 1;
             if (anchorBottom1 > num10)
             {
                 rectangle.Width = rectangle.Width + (anchorBottom1 - num10);
             }
         }
         if (tileData1.AnchorLeft.tileCount != 0)
         {
             if (rectangle.X == 0)
             {
                 rectangle.X = -1;
                 rectangle.Width = rectangle.Width + 1;
                 num7++;
             }
             int anchorLeft = tileData1.AnchorLeft.checkStart;
             if ((tileData1.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
             {
                 anchorLeft--;
             }
             if (anchorLeft < rectangle.Y)
             {
                 rectangle.Width = rectangle.Width + (rectangle.Y - anchorLeft);
                 num8 = num8 + (rectangle.Y - anchorLeft);
                 rectangle.Y = anchorLeft;
             }
             int anchorLeft1 = anchorLeft + tileData1.AnchorLeft.tileCount - 1;
             if ((tileData1.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
             {
                 anchorLeft1 = anchorLeft1 + 2;
             }
             int num11 = rectangle.Y + rectangle.Height - 1;
             if (anchorLeft1 > num11)
             {
                 rectangle.Height = rectangle.Height + (anchorLeft1 - num11);
             }
         }
         if (tileData1.AnchorRight.tileCount != 0)
         {
             if (rectangle.X + rectangle.Width == tileData1.Width)
             {
                 rectangle.Width = rectangle.Width + 1;
             }
             int anchorLeft2 = tileData1.AnchorLeft.checkStart;
             if ((tileData1.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
             {
                 anchorLeft2--;
             }
             if (anchorLeft2 < rectangle.Y)
             {
                 rectangle.Width = rectangle.Width + (rectangle.Y - anchorLeft2);
                 num8 = num8 + (rectangle.Y - anchorLeft2);
                 rectangle.Y = anchorLeft2;
             }
             int anchorRight = anchorLeft2 + tileData1.AnchorRight.tileCount - 1;
             if ((tileData1.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
             {
                 anchorRight = anchorRight + 2;
             }
             int num12 = rectangle.Y + rectangle.Height - 1;
             if (anchorRight > num12)
             {
                 rectangle.Height = rectangle.Height + (anchorRight - num12);
             }
         }
         if (onlyCheck)
         {
             TileObject.objectPreview.Reset();
             TileObject.objectPreview.Active = true;
             TileObject.objectPreview.Type = (ushort)type;
             TileObject.objectPreview.Style = (short)style;
             TileObject.objectPreview.Alternate = num4;
             TileObject.objectPreview.Size = new Point16(rectangle.Width, rectangle.Height);
             TileObject.objectPreview.ObjectStart = new Point16(num7, num8);
             TileObject.objectPreview.Coordinates = new Point16(num5 - num7, num6 - num8);
         }
         float single2 = 0f;
         float width = (float)(tileData1.Width * tileData1.Height);
         float single3 = 0f;
         float single4 = 0f;
         for (int i = 0; i < tileData1.Width; i++)
         {
             for (int j = 0; j < tileData1.Height; j++)
             {
                 tileSafely = Framing.GetTileSafely(num5 + i, num6 + j);
                 bool flag = !tileData1.LiquidPlace(tileSafely);
                 bool flag1 = false;
                 if (tileData1.AnchorWall)
                 {
                     single4 = single4 + 1f;
                     if (tileData1.isValidWallAnchor((int)tileSafely.wall))
                     {
                         single3 = single3 + 1f;
                     }
                     else
                     {
                         flag1 = true;
                     }
                 }
                 bool flag2 = false;
                 if (tileSafely.active() && !Main.tileCut[tileSafely.type])
                 {
                     flag2 = true;
                 }
                 if (!flag2 && !flag && !flag1)
                 {
                     if (onlyCheck)
                     {
                         TileObject.objectPreview[i + num7, j + num8] = 1;
                     }
                     single2 = single2 + 1f;
                 }
                 else if (onlyCheck)
                 {
                     TileObject.objectPreview[i + num7, j + num8] = 2;
                 }
             }
         }
         AnchorData anchorDatum = tileData1.AnchorBottom;
         if (anchorDatum.tileCount != 0)
         {
             single4 = single4 + (float)anchorDatum.tileCount;
             int height = tileData1.Height;
             for (int k = 0; k < anchorDatum.tileCount; k++)
             {
                 int num13 = anchorDatum.checkStart + k;
                 tileSafely = Framing.GetTileSafely(num5 + num13, num6 + height);
                 bool flag3 = false;
                 if (tileSafely.nactive())
                 {
                     if ((anchorDatum.type & AnchorType.SolidTile) == AnchorType.SolidTile && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData1.FlattenAnchors || tileSafely.blockType() == 0))
                     {
                         flag3 = tileData1.isValidTileAnchor((int)tileSafely.type);
                     }
                     if (!flag3 && ((anchorDatum.type & AnchorType.SolidWithTop) == AnchorType.SolidWithTop || (anchorDatum.type & AnchorType.Table) == AnchorType.Table))
                     {
                         if (tileSafely.type == 19)
                         {
                             int num14 = tileSafely.frameX / TileObjectData.PlatformFrameWidth();
                             if (!tileSafely.halfBrick() && num14 >= 0 && num14 <= 7 || num14 >= 12 && num14 <= 16 || num14 >= 25 && num14 <= 26)
                             {
                                 flag3 = true;
                             }
                         }
                         else if (Main.tileSolid[tileSafely.type] && Main.tileSolidTop[tileSafely.type])
                         {
                             flag3 = true;
                         }
                     }
                     if (!flag3 && (anchorDatum.type & AnchorType.Table) == AnchorType.Table && tileSafely.type != 19 && Main.tileTable[tileSafely.type] && tileSafely.blockType() == 0)
                     {
                         flag3 = true;
                     }
                     if (!flag3 && (anchorDatum.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                     {
                         switch (tileSafely.blockType())
                         {
                             case 4:
                             case 5:
                             {
                                 flag3 = tileData1.isValidTileAnchor((int)tileSafely.type);
                                 break;
                             }
                         }
                     }
                     if (!flag3 && (anchorDatum.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData1.isValidAlternateAnchor((int)tileSafely.type))
                     {
                         flag3 = true;
                     }
                 }
                 else if (!flag3 && (anchorDatum.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                 {
                     flag3 = true;
                 }
                 if (flag3)
                 {
                     if (onlyCheck)
                     {
                         TileObject.objectPreview[num13 + num7, height + num8] = 1;
                     }
                     single3 = single3 + 1f;
                 }
                 else if (onlyCheck)
                 {
                     TileObject.objectPreview[num13 + num7, height + num8] = 2;
                 }
             }
         }
         anchorDatum = tileData1.AnchorTop;
         if (anchorDatum.tileCount != 0)
         {
             single4 = single4 + (float)anchorDatum.tileCount;
             int num15 = -1;
             for (int l = 0; l < anchorDatum.tileCount; l++)
             {
                 int num16 = anchorDatum.checkStart + l;
                 tileSafely = Framing.GetTileSafely(num5 + num16, num6 + num15);
                 bool flag4 = false;
                 if (tileSafely.nactive())
                 {
                     if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData1.FlattenAnchors || tileSafely.blockType() == 0))
                     {
                         flag4 = tileData1.isValidTileAnchor((int)tileSafely.type);
                     }
                     if (!flag4 && (anchorDatum.type & AnchorType.SolidBottom) == AnchorType.SolidBottom && (Main.tileSolid[tileSafely.type] && (!Main.tileSolidTop[tileSafely.type] || tileSafely.type == 19 && (tileSafely.halfBrick() || tileSafely.topSlope())) || tileSafely.halfBrick() || tileSafely.topSlope()) && !tileSafely.bottomSlope())
                     {
                         flag4 = tileData1.isValidTileAnchor((int)tileSafely.type);
                     }
                     if (!flag4 && (anchorDatum.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                     {
                         switch (tileSafely.blockType())
                         {
                             case 2:
                             case 3:
                             {
                                 flag4 = tileData1.isValidTileAnchor((int)tileSafely.type);
                                 break;
                             }
                         }
                     }
                     if (!flag4 && (anchorDatum.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData1.isValidAlternateAnchor((int)tileSafely.type))
                     {
                         flag4 = true;
                     }
                 }
                 else if (!flag4 && (anchorDatum.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                 {
                     flag4 = true;
                 }
                 if (flag4)
                 {
                     if (onlyCheck)
                     {
                         TileObject.objectPreview[num16 + num7, num15 + num8] = 1;
                     }
                     single3 = single3 + 1f;
                 }
                 else if (onlyCheck)
                 {
                     TileObject.objectPreview[num16 + num7, num15 + num8] = 2;
                 }
             }
         }
         anchorDatum = tileData1.AnchorRight;
         if (anchorDatum.tileCount != 0)
         {
             single4 = single4 + (float)anchorDatum.tileCount;
             int width1 = tileData1.Width;
             for (int m = 0; m < anchorDatum.tileCount; m++)
             {
                 int num17 = anchorDatum.checkStart + m;
                 tileSafely = Framing.GetTileSafely(num5 + width1, num6 + num17);
                 bool flag5 = false;
                 if (tileSafely.nactive())
                 {
                     if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData1.FlattenAnchors || tileSafely.blockType() == 0))
                     {
                         flag5 = tileData1.isValidTileAnchor((int)tileSafely.type);
                     }
                     if (!flag5 && (anchorDatum.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                     {
                         switch (tileSafely.blockType())
                         {
                             case 2:
                             case 4:
                             {
                                 flag5 = tileData1.isValidTileAnchor((int)tileSafely.type);
                                 break;
                             }
                         }
                     }
                     if (!flag5 && (anchorDatum.type & AnchorType.Tree) == AnchorType.Tree && tileSafely.type == 5)
                     {
                         flag5 = true;
                         if (m == 0)
                         {
                             single4 = single4 + 1f;
                             Tile tile = Framing.GetTileSafely(num5 + width1, num6 + num17 - 1);
                             if (tile.nactive() && tile.type == 5)
                             {
                                 single3 = single3 + 1f;
                                 if (onlyCheck)
                                 {
                                     TileObject.objectPreview[width1 + num7, num17 + num8 - 1] = 1;
                                 }
                             }
                             else if (onlyCheck)
                             {
                                 TileObject.objectPreview[width1 + num7, num17 + num8 - 1] = 2;
                             }
                         }
                         if (m == anchorDatum.tileCount - 1)
                         {
                             single4 = single4 + 1f;
                             Tile tileSafely1 = Framing.GetTileSafely(num5 + width1, num6 + num17 + 1);
                             if (tileSafely1.nactive() && tileSafely1.type == 5)
                             {
                                 single3 = single3 + 1f;
                                 if (onlyCheck)
                                 {
                                     TileObject.objectPreview[width1 + num7, num17 + num8 + 1] = 1;
                                 }
                             }
                             else if (onlyCheck)
                             {
                                 TileObject.objectPreview[width1 + num7, num17 + num8 + 1] = 2;
                             }
                         }
                     }
                     if (!flag5 && (anchorDatum.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData1.isValidAlternateAnchor((int)tileSafely.type))
                     {
                         flag5 = true;
                     }
                 }
                 else if (!flag5 && (anchorDatum.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                 {
                     flag5 = true;
                 }
                 if (flag5)
                 {
                     if (onlyCheck)
                     {
                         TileObject.objectPreview[width1 + num7, num17 + num8] = 1;
                     }
                     single3 = single3 + 1f;
                 }
                 else if (onlyCheck)
                 {
                     TileObject.objectPreview[width1 + num7, num17 + num8] = 2;
                 }
             }
         }
         anchorDatum = tileData1.AnchorLeft;
         if (anchorDatum.tileCount != 0)
         {
             single4 = single4 + (float)anchorDatum.tileCount;
             int num18 = -1;
             for (int n = 0; n < anchorDatum.tileCount; n++)
             {
                 int num19 = anchorDatum.checkStart + n;
                 tileSafely = Framing.GetTileSafely(num5 + num18, num6 + num19);
                 bool flag6 = false;
                 if (tileSafely.nactive())
                 {
                     if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData1.FlattenAnchors || tileSafely.blockType() == 0))
                     {
                         flag6 = tileData1.isValidTileAnchor((int)tileSafely.type);
                     }
                     if (!flag6 && (anchorDatum.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                     {
                         switch (tileSafely.blockType())
                         {
                             case 3:
                             case 5:
                             {
                                 flag6 = tileData1.isValidTileAnchor((int)tileSafely.type);
                                 break;
                             }
                         }
                     }
                     if (!flag6 && (anchorDatum.type & AnchorType.Tree) == AnchorType.Tree && tileSafely.type == 5)
                     {
                         flag6 = true;
                         if (n == 0)
                         {
                             single4 = single4 + 1f;
                             Tile tile1 = Framing.GetTileSafely(num5 + num18, num6 + num19 - 1);
                             if (tile1.nactive() && tile1.type == 5)
                             {
                                 single3 = single3 + 1f;
                                 if (onlyCheck)
                                 {
                                     TileObject.objectPreview[num18 + num7, num19 + num8 - 1] = 1;
                                 }
                             }
                             else if (onlyCheck)
                             {
                                 TileObject.objectPreview[num18 + num7, num19 + num8 - 1] = 2;
                             }
                         }
                         if (n == anchorDatum.tileCount - 1)
                         {
                             single4 = single4 + 1f;
                             Tile tileSafely2 = Framing.GetTileSafely(num5 + num18, num6 + num19 + 1);
                             if (tileSafely2.nactive() && tileSafely2.type == 5)
                             {
                                 single3 = single3 + 1f;
                                 if (onlyCheck)
                                 {
                                     TileObject.objectPreview[num18 + num7, num19 + num8 + 1] = 1;
                                 }
                             }
                             else if (onlyCheck)
                             {
                                 TileObject.objectPreview[num18 + num7, num19 + num8 + 1] = 2;
                             }
                         }
                     }
                     if (!flag6 && (anchorDatum.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData1.isValidAlternateAnchor((int)tileSafely.type))
                     {
                         flag6 = true;
                     }
                 }
                 else if (!flag6 && (anchorDatum.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                 {
                     flag6 = true;
                 }
                 if (flag6)
                 {
                     if (onlyCheck)
                     {
                         TileObject.objectPreview[num18 + num7, num19 + num8] = 1;
                     }
                     single3 = single3 + 1f;
                 }
                 else if (onlyCheck)
                 {
                     TileObject.objectPreview[num18 + num7, num19 + num8] = 2;
                 }
             }
         }
         if (tileData1.HookCheck.hook != null)
         {
             if (tileData1.HookCheck.processedCoordinates)
             {
                 short num20 = tileData1.Origin.X;
                 short num21 = tileData1.Origin.Y;
             }
             if (tileData1.HookCheck.hook(x, y, type, style, dir) == tileData1.HookCheck.badReturn && tileData1.HookCheck.badResponse == 0)
             {
                 single3 = 0f;
                 single2 = 0f;
                 TileObject.objectPreview.AllInvalid();
             }
         }
         float single5 = single3 / single4;
         float single6 = single2 / width;
         if (single5 != 1f || single6 != 1f)
         {
             if (single5 <= single && (single5 != single || single6 <= single1))
             {
                 continue;
             }
             TileObjectPreviewData.placementCache.CopyFrom(TileObject.objectPreview);
             single = single5;
             single1 = single6;
             tileObjectDatum = tileData1;
             num3 = num4;
         }
         else
         {
             single = 1f;
             single1 = 1f;
             num3 = num4;
             tileObjectDatum = tileData1;
             break;
         }
     }
     int num22 = -1;
     if (randomStyleRange)
     {
         if (TileObjectPreviewData.randomCache == null)
         {
             TileObjectPreviewData.randomCache = new TileObjectPreviewData();
         }
         bool flag7 = false;
         if (TileObjectPreviewData.randomCache.Type != type)
         {
             flag7 = true;
         }
         else
         {
             Point16 coordinates = TileObjectPreviewData.randomCache.Coordinates;
             Point16 objectStart = TileObjectPreviewData.randomCache.ObjectStart;
             int num23 = coordinates.X + objectStart.X;
             int num24 = coordinates.Y + objectStart.Y;
             int num25 = x - tileData.Origin.X;
             int num26 = y - tileData.Origin.Y;
             if (num23 != num25 || num24 != num26)
             {
                 flag7 = true;
             }
         }
         num22 = (!flag7 ? TileObjectPreviewData.randomCache.Random : Main.rand.Next(tileData.RandomStyleRange));
     }
     if (onlyCheck)
     {
         if (single != 1f || single1 != 1f)
         {
             TileObject.objectPreview.CopyFrom(TileObjectPreviewData.placementCache);
             num4 = num3;
         }
         TileObject.objectPreview.Random = num22;
         if (tileData.RandomStyleRange > 0)
         {
             TileObjectPreviewData.randomCache.CopyFrom(TileObject.objectPreview);
         }
     }
     if (!onlyCheck)
     {
         objectData.xCoord = x - tileObjectDatum.Origin.X;
         objectData.yCoord = y - tileObjectDatum.Origin.Y;
         objectData.type = type;
         objectData.style = style;
         objectData.alternate = num4;
         objectData.random = num22;
     }
     if (single != 1f)
     {
         return false;
     }
     return single1 == 1f;
 }
Beispiel #15
0
 public void PlaceThing()
 {
     int i;
     bool flag;
     if ((this.inventory[this.selectedItem].type == 1071 || this.inventory[this.selectedItem].type == 1543) && this.position.X / 16f - (float)Player.tileRangeX - (float)this.inventory[this.selectedItem].tileBoost - (float)this.blockRange <= (float)Player.tileTargetX && (this.position.X + (float)this.width) / 16f + (float)Player.tileRangeX + (float)this.inventory[this.selectedItem].tileBoost - 1f + (float)this.blockRange >= (float)Player.tileTargetX && this.position.Y / 16f - (float)Player.tileRangeY - (float)this.inventory[this.selectedItem].tileBoost - (float)this.blockRange <= (float)Player.tileTargetY && (this.position.Y + (float)this.height) / 16f + (float)Player.tileRangeY + (float)this.inventory[this.selectedItem].tileBoost - 2f + (float)this.blockRange >= (float)Player.tileTargetY)
     {
         int num = Player.tileTargetX;
         int num1 = Player.tileTargetY;
         if (Main.tile[num, num1] != null && Main.tile[num, num1].active())
         {
             this.showItemIcon = true;
             if (this.itemTime == 0 && this.itemAnimation > 0 && this.controlUseItem)
             {
                 int num2 = -1;
                 int num3 = -1;
                 int num4 = 0;
                 while (num4 < 58)
                 {
                     if (this.inventory[num4].stack <= 0 || this.inventory[num4].paint <= 0)
                     {
                         num4++;
                     }
                     else
                     {
                         num2 = this.inventory[num4].paint;
                         num3 = num4;
                         break;
                     }
                 }
                 if (num2 > 0 && Main.tile[num, num1].color() != num2 && WorldGen.paintTile(num, num1, (byte)num2, true))
                 {
                     int num5 = num3;
                     Item item = this.inventory[num5];
                     item.stack = item.stack - 1;
                     if (this.inventory[num5].stack <= 0)
                     {
                         this.inventory[num5].SetDefaults(0, false);
                     }
                     this.itemTime = this.inventory[this.selectedItem].useTime;
                 }
             }
         }
     }
     if ((this.inventory[this.selectedItem].type == 1072 || this.inventory[this.selectedItem].type == 1544) && this.position.X / 16f - (float)Player.tileRangeX - (float)this.inventory[this.selectedItem].tileBoost - (float)this.blockRange <= (float)Player.tileTargetX && (this.position.X + (float)this.width) / 16f + (float)Player.tileRangeX + (float)this.inventory[this.selectedItem].tileBoost - 1f + (float)this.blockRange >= (float)Player.tileTargetX && this.position.Y / 16f - (float)Player.tileRangeY - (float)this.inventory[this.selectedItem].tileBoost - (float)this.blockRange <= (float)Player.tileTargetY && (this.position.Y + (float)this.height) / 16f + (float)Player.tileRangeY + (float)this.inventory[this.selectedItem].tileBoost - 2f + (float)this.blockRange >= (float)Player.tileTargetY)
     {
         int num6 = Player.tileTargetX;
         int num7 = Player.tileTargetY;
         if (Main.tile[num6, num7] != null && Main.tile[num6, num7].wall > 0)
         {
             this.showItemIcon = true;
             if (this.itemTime == 0 && this.itemAnimation > 0 && this.controlUseItem)
             {
                 int num8 = -1;
                 int num9 = -1;
                 int num10 = 0;
                 while (num10 < 58)
                 {
                     if (this.inventory[num10].stack <= 0 || this.inventory[num10].paint <= 0)
                     {
                         num10++;
                     }
                     else
                     {
                         num8 = this.inventory[num10].paint;
                         num9 = num10;
                         break;
                     }
                 }
                 if (num8 > 0 && Main.tile[num6, num7].wallColor() != num8 && WorldGen.paintWall(num6, num7, (byte)num8, true))
                 {
                     int num11 = num9;
                     Item item1 = this.inventory[num11];
                     item1.stack = item1.stack - 1;
                     if (this.inventory[num11].stack <= 0)
                     {
                         this.inventory[num11].SetDefaults(0, false);
                     }
                     this.itemTime = this.inventory[this.selectedItem].useTime;
                 }
             }
         }
     }
     if ((this.inventory[this.selectedItem].type == 1100 || this.inventory[this.selectedItem].type == 1545) && this.position.X / 16f - (float)Player.tileRangeX - (float)this.inventory[this.selectedItem].tileBoost - (float)this.blockRange <= (float)Player.tileTargetX && (this.position.X + (float)this.width) / 16f + (float)Player.tileRangeX + (float)this.inventory[this.selectedItem].tileBoost - 1f + (float)this.blockRange >= (float)Player.tileTargetX && this.position.Y / 16f - (float)Player.tileRangeY - (float)this.inventory[this.selectedItem].tileBoost - (float)this.blockRange <= (float)Player.tileTargetY && (this.position.Y + (float)this.height) / 16f + (float)Player.tileRangeY + (float)this.inventory[this.selectedItem].tileBoost - 2f + (float)this.blockRange >= (float)Player.tileTargetY)
     {
         int num12 = Player.tileTargetX;
         int num13 = Player.tileTargetY;
         if (Main.tile[num12, num13] != null && (Main.tile[num12, num13].wallColor() > 0 && Main.tile[num12, num13].wall > 0 || Main.tile[num12, num13].color() > 0 && Main.tile[num12, num13].active()))
         {
             this.showItemIcon = true;
             if (this.itemTime == 0 && this.itemAnimation > 0 && this.controlUseItem)
             {
                 if (Main.tile[num12, num13].color() > 0 && Main.tile[num12, num13].active() && WorldGen.paintTile(num12, num13, 0, true))
                 {
                     this.itemTime = this.inventory[this.selectedItem].useTime;
                 }
                 else if (Main.tile[num12, num13].wallColor() > 0 && Main.tile[num12, num13].wall > 0 && WorldGen.paintWall(num12, num13, 0, true))
                 {
                     this.itemTime = this.inventory[this.selectedItem].useTime;
                 }
             }
         }
     }
     if ((this.inventory[this.selectedItem].type == 929 || this.inventory[this.selectedItem].type == 1338 || this.inventory[this.selectedItem].type == 1345) && this.position.X / 16f - (float)Player.tileRangeX - (float)this.inventory[this.selectedItem].tileBoost - (float)this.blockRange <= (float)Player.tileTargetX && (this.position.X + (float)this.width) / 16f + (float)Player.tileRangeX + (float)this.inventory[this.selectedItem].tileBoost - 1f + (float)this.blockRange >= (float)Player.tileTargetX && this.position.Y / 16f - (float)Player.tileRangeY - (float)this.inventory[this.selectedItem].tileBoost - (float)this.blockRange <= (float)Player.tileTargetY && (this.position.Y + (float)this.height) / 16f + (float)Player.tileRangeY + (float)this.inventory[this.selectedItem].tileBoost - 2f + (float)this.blockRange >= (float)Player.tileTargetY)
     {
         int num14 = Player.tileTargetX;
         int num15 = Player.tileTargetY;
         if (Main.tile[num14, num15].active() && Main.tile[num14, num15].type == TileID.Cannon)
         {
             int num16 = 0;
             if (Main.tile[num14, num15].frameX < 72)
             {
                 if (this.inventory[this.selectedItem].type == 929)
                 {
                     num16 = 1;
                 }
             }
             else if (Main.tile[num14, num15].frameX < 144)
             {
                 if (this.inventory[this.selectedItem].type == 1338)
                 {
                     num16 = 2;
                 }
             }
             else if (Main.tile[num14, num15].frameX < 288 && this.inventory[this.selectedItem].type == 1345)
             {
                 num16 = 3;
             }
             if (num16 > 0)
             {
                 this.showItemIcon = true;
                 if (this.itemTime == 0 && this.itemAnimation > 0 && this.controlUseItem)
                 {
                     int num17 = Main.tile[num14, num15].frameX / 18;
                     int num18 = 0;
                     int num19 = 0;
                     while (num17 >= 4)
                     {
                         num18++;
                         num17 = num17 - 4;
                     }
                     num17 = num14 - num17;
                     for (i = Main.tile[num14, num15].frameY / 18; i >= 3; i = i - 3)
                     {
                         num19++;
                     }
                     i = num15 - i;
                     this.itemTime = this.inventory[this.selectedItem].useTime;
                     float single = 14f;
                     float single1 = 0f;
                     float single2 = 0f;
                     int num20 = 162;
                     if (num16 == 2)
                     {
                         num20 = 281;
                     }
                     if (num16 == 3)
                     {
                         num20 = 178;
                     }
                     int num21 = this.inventory[this.selectedItem].damage;
                     int num22 = 8;
                     if (num19 == 0)
                     {
                         single1 = 10f;
                         single2 = 0f;
                     }
                     if (num19 == 1)
                     {
                         single1 = 7.5f;
                         single2 = -2.5f;
                     }
                     if (num19 == 2)
                     {
                         single1 = 5f;
                         single2 = -5f;
                     }
                     if (num19 == 3)
                     {
                         single1 = 2.75f;
                         single2 = -6f;
                     }
                     if (num19 == 4)
                     {
                         single1 = 0f;
                         single2 = -10f;
                     }
                     if (num19 == 5)
                     {
                         single1 = -2.75f;
                         single2 = -6f;
                     }
                     if (num19 == 6)
                     {
                         single1 = -5f;
                         single2 = -5f;
                     }
                     if (num19 == 7)
                     {
                         single1 = -7.5f;
                         single2 = -2.5f;
                     }
                     if (num19 == 8)
                     {
                         single1 = -10f;
                         single2 = 0f;
                     }
                     Vector2 vector2 = new Vector2((float)((num17 + 2) * 16), (float)((i + 2) * 16));
                     float single3 = single1;
                     float single4 = single2;
                     float single5 = (float)Math.Sqrt((double)(single3 * single3 + single4 * single4));
                     single5 = single / single5;
                     single3 = single3 * single5;
                     single4 = single4 * single5;
                     Projectile.NewProjectile(vector2.X, vector2.Y, single3, single4, num20, num21, (float)num22, Main.myPlayer, 0f, 0f);
                 }
             }
         }
     }
     if (this.inventory[this.selectedItem].type >= 1874 && this.inventory[this.selectedItem].type <= 1905 && Main.tile[Player.tileTargetX, Player.tileTargetY].active() && Main.tile[Player.tileTargetX, Player.tileTargetY].type == 171 && this.position.X / 16f - (float)Player.tileRangeX - (float)this.inventory[this.selectedItem].tileBoost - (float)this.blockRange <= (float)Player.tileTargetX && (this.position.X + (float)this.width) / 16f + (float)Player.tileRangeX + (float)this.inventory[this.selectedItem].tileBoost - 1f + (float)this.blockRange >= (float)Player.tileTargetX && this.position.Y / 16f - (float)Player.tileRangeY - (float)this.inventory[this.selectedItem].tileBoost - (float)this.blockRange <= (float)Player.tileTargetY && (this.position.Y + (float)this.height) / 16f + (float)Player.tileRangeY + (float)this.inventory[this.selectedItem].tileBoost - 2f + (float)this.blockRange >= (float)Player.tileTargetY && this.itemTime == 0 && this.itemAnimation > 0 && this.controlUseItem)
     {
         int num23 = this.inventory[this.selectedItem].type;
         if (num23 >= 1874 && num23 <= 1877)
         {
             num23 = num23 - 1873;
             if (WorldGen.checkXmasTreeDrop(Player.tileTargetX, Player.tileTargetY, 0) != num23)
             {
                 this.itemTime = this.inventory[this.selectedItem].useTime;
                 WorldGen.dropXmasTree(Player.tileTargetX, Player.tileTargetY, 0);
                 WorldGen.setXmasTree(Player.tileTargetX, Player.tileTargetY, 0, num23);
                 int num24 = Player.tileTargetX;
                 int num25 = Player.tileTargetY;
                 if (Main.tile[Player.tileTargetX, Player.tileTargetY].frameX < 10)
                 {
                     num24 = num24 - Main.tile[Player.tileTargetX, Player.tileTargetY].frameX;
                     num25 = num25 - Main.tile[Player.tileTargetX, Player.tileTargetY].frameY;
                 }
                 NetMessage.SendTileSquare(-1, num24, num25, 1);
             }
         }
         else if (num23 >= 1878 && num23 <= 1883)
         {
             num23 = num23 - 1877;
             if (WorldGen.checkXmasTreeDrop(Player.tileTargetX, Player.tileTargetY, 1) != num23)
             {
                 this.itemTime = this.inventory[this.selectedItem].useTime;
                 WorldGen.dropXmasTree(Player.tileTargetX, Player.tileTargetY, 1);
                 WorldGen.setXmasTree(Player.tileTargetX, Player.tileTargetY, 1, num23);
                 int num26 = Player.tileTargetX;
                 int num27 = Player.tileTargetY;
                 if (Main.tile[Player.tileTargetX, Player.tileTargetY].frameX < 10)
                 {
                     num26 = num26 - Main.tile[Player.tileTargetX, Player.tileTargetY].frameX;
                     num27 = num27 - Main.tile[Player.tileTargetX, Player.tileTargetY].frameY;
                 }
                 NetMessage.SendTileSquare(-1, num26, num27, 1);
             }
         }
         else if (num23 >= 1884 && num23 <= 1894)
         {
             num23 = num23 - 1883;
             if (WorldGen.checkXmasTreeDrop(Player.tileTargetX, Player.tileTargetY, 2) != num23)
             {
                 this.itemTime = this.inventory[this.selectedItem].useTime;
                 WorldGen.dropXmasTree(Player.tileTargetX, Player.tileTargetY, 2);
                 WorldGen.setXmasTree(Player.tileTargetX, Player.tileTargetY, 2, num23);
                 int num28 = Player.tileTargetX;
                 int num29 = Player.tileTargetY;
                 if (Main.tile[Player.tileTargetX, Player.tileTargetY].frameX < 10)
                 {
                     num28 = num28 - Main.tile[Player.tileTargetX, Player.tileTargetY].frameX;
                     num29 = num29 - Main.tile[Player.tileTargetX, Player.tileTargetY].frameY;
                 }
                 NetMessage.SendTileSquare(-1, num28, num29, 1);
             }
         }
         else if (num23 >= 1895 && num23 <= 1905)
         {
             num23 = num23 - 1894;
             if (WorldGen.checkXmasTreeDrop(Player.tileTargetX, Player.tileTargetY, 3) != num23)
             {
                 this.itemTime = this.inventory[this.selectedItem].useTime;
                 WorldGen.dropXmasTree(Player.tileTargetX, Player.tileTargetY, 3);
                 WorldGen.setXmasTree(Player.tileTargetX, Player.tileTargetY, 3, num23);
                 int num30 = Player.tileTargetX;
                 int num31 = Player.tileTargetY;
                 if (Main.tile[Player.tileTargetX, Player.tileTargetY].frameX < 10)
                 {
                     num30 = num30 - Main.tile[Player.tileTargetX, Player.tileTargetY].frameX;
                     num31 = num31 - Main.tile[Player.tileTargetX, Player.tileTargetY].frameY;
                 }
                 NetMessage.SendTileSquare(-1, num30, num31, 1);
             }
         }
     }
     if (ItemID.Sets.ExtractinatorMode[this.inventory[this.selectedItem].type] >= 0 && Main.tile[Player.tileTargetX, Player.tileTargetY].active() && Main.tile[Player.tileTargetX, Player.tileTargetY].type == 219)
     {
         if (this.position.X / 16f - (float)Player.tileRangeX - (float)this.inventory[this.selectedItem].tileBoost - (float)this.blockRange <= (float)Player.tileTargetX && (this.position.X + (float)this.width) / 16f + (float)Player.tileRangeX + (float)this.inventory[this.selectedItem].tileBoost - 1f + (float)this.blockRange >= (float)Player.tileTargetX && this.position.Y / 16f - (float)Player.tileRangeY - (float)this.inventory[this.selectedItem].tileBoost - (float)this.blockRange <= (float)Player.tileTargetY && (this.position.Y + (float)this.height) / 16f + (float)Player.tileRangeY + (float)this.inventory[this.selectedItem].tileBoost - 2f + (float)this.blockRange >= (float)Player.tileTargetY && this.itemTime == 0 && this.itemAnimation > 0 && this.controlUseItem)
         {
             this.itemTime = this.inventory[this.selectedItem].useTime;
             int extractinatorMode = ItemID.Sets.ExtractinatorMode[this.inventory[this.selectedItem].type];
             Player.ExtractinatorUse(extractinatorMode);
         }
     }
     else if (this.inventory[this.selectedItem].createTile >= 0 && this.position.X / 16f - (float)Player.tileRangeX - (float)this.inventory[this.selectedItem].tileBoost - (float)this.blockRange <= (float)Player.tileTargetX && (this.position.X + (float)this.width) / 16f + (float)Player.tileRangeX + (float)this.inventory[this.selectedItem].tileBoost - 1f + (float)this.blockRange >= (float)Player.tileTargetX && this.position.Y / 16f - (float)Player.tileRangeY - (float)this.inventory[this.selectedItem].tileBoost - (float)this.blockRange <= (float)Player.tileTargetY && (this.position.Y + (float)this.height) / 16f + (float)Player.tileRangeY + (float)this.inventory[this.selectedItem].tileBoost - 2f + (float)this.blockRange >= (float)Player.tileTargetY)
     {
         this.showItemIcon = true;
         bool flag1 = false;
         if (Main.tile[Player.tileTargetX, Player.tileTargetY].liquid > 0 && Main.tile[Player.tileTargetX, Player.tileTargetY].lava())
         {
             if (Main.tileSolid[this.inventory[this.selectedItem].createTile])
             {
                 flag1 = true;
             }
             else if (!TileObjectData.CheckLiquidPlacement(this.inventory[this.selectedItem].createTile, this.inventory[this.selectedItem].placeStyle, Main.tile[Player.tileTargetX, Player.tileTargetY]))
             {
                 flag1 = true;
             }
         }
         bool flag2 = true;
         if (this.inventory[this.selectedItem].tileWand > 0)
         {
             int num32 = this.inventory[this.selectedItem].tileWand;
             flag2 = false;
             int num33 = 0;
             while (num33 < 58)
             {
                 if (num32 != this.inventory[num33].type || this.inventory[num33].stack <= 0)
                 {
                     num33++;
                 }
                 else
                 {
                     flag2 = true;
                     break;
                 }
             }
         }
         if (Main.tileRope[this.inventory[this.selectedItem].createTile] && flag2 && Main.tile[Player.tileTargetX, Player.tileTargetY].active() && Main.tileRope[Main.tile[Player.tileTargetX, Player.tileTargetY].type])
         {
             int num34 = Player.tileTargetY;
             int num35 = Player.tileTargetX;
             int num36 = this.inventory[this.selectedItem].createTile;
             while (Main.tile[num35, num34].active() && Main.tileRope[Main.tile[num35, num34].type] && num34 < Main.maxTilesX - 5 && Main.tile[num35, num34 + 2] != null && !Main.tile[num35, num34 + 1].lava())
             {
                 num34++;
                 if (Main.tile[num35, num34] != null)
                 {
                     continue;
                 }
                 flag2 = false;
                 num34 = Player.tileTargetY;
             }
             if (!Main.tile[num35, num34].active())
             {
                 Player.tileTargetY = num34;
             }
         }
         if (flag2 && (!Main.tile[Player.tileTargetX, Player.tileTargetY].active() && !flag1 || Main.tileCut[Main.tile[Player.tileTargetX, Player.tileTargetY].type] || Main.tile[Player.tileTargetX, Player.tileTargetY].type >= 373 && Main.tile[Player.tileTargetX, Player.tileTargetY].type <= 375 || this.inventory[this.selectedItem].createTile == 199 || this.inventory[this.selectedItem].createTile == 23 || this.inventory[this.selectedItem].createTile == 2 || this.inventory[this.selectedItem].createTile == 109 || this.inventory[this.selectedItem].createTile == 60 || this.inventory[this.selectedItem].createTile == 70 || TileID.Sets.BreakableWhenPlacing[Main.tile[Player.tileTargetX, Player.tileTargetY].type]) && this.itemTime == 0 && this.itemAnimation > 0 && this.controlUseItem)
         {
             bool flag3 = false;
             bool flag4 = false;
             TileObject tileObject = new TileObject();
             if (!TileObjectData.CustomPlace(this.inventory[this.selectedItem].createTile, this.inventory[this.selectedItem].placeStyle) || this.inventory[this.selectedItem].createTile == 82)
             {
                 if (this.inventory[this.selectedItem].type == 213)
                 {
                     if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 0 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 1)
                     {
                         flag3 = true;
                     }
                 }
                 else if (this.inventory[this.selectedItem].createTile == 23 || this.inventory[this.selectedItem].createTile == 2 || this.inventory[this.selectedItem].createTile == 109 || this.inventory[this.selectedItem].createTile == 199)
                 {
                     if (Main.tile[Player.tileTargetX, Player.tileTargetY].nactive() && Main.tile[Player.tileTargetX, Player.tileTargetY].type == 0)
                     {
                         flag3 = true;
                     }
                 }
                 else if (this.inventory[this.selectedItem].createTile == 227)
                 {
                     flag3 = true;
                 }
                 else if (this.inventory[this.selectedItem].createTile >= 373 && this.inventory[this.selectedItem].createTile <= 375)
                 {
                     int num37 = Player.tileTargetX;
                     int num38 = Player.tileTargetY - 1;
                     if (Main.tile[num37, num38].nactive() && Main.tileSolid[Main.tile[num37, num38].type] && !Main.tileSolidTop[Main.tile[num37, num38].type])
                     {
                         flag3 = true;
                     }
                 }
                 else if (this.inventory[this.selectedItem].createTile == 60 || this.inventory[this.selectedItem].createTile == 70)
                 {
                     if (Main.tile[Player.tileTargetX, Player.tileTargetY].nactive() && Main.tile[Player.tileTargetX, Player.tileTargetY].type == 59)
                     {
                         flag3 = true;
                     }
                 }
                 else if (this.inventory[this.selectedItem].createTile == 4 || this.inventory[this.selectedItem].createTile == 136)
                 {
                     if (Main.tile[Player.tileTargetX, Player.tileTargetY].wall <= 0)
                     {
                         if (!WorldGen.SolidTileNoAttach(Player.tileTargetX, Player.tileTargetY + 1) && !WorldGen.SolidTileNoAttach(Player.tileTargetX - 1, Player.tileTargetY) && !WorldGen.SolidTileNoAttach(Player.tileTargetX + 1, Player.tileTargetY))
                         {
                             if (!WorldGen.SolidTileNoAttach(Player.tileTargetX, Player.tileTargetY + 1) && (Main.tile[Player.tileTargetX, Player.tileTargetY + 1].halfBrick() || Main.tile[Player.tileTargetX, Player.tileTargetY + 1].slope() != 0))
                             {
                                 if (Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type != 19)
                                 {
                                     WorldGen.SlopeTile(Player.tileTargetX, Player.tileTargetY + 1, 0);
                                     if (Main.netMode == 1)
                                     {
                                         NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 14, (float)Player.tileTargetX, (float)(Player.tileTargetY + 1), 0f, 0, 0, 0);
                                     }
                                 }
                             }
                             else if (!WorldGen.SolidTileNoAttach(Player.tileTargetX, Player.tileTargetY + 1) && !WorldGen.SolidTileNoAttach(Player.tileTargetX - 1, Player.tileTargetY) && (Main.tile[Player.tileTargetX - 1, Player.tileTargetY].halfBrick() || Main.tile[Player.tileTargetX - 1, Player.tileTargetY].slope() != 0))
                             {
                                 if (Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type != 19)
                                 {
                                     WorldGen.SlopeTile(Player.tileTargetX - 1, Player.tileTargetY, 0);
                                     if (Main.netMode == 1)
                                     {
                                         NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 14, (float)(Player.tileTargetX - 1), (float)Player.tileTargetY, 0f, 0, 0, 0);
                                     }
                                 }
                             }
                             else if (!WorldGen.SolidTileNoAttach(Player.tileTargetX, Player.tileTargetY + 1) && !WorldGen.SolidTileNoAttach(Player.tileTargetX - 1, Player.tileTargetY) && !WorldGen.SolidTileNoAttach(Player.tileTargetX + 1, Player.tileTargetY) && (Main.tile[Player.tileTargetX + 1, Player.tileTargetY].halfBrick() || Main.tile[Player.tileTargetX + 1, Player.tileTargetY].slope() != 0) && Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type != 19)
                             {
                                 WorldGen.SlopeTile(Player.tileTargetX + 1, Player.tileTargetY, 0);
                                 if (Main.netMode == 1)
                                 {
                                     NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 14, (float)(Player.tileTargetX + 1), (float)Player.tileTargetY, 0f, 0, 0, 0);
                                 }
                             }
                         }
                         int num39 = Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type;
                         if (Main.tile[Player.tileTargetX, Player.tileTargetY].halfBrick())
                         {
                             num39 = -1;
                         }
                         int num40 = Main.tile[Player.tileTargetX - 1, Player.tileTargetY].type;
                         int num41 = Main.tile[Player.tileTargetX + 1, Player.tileTargetY].type;
                         int num42 = Main.tile[Player.tileTargetX - 1, Player.tileTargetY - 1].type;
                         int num43 = Main.tile[Player.tileTargetX + 1, Player.tileTargetY - 1].type;
                         int num44 = Main.tile[Player.tileTargetX - 1, Player.tileTargetY - 1].type;
                         int num45 = Main.tile[Player.tileTargetX + 1, Player.tileTargetY + 1].type;
                         if (!Main.tile[Player.tileTargetX, Player.tileTargetY + 1].nactive())
                         {
                             num39 = -1;
                         }
                         if (!Main.tile[Player.tileTargetX - 1, Player.tileTargetY].nactive())
                         {
                             num40 = -1;
                         }
                         if (!Main.tile[Player.tileTargetX + 1, Player.tileTargetY].nactive())
                         {
                             num41 = -1;
                         }
                         if (!Main.tile[Player.tileTargetX - 1, Player.tileTargetY - 1].nactive())
                         {
                             num42 = -1;
                         }
                         if (!Main.tile[Player.tileTargetX + 1, Player.tileTargetY - 1].nactive())
                         {
                             num43 = -1;
                         }
                         if (!Main.tile[Player.tileTargetX - 1, Player.tileTargetY + 1].nactive())
                         {
                             num44 = -1;
                         }
                         if (!Main.tile[Player.tileTargetX + 1, Player.tileTargetY + 1].nactive())
                         {
                             num45 = -1;
                         }
                         if (num39 >= 0 && Main.tileSolid[num39] && (!Main.tileNoAttach[num39] || num39 == 19))
                         {
                             flag3 = true;
                         }
                         else if (num40 >= 0 && Main.tileSolid[num40] && !Main.tileNoAttach[num40] || num40 == 5 && num42 == 5 && num44 == 5 || num40 == 124)
                         {
                             flag3 = true;
                         }
                         else if (num41 >= 0 && Main.tileSolid[num41] && !Main.tileNoAttach[num41] || num41 == 5 && num43 == 5 && num45 == 5 || num41 == 124)
                         {
                             flag3 = true;
                         }
                     }
                     else
                     {
                         flag3 = true;
                     }
                 }
                 else if (this.inventory[this.selectedItem].createTile == 78 || this.inventory[this.selectedItem].createTile == 98 || this.inventory[this.selectedItem].createTile == 100 || this.inventory[this.selectedItem].createTile == 173 || this.inventory[this.selectedItem].createTile == 174 || this.inventory[this.selectedItem].createTile == 324)
                 {
                     if (Main.tile[Player.tileTargetX, Player.tileTargetY + 1].nactive() && (Main.tileSolid[Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type] || Main.tileTable[Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type]))
                     {
                         flag3 = true;
                     }
                 }
                 else if (this.inventory[this.selectedItem].createTile == 13 || this.inventory[this.selectedItem].createTile == 29 || this.inventory[this.selectedItem].createTile == 33 || this.inventory[this.selectedItem].createTile == 49 || this.inventory[this.selectedItem].createTile == 50 || this.inventory[this.selectedItem].createTile == 103)
                 {
                     if (Main.tile[Player.tileTargetX, Player.tileTargetY + 1].nactive() && Main.tileTable[Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type])
                     {
                         flag3 = true;
                     }
                 }
                 else if (this.inventory[this.selectedItem].createTile == 275 || this.inventory[this.selectedItem].createTile == 276 || this.inventory[this.selectedItem].createTile == 277)
                 {
                     flag3 = true;
                 }
                 else if (this.inventory[this.selectedItem].createTile != 51 && this.inventory[this.selectedItem].createTile != 330 && this.inventory[this.selectedItem].createTile != 331 && this.inventory[this.selectedItem].createTile != 332 && this.inventory[this.selectedItem].createTile != 333 && this.inventory[this.selectedItem].createTile != 336 && this.inventory[this.selectedItem].createTile != 340 && this.inventory[this.selectedItem].createTile != 342 && this.inventory[this.selectedItem].createTile != 341 && this.inventory[this.selectedItem].createTile != 343 && this.inventory[this.selectedItem].createTile != 344 && this.inventory[this.selectedItem].createTile != 379 && this.inventory[this.selectedItem].createTile != 351)
                 {
                     if (this.inventory[this.selectedItem].createTile != 314)
                     {
                         Tile tile = Main.tile[Player.tileTargetX - 1, Player.tileTargetY];
                         Tile tile1 = Main.tile[Player.tileTargetX + 1, Player.tileTargetY];
                         Tile tile2 = Main.tile[Player.tileTargetX, Player.tileTargetY - 1];
                         Tile tile3 = Main.tile[Player.tileTargetX, Player.tileTargetY + 1];
                         if (tile1.active() && (Main.tileSolid[tile1.type] || Main.tileRope[tile1.type] || tile1.type == 314) || tile1.wall > 0 || tile.active() && (Main.tileSolid[tile.type] || Main.tileRope[tile.type] || tile.type == TileID.MinecartTrack) || tile.wall > 0 || tile3.active() && (Main.tileSolid[tile3.type] || tile3.type == 124 || Main.tileRope[tile3.type] || tile3.type == 314) || tile3.wall > 0 || tile2.active() && (Main.tileSolid[tile2.type] || tile2.type == 124 || Main.tileRope[tile2.type] || tile2.type == 314) || tile2.wall > 0)
                         {
                             flag3 = true;
                         }
                     }
                     else
                     {
                         for (int j = Player.tileTargetX - 1; j <= Player.tileTargetX + 1; j++)
                         {
                             int num46 = Player.tileTargetY - 1;
                             while (num46 <= Player.tileTargetY + 1)
                             {
                                 Tile tile4 = Main.tile[j, num46];
                                 if (tile4.active() || tile4.wall > 0)
                                 {
                                     flag3 = true;
                                     break;
                                 }
                                 else
                                 {
                                     num46++;
                                 }
                             }
                         }
                     }
                 }
                 else if (Main.tile[Player.tileTargetX + 1, Player.tileTargetY].active() || Main.tile[Player.tileTargetX + 1, Player.tileTargetY].wall > 0 || Main.tile[Player.tileTargetX - 1, Player.tileTargetY].active() || Main.tile[Player.tileTargetX - 1, Player.tileTargetY].wall > 0 || Main.tile[Player.tileTargetX, Player.tileTargetY + 1].active() || Main.tile[Player.tileTargetX, Player.tileTargetY + 1].wall > 0 || Main.tile[Player.tileTargetX, Player.tileTargetY - 1].active() || Main.tile[Player.tileTargetX, Player.tileTargetY - 1].wall > 0)
                 {
                     flag3 = true;
                 }
                 if (this.inventory[this.selectedItem].type == 213 && Main.tile[Player.tileTargetX, Player.tileTargetY].active())
                 {
                     int num47 = Player.tileTargetX;
                     int num48 = Player.tileTargetY;
                     if (Main.tile[num47, num48].type == TileID.Plants || Main.tile[num47, num48].type == TileID.Plants2 || Main.tile[num47, num48].type == TileID.BloomingHerbs)
                     {
                         WorldGen.KillTile(Player.tileTargetX, Player.tileTargetY, false, false, false);
                         if (!Main.tile[Player.tileTargetX, Player.tileTargetY].active() && Main.netMode == 1)
                         {
                             NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 0, (float)Player.tileTargetX, (float)Player.tileTargetY, 0f, 0, 0, 0);
                         }
                     }
                     else if (Main.tile[num47, num48].type == TileID.MatureHerbs)
                     {
                         bool flag5 = false;
                         int num49 = Main.tile[num47, num48].frameX / 18;
                         if (num49 == 0 && Main.dayTime)
                         {
                             flag5 = true;
                         }
                         if (num49 == 1 && !Main.dayTime)
                         {
                             flag5 = true;
                         }
                         if (num49 == 3 && !Main.dayTime && (Main.bloodMoon || Main.moonPhase == 0))
                         {
                             flag5 = true;
                         }
                         if (num49 == 4 && (Main.raining || Main.cloudAlpha > 0f))
                         {
                             flag5 = true;
                         }
                         if (num49 == 5 && !Main.raining && Main.dayTime && Main.time > 40500)
                         {
                             flag5 = true;
                         }
                         if (flag5)
                         {
                             WorldGen.KillTile(Player.tileTargetX, Player.tileTargetY, false, false, false);
                             NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 0, (float)Player.tileTargetX, (float)Player.tileTargetY, 0f, 0, 0, 0);
                         }
                     }
                 }
                 if (Main.tileAlch[this.inventory[this.selectedItem].createTile])
                 {
                     flag3 = true;
                 }
                 if (Main.tile[Player.tileTargetX, Player.tileTargetY].active() && (Main.tileCut[Main.tile[Player.tileTargetX, Player.tileTargetY].type] || TileID.Sets.BreakableWhenPlacing[Main.tile[Player.tileTargetX, Player.tileTargetY].type] || Main.tile[Player.tileTargetX, Player.tileTargetY].type >= 373 && Main.tile[Player.tileTargetX, Player.tileTargetY].type <= 375))
                 {
                     if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == this.inventory[this.selectedItem].createTile)
                     {
                         flag3 = false;
                     }
                     else if ((Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type == 78 || Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type == 380) && (Main.tile[Player.tileTargetX, Player.tileTargetY].type != 3 && Main.tile[Player.tileTargetX, Player.tileTargetY].type != 73 || !Main.tileAlch[this.inventory[this.selectedItem].createTile]))
                     {
                         flag3 = false;
                     }
                     else
                     {
                         WorldGen.KillTile(Player.tileTargetX, Player.tileTargetY, false, false, false);
                         if (!Main.tile[Player.tileTargetX, Player.tileTargetY].active() && Main.netMode == 1)
                         {
                             NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 4, (float)Player.tileTargetX, (float)Player.tileTargetY, 0f, 0, 0, 0);
                         }
                     }
                 }
                 if (!flag3 && this.inventory[this.selectedItem].createTile == 19)
                 {
                     for (int k = Player.tileTargetX - 1; k <= Player.tileTargetX + 1; k++)
                     {
                         int num50 = Player.tileTargetY - 1;
                         while (num50 <= Player.tileTargetY + 1)
                         {
                             if (!Main.tile[k, num50].active())
                             {
                                 num50++;
                             }
                             else
                             {
                                 flag3 = true;
                                 break;
                             }
                         }
                     }
                 }
             }
             else
             {
                 flag4 = true;
                 flag3 = TileObject.CanPlace(Player.tileTargetX, Player.tileTargetY, (int)this.inventory[this.selectedItem].createTile, this.inventory[this.selectedItem].placeStyle, this.direction, out tileObject, false);
             }
             if (flag3)
             {
                 int num51 = this.inventory[this.selectedItem].placeStyle;
                 if (!flag4)
                 {
                     if (this.inventory[this.selectedItem].createTile == 36)
                     {
                         num51 = Main.rand.Next(7);
                     }
                     if (this.inventory[this.selectedItem].createTile == 212 && this.direction > 0)
                     {
                         num51 = 1;
                     }
                     if (this.inventory[this.selectedItem].createTile == 141)
                     {
                         num51 = Main.rand.Next(2);
                     }
                     if (this.inventory[this.selectedItem].createTile == 128 || this.inventory[this.selectedItem].createTile == 269 || this.inventory[this.selectedItem].createTile == 334)
                     {
                         num51 = (this.direction >= 0 ? 1 : -1);
                     }
                     if (this.inventory[this.selectedItem].createTile == 241 && this.inventory[this.selectedItem].placeStyle == 0)
                     {
                         num51 = Main.rand.Next(0, 9);
                     }
                     if (this.inventory[this.selectedItem].createTile == 35 && this.inventory[this.selectedItem].placeStyle == 0)
                     {
                         num51 = Main.rand.Next(9);
                     }
                 }
                 if (this.inventory[this.selectedItem].createTile == 314 && num51 == 2 && this.direction == 1)
                 {
                     num51++;
                 }
                 int[,] numArray = new int[11, 11];
                 if (this.autoPaint)
                 {
                     for (int l = 0; l < 11; l++)
                     {
                         for (int m = 0; m < 11; m++)
                         {
                             int num52 = Player.tileTargetX - 5 + l;
                             int num53 = Player.tileTargetY - 5 + m;
                             if (!Main.tile[num52, num53].active())
                             {
                                 numArray[l, m] = -1;
                             }
                             else
                             {
                                 numArray[l, m] = Main.tile[num52, num53].type;
                             }
                         }
                     }
                 }
                 bool flag6 = false;
                 if (!flag4)
                 {
                     flag = WorldGen.PlaceTile(Player.tileTargetX, Player.tileTargetY, this.inventory[this.selectedItem].createTile, false, flag6, this.whoAmI, num51);
                 }
                 else
                 {
                     flag = TileObject.Place(tileObject);
                     WorldGen.SquareTileFrame(Player.tileTargetX, Player.tileTargetY, true);
                 }
                 if (this.inventory[this.selectedItem].type == 213 && !flag && Main.tile[Player.tileTargetX, Player.tileTargetY].type == 1 && Main.tile[Player.tileTargetX, Player.tileTargetY].active())
                 {
                     int key = 0;
                     int value = 0;
                     Point tileCoordinates = base.Center.ToTileCoordinates();
                     Dictionary<ushort, int> nums = new Dictionary<ushort, int>();
                     Point point = new Point(tileCoordinates.X - 25, tileCoordinates.Y - 25);
                     Shapes.Rectangle rectangle = new Shapes.Rectangle(50, 50);
                     ushort[] numArray1 = new ushort[] { 182, 180, 179, 183, 181, 381 };
                     WorldUtils.Gen(point, rectangle, (new Actions.TileScanner(numArray1)).Output(nums));
                     foreach (KeyValuePair<ushort, int> keyValuePair in nums)
                     {
                         if (keyValuePair.Value <= value)
                         {
                             continue;
                         }
                         value = keyValuePair.Value;
                         key = keyValuePair.Key;
                     }
                     if (value == 0)
                     {
                         Random random = Main.rand;
                         int[] numArray2 = new int[] { 182, 180, 179, 183, 181 };
                         key = Terraria.Utils.SelectRandom<int>(random, numArray2);
                     }
                     if (key != 0)
                     {
                         Main.tile[Player.tileTargetX, Player.tileTargetY].type = (ushort)key;
                         WorldGen.SquareTileFrame(Player.tileTargetX, Player.tileTargetY, true);
                         flag = true;
                     }
                 }
                 if (flag)
                 {
                     this.itemTime = (int)((float)this.inventory[this.selectedItem].useTime * this.tileSpeed);
                     if (!flag4)
                     {
                         NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 1, (float)Player.tileTargetX, (float)Player.tileTargetY, (float)this.inventory[this.selectedItem].createTile, num51, 0, 0);
                         if (this.inventory[this.selectedItem].createTile == 15)
                         {
                             if (this.direction == 1)
                             {
                                 Tile tile5 = Main.tile[Player.tileTargetX, Player.tileTargetY];
                                 tile5.frameX = (short)(tile5.frameX + 18);
                                 Tile tile6 = Main.tile[Player.tileTargetX, Player.tileTargetY - 1];
                                 tile6.frameX = (short)(tile6.frameX + 18);
                             }
                             if (Main.netMode == 1)
                             {
                                 NetMessage.SendTileSquare(-1, Player.tileTargetX - 1, Player.tileTargetY - 1, 3);
                             }
                         }
                         else if ((this.inventory[this.selectedItem].createTile == 79 || this.inventory[this.selectedItem].createTile == 90) && Main.netMode == 1)
                         {
                             NetMessage.SendTileSquare(-1, Player.tileTargetX, Player.tileTargetY, 5);
                         }
                     }
                     else
                     {
                         TileObjectData.CallPostPlacementPlayerHook(Player.tileTargetX, Player.tileTargetY, this.inventory[this.selectedItem].createTile, num51, this.direction, tileObject);
                         if (Main.netMode == 1 && !Main.tileContainer[this.inventory[this.selectedItem].createTile])
                         {
                             NetMessage.SendObjectPlacment(-1, Player.tileTargetX, Player.tileTargetY, tileObject.type, tileObject.style, tileObject.alternate, tileObject.random, this.direction);
                         }
                     }
                     if (this.inventory[this.selectedItem].createTile == 137)
                     {
                         if (this.direction == 1)
                         {
                             Tile tile7 = Main.tile[Player.tileTargetX, Player.tileTargetY];
                             tile7.frameX = (short)(tile7.frameX + 18);
                         }
                         if (Main.netMode == 1)
                         {
                             NetMessage.SendTileSquare(-1, Player.tileTargetX, Player.tileTargetY, 1);
                         }
                     }
                     if (this.inventory[this.selectedItem].createTile == 19 && Main.smartDigEnabled)
                     {
                         int num54 = Player.tileTargetX;
                         int num55 = Player.tileTargetY;
                         int num56 = -1;
                         int num57 = 0;
                         int num58 = 0;
                         bool flag7 = true;
                         for (int n = -1; n < 2; n++)
                         {
                             for (int o = -1; o < 2; o++)
                             {
                                 if ((n != 0 || o != 0) && Main.tile[num54 + n, num55 + o].type == 19)
                                 {
                                     flag7 = false;
                                 }
                             }
                         }
                         if (!flag7)
                         {
                             Tile tile8 = Main.tile[num54 - 1, num55 - 1];
                             if (tile8.active() && tile8.type == 19 && tile8.slope() != 2)
                             {
                                 num57++;
                             }
                             tile8 = Main.tile[num54 - 1, num55 + 1];
                             if (tile8.active() && tile8.type == 19 && tile8.slope() != 1)
                             {
                                 num58++;
                             }
                             tile8 = Main.tile[num54 + 1, num55 - 1];
                             if (tile8.active() && tile8.type == 19 && tile8.slope() != 1)
                             {
                                 num58++;
                             }
                             tile8 = Main.tile[num54 + 1, num55 + 1];
                             if (tile8.active() && tile8.type == 19 && tile8.slope() != 2)
                             {
                                 num57++;
                             }
                             tile8 = Main.tile[num54 - 1, num55];
                             if (WorldGen.SolidTile(tile8))
                             {
                                 num57++;
                                 if (tile8.type == 19 && tile8.slope() == 0)
                                 {
                                     num57++;
                                 }
                             }
                             tile8 = Main.tile[num54 + 1, num55];
                             if (WorldGen.SolidTile(tile8))
                             {
                                 num58++;
                                 if (tile8.type == 19 && tile8.slope() == 0)
                                 {
                                     num58++;
                                 }
                             }
                             if (num57 > num58)
                             {
                                 num56 = 1;
                             }
                             else if (num58 > num57)
                             {
                                 num56 = 2;
                             }
                             tile8 = Main.tile[num54 - 1, num55];
                             if (tile8.active() && tile8.type == 19)
                             {
                                 num56 = 0;
                             }
                             tile8 = Main.tile[num54 + 1, num55];
                             if (tile8.active() && tile8.type == 19)
                             {
                                 num56 = 0;
                             }
                             int num59 = 0;
                             int num60 = 0;
                             if (num56 == -1)
                             {
                                 num56 = 0;
                                 int num61 = 0;
                                 num59 = -1;
                                 tile8 = Main.tile[num54 + num59, num55];
                                 if (tile8.active() && tile8.type == 19 && tile8.slope() != 0)
                                 {
                                     int directionInt = (tile8.slope() == 1).ToDirectionInt() * num59;
                                     num56 = (directionInt == -1 ? 0 : (int)tile8.slope());
                                     bool flag8 = true;
                                     if (Main.tile[num54 + num59 * 2, num55 + directionInt].active() && Main.tile[num54 + num59 * 2, num55].type == 19 && num56 == Main.tile[num54 + num59 * 2, num55 + directionInt].slope())
                                     {
                                         flag8 = false;
                                     }
                                     if (Main.tile[num54, num55 - directionInt].active() && Main.tile[num54, num55 - directionInt].type == 19 && tile8.slope() == Main.tile[num54, num55 - directionInt].slope())
                                     {
                                         flag8 = false;
                                     }
                                     if (flag8)
                                     {
                                         WorldGen.SlopeTile(num54 + num59, num55, num56);
                                         num61 = tile8.slope();
                                         if (Main.netMode == 1)
                                         {
                                             NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 14, (float)(num54 + num59), (float)num55, (float)num61, 0, 0, 0);
                                         }
                                     }
                                 }
                                 num59 = 1;
                                 num60 = 0;
                                 tile8 = Main.tile[num54 + num59, num55 + num60];
                                 if (tile8.active() && tile8.type == 19 && tile8.slope() != 0)
                                 {
                                     int directionInt1 = (tile8.slope() == 1).ToDirectionInt() * num59;
                                     num56 = (directionInt1 == -1 ? 0 : (int)tile8.slope());
                                     bool flag9 = true;
                                     if (Main.tile[num54 + num59 * 2, num55 + directionInt1].active() && Main.tile[num54 + num59 * 2, num55].type == 19 && num56 == Main.tile[num54 + num59 * 2, num55 + directionInt1].slope())
                                     {
                                         flag9 = false;
                                     }
                                     if (Main.tile[num54, num55 - directionInt1].active() && Main.tile[num54, num55 - directionInt1].type == 19 && tile8.slope() == Main.tile[num54, num55 - directionInt1].slope())
                                     {
                                         flag9 = false;
                                     }
                                     if (flag9)
                                     {
                                         WorldGen.SlopeTile(num54 + num59, num55, num56);
                                         num61 = tile8.slope();
                                         if (Main.netMode == 1)
                                         {
                                             NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 14, (float)(num54 + num59), (float)num55, (float)num61, 0, 0, 0);
                                         }
                                     }
                                 }
                                 if (num57 == num58 && WorldGen.PlatformProperSides(num54, num55, false) == 0)
                                 {
                                     tile8 = Main.tile[num54, num55 + 1];
                                     if (tile8.active() && !tile8.halfBrick() && tile8.slope() == 0 && Main.tileSolid[tile8.type])
                                     {
                                         num56 = (this.direction == 1 ? 2 : 1);
                                         WorldGen.SlopeTile(num54, num55, num56);
                                         num61 = Main.tile[num54, num55].slope();
                                         if (Main.netMode == 1)
                                         {
                                             NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 14, (float)Player.tileTargetX, (float)Player.tileTargetY, (float)num61, 0, 0, 0);
                                         }
                                     }
                                 }
                             }
                             else
                             {
                                 WorldGen.SlopeTile(num54, num55, num56);
                                 int num62 = Main.tile[num54, num55].slope();
                                 if (Main.netMode == 1)
                                 {
                                     NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 14, (float)Player.tileTargetX, (float)Player.tileTargetY, (float)num62, 0, 0, 0);
                                 }
                                 if (num56 != 1)
                                 {
                                     num59 = 1;
                                     num60 = -1;
                                 }
                                 else
                                 {
                                     num59 = -1;
                                     num60 = -1;
                                 }
                                 tile8 = Main.tile[num54 + num59, num55 + num60];
                                 if (tile8.active() && tile8.type == 19 && tile8.slope() == 0 && (!Main.tile[num54 + num59 + num59, num55 + num60].active() || Main.tile[num54 + num59 + num59, num55 + num60].type != 19 || !Main.tile[num54 + num59 + num59, num55 + num60].halfBrick()))
                                 {
                                     WorldGen.SlopeTile(num54 + num59, num55 + num60, num56);
                                     num62 = tile8.slope();
                                     if (Main.netMode == 1)
                                     {
                                         NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 14, (float)(num54 + num59), (float)(num55 + num60), (float)num62, 0, 0, 0);
                                     }
                                 }
                                 if (num56 != 1)
                                 {
                                     num59 = -1;
                                     num60 = 1;
                                 }
                                 else
                                 {
                                     num59 = 1;
                                     num60 = 1;
                                 }
                                 tile8 = Main.tile[num54 + num59, num55 + num60];
                                 if (tile8.active() && tile8.type == 19 && tile8.slope() == 0 && WorldGen.PlatformProperSides(num54 + num59, num55 + num60, true) <= 0)
                                 {
                                     WorldGen.SlopeTile(num54 + num59, num55 + num60, num56);
                                     num62 = tile8.slope();
                                     if (Main.netMode == 1)
                                     {
                                         NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 14, (float)(num54 + num59), (float)(num55 + num60), (float)num62, 0, 0, 0);
                                     }
                                 }
                             }
                         }
                     }
                     if (Main.tileSolid[this.inventory[this.selectedItem].createTile] && this.inventory[this.selectedItem].createTile != 19)
                     {
                         int num63 = Player.tileTargetX;
                         int num64 = Player.tileTargetY + 1;
                         if (Main.tile[num63, num64] != null && Main.tile[num63, num64].type != TileID.Platforms && (Main.tile[num63, num64].topSlope() || Main.tile[num63, num64].halfBrick()))
                         {
                             WorldGen.SlopeTile(num63, num64, 0);
                             if (Main.netMode == 1)
                             {
                                 NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 14, (float)num63, (float)num64, 0f, 0, 0, 0);
                             }
                         }
                         num63 = Player.tileTargetX;
                         num64 = Player.tileTargetY - 1;
                         if (Main.tile[num63, num64] != null && Main.tile[num63, num64].type != TileID.Platforms && Main.tile[num63, num64].bottomSlope())
                         {
                             WorldGen.SlopeTile(num63, num64, 0);
                             if (Main.netMode == 1)
                             {
                                 NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 14, (float)num63, (float)num64, 0f, 0, 0, 0);
                             }
                         }
                     }
                     if (Main.tileSolid[this.inventory[this.selectedItem].createTile])
                     {
                         for (int p = Player.tileTargetX - 1; p <= Player.tileTargetX + 1; p++)
                         {
                             for (int q = Player.tileTargetY - 1; q <= Player.tileTargetY + 1; q++)
                             {
                                 if (Main.tile[p, q].active() && this.inventory[this.selectedItem].createTile != Main.tile[p, q].type && (Main.tile[p, q].type == TileID.Grass || Main.tile[p, q].type == TileID.CorruptGrass || Main.tile[p, q].type == TileID.JungleGrass || Main.tile[p, q].type == TileID.MushroomGrass || Main.tile[p, q].type == TileID.HallowedGrass || Main.tile[p, q].type == TileID.FleshGrass))
                                 {
                                     bool flag10 = true;
                                     for (int r = p - 1; r <= p + 1; r++)
                                     {
                                         for (int s = q - 1; s <= q + 1; s++)
                                         {
                                             if (!WorldGen.SolidTile(r, s))
                                             {
                                                 flag10 = false;
                                             }
                                         }
                                     }
                                     if (flag10)
                                     {
                                         WorldGen.KillTile(p, q, true, false, false);
                                         if (Main.netMode == 1)
                                         {
                                             NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 0, (float)p, (float)q, 1f, 0, 0, 0);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     if (this.autoPaint)
                     {
                         for (int t = 0; t < 11; t++)
                         {
                             for (int u = 0; u < 11; u++)
                             {
                                 int num65 = Player.tileTargetX - 5 + t;
                                 int num66 = Player.tileTargetY - 5 + u;
                                 if ((Main.tile[num65, num66].active() || numArray[t, u] != -1) && (!Main.tile[num65, num66].active() || numArray[t, u] != Main.tile[num65, num66].type))
                                 {
                                     int num67 = -1;
                                     int num68 = -1;
                                     int num69 = 0;
                                     while (num69 < 58)
                                     {
                                         if (this.inventory[num69].stack <= 0 || this.inventory[num69].paint <= 0)
                                         {
                                             num69++;
                                         }
                                         else
                                         {
                                             num67 = this.inventory[num69].paint;
                                             num68 = num69;
                                             break;
                                         }
                                     }
                                     if (num67 > 0 && Main.tile[num65, num66].color() != num67 && WorldGen.paintTile(num65, num66, (byte)num67, true))
                                     {
                                         int num70 = num68;
                                         Item item2 = this.inventory[num70];
                                         item2.stack = item2.stack - 1;
                                         if (this.inventory[num70].stack <= 0)
                                         {
                                             this.inventory[num70].SetDefaults(0, false);
                                         }
                                         this.itemTime = (int)((float)this.inventory[this.selectedItem].useTime * this.tileSpeed);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (this.inventory[this.selectedItem].createWall >= 0 && this.position.X / 16f - (float)Player.tileRangeX - (float)this.inventory[this.selectedItem].tileBoost <= (float)Player.tileTargetX && (this.position.X + (float)this.width) / 16f + (float)Player.tileRangeX + (float)this.inventory[this.selectedItem].tileBoost - 1f >= (float)Player.tileTargetX && this.position.Y / 16f - (float)Player.tileRangeY - (float)this.inventory[this.selectedItem].tileBoost <= (float)Player.tileTargetY && (this.position.Y + (float)this.height) / 16f + (float)Player.tileRangeY + (float)this.inventory[this.selectedItem].tileBoost - 2f >= (float)Player.tileTargetY)
     {
         this.showItemIcon = true;
         if (this.itemTime == 0 && this.itemAnimation > 0 && this.controlUseItem && (Main.tile[Player.tileTargetX + 1, Player.tileTargetY].active() || Main.tile[Player.tileTargetX + 1, Player.tileTargetY].wall > 0 || Main.tile[Player.tileTargetX - 1, Player.tileTargetY].active() || Main.tile[Player.tileTargetX - 1, Player.tileTargetY].wall > 0 || Main.tile[Player.tileTargetX, Player.tileTargetY + 1].active() || Main.tile[Player.tileTargetX, Player.tileTargetY + 1].wall > 0 || Main.tile[Player.tileTargetX, Player.tileTargetY - 1].active() || Main.tile[Player.tileTargetX, Player.tileTargetY - 1].wall > 0) && Main.tile[Player.tileTargetX, Player.tileTargetY].wall != this.inventory[this.selectedItem].createWall)
         {
             if (Main.tile[Player.tileTargetX, Player.tileTargetY].wall != 0 && WorldGen.NearFriendlyWall(Player.tileTargetX, Player.tileTargetY))
             {
                 WorldGen.KillWall(Player.tileTargetX, Player.tileTargetY, false);
                 if (Main.tile[Player.tileTargetX, Player.tileTargetY].wall == 0 && Main.netMode == 1)
                 {
                     NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 2, (float)Player.tileTargetX, (float)Player.tileTargetY, 0f, 0, 0, 0);
                 }
                 if (this.inventory[this.selectedItem].consumable)
                 {
                     Item item3 = this.inventory[this.selectedItem];
                     item3.stack = item3.stack + 1;
                 }
                 this.itemTime = (int)((float)this.inventory[this.selectedItem].useTime * this.wallSpeed);
                 return;
             }
             WorldGen.PlaceWall(Player.tileTargetX, Player.tileTargetY, this.inventory[this.selectedItem].createWall, false);
             if (Main.tile[Player.tileTargetX, Player.tileTargetY].wall == this.inventory[this.selectedItem].createWall)
             {
                 this.itemTime = (int)((float)this.inventory[this.selectedItem].useTime * this.wallSpeed);
                 if (Main.netMode == 1)
                 {
                     NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 3, (float)Player.tileTargetX, (float)Player.tileTargetY, (float)this.inventory[this.selectedItem].createWall, 0, 0, 0);
                 }
                 if (this.inventory[this.selectedItem].stack > 1)
                 {
                     int num71 = this.inventory[this.selectedItem].createWall;
                     for (int v = 0; v < 4; v++)
                     {
                         int num72 = Player.tileTargetX;
                         int num73 = Player.tileTargetY;
                         if (v == 0)
                         {
                             num72--;
                         }
                         if (v == 1)
                         {
                             num72++;
                         }
                         if (v == 2)
                         {
                             num73--;
                         }
                         if (v == 3)
                         {
                             num73++;
                         }
                         if (Main.tile[num72, num73].wall == WallID.None)
                         {
                             int num74 = 0;
                             for (int w = 0; w < 4; w++)
                             {
                                 int num75 = num72;
                                 int num76 = num73;
                                 if (w == 0)
                                 {
                                     num75--;
                                 }
                                 if (w == 1)
                                 {
                                     num75++;
                                 }
                                 if (w == 2)
                                 {
                                     num76--;
                                 }
                                 if (w == 3)
                                 {
                                     num76++;
                                 }
                                 if (Main.tile[num75, num76].wall == num71)
                                 {
                                     num74++;
                                 }
                             }
                             if (num74 == 4)
                             {
                                 WorldGen.PlaceWall(num72, num73, num71, false);
                                 if (Main.tile[num72, num73].wall == num71)
                                 {
                                     Item item4 = this.inventory[this.selectedItem];
                                     item4.stack = item4.stack - 1;
                                     if (this.inventory[this.selectedItem].stack == 0)
                                     {
                                         this.inventory[this.selectedItem].SetDefaults(0, false);
                                     }
                                     if (Main.netMode == 1)
                                     {
                                         NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", 3, (float)num72, (float)num73, (float)num71, 0, 0, 0);
                                     }
                                     if (this.autoPaint)
                                     {
                                         int num77 = num72;
                                         int num78 = num73;
                                         int num79 = -1;
                                         int num80 = -1;
                                         int num81 = 0;
                                         while (num81 < 58)
                                         {
                                             if (this.inventory[num81].stack <= 0 || this.inventory[num81].paint <= 0)
                                             {
                                                 num81++;
                                             }
                                             else
                                             {
                                                 num79 = this.inventory[num81].paint;
                                                 num80 = num81;
                                                 break;
                                             }
                                         }
                                         if (num79 > 0 && Main.tile[num77, num78].wallColor() != num79 && WorldGen.paintWall(num77, num78, (byte)num79, true))
                                         {
                                             int num82 = num80;
                                             Item item5 = this.inventory[num82];
                                             item5.stack = item5.stack - 1;
                                             if (this.inventory[num82].stack <= 0)
                                             {
                                                 this.inventory[num82].SetDefaults(0, false);
                                             }
                                             this.itemTime = (int)((float)this.inventory[this.selectedItem].useTime * this.wallSpeed);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (this.autoPaint)
                 {
                     int num83 = Player.tileTargetX;
                     int num84 = Player.tileTargetY;
                     int num85 = -1;
                     int num86 = -1;
                     int num87 = 0;
                     while (num87 < 58)
                     {
                         if (this.inventory[num87].stack <= 0 || this.inventory[num87].paint <= 0)
                         {
                             num87++;
                         }
                         else
                         {
                             num85 = this.inventory[num87].paint;
                             num86 = num87;
                             break;
                         }
                     }
                     if (num85 > 0 && Main.tile[num83, num84].wallColor() != num85 && WorldGen.paintWall(num83, num84, (byte)num85, true))
                     {
                         int num88 = num86;
                         Item item6 = this.inventory[num88];
                         item6.stack = item6.stack - 1;
                         if (this.inventory[num88].stack <= 0)
                         {
                             this.inventory[num88].SetDefaults(0, false);
                         }
                         this.itemTime = (int)((float)this.inventory[this.selectedItem].useTime * this.wallSpeed);
                     }
                 }
             }
         }
     }
 }
		static TileObject()
		{
			TileObject.Empty = new TileObject();
			TileObject.objectPreview = new TileObjectPreviewData();
		}
Beispiel #17
0
        public static bool CanPlace(int x, int y, int type, int style, int dir, out TileObject objectData, bool onlyCheck = false)
        {
            TileObjectData tileData1 = TileObjectData.GetTileData(type, style, 0);

            objectData = TileObject.Empty;
            if (tileData1 == null)
            {
                return(false);
            }
            int num1 = x - (int)tileData1.Origin.X;
            int num2 = y - (int)tileData1.Origin.Y;

            if (num1 < 0 || num1 + tileData1.Width >= Main.maxTilesX || (num2 < 0 || num2 + tileData1.Height >= Main.maxTilesY))
            {
                return(false);
            }
            bool flag1 = tileData1.RandomStyleRange > 0;

            if (TileObjectPreviewData.placementCache == null)
            {
                TileObjectPreviewData.placementCache = new TileObjectPreviewData();
            }
            TileObjectPreviewData.placementCache.Reset();
            int num3 = 0;
            int num4 = 0;

            if (tileData1.AlternatesCount != 0)
            {
                num4 = tileData1.AlternatesCount;
            }
            float          num5           = -1f;
            float          num6           = -1f;
            int            num7           = 0;
            TileObjectData tileObjectData = (TileObjectData)null;
            int            alternate      = num3 - 1;

            while (alternate < num4)
            {
                ++alternate;
                TileObjectData tileData2 = TileObjectData.GetTileData(type, style, alternate);
                if (tileData2.Direction == TileObjectDirection.None || (tileData2.Direction != TileObjectDirection.PlaceLeft || dir != 1) && (tileData2.Direction != TileObjectDirection.PlaceRight || dir != -1))
                {
                    int num8 = x - (int)tileData2.Origin.X;
                    int num9 = y - (int)tileData2.Origin.Y;
                    if (num8 < 5 || num8 + tileData2.Width > Main.maxTilesX - 5 || (num9 < 5 || num9 + tileData2.Height > Main.maxTilesY - 5))
                    {
                        return(false);
                    }
                    Rectangle rectangle;
                    // ISSUE: explicit reference operation
                    ((Rectangle)@rectangle).\u002Ector(0, 0, tileData2.Width, tileData2.Height);
                    int X = 0;
                    int Y = 0;
                    if (tileData2.AnchorTop.tileCount != 0)
                    {
                        if (rectangle.Y == null)
                        {
                            rectangle.Y = (__Null) - 1;
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Height + 1;
                            // ISSUE: explicit reference operation
                            (^ local).Height = (__Null)num10;
                            ++Y;
                        }
                        int checkStart = tileData2.AnchorTop.checkStart;
                        if (checkStart < rectangle.X)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Width + (rectangle.X - checkStart);
                            // ISSUE: explicit reference operation
                            (^ local).Width = (__Null)num10;
                            X          += rectangle.X - checkStart;
                            rectangle.X = (__Null)checkStart;
                        }
                        int num11 = checkStart + tileData2.AnchorTop.tileCount - 1;
                        int num12 = rectangle.X + rectangle.Width - 1;
                        if (num11 > num12)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Width + (num11 - num12);
                            // ISSUE: explicit reference operation
                            (^ local).Width = (__Null)num10;
                        }
                    }
                    if (tileData2.AnchorBottom.tileCount != 0)
                    {
                        if (rectangle.Y + rectangle.Height == tileData2.Height)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Height + 1;
                            // ISSUE: explicit reference operation
                            (^ local).Height = (__Null)num10;
                        }
                        int checkStart = tileData2.AnchorBottom.checkStart;
                        if (checkStart < rectangle.X)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Width + (rectangle.X - checkStart);
                            // ISSUE: explicit reference operation
                            (^ local).Width = (__Null)num10;
                            X          += rectangle.X - checkStart;
                            rectangle.X = (__Null)checkStart;
                        }
                        int num11 = checkStart + tileData2.AnchorBottom.tileCount - 1;
                        int num12 = rectangle.X + rectangle.Width - 1;
                        if (num11 > num12)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Width + (num11 - num12);
                            // ISSUE: explicit reference operation
                            (^ local).Width = (__Null)num10;
                        }
                    }
                    if (tileData2.AnchorLeft.tileCount != 0)
                    {
                        if (rectangle.X == null)
                        {
                            rectangle.X = (__Null) - 1;
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Width + 1;
                            // ISSUE: explicit reference operation
                            (^ local).Width = (__Null)num10;
                            ++X;
                        }
                        int checkStart = tileData2.AnchorLeft.checkStart;
                        if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            --checkStart;
                        }
                        if (checkStart < rectangle.Y)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Width + (rectangle.Y - checkStart);
                            // ISSUE: explicit reference operation
                            (^ local).Width = (__Null)num10;
                            Y          += rectangle.Y - checkStart;
                            rectangle.Y = (__Null)checkStart;
                        }
                        int num11 = checkStart + tileData2.AnchorLeft.tileCount - 1;
                        if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            num11 += 2;
                        }
                        int num12 = rectangle.Y + rectangle.Height - 1;
                        if (num11 > num12)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Height + (num11 - num12);
                            // ISSUE: explicit reference operation
                            (^ local).Height = (__Null)num10;
                        }
                    }
                    if (tileData2.AnchorRight.tileCount != 0)
                    {
                        if (rectangle.X + rectangle.Width == tileData2.Width)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Width + 1;
                            // ISSUE: explicit reference operation
                            (^ local).Width = (__Null)num10;
                        }
                        int checkStart = tileData2.AnchorLeft.checkStart;
                        if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            --checkStart;
                        }
                        if (checkStart < rectangle.Y)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Width + (rectangle.Y - checkStart);
                            // ISSUE: explicit reference operation
                            (^ local).Width = (__Null)num10;
                            Y          += rectangle.Y - checkStart;
                            rectangle.Y = (__Null)checkStart;
                        }
                        int num11 = checkStart + tileData2.AnchorRight.tileCount - 1;
                        if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            num11 += 2;
                        }
                        int num12 = rectangle.Y + rectangle.Height - 1;
                        if (num11 > num12)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Height + (num11 - num12);
                            // ISSUE: explicit reference operation
                            (^ local).Height = (__Null)num10;
                        }
                    }
                    if (onlyCheck)
                    {
                        TileObject.objectPreview.Reset();
                        TileObject.objectPreview.Active      = true;
                        TileObject.objectPreview.Type        = (ushort)type;
                        TileObject.objectPreview.Style       = (short)style;
                        TileObject.objectPreview.Alternate   = alternate;
                        TileObject.objectPreview.Size        = new Point16((int)rectangle.Width, (int)rectangle.Height);
                        TileObject.objectPreview.ObjectStart = new Point16(X, Y);
                        TileObject.objectPreview.Coordinates = new Point16(num8 - X, num9 - Y);
                    }
                    float num13 = 0.0f;
                    float num14 = (float)(tileData2.Width * tileData2.Height);
                    float num15 = 0.0f;
                    float num16 = 0.0f;
                    for (int index1 = 0; index1 < tileData2.Width; ++index1)
                    {
                        for (int index2 = 0; index2 < tileData2.Height; ++index2)
                        {
                            Tile tileSafely = Framing.GetTileSafely(num8 + index1, num9 + index2);
                            bool flag2      = !tileData2.LiquidPlace(tileSafely);
                            bool flag3      = false;
                            if (tileData2.AnchorWall)
                            {
                                ++num16;
                                if (!tileData2.isValidWallAnchor((int)tileSafely.wall))
                                {
                                    flag3 = true;
                                }
                                else
                                {
                                    ++num15;
                                }
                            }
                            bool flag4 = false;
                            if (tileSafely.active() && !Main.tileCut[(int)tileSafely.type])
                            {
                                flag4 = true;
                            }
                            if (flag4 || flag2 || flag3)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[index1 + X, index2 + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[index1 + X, index2 + Y] = 1;
                                }
                                ++num13;
                            }
                        }
                    }
                    AnchorData anchorBottom = tileData2.AnchorBottom;
                    if (anchorBottom.tileCount != 0)
                    {
                        num16 += (float)anchorBottom.tileCount;
                        int height = tileData2.Height;
                        for (int index = 0; index < anchorBottom.tileCount; ++index)
                        {
                            int  num10      = anchorBottom.checkStart + index;
                            Tile tileSafely = Framing.GetTileSafely(num8 + num10, num9 + height);
                            bool flag2      = false;
                            if (tileSafely.nactive())
                            {
                                if ((anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile && Main.tileSolid[(int)tileSafely.type] && (!Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type]) && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag2 && ((anchorBottom.type & AnchorType.SolidWithTop) == AnchorType.SolidWithTop || (anchorBottom.type & AnchorType.Table) == AnchorType.Table))
                                {
                                    if (TileID.Sets.Platforms[(int)tileSafely.type])
                                    {
                                        int num11 = (int)tileSafely.frameX / TileObjectData.PlatformFrameWidth();
                                        if (!tileSafely.halfBrick() && num11 >= 0 && num11 <= 7 || (num11 >= 12 && num11 <= 16 || num11 >= 25 && num11 <= 26))
                                        {
                                            flag2 = true;
                                        }
                                    }
                                    else if (Main.tileSolid[(int)tileSafely.type] && Main.tileSolidTop[(int)tileSafely.type])
                                    {
                                        flag2 = true;
                                    }
                                }
                                if (!flag2 && (anchorBottom.type & AnchorType.Table) == AnchorType.Table && (!TileID.Sets.Platforms[(int)tileSafely.type] && Main.tileTable[(int)tileSafely.type]) && tileSafely.blockType() == 0)
                                {
                                    flag2 = true;
                                }
                                if (!flag2 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type]))
                                {
                                    switch (tileSafely.blockType())
                                    {
                                    case 4:
                                    case 5:
                                        flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                        break;
                                    }
                                }
                                if (!flag2 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
                                {
                                    flag2 = true;
                                }
                            }
                            else if (!flag2 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag2 = true;
                            }
                            if (!flag2)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num10 + X, height + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num10 + X, height + Y] = 1;
                                }
                                ++num15;
                            }
                        }
                    }
                    AnchorData anchorTop = tileData2.AnchorTop;
                    if (anchorTop.tileCount != 0)
                    {
                        num16 += (float)anchorTop.tileCount;
                        int num10 = -1;
                        for (int index = 0; index < anchorTop.tileCount; ++index)
                        {
                            int  num11      = anchorTop.checkStart + index;
                            Tile tileSafely = Framing.GetTileSafely(num8 + num11, num9 + num10);
                            bool flag2      = false;
                            if (tileSafely.nactive())
                            {
                                if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag2 && (anchorTop.type & AnchorType.SolidBottom) == AnchorType.SolidBottom && (Main.tileSolid[(int)tileSafely.type] && (!Main.tileSolidTop[(int)tileSafely.type] || TileID.Sets.Platforms[(int)tileSafely.type] && (tileSafely.halfBrick() || tileSafely.topSlope())) || (tileSafely.halfBrick() || tileSafely.topSlope())) && (!TileID.Sets.NotReallySolid[(int)tileSafely.type] && !tileSafely.bottomSlope()))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag2 && (anchorTop.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type]))
                                {
                                    switch (tileSafely.blockType())
                                    {
                                    case 2:
                                    case 3:
                                        flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                        break;
                                    }
                                }
                                if (!flag2 && (anchorTop.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
                                {
                                    flag2 = true;
                                }
                            }
                            else if (!flag2 && (anchorTop.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag2 = true;
                            }
                            if (!flag2)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num11 + X, num10 + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num11 + X, num10 + Y] = 1;
                                }
                                ++num15;
                            }
                        }
                    }
                    AnchorData anchorRight = tileData2.AnchorRight;
                    if (anchorRight.tileCount != 0)
                    {
                        num16 += (float)anchorRight.tileCount;
                        int width = tileData2.Width;
                        for (int index = 0; index < anchorRight.tileCount; ++index)
                        {
                            int  num10       = anchorRight.checkStart + index;
                            Tile tileSafely1 = Framing.GetTileSafely(num8 + width, num9 + num10);
                            bool flag2       = false;
                            if (tileSafely1.nactive())
                            {
                                if (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type] && !Main.tileNoAttach[(int)tileSafely1.type] && (tileData2.FlattenAnchors || tileSafely1.blockType() == 0))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                                }
                                if (!flag2 && (anchorRight.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type]))
                                {
                                    switch (tileSafely1.blockType())
                                    {
                                    case 2:
                                    case 4:
                                        flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                                        break;
                                    }
                                }
                                if (!flag2 && (anchorRight.type & AnchorType.Tree) == AnchorType.Tree && (int)tileSafely1.type == 5)
                                {
                                    flag2 = true;
                                    if (index == 0)
                                    {
                                        ++num16;
                                        Tile tileSafely2 = Framing.GetTileSafely(num8 + width, num9 + num10 - 1);
                                        if (tileSafely2.nactive() && (int)tileSafely2.type == 5)
                                        {
                                            ++num15;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[width + X, num10 + Y - 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[width + X, num10 + Y - 1] = 2;
                                        }
                                    }
                                    if (index == anchorRight.tileCount - 1)
                                    {
                                        ++num16;
                                        Tile tileSafely2 = Framing.GetTileSafely(num8 + width, num9 + num10 + 1);
                                        if (tileSafely2.nactive() && (int)tileSafely2.type == 5)
                                        {
                                            ++num15;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[width + X, num10 + Y + 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[width + X, num10 + Y + 1] = 2;
                                        }
                                    }
                                }
                                if (!flag2 && (anchorRight.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely1.type))
                                {
                                    flag2 = true;
                                }
                            }
                            else if (!flag2 && (anchorRight.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag2 = true;
                            }
                            if (!flag2)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[width + X, num10 + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[width + X, num10 + Y] = 1;
                                }
                                ++num15;
                            }
                        }
                    }
                    AnchorData anchorLeft = tileData2.AnchorLeft;
                    if (anchorLeft.tileCount != 0)
                    {
                        num16 += (float)anchorLeft.tileCount;
                        int num10 = -1;
                        for (int index = 0; index < anchorLeft.tileCount; ++index)
                        {
                            int  num11       = anchorLeft.checkStart + index;
                            Tile tileSafely1 = Framing.GetTileSafely(num8 + num10, num9 + num11);
                            bool flag2       = false;
                            if (tileSafely1.nactive())
                            {
                                if (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type] && !Main.tileNoAttach[(int)tileSafely1.type] && (tileData2.FlattenAnchors || tileSafely1.blockType() == 0))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                                }
                                if (!flag2 && (anchorLeft.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type]))
                                {
                                    switch (tileSafely1.blockType())
                                    {
                                    case 3:
                                    case 5:
                                        flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                                        break;
                                    }
                                }
                                if (!flag2 && (anchorLeft.type & AnchorType.Tree) == AnchorType.Tree && (int)tileSafely1.type == 5)
                                {
                                    flag2 = true;
                                    if (index == 0)
                                    {
                                        ++num16;
                                        Tile tileSafely2 = Framing.GetTileSafely(num8 + num10, num9 + num11 - 1);
                                        if (tileSafely2.nactive() && (int)tileSafely2.type == 5)
                                        {
                                            ++num15;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[num10 + X, num11 + Y - 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[num10 + X, num11 + Y - 1] = 2;
                                        }
                                    }
                                    if (index == anchorLeft.tileCount - 1)
                                    {
                                        ++num16;
                                        Tile tileSafely2 = Framing.GetTileSafely(num8 + num10, num9 + num11 + 1);
                                        if (tileSafely2.nactive() && (int)tileSafely2.type == 5)
                                        {
                                            ++num15;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[num10 + X, num11 + Y + 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[num10 + X, num11 + Y + 1] = 2;
                                        }
                                    }
                                }
                                if (!flag2 && (anchorLeft.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely1.type))
                                {
                                    flag2 = true;
                                }
                            }
                            else if (!flag2 && (anchorLeft.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag2 = true;
                            }
                            if (!flag2)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num10 + X, num11 + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num10 + X, num11 + Y] = 1;
                                }
                                ++num15;
                            }
                        }
                    }
                    if (tileData2.HookCheck.hook != null)
                    {
                        if (tileData2.HookCheck.processedCoordinates)
                        {
                            int x1 = (int)tileData2.Origin.X;
                            int y1 = (int)tileData2.Origin.Y;
                        }
                        if (tileData2.HookCheck.hook.Invoke(x, y, type, style, dir) == tileData2.HookCheck.badReturn && tileData2.HookCheck.badResponse == 0)
                        {
                            num15 = 0.0f;
                            num13 = 0.0f;
                            TileObject.objectPreview.AllInvalid();
                        }
                    }
                    float num17 = num15 / num16;
                    float num18 = num13 / num14;
                    if ((double)num18 == 1.0 && (double)num16 == 0.0)
                    {
                        num17 = 1f;
                        num18 = 1f;
                    }
                    if ((double)num17 == 1.0 && (double)num18 == 1.0)
                    {
                        num5           = 1f;
                        num6           = 1f;
                        num7           = alternate;
                        tileObjectData = tileData2;
                        break;
                    }
                    if ((double)num17 > (double)num5 || (double)num17 == (double)num5 && (double)num18 > (double)num6)
                    {
                        TileObjectPreviewData.placementCache.CopyFrom(TileObject.objectPreview);
                        num5           = num17;
                        num6           = num18;
                        tileObjectData = tileData2;
                        num7           = alternate;
                    }
                }
            }
            int num19 = -1;

            if (flag1)
            {
                if (TileObjectPreviewData.randomCache == null)
                {
                    TileObjectPreviewData.randomCache = new TileObjectPreviewData();
                }
                bool flag2 = false;
                if ((int)TileObjectPreviewData.randomCache.Type == type)
                {
                    Point16 coordinates = TileObjectPreviewData.randomCache.Coordinates;
                    Point16 objectStart = TileObjectPreviewData.randomCache.ObjectStart;
                    int     num8        = (int)coordinates.X + (int)objectStart.X;
                    int     num9        = (int)coordinates.Y + (int)objectStart.Y;
                    int     num10       = x - (int)tileData1.Origin.X;
                    int     num11       = y - (int)tileData1.Origin.Y;
                    if (num8 != num10 || num9 != num11)
                    {
                        flag2 = true;
                    }
                }
                else
                {
                    flag2 = true;
                }
                num19 = !flag2 ? TileObjectPreviewData.randomCache.Random : Main.rand.Next(tileData1.RandomStyleRange);
            }
            if (onlyCheck)
            {
                if ((double)num5 != 1.0 || (double)num6 != 1.0)
                {
                    TileObject.objectPreview.CopyFrom(TileObjectPreviewData.placementCache);
                    alternate = num7;
                }
                TileObject.objectPreview.Random = num19;
                if (tileData1.RandomStyleRange > 0)
                {
                    TileObjectPreviewData.randomCache.CopyFrom(TileObject.objectPreview);
                }
            }
            if (!onlyCheck)
            {
                objectData.xCoord    = x - (int)tileObjectData.Origin.X;
                objectData.yCoord    = y - (int)tileObjectData.Origin.Y;
                objectData.type      = type;
                objectData.style     = style;
                objectData.alternate = alternate;
                objectData.random    = num19;
            }
            if ((double)num5 == 1.0)
            {
                return((double)num6 == 1.0);
            }
            return(false);
        }
		public static bool CanPlace(int x, int y, int type, int style, int dir, out TileObject objectData, bool onlyCheck = false)
		{
			Tile tileSafely;
			TileObjectData tileData = TileObjectData.GetTileData(type, style, 0);
			objectData = TileObject.Empty;
			if (tileData == null)
			{
				return false;
			}
			int num = x - tileData.Origin.X;
			int num1 = y - tileData.Origin.Y;
			if (num < 0 || num + tileData.Width >= Main.maxTilesX || num1 < 0 || num1 + tileData.Height >= Main.maxTilesY)
			{
				return false;
			}
			bool randomStyleRange = tileData.RandomStyleRange > 0;
			if (TileObjectPreviewData.placementCache == null)
			{
				TileObjectPreviewData.placementCache = new TileObjectPreviewData();
			}
			TileObjectPreviewData.placementCache.Reset();
			int num2 = 0;
			int alternatesCount = 0;
			if (tileData.AlternatesCount != 0)
			{
				alternatesCount = tileData.AlternatesCount;
			}
			float single = -1f;
			float single1 = -1f;
			int num3 = 0;
			TileObjectData tileObjectDatum = null;
			int num4 = num2 - 1;
			while (num4 < alternatesCount)
			{
				num4++;
				TileObjectData tileData1 = TileObjectData.GetTileData(type, style, num4);
				if (tileData1.Direction != TileObjectDirection.None && (tileData1.Direction == TileObjectDirection.PlaceLeft && dir == 1 || tileData1.Direction == TileObjectDirection.PlaceRight && dir == -1))
				{
					continue;
				}
				int num5 = x - tileData1.Origin.X;
				int num6 = y - tileData1.Origin.Y;
				if (num5 < 5 || num5 + tileData1.Width > Main.maxTilesX - 5 || num6 < 5 || num6 + tileData1.Height > Main.maxTilesY - 5)
				{
					return false;
				}
				Rectangle rectangle = new Rectangle(0, 0, tileData1.Width, tileData1.Height);
				int num7 = 0;
				int num8 = 0;
				if (tileData1.AnchorTop.tileCount != 0)
				{
					if (rectangle.Y == 0)
					{
						rectangle.Y = -1;
						rectangle.Height = rectangle.Height + 1;
						num8++;
					}
					int anchorTop = tileData1.AnchorTop.checkStart;
					if (anchorTop < rectangle.X)
					{
						rectangle.Width = rectangle.Width + (rectangle.X - anchorTop);
						num7 = num7 + (rectangle.X - anchorTop);
						rectangle.X = anchorTop;
					}
					int anchorTop1 = anchorTop + tileData1.AnchorTop.tileCount - 1;
					int num9 = rectangle.X + rectangle.Width - 1;
					if (anchorTop1 > num9)
					{
						rectangle.Width = rectangle.Width + (anchorTop1 - num9);
					}
				}
				if (tileData1.AnchorBottom.tileCount != 0)
				{
					if (rectangle.Y + rectangle.Height == tileData1.Height)
					{
						rectangle.Height = rectangle.Height + 1;
					}
					int anchorBottom = tileData1.AnchorBottom.checkStart;
					if (anchorBottom < rectangle.X)
					{
						rectangle.Width = rectangle.Width + (rectangle.X - anchorBottom);
						num7 = num7 + (rectangle.X - anchorBottom);
						rectangle.X = anchorBottom;
					}
					int anchorBottom1 = anchorBottom + tileData1.AnchorBottom.tileCount - 1;
					int num10 = rectangle.X + rectangle.Width - 1;
					if (anchorBottom1 > num10)
					{
						rectangle.Width = rectangle.Width + (anchorBottom1 - num10);
					}
				}
				if (tileData1.AnchorLeft.tileCount != 0)
				{
					if (rectangle.X == 0)
					{
						rectangle.X = -1;
						rectangle.Width = rectangle.Width + 1;
						num7++;
					}
					int anchorLeft = tileData1.AnchorLeft.checkStart;
					if ((tileData1.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
					{
						anchorLeft--;
					}
					if (anchorLeft < rectangle.Y)
					{
						rectangle.Width = rectangle.Width + (rectangle.Y - anchorLeft);
						num8 = num8 + (rectangle.Y - anchorLeft);
						rectangle.Y = anchorLeft;
					}
					int anchorLeft1 = anchorLeft + tileData1.AnchorLeft.tileCount - 1;
					if ((tileData1.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
					{
						anchorLeft1 = anchorLeft1 + 2;
					}
					int num11 = rectangle.Y + rectangle.Height - 1;
					if (anchorLeft1 > num11)
					{
						rectangle.Height = rectangle.Height + (anchorLeft1 - num11);
					}
				}
				if (tileData1.AnchorRight.tileCount != 0)
				{
					if (rectangle.X + rectangle.Width == tileData1.Width)
					{
						rectangle.Width = rectangle.Width + 1;
					}
					int anchorLeft2 = tileData1.AnchorLeft.checkStart;
					if ((tileData1.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
					{
						anchorLeft2--;
					}
					if (anchorLeft2 < rectangle.Y)
					{
						rectangle.Width = rectangle.Width + (rectangle.Y - anchorLeft2);
						num8 = num8 + (rectangle.Y - anchorLeft2);
						rectangle.Y = anchorLeft2;
					}
					int anchorRight = anchorLeft2 + tileData1.AnchorRight.tileCount - 1;
					if ((tileData1.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
					{
						anchorRight = anchorRight + 2;
					}
					int num12 = rectangle.Y + rectangle.Height - 1;
					if (anchorRight > num12)
					{
						rectangle.Height = rectangle.Height + (anchorRight - num12);
					}
				}
				if (onlyCheck)
				{
					TileObject.objectPreview.Reset();
					TileObject.objectPreview.Active = true;
					TileObject.objectPreview.Type = (ushort)type;
					TileObject.objectPreview.Style = (short)style;
					TileObject.objectPreview.Alternate = num4;
					TileObject.objectPreview.Size = new Point16(rectangle.Width, rectangle.Height);
					TileObject.objectPreview.ObjectStart = new Point16(num7, num8);
					TileObject.objectPreview.Coordinates = new Point16(num5 - num7, num6 - num8);
				}
				float single2 = 0f;
				float width = (float)(tileData1.Width * tileData1.Height);
				float single3 = 0f;
				float single4 = 0f;
				for (int i = 0; i < tileData1.Width; i++)
				{
					for (int j = 0; j < tileData1.Height; j++)
					{
						tileSafely = Framing.GetTileSafely(num5 + i, num6 + j);
						bool flag = !tileData1.LiquidPlace(tileSafely);
						bool flag1 = false;
						if (tileData1.AnchorWall)
						{
							single4 = single4 + 1f;
							if (tileData1.isValidWallAnchor((int)tileSafely.wall))
							{
								single3 = single3 + 1f;
							}
							else
							{
								flag1 = true;
							}
						}
						bool flag2 = false;
						if (tileSafely.active() && !Main.tileCut[tileSafely.type])
						{
							flag2 = true;
						}
						if (!flag2 && !flag && !flag1)
						{
							if (onlyCheck)
							{
								TileObject.objectPreview[i + num7, j + num8] = 1;
							}
							single2 = single2 + 1f;
						}
						else if (onlyCheck)
						{
							TileObject.objectPreview[i + num7, j + num8] = 2;
						}
					}
				}
				AnchorData anchorDatum = tileData1.AnchorBottom;
				if (anchorDatum.tileCount != 0)
				{
					single4 = single4 + (float)anchorDatum.tileCount;
					int height = tileData1.Height;
					for (int k = 0; k < anchorDatum.tileCount; k++)
					{
						int num13 = anchorDatum.checkStart + k;
						tileSafely = Framing.GetTileSafely(num5 + num13, num6 + height);
						bool flag3 = false;
						if (tileSafely.nactive())
						{
							if ((anchorDatum.type & AnchorType.SolidTile) == AnchorType.SolidTile && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData1.FlattenAnchors || tileSafely.blockType() == 0))
							{
								flag3 = tileData1.isValidTileAnchor((int)tileSafely.type);
							}
							if (!flag3 && ((anchorDatum.type & AnchorType.SolidWithTop) == AnchorType.SolidWithTop || (anchorDatum.type & AnchorType.Table) == AnchorType.Table))
							{
								if (tileSafely.type == 19)
								{
									int num14 = tileSafely.frameX / TileObjectData.PlatformFrameWidth();
									if (!tileSafely.halfBrick() && num14 >= 0 && num14 <= 7 || num14 >= 12 && num14 <= 16 || num14 >= 25 && num14 <= 26)
									{
										flag3 = true;
									}
								}
								else if (Main.tileSolid[tileSafely.type] && Main.tileSolidTop[tileSafely.type])
								{
									flag3 = true;
								}
							}
							if (!flag3 && (anchorDatum.type & AnchorType.Table) == AnchorType.Table && tileSafely.type != 19 && Main.tileTable[tileSafely.type] && tileSafely.blockType() == 0)
							{
								flag3 = true;
							}
							if (!flag3 && (anchorDatum.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
							{
								switch (tileSafely.blockType())
								{
									case 4:
									case 5:
									{
										flag3 = tileData1.isValidTileAnchor((int)tileSafely.type);
										break;
									}
								}
							}
							if (!flag3 && (anchorDatum.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData1.isValidAlternateAnchor((int)tileSafely.type))
							{
								flag3 = true;
							}
						}
						else if (!flag3 && (anchorDatum.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
						{
							flag3 = true;
						}
						if (flag3)
						{
							if (onlyCheck)
							{
								TileObject.objectPreview[num13 + num7, height + num8] = 1;
							}
							single3 = single3 + 1f;
						}
						else if (onlyCheck)
						{
							TileObject.objectPreview[num13 + num7, height + num8] = 2;
						}
					}
				}
				anchorDatum = tileData1.AnchorTop;
				if (anchorDatum.tileCount != 0)
				{
					single4 = single4 + (float)anchorDatum.tileCount;
					int num15 = -1;
					for (int l = 0; l < anchorDatum.tileCount; l++)
					{
						int num16 = anchorDatum.checkStart + l;
						tileSafely = Framing.GetTileSafely(num5 + num16, num6 + num15);
						bool flag4 = false;
						if (tileSafely.nactive())
						{
							if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData1.FlattenAnchors || tileSafely.blockType() == 0))
							{
								flag4 = tileData1.isValidTileAnchor((int)tileSafely.type);
							}
							if (!flag4 && (anchorDatum.type & AnchorType.SolidBottom) == AnchorType.SolidBottom && (Main.tileSolid[tileSafely.type] && (!Main.tileSolidTop[tileSafely.type] || tileSafely.type == 19 && (tileSafely.halfBrick() || tileSafely.topSlope())) || tileSafely.halfBrick() || tileSafely.topSlope()) && !tileSafely.bottomSlope())
							{
								flag4 = tileData1.isValidTileAnchor((int)tileSafely.type);
							}
							if (!flag4 && (anchorDatum.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
							{
								switch (tileSafely.blockType())
								{
									case 2:
									case 3:
									{
										flag4 = tileData1.isValidTileAnchor((int)tileSafely.type);
										break;
									}
								}
							}
							if (!flag4 && (anchorDatum.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData1.isValidAlternateAnchor((int)tileSafely.type))
							{
								flag4 = true;
							}
						}
						else if (!flag4 && (anchorDatum.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
						{
							flag4 = true;
						}
						if (flag4)
						{
							if (onlyCheck)
							{
								TileObject.objectPreview[num16 + num7, num15 + num8] = 1;
							}
							single3 = single3 + 1f;
						}
						else if (onlyCheck)
						{
							TileObject.objectPreview[num16 + num7, num15 + num8] = 2;
						}
					}
				}
				anchorDatum = tileData1.AnchorRight;
				if (anchorDatum.tileCount != 0)
				{
					single4 = single4 + (float)anchorDatum.tileCount;
					int width1 = tileData1.Width;
					for (int m = 0; m < anchorDatum.tileCount; m++)
					{
						int num17 = anchorDatum.checkStart + m;
						tileSafely = Framing.GetTileSafely(num5 + width1, num6 + num17);
						bool flag5 = false;
						if (tileSafely.nactive())
						{
							if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData1.FlattenAnchors || tileSafely.blockType() == 0))
							{
								flag5 = tileData1.isValidTileAnchor((int)tileSafely.type);
							}
							if (!flag5 && (anchorDatum.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
							{
								switch (tileSafely.blockType())
								{
									case 2:
									case 4:
									{
										flag5 = tileData1.isValidTileAnchor((int)tileSafely.type);
										break;
									}
								}
							}
							if (!flag5 && (anchorDatum.type & AnchorType.Tree) == AnchorType.Tree && tileSafely.type == 5)
							{
								flag5 = true;
								if (m == 0)
								{
									single4 = single4 + 1f;
									Tile tile = Framing.GetTileSafely(num5 + width1, num6 + num17 - 1);
									if (tile.nactive() && tile.type == TileID.Trees)
									{
										single3 = single3 + 1f;
										if (onlyCheck)
										{
											TileObject.objectPreview[width1 + num7, num17 + num8 - 1] = 1;
										}
									}
									else if (onlyCheck)
									{
										TileObject.objectPreview[width1 + num7, num17 + num8 - 1] = 2;
									}
								}
								if (m == anchorDatum.tileCount - 1)
								{
									single4 = single4 + 1f;
									Tile tileSafely1 = Framing.GetTileSafely(num5 + width1, num6 + num17 + 1);
									if (tileSafely1.nactive() && tileSafely1.type == 5)
									{
										single3 = single3 + 1f;
										if (onlyCheck)
										{
											TileObject.objectPreview[width1 + num7, num17 + num8 + 1] = 1;
										}
									}
									else if (onlyCheck)
									{
										TileObject.objectPreview[width1 + num7, num17 + num8 + 1] = 2;
									}
								}
							}
							if (!flag5 && (anchorDatum.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData1.isValidAlternateAnchor((int)tileSafely.type))
							{
								flag5 = true;
							}
						}
						else if (!flag5 && (anchorDatum.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
						{
							flag5 = true;
						}
						if (flag5)
						{
							if (onlyCheck)
							{
								TileObject.objectPreview[width1 + num7, num17 + num8] = 1;
							}
							single3 = single3 + 1f;
						}
						else if (onlyCheck)
						{
							TileObject.objectPreview[width1 + num7, num17 + num8] = 2;
						}
					}
				}
				anchorDatum = tileData1.AnchorLeft;
				if (anchorDatum.tileCount != 0)
				{
					single4 = single4 + (float)anchorDatum.tileCount;
					int num18 = -1;
					for (int n = 0; n < anchorDatum.tileCount; n++)
					{
						int num19 = anchorDatum.checkStart + n;
						tileSafely = Framing.GetTileSafely(num5 + num18, num6 + num19);
						bool flag6 = false;
						if (tileSafely.nactive())
						{
							if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData1.FlattenAnchors || tileSafely.blockType() == 0))
							{
								flag6 = tileData1.isValidTileAnchor((int)tileSafely.type);
							}
							if (!flag6 && (anchorDatum.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
							{
								switch (tileSafely.blockType())
								{
									case 3:
									case 5:
									{
										flag6 = tileData1.isValidTileAnchor((int)tileSafely.type);
										break;
									}
								}
							}
							if (!flag6 && (anchorDatum.type & AnchorType.Tree) == AnchorType.Tree && tileSafely.type == 5)
							{
								flag6 = true;
								if (n == 0)
								{
									single4 = single4 + 1f;
									Tile tile1 = Framing.GetTileSafely(num5 + num18, num6 + num19 - 1);
									if (tile1.nactive() && tile1.type == 5)
									{
										single3 = single3 + 1f;
										if (onlyCheck)
										{
											TileObject.objectPreview[num18 + num7, num19 + num8 - 1] = 1;
										}
									}
									else if (onlyCheck)
									{
										TileObject.objectPreview[num18 + num7, num19 + num8 - 1] = 2;
									}
								}
								if (n == anchorDatum.tileCount - 1)
								{
									single4 = single4 + 1f;
									Tile tileSafely2 = Framing.GetTileSafely(num5 + num18, num6 + num19 + 1);
									if (tileSafely2.nactive() && tileSafely2.type == 5)
									{
										single3 = single3 + 1f;
										if (onlyCheck)
										{
											TileObject.objectPreview[num18 + num7, num19 + num8 + 1] = 1;
										}
									}
									else if (onlyCheck)
									{
										TileObject.objectPreview[num18 + num7, num19 + num8 + 1] = 2;
									}
								}
							}
							if (!flag6 && (anchorDatum.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData1.isValidAlternateAnchor((int)tileSafely.type))
							{
								flag6 = true;
							}
						}
						else if (!flag6 && (anchorDatum.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
						{
							flag6 = true;
						}
						if (flag6)
						{
							if (onlyCheck)
							{
								TileObject.objectPreview[num18 + num7, num19 + num8] = 1;
							}
							single3 = single3 + 1f;
						}
						else if (onlyCheck)
						{
							TileObject.objectPreview[num18 + num7, num19 + num8] = 2;
						}
					}
				}
				if (tileData1.HookCheck.hook != null)
				{
					if (tileData1.HookCheck.processedCoordinates)
					{
						short num20 = tileData1.Origin.X;
						short num21 = tileData1.Origin.Y;
					}
					if (tileData1.HookCheck.hook(x, y, type, style, dir) == tileData1.HookCheck.badReturn && tileData1.HookCheck.badResponse == 0)
					{
						single3 = 0f;
						single2 = 0f;
						TileObject.objectPreview.AllInvalid();
					}
				}
				float single5 = single3 / single4;
				float single6 = single2 / width;
				if (single5 != 1f || single6 != 1f)
				{
					if (single5 <= single && (single5 != single || single6 <= single1))
					{
						continue;
					}
					TileObjectPreviewData.placementCache.CopyFrom(TileObject.objectPreview);
					single = single5;
					single1 = single6;
					tileObjectDatum = tileData1;
					num3 = num4;
				}
				else
				{
					single = 1f;
					single1 = 1f;
					num3 = num4;
					tileObjectDatum = tileData1;
					break;
				}
			}
			int num22 = -1;
			if (randomStyleRange)
			{
				if (TileObjectPreviewData.randomCache == null)
				{
					TileObjectPreviewData.randomCache = new TileObjectPreviewData();
				}
				bool flag7 = false;
				if (TileObjectPreviewData.randomCache.Type != type)
				{
					flag7 = true;
				}
				else
				{
					Point16 coordinates = TileObjectPreviewData.randomCache.Coordinates;
					Point16 objectStart = TileObjectPreviewData.randomCache.ObjectStart;
					int num23 = coordinates.X + objectStart.X;
					int num24 = coordinates.Y + objectStart.Y;
					int num25 = x - tileData.Origin.X;
					int num26 = y - tileData.Origin.Y;
					if (num23 != num25 || num24 != num26)
					{
						flag7 = true;
					}
				}
				num22 = (!flag7 ? TileObjectPreviewData.randomCache.Random : Main.rand.Next(tileData.RandomStyleRange));
			}
			if (onlyCheck)
			{
				if (single != 1f || single1 != 1f)
				{
					TileObject.objectPreview.CopyFrom(TileObjectPreviewData.placementCache);
					num4 = num3;
				}
				TileObject.objectPreview.Random = num22;
				if (tileData.RandomStyleRange > 0)
				{
					TileObjectPreviewData.randomCache.CopyFrom(TileObject.objectPreview);
				}
			}
			if (!onlyCheck)
			{
				objectData.xCoord = x - tileObjectDatum.Origin.X;
				objectData.yCoord = y - tileObjectDatum.Origin.Y;
				objectData.type = type;
				objectData.style = style;
				objectData.alternate = num4;
				objectData.random = num22;
			}
			if (single != 1f)
			{
				return false;
			}
			return single1 == 1f;
		}
Beispiel #19
0
        public static bool Place(TileObject toBePlaced)
        {
            TileObjectData tileData = TileObjectData.GetTileData(toBePlaced.type, toBePlaced.style, toBePlaced.alternate);

            if (tileData == null)
            {
                return(false);
            }
            if (tileData.HookPlaceOverride.hook != null)
            {
                int arg;
                int arg2;
                if (tileData.HookPlaceOverride.processedCoordinates)
                {
                    arg  = toBePlaced.xCoord;
                    arg2 = toBePlaced.yCoord;
                }
                else
                {
                    arg  = toBePlaced.xCoord + tileData.Origin.X;
                    arg2 = toBePlaced.yCoord + tileData.Origin.Y;
                }
                if (tileData.HookPlaceOverride.hook(arg, arg2, toBePlaced.type, toBePlaced.style, 1, toBePlaced.alternate) == tileData.HookPlaceOverride.badReturn)
                {
                    return(false);
                }
            }
            else
            {
                ushort num  = (ushort)toBePlaced.type;
                int    num2 = 0;
                int    num3 = 0;
                int    num4 = tileData.CalculatePlacementStyle(toBePlaced.style, toBePlaced.alternate, toBePlaced.random);
                int    num5 = 0;
                if (tileData.StyleWrapLimit > 0)
                {
                    num5  = num4 / tileData.StyleWrapLimit * tileData.StyleLineSkip;
                    num4 %= tileData.StyleWrapLimit;
                }
                if (tileData.StyleHorizontal)
                {
                    num2 = tileData.CoordinateFullWidth * num4;
                    num3 = tileData.CoordinateFullHeight * num5;
                }
                else
                {
                    num2 = tileData.CoordinateFullWidth * num5;
                    num3 = tileData.CoordinateFullHeight * num4;
                }
                int num6 = toBePlaced.xCoord;
                int num7 = toBePlaced.yCoord;
                for (int i = 0; i < tileData.Width; i++)
                {
                    for (int j = 0; j < tileData.Height; j++)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num6 + i, num7 + j);
                        if (tileSafely.active() && tileSafely.type != 484 && (Main.tileCut[tileSafely.type] || TileID.Sets.BreakableWhenPlacing[tileSafely.type]))
                        {
                            WorldGen.KillTile(num6 + i, num7 + j);
                            if (!Main.tile[num6 + i, num7 + j].active() && Main.netMode == 1)
                            {
                                NetMessage.SendData(17, -1, -1, null, 0, num7 + i, num7 + j);
                            }
                        }
                    }
                }
                for (int k = 0; k < tileData.Width; k++)
                {
                    int num8 = num2 + k * (tileData.CoordinateWidth + tileData.CoordinatePadding);
                    int num9 = num3;
                    for (int l = 0; l < tileData.Height; l++)
                    {
                        Tile tileSafely2 = Framing.GetTileSafely(num6 + k, num7 + l);
                        if (!tileSafely2.active())
                        {
                            tileSafely2.active(active: true);
                            tileSafely2.frameX = (short)num8;
                            tileSafely2.frameY = (short)num9;
                            tileSafely2.type   = num;
                        }
                        num9 += tileData.CoordinateHeights[l] + tileData.CoordinatePadding;
                    }
                }
            }
            if (tileData.FlattenAnchors)
            {
                AnchorData anchorBottom = tileData.AnchorBottom;
                if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int num10 = toBePlaced.xCoord + anchorBottom.checkStart;
                    int j2    = toBePlaced.yCoord + tileData.Height;
                    for (int m = 0; m < anchorBottom.tileCount; m++)
                    {
                        Tile tileSafely3 = Framing.GetTileSafely(num10 + m, j2);
                        if (Main.tileSolid[tileSafely3.type] && !Main.tileSolidTop[tileSafely3.type] && tileSafely3.blockType() != 0)
                        {
                            WorldGen.SlopeTile(num10 + m, j2);
                        }
                    }
                }
                anchorBottom = tileData.AnchorTop;
                if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int num11 = toBePlaced.xCoord + anchorBottom.checkStart;
                    int j3    = toBePlaced.yCoord - 1;
                    for (int n = 0; n < anchorBottom.tileCount; n++)
                    {
                        Tile tileSafely4 = Framing.GetTileSafely(num11 + n, j3);
                        if (Main.tileSolid[tileSafely4.type] && !Main.tileSolidTop[tileSafely4.type] && tileSafely4.blockType() != 0)
                        {
                            WorldGen.SlopeTile(num11 + n, j3);
                        }
                    }
                }
                anchorBottom = tileData.AnchorRight;
                if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int i2    = toBePlaced.xCoord + tileData.Width;
                    int num12 = toBePlaced.yCoord + anchorBottom.checkStart;
                    for (int num13 = 0; num13 < anchorBottom.tileCount; num13++)
                    {
                        Tile tileSafely5 = Framing.GetTileSafely(i2, num12 + num13);
                        if (Main.tileSolid[tileSafely5.type] && !Main.tileSolidTop[tileSafely5.type] && tileSafely5.blockType() != 0)
                        {
                            WorldGen.SlopeTile(i2, num12 + num13);
                        }
                    }
                }
                anchorBottom = tileData.AnchorLeft;
                if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int i3    = toBePlaced.xCoord - 1;
                    int num14 = toBePlaced.yCoord + anchorBottom.checkStart;
                    for (int num15 = 0; num15 < anchorBottom.tileCount; num15++)
                    {
                        Tile tileSafely6 = Framing.GetTileSafely(i3, num14 + num15);
                        if (Main.tileSolid[tileSafely6.type] && !Main.tileSolidTop[tileSafely6.type] && tileSafely6.blockType() != 0)
                        {
                            WorldGen.SlopeTile(i3, num14 + num15);
                        }
                    }
                }
            }
            return(true);
        }
		public static bool Place(TileObject toBePlaced)
		{
			int num;
			int num1;
			TileObjectData tileData = TileObjectData.GetTileData(toBePlaced.type, toBePlaced.style, toBePlaced.alternate);
			if (tileData == null)
			{
				return false;
			}
			if (tileData.HookPlaceOverride.hook == null)
			{
				ushort num2 = (ushort)toBePlaced.type;
				int coordinateFullWidth = 0;
				int coordinateFullHeight = 0;
				int styleWrapLimit = tileData.CalculatePlacementStyle(toBePlaced.style, toBePlaced.alternate, toBePlaced.random);
				int styleWrapLimit1 = 0;
				if (tileData.StyleWrapLimit > 0)
				{
					styleWrapLimit1 = styleWrapLimit / tileData.StyleWrapLimit;
					styleWrapLimit = styleWrapLimit % tileData.StyleWrapLimit;
				}
				if (!tileData.StyleHorizontal)
				{
					coordinateFullWidth = tileData.CoordinateFullWidth * styleWrapLimit1;
					coordinateFullHeight = tileData.CoordinateFullHeight * styleWrapLimit;
				}
				else
				{
					coordinateFullWidth = tileData.CoordinateFullWidth * styleWrapLimit;
					coordinateFullHeight = tileData.CoordinateFullHeight * styleWrapLimit1;
				}
				int num3 = toBePlaced.xCoord;
				int num4 = toBePlaced.yCoord;
				for (int i = 0; i < tileData.Width; i++)
				{
					for (int j = 0; j < tileData.Height; j++)
					{
						Tile tileSafely = Framing.GetTileSafely(num3 + i, num4 + j);
						if (tileSafely.active() && Main.tileCut[tileSafely.type])
						{
							WorldGen.KillTile(num3 + i, num4 + j, false, false, false);
						}
					}
				}
				for (int k = 0; k < tileData.Width; k++)
				{
					int coordinateWidth = coordinateFullWidth + k * (tileData.CoordinateWidth + tileData.CoordinatePadding);
					int coordinateHeights = coordinateFullHeight;
					for (int l = 0; l < tileData.Height; l++)
					{
						Tile tile = Framing.GetTileSafely(num3 + k, num4 + l);
						if (!tile.active())
						{
							tile.active(true);
							tile.frameX = (short)coordinateWidth;
							tile.frameY = (short)coordinateHeights;
							tile.type = num2;
						}
						coordinateHeights = coordinateHeights + tileData.CoordinateHeights[l] + tileData.CoordinatePadding;
					}
				}
			}
			else
			{
				if (!tileData.HookPlaceOverride.processedCoordinates)
				{
					num = toBePlaced.xCoord + tileData.Origin.X;
					num1 = toBePlaced.yCoord + tileData.Origin.Y;
				}
				else
				{
					num = toBePlaced.xCoord;
					num1 = toBePlaced.yCoord;
				}
				if (tileData.HookPlaceOverride.hook(num, num1, toBePlaced.type, toBePlaced.style, 1) == tileData.HookPlaceOverride.badReturn)
				{
					return false;
				}
			}
			if (tileData.FlattenAnchors)
			{
				AnchorData anchorBottom = tileData.AnchorBottom;
				if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
				{
					int num5 = toBePlaced.xCoord + anchorBottom.checkStart;
					int num6 = toBePlaced.yCoord + tileData.Height;
					for (int m = 0; m < anchorBottom.tileCount; m++)
					{
						Tile tileSafely1 = Framing.GetTileSafely(num5 + m, num6);
						if (Main.tileSolid[tileSafely1.type] && !Main.tileSolidTop[tileSafely1.type] && tileSafely1.blockType() != 0)
						{
							WorldGen.SlopeTile(num5 + m, num6, 0);
						}
					}
				}
				anchorBottom = tileData.AnchorTop;
				if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
				{
					int num7 = toBePlaced.xCoord + anchorBottom.checkStart;
					int num8 = toBePlaced.yCoord - 1;
					for (int n = 0; n < anchorBottom.tileCount; n++)
					{
						Tile tile1 = Framing.GetTileSafely(num7 + n, num8);
						if (Main.tileSolid[tile1.type] && !Main.tileSolidTop[tile1.type] && tile1.blockType() != 0)
						{
							WorldGen.SlopeTile(num7 + n, num8, 0);
						}
					}
				}
				anchorBottom = tileData.AnchorRight;
				if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
				{
					int num9 = toBePlaced.xCoord + tileData.Width;
					int num10 = toBePlaced.yCoord + anchorBottom.checkStart;
					for (int o = 0; o < anchorBottom.tileCount; o++)
					{
						Tile tileSafely2 = Framing.GetTileSafely(num9, num10 + o);
						if (Main.tileSolid[tileSafely2.type] && !Main.tileSolidTop[tileSafely2.type] && tileSafely2.blockType() != 0)
						{
							WorldGen.SlopeTile(num9, num10 + o, 0);
						}
					}
				}
				anchorBottom = tileData.AnchorLeft;
				if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
				{
					int num11 = toBePlaced.xCoord - 1;
					int num12 = toBePlaced.yCoord + anchorBottom.checkStart;
					for (int p = 0; p < anchorBottom.tileCount; p++)
					{
						Tile tile2 = Framing.GetTileSafely(num11, num12 + p);
						if (Main.tileSolid[tile2.type] && !Main.tileSolidTop[tile2.type] && tile2.blockType() != 0)
						{
							WorldGen.SlopeTile(num11, num12 + p, 0);
						}
					}
				}
			}
			return true;
		}
Beispiel #21
0
        public static bool Place(TileObject toBePlaced)
        {
            TileObjectData tileData = TileObjectData.GetTileData(toBePlaced.type, toBePlaced.style, toBePlaced.alternate);

            if (tileData == null)
            {
                return(false);
            }
            if (tileData.HookPlaceOverride.hook != null)
            {
                int num1;
                int num2;
                if (tileData.HookPlaceOverride.processedCoordinates)
                {
                    num1 = toBePlaced.xCoord;
                    num2 = toBePlaced.yCoord;
                }
                else
                {
                    num1 = toBePlaced.xCoord + (int)tileData.Origin.X;
                    num2 = toBePlaced.yCoord + (int)tileData.Origin.Y;
                }
                if (tileData.HookPlaceOverride.hook(num1, num2, toBePlaced.type, toBePlaced.style, 1, toBePlaced.alternate) == tileData.HookPlaceOverride.badReturn)
                {
                    return(false);
                }
            }
            else
            {
                ushort type           = (ushort)toBePlaced.type;
                int    placementStyle = tileData.CalculatePlacementStyle(toBePlaced.style, toBePlaced.alternate, toBePlaced.random);
                int    num1           = 0;
                if (tileData.StyleWrapLimit > 0)
                {
                    num1            = placementStyle / tileData.StyleWrapLimit * tileData.StyleLineSkip;
                    placementStyle %= tileData.StyleWrapLimit;
                }
                int num2;
                int num3;
                if (tileData.StyleHorizontal)
                {
                    num2 = tileData.CoordinateFullWidth * placementStyle;
                    num3 = tileData.CoordinateFullHeight * num1;
                }
                else
                {
                    num2 = tileData.CoordinateFullWidth * num1;
                    num3 = tileData.CoordinateFullHeight * placementStyle;
                }
                int xCoord = toBePlaced.xCoord;
                int yCoord = toBePlaced.yCoord;
                for (int index1 = 0; index1 < tileData.Width; ++index1)
                {
                    for (int index2 = 0; index2 < tileData.Height; ++index2)
                    {
                        Tile tileSafely = Framing.GetTileSafely(xCoord + index1, yCoord + index2);
                        if (tileSafely.active() && tileSafely.type != (ushort)484 && (Main.tileCut[(int)tileSafely.type] || TileID.Sets.BreakableWhenPlacing[(int)tileSafely.type]))
                        {
                            WorldGen.KillTile(xCoord + index1, yCoord + index2, false, false, false);
                            if (!Main.tile[xCoord + index1, yCoord + index2].active() && Main.netMode == 1)
                            {
                                NetMessage.SendData(17, -1, -1, (NetworkText)null, 0, (float)(yCoord + index1), (float)(yCoord + index2), 0.0f, 0, 0, 0);
                            }
                        }
                    }
                }
                for (int index1 = 0; index1 < tileData.Width; ++index1)
                {
                    int num4 = num2 + index1 * (tileData.CoordinateWidth + tileData.CoordinatePadding);
                    int num5 = num3;
                    for (int index2 = 0; index2 < tileData.Height; ++index2)
                    {
                        Tile tileSafely = Framing.GetTileSafely(xCoord + index1, yCoord + index2);
                        if (!tileSafely.active())
                        {
                            tileSafely.active(true);
                            tileSafely.frameX = (short)num4;
                            tileSafely.frameY = (short)num5;
                            tileSafely.type   = type;
                        }
                        num5 += tileData.CoordinateHeights[index2] + tileData.CoordinatePadding;
                    }
                }
            }
            if (tileData.FlattenAnchors)
            {
                AnchorData anchorBottom = tileData.AnchorBottom;
                if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int num = toBePlaced.xCoord + anchorBottom.checkStart;
                    int j   = toBePlaced.yCoord + tileData.Height;
                    for (int index = 0; index < anchorBottom.tileCount; ++index)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num + index, j);
                        if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                        {
                            WorldGen.SlopeTile(num + index, j, 0, false);
                        }
                    }
                }
                AnchorData anchorTop = tileData.AnchorTop;
                if (anchorTop.tileCount != 0 && (anchorTop.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int num = toBePlaced.xCoord + anchorTop.checkStart;
                    int j   = toBePlaced.yCoord - 1;
                    for (int index = 0; index < anchorTop.tileCount; ++index)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num + index, j);
                        if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                        {
                            WorldGen.SlopeTile(num + index, j, 0, false);
                        }
                    }
                }
                AnchorData anchorRight = tileData.AnchorRight;
                if (anchorRight.tileCount != 0 && (anchorRight.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int i   = toBePlaced.xCoord + tileData.Width;
                    int num = toBePlaced.yCoord + anchorRight.checkStart;
                    for (int index = 0; index < anchorRight.tileCount; ++index)
                    {
                        Tile tileSafely = Framing.GetTileSafely(i, num + index);
                        if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                        {
                            WorldGen.SlopeTile(i, num + index, 0, false);
                        }
                    }
                }
                AnchorData anchorLeft = tileData.AnchorLeft;
                if (anchorLeft.tileCount != 0 && (anchorLeft.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int i   = toBePlaced.xCoord - 1;
                    int num = toBePlaced.yCoord + anchorLeft.checkStart;
                    for (int index = 0; index < anchorLeft.tileCount; ++index)
                    {
                        Tile tileSafely = Framing.GetTileSafely(i, num + index);
                        if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                        {
                            WorldGen.SlopeTile(i, num + index, 0, false);
                        }
                    }
                }
            }
            return(true);
        }
Beispiel #22
0
 public void PlaceThing()
 {
     if ((this.inventory[this.selectedItem].itemId == 1071 || this.inventory[this.selectedItem].itemId == 1543) && ((double)this.position.X / 16.0 - (double)Player.tileRangeX - (double)this.inventory[this.selectedItem].tileBoost - (double)this.blockRange <= (double)Player.tileTargetX && ((double)this.position.X + (double)this.width) / 16.0 + (double)Player.tileRangeX + (double)this.inventory[this.selectedItem].tileBoost - 1.0 + (double)this.blockRange >= (double)Player.tileTargetX) && ((double)this.position.Y / 16.0 - (double)Player.tileRangeY - (double)this.inventory[this.selectedItem].tileBoost - (double)this.blockRange <= (double)Player.tileTargetY && ((double)this.position.Y + (double)this.height) / 16.0 + (double)Player.tileRangeY + (double)this.inventory[this.selectedItem].tileBoost - 2.0 + (double)this.blockRange >= (double)Player.tileTargetY))
     {
         int x = Player.tileTargetX;
         int y = Player.tileTargetY;
         if (Main.tile[x, y] != null && Main.tile[x, y].active())
         {
             this.showItemIcon = true;
             if (this.itemTime == 0 && this.itemAnimation > 0 && this.controlUseItem)
             {
                 int num1 = -1;
                 int num2 = -1;
                 for (int index = 0; index < 58; ++index)
                 {
                     if (this.inventory[index].stack > 0 && (int)this.inventory[index].paint > 0)
                     {
                         num1 = (int)this.inventory[index].paint;
                         num2 = index;
                         break;
                     }
                 }
                 if (num1 > 0 && (int)Main.tile[x, y].color() != num1 && WorldGen.paintTile(x, y, (byte)num1, true))
                 {
                     int index = num2;
                     --this.inventory[index].stack;
                     if (this.inventory[index].stack <= 0)
                         this.inventory[index].SetDefaults(0, false);
                     this.itemTime = this.inventory[this.selectedItem].useTime;
                 }
             }
         }
     }
     if ((this.inventory[this.selectedItem].itemId == 1072 || this.inventory[this.selectedItem].itemId == 1544) && ((double)this.position.X / 16.0 - (double)Player.tileRangeX - (double)this.inventory[this.selectedItem].tileBoost - (double)this.blockRange <= (double)Player.tileTargetX && ((double)this.position.X + (double)this.width) / 16.0 + (double)Player.tileRangeX + (double)this.inventory[this.selectedItem].tileBoost - 1.0 + (double)this.blockRange >= (double)Player.tileTargetX) && ((double)this.position.Y / 16.0 - (double)Player.tileRangeY - (double)this.inventory[this.selectedItem].tileBoost - (double)this.blockRange <= (double)Player.tileTargetY && ((double)this.position.Y + (double)this.height) / 16.0 + (double)Player.tileRangeY + (double)this.inventory[this.selectedItem].tileBoost - 2.0 + (double)this.blockRange >= (double)Player.tileTargetY))
     {
         int x = Player.tileTargetX;
         int y = Player.tileTargetY;
         if (Main.tile[x, y] != null && (int)Main.tile[x, y].wall > 0)
         {
             this.showItemIcon = true;
             if (this.itemTime == 0 && this.itemAnimation > 0 && this.controlUseItem)
             {
                 int num1 = -1;
                 int num2 = -1;
                 for (int index = 0; index < 58; ++index)
                 {
                     if (this.inventory[index].stack > 0 && (int)this.inventory[index].paint > 0)
                     {
                         num1 = (int)this.inventory[index].paint;
                         num2 = index;
                         break;
                     }
                 }
                 if (num1 > 0 && (int)Main.tile[x, y].wallColor() != num1 && WorldGen.paintWall(x, y, (byte)num1, true))
                 {
                     int index = num2;
                     --this.inventory[index].stack;
                     if (this.inventory[index].stack <= 0)
                         this.inventory[index].SetDefaults(0, false);
                     this.itemTime = this.inventory[this.selectedItem].useTime;
                 }
             }
         }
     }
     if ((this.inventory[this.selectedItem].itemId == 1100 || this.inventory[this.selectedItem].itemId == 1545) && ((double)this.position.X / 16.0 - (double)Player.tileRangeX - (double)this.inventory[this.selectedItem].tileBoost - (double)this.blockRange <= (double)Player.tileTargetX && ((double)this.position.X + (double)this.width) / 16.0 + (double)Player.tileRangeX + (double)this.inventory[this.selectedItem].tileBoost - 1.0 + (double)this.blockRange >= (double)Player.tileTargetX) && ((double)this.position.Y / 16.0 - (double)Player.tileRangeY - (double)this.inventory[this.selectedItem].tileBoost - (double)this.blockRange <= (double)Player.tileTargetY && ((double)this.position.Y + (double)this.height) / 16.0 + (double)Player.tileRangeY + (double)this.inventory[this.selectedItem].tileBoost - 2.0 + (double)this.blockRange >= (double)Player.tileTargetY))
     {
         int x = Player.tileTargetX;
         int y = Player.tileTargetY;
         if (Main.tile[x, y] != null && ((int)Main.tile[x, y].wallColor() > 0 && (int)Main.tile[x, y].wall > 0 || (int)Main.tile[x, y].color() > 0 && Main.tile[x, y].active()))
         {
             this.showItemIcon = true;
             if (this.itemTime == 0 && this.itemAnimation > 0 && this.controlUseItem)
             {
                 if ((int)Main.tile[x, y].color() > 0 && Main.tile[x, y].active() && WorldGen.paintTile(x, y, (byte)0, true))
                     this.itemTime = this.inventory[this.selectedItem].useTime;
                 else if ((int)Main.tile[x, y].wallColor() > 0 && (int)Main.tile[x, y].wall > 0 && WorldGen.paintWall(x, y, (byte)0, true))
                     this.itemTime = this.inventory[this.selectedItem].useTime;
             }
         }
     }
     if ((this.inventory[this.selectedItem].itemId == 929 || this.inventory[this.selectedItem].itemId == 1338 || this.inventory[this.selectedItem].itemId == 1345) && ((double)this.position.X / 16.0 - (double)Player.tileRangeX - (double)this.inventory[this.selectedItem].tileBoost - (double)this.blockRange <= (double)Player.tileTargetX && ((double)this.position.X + (double)this.width) / 16.0 + (double)Player.tileRangeX + (double)this.inventory[this.selectedItem].tileBoost - 1.0 + (double)this.blockRange >= (double)Player.tileTargetX && ((double)this.position.Y / 16.0 - (double)Player.tileRangeY - (double)this.inventory[this.selectedItem].tileBoost - (double)this.blockRange <= (double)Player.tileTargetY && ((double)this.position.Y + (double)this.height) / 16.0 + (double)Player.tileRangeY + (double)this.inventory[this.selectedItem].tileBoost - 2.0 + (double)this.blockRange >= (double)Player.tileTargetY)))
     {
         int index1 = Player.tileTargetX;
         int index2 = Player.tileTargetY;
         if (Main.tile[index1, index2].active() && (int)Main.tile[index1, index2].type == 209)
         {
             int num1 = 0;
             if ((int)Main.tile[index1, index2].frameX < 72)
             {
                 if (this.inventory[this.selectedItem].itemId == 929)
                     num1 = 1;
             }
             else if ((int)Main.tile[index1, index2].frameX < 144)
             {
                 if (this.inventory[this.selectedItem].itemId == 1338)
                     num1 = 2;
             }
             else if ((int)Main.tile[index1, index2].frameX < 288 && this.inventory[this.selectedItem].itemId == 1345)
                 num1 = 3;
             if (num1 > 0)
             {
                 this.showItemIcon = true;
                 if (this.itemTime == 0 && this.itemAnimation > 0 && this.controlUseItem)
                 {
                     int num2 = (int)Main.tile[index1, index2].frameX / 18;
                     int num3 = 0;
                     int num4 = 0;
                     while (num2 >= 4)
                     {
                         ++num3;
                         num2 -= 4;
                     }
                     int num5 = index1 - num2;
                     int num6 = (int)Main.tile[index1, index2].frameY / 18;
                     while (num6 >= 3)
                     {
                         ++num4;
                         num6 -= 3;
                     }
                     int num7 = index2 - num6;
                     this.itemTime = this.inventory[this.selectedItem].useTime;
                     float num8 = 14f;
                     float num9 = 0.0f;
                     float num10 = 0.0f;
                     int Type = 162;
                     if (num1 == 2)
                         Type = 281;
                     if (num1 == 3)
                         Type = 178;
                     int Damage = this.inventory[this.selectedItem].damage;
                     int num11 = 8;
                     if (num4 == 0)
                     {
                         num9 = 10f;
                         num10 = 0.0f;
                     }
                     if (num4 == 1)
                     {
                         num9 = 7.5f;
                         num10 = -2.5f;
                     }
                     if (num4 == 2)
                     {
                         num9 = 5f;
                         num10 = -5f;
                     }
                     if (num4 == 3)
                     {
                         num9 = 2.75f;
                         num10 = -6f;
                     }
                     if (num4 == 4)
                     {
                         num9 = 0.0f;
                         num10 = -10f;
                     }
                     if (num4 == 5)
                     {
                         num9 = -2.75f;
                         num10 = -6f;
                     }
                     if (num4 == 6)
                     {
                         num9 = -5f;
                         num10 = -5f;
                     }
                     if (num4 == 7)
                     {
                         num9 = -7.5f;
                         num10 = -2.5f;
                     }
                     if (num4 == 8)
                     {
                         num9 = -10f;
                         num10 = 0.0f;
                     }
                     Vector2 vector2 = new Vector2((float)((num5 + 2) * 16), (float)((num7 + 2) * 16));
                     float num12 = num9;
                     float num13 = num10;
                     float num14 = (float)Math.Sqrt((double)num12 * (double)num12 + (double)num13 * (double)num13);
                     float num15 = num8 / num14;
                     float SpeedX = num12 * num15;
                     float SpeedY = num13 * num15;
                     Projectile.NewProjectile(vector2.X, vector2.Y, SpeedX, SpeedY, Type, Damage, (float)num11, Main.myPlayer, 0.0f, 0.0f);
                 }
             }
         }
     }
     if (this.inventory[this.selectedItem].itemId >= 1874 && this.inventory[this.selectedItem].itemId <= 1905 && (Main.tile[Player.tileTargetX, Player.tileTargetY].active() && (int)Main.tile[Player.tileTargetX, Player.tileTargetY].type == 171) && ((double)this.position.X / 16.0 - (double)Player.tileRangeX - (double)this.inventory[this.selectedItem].tileBoost - (double)this.blockRange <= (double)Player.tileTargetX && ((double)this.position.X + (double)this.width) / 16.0 + (double)Player.tileRangeX + (double)this.inventory[this.selectedItem].tileBoost - 1.0 + (double)this.blockRange >= (double)Player.tileTargetX && ((double)this.position.Y / 16.0 - (double)Player.tileRangeY - (double)this.inventory[this.selectedItem].tileBoost - (double)this.blockRange <= (double)Player.tileTargetY && ((double)this.position.Y + (double)this.height) / 16.0 + (double)Player.tileRangeY + (double)this.inventory[this.selectedItem].tileBoost - 2.0 + (double)this.blockRange >= (double)Player.tileTargetY)) && (this.itemTime == 0 && this.itemAnimation > 0 && this.controlUseItem))
     {
         int num = this.inventory[this.selectedItem].itemId;
         if (num >= 1874 && num <= 1877)
         {
             int style = num - 1873;
             if (WorldGen.checkXmasTreeDrop(Player.tileTargetX, Player.tileTargetY, 0) != style)
             {
                 this.itemTime = this.inventory[this.selectedItem].useTime;
                 WorldGen.dropXmasTree(Player.tileTargetX, Player.tileTargetY, 0);
                 WorldGen.setXmasTree(Player.tileTargetX, Player.tileTargetY, 0, style);
                 int tileX = Player.tileTargetX;
                 int tileY = Player.tileTargetY;
                 if ((int)Main.tile[Player.tileTargetX, Player.tileTargetY].frameX < 10)
                 {
                     tileX -= (int)Main.tile[Player.tileTargetX, Player.tileTargetY].frameX;
                     tileY -= (int)Main.tile[Player.tileTargetX, Player.tileTargetY].frameY;
                 }
                 NetMessage.SendTileSquare(-1, tileX, tileY, 1);
             }
         }
         else if (num >= 1878 && num <= 1883)
         {
             int style = num - 1877;
             if (WorldGen.checkXmasTreeDrop(Player.tileTargetX, Player.tileTargetY, 1) != style)
             {
                 this.itemTime = this.inventory[this.selectedItem].useTime;
                 WorldGen.dropXmasTree(Player.tileTargetX, Player.tileTargetY, 1);
                 WorldGen.setXmasTree(Player.tileTargetX, Player.tileTargetY, 1, style);
                 int tileX = Player.tileTargetX;
                 int tileY = Player.tileTargetY;
                 if ((int)Main.tile[Player.tileTargetX, Player.tileTargetY].frameX < 10)
                 {
                     tileX -= (int)Main.tile[Player.tileTargetX, Player.tileTargetY].frameX;
                     tileY -= (int)Main.tile[Player.tileTargetX, Player.tileTargetY].frameY;
                 }
                 NetMessage.SendTileSquare(-1, tileX, tileY, 1);
             }
         }
         else if (num >= 1884 && num <= 1894)
         {
             int style = num - 1883;
             if (WorldGen.checkXmasTreeDrop(Player.tileTargetX, Player.tileTargetY, 2) != style)
             {
                 this.itemTime = this.inventory[this.selectedItem].useTime;
                 WorldGen.dropXmasTree(Player.tileTargetX, Player.tileTargetY, 2);
                 WorldGen.setXmasTree(Player.tileTargetX, Player.tileTargetY, 2, style);
                 int tileX = Player.tileTargetX;
                 int tileY = Player.tileTargetY;
                 if ((int)Main.tile[Player.tileTargetX, Player.tileTargetY].frameX < 10)
                 {
                     tileX -= (int)Main.tile[Player.tileTargetX, Player.tileTargetY].frameX;
                     tileY -= (int)Main.tile[Player.tileTargetX, Player.tileTargetY].frameY;
                 }
                 NetMessage.SendTileSquare(-1, tileX, tileY, 1);
             }
         }
         else if (num >= 1895 && num <= 1905)
         {
             int style = num - 1894;
             if (WorldGen.checkXmasTreeDrop(Player.tileTargetX, Player.tileTargetY, 3) != style)
             {
                 this.itemTime = this.inventory[this.selectedItem].useTime;
                 WorldGen.dropXmasTree(Player.tileTargetX, Player.tileTargetY, 3);
                 WorldGen.setXmasTree(Player.tileTargetX, Player.tileTargetY, 3, style);
                 int tileX = Player.tileTargetX;
                 int tileY = Player.tileTargetY;
                 if ((int)Main.tile[Player.tileTargetX, Player.tileTargetY].frameX < 10)
                 {
                     tileX -= (int)Main.tile[Player.tileTargetX, Player.tileTargetY].frameX;
                     tileY -= (int)Main.tile[Player.tileTargetX, Player.tileTargetY].frameY;
                 }
                 NetMessage.SendTileSquare(-1, tileX, tileY, 1);
             }
         }
     }
     if (ItemID.Sets.ExtractinatorMode[this.inventory[this.selectedItem].itemId] >= 0 && Main.tile[Player.tileTargetX, Player.tileTargetY].active() && (int)Main.tile[Player.tileTargetX, Player.tileTargetY].type == 219)
     {
         if ((double)this.position.X / 16.0 - (double)Player.tileRangeX - (double)this.inventory[this.selectedItem].tileBoost - (double)this.blockRange <= (double)Player.tileTargetX && ((double)this.position.X + (double)this.width) / 16.0 + (double)Player.tileRangeX + (double)this.inventory[this.selectedItem].tileBoost - 1.0 + (double)this.blockRange >= (double)Player.tileTargetX && ((double)this.position.Y / 16.0 - (double)Player.tileRangeY - (double)this.inventory[this.selectedItem].tileBoost - (double)this.blockRange <= (double)Player.tileTargetY && ((double)this.position.Y + (double)this.height) / 16.0 + (double)Player.tileRangeY + (double)this.inventory[this.selectedItem].tileBoost - 2.0 + (double)this.blockRange >= (double)Player.tileTargetY) && (this.itemTime == 0 && this.itemAnimation > 0 && this.controlUseItem))
         {
             this.itemTime = this.inventory[this.selectedItem].useTime;
             Main.PlaySound(7, -1, -1, 1);
             Player.ExtractinatorUse(ItemID.Sets.ExtractinatorMode[this.inventory[this.selectedItem].itemId]);
         }
     }
     else if (this.inventory[this.selectedItem].createTile >= 0 && (double)this.position.X / 16.0 - (double)Player.tileRangeX - (double)this.inventory[this.selectedItem].tileBoost - (double)this.blockRange <= (double)Player.tileTargetX && (((double)this.position.X + (double)this.width) / 16.0 + (double)Player.tileRangeX + (double)this.inventory[this.selectedItem].tileBoost - 1.0 + (double)this.blockRange >= (double)Player.tileTargetX && (double)this.position.Y / 16.0 - (double)Player.tileRangeY - (double)this.inventory[this.selectedItem].tileBoost - (double)this.blockRange <= (double)Player.tileTargetY) && ((double)this.position.Y + (double)this.height) / 16.0 + (double)Player.tileRangeY + (double)this.inventory[this.selectedItem].tileBoost - 2.0 + (double)this.blockRange >= (double)Player.tileTargetY)
     {
         this.showItemIcon = true;
         bool flag1 = false;
         if ((int)Main.tile[Player.tileTargetX, Player.tileTargetY].liquid > 0 && Main.tile[Player.tileTargetX, Player.tileTargetY].lava())
         {
             if (Main.tileSolid[this.inventory[this.selectedItem].createTile])
                 flag1 = true;
             else if (!TileObjectData.CheckLiquidPlacement(this.inventory[this.selectedItem].createTile, this.inventory[this.selectedItem].placeStyle, Main.tile[Player.tileTargetX, Player.tileTargetY]))
                 flag1 = true;
         }
         bool flag2 = true;
         if (this.inventory[this.selectedItem].tileWand > 0)
         {
             int num = this.inventory[this.selectedItem].tileWand;
             flag2 = false;
             for (int index = 0; index < 58; ++index)
             {
                 if (num == this.inventory[index].itemId && this.inventory[index].stack > 0)
                 {
                     flag2 = true;
                     break;
                 }
             }
         }
         if (Main.tileRope[this.inventory[this.selectedItem].createTile] && flag2 && (Main.tile[Player.tileTargetX, Player.tileTargetY].active() && Main.tileRope[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type]))
         {
             int index1 = Player.tileTargetY;
             int index2 = Player.tileTargetX;
             int num = this.inventory[this.selectedItem].createTile;
             while (Main.tile[index2, index1].active() && Main.tileRope[(int)Main.tile[index2, index1].type] && (index1 < Main.maxTilesX - 5 && Main.tile[index2, index1 + 2] != null) && !Main.tile[index2, index1 + 1].lava())
             {
                 ++index1;
                 if (Main.tile[index2, index1] == null)
                 {
                     flag2 = false;
                     index1 = Player.tileTargetY;
                 }
             }
             if (!Main.tile[index2, index1].active())
                 Player.tileTargetY = index1;
         }
         if (flag2 && (!Main.tile[Player.tileTargetX, Player.tileTargetY].active() && !flag1 || Main.tileCut[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type] || ((int)Main.tile[Player.tileTargetX, Player.tileTargetY].type >= 373 && (int)Main.tile[Player.tileTargetX, Player.tileTargetY].type <= 375 || (this.inventory[this.selectedItem].createTile == 199 || this.inventory[this.selectedItem].createTile == 23)) || (this.inventory[this.selectedItem].createTile == 2 || this.inventory[this.selectedItem].createTile == 109 || (this.inventory[this.selectedItem].createTile == 60 || this.inventory[this.selectedItem].createTile == 70) || TileID.Sets.BreakableWhenPlacing[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type])) && (this.itemTime == 0 && this.itemAnimation > 0 && this.controlUseItem))
         {
             bool flag3 = false;
             bool flag4 = false;
             TileObject objectData = new TileObject();
             if (TileObjectData.CustomPlace(this.inventory[this.selectedItem].createTile, this.inventory[this.selectedItem].placeStyle) && this.inventory[this.selectedItem].createTile != 82)
             {
                 flag4 = true;
                 flag3 = TileObject.CanPlace(Player.tileTargetX, Player.tileTargetY, (int)(ushort)this.inventory[this.selectedItem].createTile, this.inventory[this.selectedItem].placeStyle, this.direction, out objectData, false);
             }
             else
             {
                 if (this.inventory[this.selectedItem].itemId == 213)
                 {
                     if ((int)Main.tile[Player.tileTargetX, Player.tileTargetY].type == 0 || (int)Main.tile[Player.tileTargetX, Player.tileTargetY].type == 1)
                         flag3 = true;
                 }
                 else if (this.inventory[this.selectedItem].createTile == 23 || this.inventory[this.selectedItem].createTile == 2 || (this.inventory[this.selectedItem].createTile == 109 || this.inventory[this.selectedItem].createTile == 199))
                 {
                     if (Main.tile[Player.tileTargetX, Player.tileTargetY].nactive() && (int)Main.tile[Player.tileTargetX, Player.tileTargetY].type == 0)
                         flag3 = true;
                 }
                 else if (this.inventory[this.selectedItem].createTile == 227)
                     flag3 = true;
                 else if (this.inventory[this.selectedItem].createTile >= 373 && this.inventory[this.selectedItem].createTile <= 375)
                 {
                     int index1 = Player.tileTargetX;
                     int index2 = Player.tileTargetY - 1;
                     if (Main.tile[index1, index2].nactive() && Main.tileSolid[(int)Main.tile[index1, index2].type] && !Main.tileSolidTop[(int)Main.tile[index1, index2].type])
                         flag3 = true;
                 }
                 else if (this.inventory[this.selectedItem].createTile == 60 || this.inventory[this.selectedItem].createTile == 70)
                 {
                     if (Main.tile[Player.tileTargetX, Player.tileTargetY].nactive() && (int)Main.tile[Player.tileTargetX, Player.tileTargetY].type == 59)
                         flag3 = true;
                 }
                 else if (this.inventory[this.selectedItem].createTile == 4 || this.inventory[this.selectedItem].createTile == 136)
                 {
                     if ((int)Main.tile[Player.tileTargetX, Player.tileTargetY].wall > 0)
                     {
                         flag3 = true;
                     }
                     else
                     {
                         if (!WorldGen.SolidTileNoAttach(Player.tileTargetX, Player.tileTargetY + 1) && !WorldGen.SolidTileNoAttach(Player.tileTargetX - 1, Player.tileTargetY) && !WorldGen.SolidTileNoAttach(Player.tileTargetX + 1, Player.tileTargetY))
                         {
                             if (!WorldGen.SolidTileNoAttach(Player.tileTargetX, Player.tileTargetY + 1) && (Main.tile[Player.tileTargetX, Player.tileTargetY + 1].halfBrick() || (int)Main.tile[Player.tileTargetX, Player.tileTargetY + 1].slope() != 0))
                             {
                                 if ((int)Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type != 19)
                                 {
                                     WorldGen.SlopeTile(Player.tileTargetX, Player.tileTargetY + 1, 0);
                                     if (Main.netMode == 1)
                                         NetMessage.SendData(17, -1, -1, "", 14, (float)Player.tileTargetX, (float)(Player.tileTargetY + 1), 0.0f, 0, 0, 0);
                                 }
                             }
                             else if (!WorldGen.SolidTileNoAttach(Player.tileTargetX, Player.tileTargetY + 1) && !WorldGen.SolidTileNoAttach(Player.tileTargetX - 1, Player.tileTargetY) && (Main.tile[Player.tileTargetX - 1, Player.tileTargetY].halfBrick() || (int)Main.tile[Player.tileTargetX - 1, Player.tileTargetY].slope() != 0))
                             {
                                 if ((int)Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type != 19)
                                 {
                                     WorldGen.SlopeTile(Player.tileTargetX - 1, Player.tileTargetY, 0);
                                     if (Main.netMode == 1)
                                         NetMessage.SendData(17, -1, -1, "", 14, (float)(Player.tileTargetX - 1), (float)Player.tileTargetY, 0.0f, 0, 0, 0);
                                 }
                             }
                             else if (!WorldGen.SolidTileNoAttach(Player.tileTargetX, Player.tileTargetY + 1) && !WorldGen.SolidTileNoAttach(Player.tileTargetX - 1, Player.tileTargetY) && !WorldGen.SolidTileNoAttach(Player.tileTargetX + 1, Player.tileTargetY) && ((Main.tile[Player.tileTargetX + 1, Player.tileTargetY].halfBrick() || (int)Main.tile[Player.tileTargetX + 1, Player.tileTargetY].slope() != 0) && (int)Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type != 19))
                             {
                                 WorldGen.SlopeTile(Player.tileTargetX + 1, Player.tileTargetY, 0);
                                 if (Main.netMode == 1)
                                     NetMessage.SendData(17, -1, -1, "", 14, (float)(Player.tileTargetX + 1), (float)Player.tileTargetY, 0.0f, 0, 0, 0);
                             }
                         }
                         int index1 = (int)Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type;
                         if (Main.tile[Player.tileTargetX, Player.tileTargetY].halfBrick())
                             index1 = -1;
                         int index2 = (int)Main.tile[Player.tileTargetX - 1, Player.tileTargetY].type;
                         int index3 = (int)Main.tile[Player.tileTargetX + 1, Player.tileTargetY].type;
                         int num1 = (int)Main.tile[Player.tileTargetX - 1, Player.tileTargetY - 1].type;
                         int num2 = (int)Main.tile[Player.tileTargetX + 1, Player.tileTargetY - 1].type;
                         int num3 = (int)Main.tile[Player.tileTargetX - 1, Player.tileTargetY - 1].type;
                         int num4 = (int)Main.tile[Player.tileTargetX + 1, Player.tileTargetY + 1].type;
                         if (!Main.tile[Player.tileTargetX, Player.tileTargetY + 1].nactive())
                             index1 = -1;
                         if (!Main.tile[Player.tileTargetX - 1, Player.tileTargetY].nactive())
                             index2 = -1;
                         if (!Main.tile[Player.tileTargetX + 1, Player.tileTargetY].nactive())
                             index3 = -1;
                         if (!Main.tile[Player.tileTargetX - 1, Player.tileTargetY - 1].nactive())
                             num1 = -1;
                         if (!Main.tile[Player.tileTargetX + 1, Player.tileTargetY - 1].nactive())
                             num2 = -1;
                         if (!Main.tile[Player.tileTargetX - 1, Player.tileTargetY + 1].nactive())
                             num3 = -1;
                         if (!Main.tile[Player.tileTargetX + 1, Player.tileTargetY + 1].nactive())
                             num4 = -1;
                         if (index1 >= 0 && Main.tileSolid[index1] && (!Main.tileNoAttach[index1] || index1 == 19))
                             flag3 = true;
                         else if (index2 >= 0 && Main.tileSolid[index2] && !Main.tileNoAttach[index2] || index2 == 5 && num1 == 5 && num3 == 5 || index2 == 124)
                             flag3 = true;
                         else if (index3 >= 0 && Main.tileSolid[index3] && !Main.tileNoAttach[index3] || index3 == 5 && num2 == 5 && num4 == 5 || index3 == 124)
                             flag3 = true;
                     }
                 }
                 else if (this.inventory[this.selectedItem].createTile == 78 || this.inventory[this.selectedItem].createTile == 98 || (this.inventory[this.selectedItem].createTile == 100 || this.inventory[this.selectedItem].createTile == 173) || (this.inventory[this.selectedItem].createTile == 174 || this.inventory[this.selectedItem].createTile == 324))
                 {
                     if (Main.tile[Player.tileTargetX, Player.tileTargetY + 1].nactive() && (Main.tileSolid[(int)Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type] || Main.tileTable[(int)Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type]))
                         flag3 = true;
                 }
                 else if (this.inventory[this.selectedItem].createTile == 13 || this.inventory[this.selectedItem].createTile == 29 || (this.inventory[this.selectedItem].createTile == 33 || this.inventory[this.selectedItem].createTile == 49) || (this.inventory[this.selectedItem].createTile == 50 || this.inventory[this.selectedItem].createTile == 103))
                 {
                     if (Main.tile[Player.tileTargetX, Player.tileTargetY + 1].nactive() && Main.tileTable[(int)Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type])
                         flag3 = true;
                 }
                 else if (this.inventory[this.selectedItem].createTile == 275 || this.inventory[this.selectedItem].createTile == 276 || this.inventory[this.selectedItem].createTile == 277)
                     flag3 = true;
                 else if (this.inventory[this.selectedItem].createTile == 51 || this.inventory[this.selectedItem].createTile == 330 || (this.inventory[this.selectedItem].createTile == 331 || this.inventory[this.selectedItem].createTile == 332) || (this.inventory[this.selectedItem].createTile == 333 || this.inventory[this.selectedItem].createTile == 336 || (this.inventory[this.selectedItem].createTile == 340 || this.inventory[this.selectedItem].createTile == 342)) || (this.inventory[this.selectedItem].createTile == 341 || this.inventory[this.selectedItem].createTile == 343 || (this.inventory[this.selectedItem].createTile == 344 || this.inventory[this.selectedItem].createTile == 379) || this.inventory[this.selectedItem].createTile == 351))
                 {
                     if (Main.tile[Player.tileTargetX + 1, Player.tileTargetY].active() || (int)Main.tile[Player.tileTargetX + 1, Player.tileTargetY].wall > 0 || (Main.tile[Player.tileTargetX - 1, Player.tileTargetY].active() || (int)Main.tile[Player.tileTargetX - 1, Player.tileTargetY].wall > 0) || (Main.tile[Player.tileTargetX, Player.tileTargetY + 1].active() || (int)Main.tile[Player.tileTargetX, Player.tileTargetY + 1].wall > 0 || (Main.tile[Player.tileTargetX, Player.tileTargetY - 1].active() || (int)Main.tile[Player.tileTargetX, Player.tileTargetY - 1].wall > 0)))
                         flag3 = true;
                 }
                 else if (this.inventory[this.selectedItem].createTile == 314)
                 {
                     for (int index1 = Player.tileTargetX - 1; index1 <= Player.tileTargetX + 1; ++index1)
                     {
                         for (int index2 = Player.tileTargetY - 1; index2 <= Player.tileTargetY + 1; ++index2)
                         {
                             Tile tile = Main.tile[index1, index2];
                             if (tile.active() || (int)tile.wall > 0)
                             {
                                 flag3 = true;
                                 break;
                             }
                         }
                     }
                 }
                 else
                 {
                     Tile tile1 = Main.tile[Player.tileTargetX - 1, Player.tileTargetY];
                     Tile tile2 = Main.tile[Player.tileTargetX + 1, Player.tileTargetY];
                     Tile tile3 = Main.tile[Player.tileTargetX, Player.tileTargetY - 1];
                     Tile tile4 = Main.tile[Player.tileTargetX, Player.tileTargetY + 1];
                     if (tile2.active() && (Main.tileSolid[(int)tile2.type] || Main.tileRope[(int)tile2.type] || (int)tile2.type == 314) || (int)tile2.wall > 0 || (tile1.active() && (Main.tileSolid[(int)tile1.type] || Main.tileRope[(int)tile1.type] || (int)tile1.type == 314) || (int)tile1.wall > 0) || (tile4.active() && (Main.tileSolid[(int)tile4.type] || (int)tile4.type == 124 || (Main.tileRope[(int)tile4.type] || (int)tile4.type == 314)) || (int)tile4.wall > 0 || (tile3.active() && (Main.tileSolid[(int)tile3.type] || (int)tile3.type == 124 || (Main.tileRope[(int)tile3.type] || (int)tile3.type == 314)) || (int)tile3.wall > 0)))
                         flag3 = true;
                 }
                 if (this.inventory[this.selectedItem].itemId == 213 && Main.tile[Player.tileTargetX, Player.tileTargetY].active())
                 {
                     int index1 = Player.tileTargetX;
                     int index2 = Player.tileTargetY;
                     if ((int)Main.tile[index1, index2].type == 3 || (int)Main.tile[index1, index2].type == 73 || (int)Main.tile[index1, index2].type == 84)
                     {
                         WorldGen.KillTile(Player.tileTargetX, Player.tileTargetY, false, false, false);
                         if (!Main.tile[Player.tileTargetX, Player.tileTargetY].active() && Main.netMode == 1)
                             NetMessage.SendData(17, -1, -1, "", 0, (float)Player.tileTargetX, (float)Player.tileTargetY, 0.0f, 0, 0, 0);
                     }
                     else if ((int)Main.tile[index1, index2].type == 83)
                     {
                         bool flag5 = false;
                         int num = (int)Main.tile[index1, index2].frameX / 18;
                         if (num == 0 && Main.dayTime)
                             flag5 = true;
                         if (num == 1 && !Main.dayTime)
                             flag5 = true;
                         if (num == 3 && !Main.dayTime && (Main.bloodMoon || Main.moonPhase == 0))
                             flag5 = true;
                         if (num == 4 && (Main.raining || (double)Main.cloudAlpha > 0.0))
                             flag5 = true;
                         if (num == 5 && !Main.raining && (Main.dayTime && Main.time > 40500.0))
                             flag5 = true;
                         if (flag5)
                         {
                             WorldGen.KillTile(Player.tileTargetX, Player.tileTargetY, false, false, false);
                             NetMessage.SendData(17, -1, -1, "", 0, (float)Player.tileTargetX, (float)Player.tileTargetY, 0.0f, 0, 0, 0);
                         }
                     }
                 }
                 if (Main.tileAlch[this.inventory[this.selectedItem].createTile])
                     flag3 = true;
                 if (Main.tile[Player.tileTargetX, Player.tileTargetY].active() && (Main.tileCut[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type] || TileID.Sets.BreakableWhenPlacing[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type] || (int)Main.tile[Player.tileTargetX, Player.tileTargetY].type >= 373 && (int)Main.tile[Player.tileTargetX, Player.tileTargetY].type <= 375))
                 {
                     if ((int)Main.tile[Player.tileTargetX, Player.tileTargetY].type != this.inventory[this.selectedItem].createTile)
                     {
                         if ((int)Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type != 78 && (int)Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type != 380 || ((int)Main.tile[Player.tileTargetX, Player.tileTargetY].type == 3 || (int)Main.tile[Player.tileTargetX, Player.tileTargetY].type == 73) && Main.tileAlch[this.inventory[this.selectedItem].createTile])
                         {
                             WorldGen.KillTile(Player.tileTargetX, Player.tileTargetY, false, false, false);
                             if (!Main.tile[Player.tileTargetX, Player.tileTargetY].active() && Main.netMode == 1)
                                 NetMessage.SendData(17, -1, -1, "", 4, (float)Player.tileTargetX, (float)Player.tileTargetY, 0.0f, 0, 0, 0);
                         }
                         else
                             flag3 = false;
                     }
                     else
                         flag3 = false;
                 }
                 if (!flag3 && this.inventory[this.selectedItem].createTile == 19)
                 {
                     for (int index1 = Player.tileTargetX - 1; index1 <= Player.tileTargetX + 1; ++index1)
                     {
                         for (int index2 = Player.tileTargetY - 1; index2 <= Player.tileTargetY + 1; ++index2)
                         {
                             if (Main.tile[index1, index2].active())
                             {
                                 flag3 = true;
                                 break;
                             }
                         }
                     }
                 }
             }
             if (flag3)
             {
                 int num1 = this.inventory[this.selectedItem].placeStyle;
                 if (!flag4)
                 {
                     if (this.inventory[this.selectedItem].createTile == 36)
                         num1 = Main.rand.Next(7);
                     if (this.inventory[this.selectedItem].createTile == 212 && this.direction > 0)
                         num1 = 1;
                     if (this.inventory[this.selectedItem].createTile == 141)
                         num1 = Main.rand.Next(2);
                     if (this.inventory[this.selectedItem].createTile == 128 || this.inventory[this.selectedItem].createTile == 269 || this.inventory[this.selectedItem].createTile == 334)
                         num1 = this.direction >= 0 ? 1 : -1;
                     if (this.inventory[this.selectedItem].createTile == 241 && this.inventory[this.selectedItem].placeStyle == 0)
                         num1 = Main.rand.Next(0, 9);
                     if (this.inventory[this.selectedItem].createTile == 35 && this.inventory[this.selectedItem].placeStyle == 0)
                         num1 = Main.rand.Next(9);
                 }
                 if (this.inventory[this.selectedItem].createTile == 314 && num1 == 2 && this.direction == 1)
                     ++num1;
                 int[,] numArray = new int[11, 11];
                 if (this.autoPaint)
                 {
                     for (int index1 = 0; index1 < 11; ++index1)
                     {
                         for (int index2 = 0; index2 < 11; ++index2)
                         {
                             int index3 = Player.tileTargetX - 5 + index1;
                             int index4 = Player.tileTargetY - 5 + index2;
                             numArray[index1, index2] = !Main.tile[index3, index4].active() ? -1 : (int)Main.tile[index3, index4].type;
                         }
                     }
                 }
                 bool forced = false;
                 bool flag5;
                 if (flag4)
                 {
                     flag5 = TileObject.Place(objectData);
                     WorldGen.SquareTileFrame(Player.tileTargetX, Player.tileTargetY, true);
                     Main.PlaySound(0, Player.tileTargetX * 16, Player.tileTargetY * 16, 1);
                 }
                 else
                     flag5 = WorldGen.PlaceTile(Player.tileTargetX, Player.tileTargetY, this.inventory[this.selectedItem].createTile, false, forced, this.whoAmI, num1);
                 if (this.inventory[this.selectedItem].itemId == 213 && !flag5 && ((int)Main.tile[Player.tileTargetX, Player.tileTargetY].type == 1 && Main.tile[Player.tileTargetX, Player.tileTargetY].active()))
                 {
                     int num2 = 0;
                     int num3 = 0;
                     Point point = Utils.ToTileCoordinates(this.Center);
                     Dictionary<ushort, int> resultsOutput = new Dictionary<ushort, int>();
                     WorldUtils.Gen(new Point(point.X - 25, point.Y - 25), (GenShape)new Shapes.Rectangle(50, 50), (GenAction)new Actions.TileScanner(new ushort[6]
       {
         (ushort) 182,
         (ushort) 180,
         (ushort) 179,
         (ushort) 183,
         (ushort) 181,
         (ushort) 381
       }).Output(resultsOutput));
                     foreach (KeyValuePair<ushort, int> keyValuePair in resultsOutput)
                     {
                         if (keyValuePair.Value > num3)
                         {
                             num3 = keyValuePair.Value;
                             num2 = (int)keyValuePair.Key;
                         }
                     }
                     if (num3 == 0)
                         num2 = Utils.SelectRandom<int>(Main.rand, 182, 180, 179, 183, 181);
                     if (num2 != 0)
                     {
                         Main.tile[Player.tileTargetX, Player.tileTargetY].type = (ushort)num2;
                         WorldGen.SquareTileFrame(Player.tileTargetX, Player.tileTargetY, true);
                         NetMessage.SendTileSquare(-1, Player.tileTargetX, Player.tileTargetY, 1);
                         flag5 = true;
                     }
                 }
                 if (flag5)
                 {
                     this.itemTime = (int)((double)this.inventory[this.selectedItem].useTime * (double)this.tileSpeed);
                     if (flag4)
                     {
                         TileObjectData.CallPostPlacementPlayerHook(Player.tileTargetX, Player.tileTargetY, this.inventory[this.selectedItem].createTile, num1, this.direction, objectData);
                         if (Main.netMode == 1 && !Main.tileContainer[this.inventory[this.selectedItem].createTile])
                             NetMessage.SendObjectPlacment(-1, Player.tileTargetX, Player.tileTargetY, objectData.type, objectData.style, objectData.alternate, objectData.random, this.direction);
                     }
                     else
                     {
                         NetMessage.SendData(17, -1, -1, "", 1, (float)Player.tileTargetX, (float)Player.tileTargetY, (float)this.inventory[this.selectedItem].createTile, num1, 0, 0);
                         if (this.inventory[this.selectedItem].createTile == 15)
                         {
                             if (this.direction == 1)
                             {
                                 Main.tile[Player.tileTargetX, Player.tileTargetY].frameX += (short)18;
                                 Main.tile[Player.tileTargetX, Player.tileTargetY - 1].frameX += (short)18;
                             }
                             if (Main.netMode == 1)
                                 NetMessage.SendTileSquare(-1, Player.tileTargetX - 1, Player.tileTargetY - 1, 3);
                         }
                         else if ((this.inventory[this.selectedItem].createTile == 79 || this.inventory[this.selectedItem].createTile == 90) && Main.netMode == 1)
                             NetMessage.SendTileSquare(-1, Player.tileTargetX, Player.tileTargetY, 5);
                     }
                     if (this.inventory[this.selectedItem].createTile == 137)
                     {
                         if (this.direction == 1)
                             Main.tile[Player.tileTargetX, Player.tileTargetY].frameX += (short)18;
                         if (Main.netMode == 1)
                             NetMessage.SendTileSquare(-1, Player.tileTargetX, Player.tileTargetY, 1);
                     }
                     if (this.inventory[this.selectedItem].createTile == 19 && Main.smartDigEnabled)
                     {
                         int index1 = Player.tileTargetX;
                         int index2 = Player.tileTargetY;
                         int slope1 = -1;
                         int num2 = 0;
                         int num3 = 0;
                         bool flag6 = true;
                         for (int index3 = -1; index3 < 2; ++index3)
                         {
                             for (int index4 = -1; index4 < 2; ++index4)
                             {
                                 if ((index3 != 0 || index4 != 0) && (int)Main.tile[index1 + index3, index2 + index4].type == 19)
                                     flag6 = false;
                             }
                         }
                         if (!flag6)
                         {
                             Tile tile1 = Main.tile[index1 - 1, index2 - 1];
                             if (tile1.active() && (int)tile1.type == 19 && (int)tile1.slope() != 2)
                                 ++num2;
                             Tile tile2 = Main.tile[index1 - 1, index2 + 1];
                             if (tile2.active() && (int)tile2.type == 19 && (int)tile2.slope() != 1)
                                 ++num3;
                             Tile tile3 = Main.tile[index1 + 1, index2 - 1];
                             if (tile3.active() && (int)tile3.type == 19 && (int)tile3.slope() != 1)
                                 ++num3;
                             Tile tile4 = Main.tile[index1 + 1, index2 + 1];
                             if (tile4.active() && (int)tile4.type == 19 && (int)tile4.slope() != 2)
                                 ++num2;
                             Tile testTile1 = Main.tile[index1 - 1, index2];
                             if (WorldGen.SolidTile(testTile1))
                             {
                                 ++num2;
                                 if ((int)testTile1.type == 19 && (int)testTile1.slope() == 0)
                                     ++num2;
                             }
                             Tile testTile2 = Main.tile[index1 + 1, index2];
                             if (WorldGen.SolidTile(testTile2))
                             {
                                 ++num3;
                                 if ((int)testTile2.type == 19 && (int)testTile2.slope() == 0)
                                     ++num3;
                             }
                             if (num2 > num3)
                                 slope1 = 1;
                             else if (num3 > num2)
                                 slope1 = 2;
                             Tile tile5 = Main.tile[index1 - 1, index2];
                             if (tile5.active() && (int)tile5.type == 19)
                                 slope1 = 0;
                             Tile tile6 = Main.tile[index1 + 1, index2];
                             if (tile6.active() && (int)tile6.type == 19)
                                 slope1 = 0;
                             if (slope1 != -1)
                             {
                                 WorldGen.SlopeTile(index1, index2, slope1);
                                 int num4 = (int)Main.tile[index1, index2].slope();
                                 if (Main.netMode == 1)
                                     NetMessage.SendData(17, -1, -1, "", 14, (float)Player.tileTargetX, (float)Player.tileTargetY, (float)num4, 0, 0, 0);
                                 int num5;
                                 int num6;
                                 if (slope1 == 1)
                                 {
                                     num5 = -1;
                                     num6 = -1;
                                 }
                                 else
                                 {
                                     num5 = 1;
                                     num6 = -1;
                                 }
                                 Tile tile7 = Main.tile[index1 + num5, index2 + num6];
                                 if (tile7.active() && (int)tile7.type == 19 && (int)tile7.slope() == 0 && (!Main.tile[index1 + num5 + num5, index2 + num6].active() || (int)Main.tile[index1 + num5 + num5, index2 + num6].type != 19 || !Main.tile[index1 + num5 + num5, index2 + num6].halfBrick()))
                                 {
                                     WorldGen.SlopeTile(index1 + num5, index2 + num6, slope1);
                                     int num7 = (int)tile7.slope();
                                     if (Main.netMode == 1)
                                         NetMessage.SendData(17, -1, -1, "", 14, (float)(index1 + num5), (float)(index2 + num6), (float)num7, 0, 0, 0);
                                 }
                                 int num8;
                                 int num9;
                                 if (slope1 == 1)
                                 {
                                     num8 = 1;
                                     num9 = 1;
                                 }
                                 else
                                 {
                                     num8 = -1;
                                     num9 = 1;
                                 }
                                 Tile tile8 = Main.tile[index1 + num8, index2 + num9];
                                 if (tile8.active() && (int)tile8.type == 19 && ((int)tile8.slope() == 0 && WorldGen.PlatformProperSides(index1 + num8, index2 + num9, true) <= 0))
                                 {
                                     WorldGen.SlopeTile(index1 + num8, index2 + num9, slope1);
                                     int num7 = (int)tile8.slope();
                                     if (Main.netMode == 1)
                                         NetMessage.SendData(17, -1, -1, "", 14, (float)(index1 + num8), (float)(index2 + num9), (float)num7, 0, 0, 0);
                                 }
                             }
                             else
                             {
                                 int num4 = -1;
                                 Tile tile7 = Main.tile[index1 + num4, index2];
                                 if (tile7.active() && (int)tile7.type == 19 && (int)tile7.slope() != 0)
                                 {
                                     int num5 = Utils.ToDirectionInt((int)tile7.slope() == 1) * num4;
                                     int slope2 = num5 == -1 ? 0 : (int)tile7.slope();
                                     bool flag7 = true;
                                     if (Main.tile[index1 + num4 * 2, index2 + num5].active() && (int)Main.tile[index1 + num4 * 2, index2].type == 19 && slope2 == (int)Main.tile[index1 + num4 * 2, index2 + num5].slope())
                                         flag7 = false;
                                     if (Main.tile[index1, index2 - num5].active() && (int)Main.tile[index1, index2 - num5].type == 19 && (int)tile7.slope() == (int)Main.tile[index1, index2 - num5].slope())
                                         flag7 = false;
                                     if (flag7)
                                     {
                                         WorldGen.SlopeTile(index1 + num4, index2, slope2);
                                         int num6 = (int)tile7.slope();
                                         if (Main.netMode == 1)
                                             NetMessage.SendData(17, -1, -1, "", 14, (float)(index1 + num4), (float)index2, (float)num6, 0, 0, 0);
                                     }
                                 }
                                 int num7 = 1;
                                 int num8 = 0;
                                 Tile tile8 = Main.tile[index1 + num7, index2 + num8];
                                 if (tile8.active() && (int)tile8.type == 19 && (int)tile8.slope() != 0)
                                 {
                                     int num5 = Utils.ToDirectionInt((int)tile8.slope() == 1) * num7;
                                     int slope2 = num5 == -1 ? 0 : (int)tile8.slope();
                                     bool flag7 = true;
                                     if (Main.tile[index1 + num7 * 2, index2 + num5].active() && (int)Main.tile[index1 + num7 * 2, index2].type == 19 && slope2 == (int)Main.tile[index1 + num7 * 2, index2 + num5].slope())
                                         flag7 = false;
                                     if (Main.tile[index1, index2 - num5].active() && (int)Main.tile[index1, index2 - num5].type == 19 && (int)tile8.slope() == (int)Main.tile[index1, index2 - num5].slope())
                                         flag7 = false;
                                     if (flag7)
                                     {
                                         WorldGen.SlopeTile(index1 + num7, index2, slope2);
                                         int num6 = (int)tile8.slope();
                                         if (Main.netMode == 1)
                                             NetMessage.SendData(17, -1, -1, "", 14, (float)(index1 + num7), (float)index2, (float)num6, 0, 0, 0);
                                     }
                                 }
                                 if (num2 == num3 && WorldGen.PlatformProperSides(index1, index2, false) == 0)
                                 {
                                     Tile tile9 = Main.tile[index1, index2 + 1];
                                     if (tile9.active() && !tile9.halfBrick() && ((int)tile9.slope() == 0 && Main.tileSolid[(int)tile9.type]))
                                     {
                                         int slope2 = this.direction == 1 ? 2 : 1;
                                         WorldGen.SlopeTile(index1, index2, slope2);
                                         int num5 = (int)Main.tile[index1, index2].slope();
                                         if (Main.netMode == 1)
                                             NetMessage.SendData(17, -1, -1, "", 14, (float)Player.tileTargetX, (float)Player.tileTargetY, (float)num5, 0, 0, 0);
                                     }
                                 }
                             }
                         }
                     }
                     if (Main.tileSolid[this.inventory[this.selectedItem].createTile] && this.inventory[this.selectedItem].createTile != 19)
                     {
                         int i1 = Player.tileTargetX;
                         int j1 = Player.tileTargetY + 1;
                         if (Main.tile[i1, j1] != null && (int)Main.tile[i1, j1].type != 19 && (Main.tile[i1, j1].topSlope() || Main.tile[i1, j1].halfBrick()))
                         {
                             WorldGen.SlopeTile(i1, j1, 0);
                             if (Main.netMode == 1)
                                 NetMessage.SendData(17, -1, -1, "", 14, (float)i1, (float)j1, 0.0f, 0, 0, 0);
                         }
                         int i2 = Player.tileTargetX;
                         int j2 = Player.tileTargetY - 1;
                         if (Main.tile[i2, j2] != null && (int)Main.tile[i2, j2].type != 19 && Main.tile[i2, j2].bottomSlope())
                         {
                             WorldGen.SlopeTile(i2, j2, 0);
                             if (Main.netMode == 1)
                                 NetMessage.SendData(17, -1, -1, "", 14, (float)i2, (float)j2, 0.0f, 0, 0, 0);
                         }
                     }
                     if (Main.tileSolid[this.inventory[this.selectedItem].createTile])
                     {
                         for (int i1 = Player.tileTargetX - 1; i1 <= Player.tileTargetX + 1; ++i1)
                         {
                             for (int j1 = Player.tileTargetY - 1; j1 <= Player.tileTargetY + 1; ++j1)
                             {
                                 if (Main.tile[i1, j1].active() && this.inventory[this.selectedItem].createTile != (int)Main.tile[i1, j1].type && ((int)Main.tile[i1, j1].type == 2 || (int)Main.tile[i1, j1].type == 23 || ((int)Main.tile[i1, j1].type == 60 || (int)Main.tile[i1, j1].type == 70) || ((int)Main.tile[i1, j1].type == 109 || (int)Main.tile[i1, j1].type == 199)))
                                 {
                                     bool flag6 = true;
                                     for (int i2 = i1 - 1; i2 <= i1 + 1; ++i2)
                                     {
                                         for (int j2 = j1 - 1; j2 <= j1 + 1; ++j2)
                                         {
                                             if (!WorldGen.SolidTile(i2, j2))
                                                 flag6 = false;
                                         }
                                     }
                                     if (flag6)
                                     {
                                         WorldGen.KillTile(i1, j1, true, false, false);
                                         if (Main.netMode == 1)
                                             NetMessage.SendData(17, -1, -1, "", 0, (float)i1, (float)j1, 1f, 0, 0, 0);
                                     }
                                 }
                             }
                         }
                     }
                     if (this.autoPaint)
                     {
                         for (int index1 = 0; index1 < 11; ++index1)
                         {
                             for (int index2 = 0; index2 < 11; ++index2)
                             {
                                 int x = Player.tileTargetX - 5 + index1;
                                 int y = Player.tileTargetY - 5 + index2;
                                 if ((Main.tile[x, y].active() || numArray[index1, index2] != -1) && (!Main.tile[x, y].active() || numArray[index1, index2] != (int)Main.tile[x, y].type))
                                 {
                                     int num2 = -1;
                                     int num3 = -1;
                                     for (int index3 = 0; index3 < 58; ++index3)
                                     {
                                         if (this.inventory[index3].stack > 0 && (int)this.inventory[index3].paint > 0)
                                         {
                                             num2 = (int)this.inventory[index3].paint;
                                             num3 = index3;
                                             break;
                                         }
                                     }
                                     if (num2 > 0 && (int)Main.tile[x, y].color() != num2 && WorldGen.paintTile(x, y, (byte)num2, true))
                                     {
                                         int index3 = num3;
                                         --this.inventory[index3].stack;
                                         if (this.inventory[index3].stack <= 0)
                                             this.inventory[index3].SetDefaults(0, false);
                                         this.itemTime = (int)((double)this.inventory[this.selectedItem].useTime * (double)this.tileSpeed);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (this.inventory[this.selectedItem].createWall < 0 || (double)this.position.X / 16.0 - (double)Player.tileRangeX - (double)this.inventory[this.selectedItem].tileBoost > (double)Player.tileTargetX || (((double)this.position.X + (double)this.width) / 16.0 + (double)Player.tileRangeX + (double)this.inventory[this.selectedItem].tileBoost - 1.0 < (double)Player.tileTargetX || (double)this.position.Y / 16.0 - (double)Player.tileRangeY - (double)this.inventory[this.selectedItem].tileBoost > (double)Player.tileTargetY) || ((double)this.position.Y + (double)this.height) / 16.0 + (double)Player.tileRangeY + (double)this.inventory[this.selectedItem].tileBoost - 2.0 < (double)Player.tileTargetY)
         return;
     this.showItemIcon = true;
     if (this.itemTime != 0 || this.itemAnimation <= 0 || !this.controlUseItem || !Main.tile[Player.tileTargetX + 1, Player.tileTargetY].active() && (int)Main.tile[Player.tileTargetX + 1, Player.tileTargetY].wall <= 0 && (!Main.tile[Player.tileTargetX - 1, Player.tileTargetY].active() && (int)Main.tile[Player.tileTargetX - 1, Player.tileTargetY].wall <= 0) && (!Main.tile[Player.tileTargetX, Player.tileTargetY + 1].active() && (int)Main.tile[Player.tileTargetX, Player.tileTargetY + 1].wall <= 0 && (!Main.tile[Player.tileTargetX, Player.tileTargetY - 1].active() && (int)Main.tile[Player.tileTargetX, Player.tileTargetY - 1].wall <= 0)) || (int)Main.tile[Player.tileTargetX, Player.tileTargetY].wall == this.inventory[this.selectedItem].createWall)
         return;
     if (Player.SmartCursorSettings.SmartWallReplacement && (int)Main.tile[Player.tileTargetX, Player.tileTargetY].wall != 0 && WorldGen.NearFriendlyWall(Player.tileTargetX, Player.tileTargetY))
     {
         WorldGen.KillWall(Player.tileTargetX, Player.tileTargetY, false);
         if ((int)Main.tile[Player.tileTargetX, Player.tileTargetY].wall == 0 && Main.netMode == 1)
             NetMessage.SendData(17, -1, -1, "", 2, (float)Player.tileTargetX, (float)Player.tileTargetY, 0.0f, 0, 0, 0);
         if (this.inventory[this.selectedItem].consumable)
             ++this.inventory[this.selectedItem].stack;
         this.itemTime = (int)((double)this.inventory[this.selectedItem].useTime * (double)this.wallSpeed);
     }
     else
     {
         WorldGen.PlaceWall(Player.tileTargetX, Player.tileTargetY, this.inventory[this.selectedItem].createWall, false);
         if ((int)Main.tile[Player.tileTargetX, Player.tileTargetY].wall != this.inventory[this.selectedItem].createWall)
             return;
         this.itemTime = (int)((double)this.inventory[this.selectedItem].useTime * (double)this.wallSpeed);
         if (Main.netMode == 1)
             NetMessage.SendData(17, -1, -1, "", 3, (float)Player.tileTargetX, (float)Player.tileTargetY, (float)this.inventory[this.selectedItem].createWall, 0, 0, 0);
         if (this.inventory[this.selectedItem].stack > 1)
         {
             int type = this.inventory[this.selectedItem].createWall;
             for (int index1 = 0; index1 < 4; ++index1)
             {
                 int i = Player.tileTargetX;
                 int j = Player.tileTargetY;
                 if (index1 == 0)
                     --i;
                 if (index1 == 1)
                     ++i;
                 if (index1 == 2)
                     --j;
                 if (index1 == 3)
                     ++j;
                 if ((int)Main.tile[i, j].wall == 0)
                 {
                     int num1 = 0;
                     for (int index2 = 0; index2 < 4; ++index2)
                     {
                         int index3 = i;
                         int index4 = j;
                         if (index2 == 0)
                             --index3;
                         if (index2 == 1)
                             ++index3;
                         if (index2 == 2)
                             --index4;
                         if (index2 == 3)
                             ++index4;
                         if ((int)Main.tile[index3, index4].wall == type)
                             ++num1;
                     }
                     if (num1 == 4)
                     {
                         WorldGen.PlaceWall(i, j, type, false);
                         if ((int)Main.tile[i, j].wall == type)
                         {
                             --this.inventory[this.selectedItem].stack;
                             if (this.inventory[this.selectedItem].stack == 0)
                                 this.inventory[this.selectedItem].SetDefaults(0, false);
                             if (Main.netMode == 1)
                                 NetMessage.SendData(17, -1, -1, "", 3, (float)i, (float)j, (float)type, 0, 0, 0);
                             if (this.autoPaint)
                             {
                                 int x = i;
                                 int y = j;
                                 int num2 = -1;
                                 int num3 = -1;
                                 for (int index2 = 0; index2 < 58; ++index2)
                                 {
                                     if (this.inventory[index2].stack > 0 && (int)this.inventory[index2].paint > 0)
                                     {
                                         num2 = (int)this.inventory[index2].paint;
                                         num3 = index2;
                                         break;
                                     }
                                 }
                                 if (num2 > 0 && (int)Main.tile[x, y].wallColor() != num2 && WorldGen.paintWall(x, y, (byte)num2, true))
                                 {
                                     int index2 = num3;
                                     --this.inventory[index2].stack;
                                     if (this.inventory[index2].stack <= 0)
                                         this.inventory[index2].SetDefaults(0, false);
                                     this.itemTime = (int)((double)this.inventory[this.selectedItem].useTime * (double)this.wallSpeed);
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (!this.autoPaint)
             return;
         int x1 = Player.tileTargetX;
         int y1 = Player.tileTargetY;
         int num4 = -1;
         int num5 = -1;
         for (int index = 0; index < 58; ++index)
         {
             if (this.inventory[index].stack > 0 && (int)this.inventory[index].paint > 0)
             {
                 num4 = (int)this.inventory[index].paint;
                 num5 = index;
                 break;
             }
         }
         if (num4 <= 0 || (int)Main.tile[x1, y1].wallColor() == num4 || !WorldGen.paintWall(x1, y1, (byte)num4, true))
             return;
         int index5 = num5;
         --this.inventory[index5].stack;
         if (this.inventory[index5].stack <= 0)
             this.inventory[index5].SetDefaults(0, false);
         this.itemTime = (int)((double)this.inventory[this.selectedItem].useTime * (double)this.wallSpeed);
     }
 }