GetTileSafely() public static method

public static GetTileSafely ( int i, int j ) : Tile
i int
j int
return Tile
Beispiel #1
0
        public void DrawFreshAnimations(SpriteBatch spriteBatch)
        {
            for (int index = 0; index < this.data.Length; ++index)
            {
                ++this.data[index].animationTimeElapsed;
            }
            if (!Main.SettingsEnabled_MinersWobble)
            {
                return;
            }
            int     num1 = 1;
            Vector2 zero1;

            // ISSUE: explicit reference operation
            ((Vector2)@zero1).\u002Ector((float)Main.offScreenRange);
            if (Main.drawToScreen)
            {
                zero1 = Vector2.get_Zero();
            }
            zero1 = Vector2.get_Zero();
            for (int index = 0; index < this.data.Length; ++index)
            {
                if (this.data[index].type == num1)
                {
                    int damage = this.data[index].damage;
                    if (damage >= 20)
                    {
                        int x = this.data[index].X;
                        int y = this.data[index].Y;
                        if (WorldGen.InWorld(x, y, 0))
                        {
                            bool flag1 = Main.tile[x, y] != null;
                            if (flag1 && num1 == 1)
                            {
                                flag1 = flag1 && Main.tile[x, y].active() && Main.tileSolid[(int)Main.tile[x, y].type];
                            }
                            if (flag1 && num1 == 2)
                            {
                                flag1 = flag1 && (uint)Main.tile[x, y].wall > 0U;
                            }
                            if (flag1)
                            {
                                bool flag2 = false;
                                bool flag3 = false;
                                if ((int)Main.tile[x, y].type == 10)
                                {
                                    flag2 = false;
                                }
                                else if (Main.tileSolid[(int)Main.tile[x, y].type] && !Main.tileSolidTop[(int)Main.tile[x, y].type])
                                {
                                    flag2 = true;
                                }
                                else if ((int)Main.tile[x, y].type == 5)
                                {
                                    flag3 = true;
                                    int num2 = (int)Main.tile[x, y].frameX / 22;
                                    int num3 = (int)Main.tile[x, y].frameY / 22;
                                    if (num3 < 9)
                                    {
                                        flag2 = (num2 != 1 && num2 != 2 || (num3 < 6 || num3 > 8)) && ((num2 != 3 || num3 > 2) && ((num2 != 4 || num3 < 3 || num3 > 5) && (num2 != 5 || num3 < 6 || num3 > 8)));
                                    }
                                }
                                else if ((int)Main.tile[x, y].type == 72)
                                {
                                    flag3 = true;
                                    if ((int)Main.tile[x, y].frameX <= 34)
                                    {
                                        flag2 = true;
                                    }
                                }
                                if (flag2 && (int)Main.tile[x, y].slope() == 0 && !Main.tile[x, y].halfBrick())
                                {
                                    int num2 = 0;
                                    if (damage >= 80)
                                    {
                                        num2 = 3;
                                    }
                                    else if (damage >= 60)
                                    {
                                        num2 = 2;
                                    }
                                    else if (damage >= 40)
                                    {
                                        num2 = 1;
                                    }
                                    else if (damage >= 20)
                                    {
                                        num2 = 0;
                                    }
                                    Rectangle rectangle;
                                    // ISSUE: explicit reference operation
                                    ((Rectangle)@rectangle).\u002Ector(this.data[index].crackStyle * 18, num2 * 18, 16, 16);
                                    // ISSUE: explicit reference operation
                                    ((Rectangle)@rectangle).Inflate(-2, -2);
                                    if (flag3)
                                    {
                                        rectangle.X = (__Null)((4 + this.data[index].crackStyle / 2) * 18);
                                    }
                                    int animationTimeElapsed = this.data[index].animationTimeElapsed;
                                    if ((double)animationTimeElapsed < 10.0)
                                    {
                                        double  num3   = (double)animationTimeElapsed / 10.0;
                                        Color   color1 = Lighting.GetColor(x, y);
                                        float   num4   = 0.0f;
                                        Vector2 zero2  = Vector2.get_Zero();
                                        float   num5   = 0.5f;
                                        double  num6   = (double)num5;
                                        float   num7   = (float)(num3 % num6) * (1f / num5);
                                        double  num8   = (double)num5;
                                        if ((int)(num3 / num8) % 2 == 1)
                                        {
                                            num7 = 1f - num7;
                                        }
                                        Tile      tileSafely = Framing.GetTileSafely(x, y);
                                        Tile      tile       = tileSafely;
                                        Texture2D texture2D  = !Main.canDrawColorTile(tileSafely.type, (int)tileSafely.color()) ? Main.tileTexture[(int)tileSafely.type] : (Texture2D)Main.tileAltTexture[(int)tileSafely.type, (int)tileSafely.color()];
                                        Vector2   vector2_1;
                                        // ISSUE: explicit reference operation
                                        ((Vector2)@vector2_1).\u002Ector(8f);
                                        Vector2 vector2_2;
                                        // ISSUE: explicit reference operation
                                        ((Vector2)@vector2_2).\u002Ector(1f);
                                        double  num9      = (double)num7 * 0.200000002980232 + 1.0;
                                        float   num10     = 1f - num7;
                                        float   num11     = 1f;
                                        Color   color2    = Color.op_Multiply(color1, (float)((double)num11 * (double)num11 * 0.800000011920929));
                                        Vector2 vector2_3 = vector2_2;
                                        Vector2 vector2_4 = Vector2.op_Multiply((float)num9, vector2_3);
                                        Vector2 vector2_5 = Vector2.op_Addition(Vector2.op_Addition(Vector2.op_Addition(new Vector2((float)(x * 16 - (int)Main.screenPosition.X), (float)(y * 16 - (int)Main.screenPosition.Y)), zero1), vector2_1), zero2).Floor();
                                        spriteBatch.Draw(texture2D, vector2_5, new Rectangle?(new Rectangle((int)tile.frameX, (int)tile.frameY, 16, 16)), color2, num4, vector2_1, vector2_4, (SpriteEffects)0, 0.0f);
                                        // ISSUE: explicit reference operation
                                        ((Color)@color2).set_A((byte)180);
                                        spriteBatch.Draw(Main.tileCrackTexture, vector2_5, new Rectangle?(rectangle), color2, num4, vector2_1, vector2_4, (SpriteEffects)0, 0.0f);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public static void SelfFrame8Way(int i, int j, Tile centerTile, bool resetFrame)
        {
            if (!centerTile.active())
            {
                return;
            }
            ushort num = TileID.Sets.GemsparkFramingTypes[(int)centerTile.type];

            Framing.BlockStyle blockStyle = Framing.FindBlockStyle(centerTile);
            int num2 = 0;

            Framing.BlockStyle blockStyle2 = default(Framing.BlockStyle);
            if (blockStyle.top)
            {
                Tile tileSafely = Framing.GetTileSafely(i, j - 1);
                if (tileSafely.active() && TileID.Sets.GemsparkFramingTypes[(int)tileSafely.type] == num)
                {
                    blockStyle2 = Framing.FindBlockStyle(tileSafely);
                    if (blockStyle2.bottom)
                    {
                        num2 |= 1;
                    }
                    else
                    {
                        blockStyle2.Clear();
                    }
                }
            }
            Framing.BlockStyle blockStyle3 = default(Framing.BlockStyle);
            if (blockStyle.left)
            {
                Tile tileSafely2 = Framing.GetTileSafely(i - 1, j);
                if (tileSafely2.active() && TileID.Sets.GemsparkFramingTypes[(int)tileSafely2.type] == num)
                {
                    blockStyle3 = Framing.FindBlockStyle(tileSafely2);
                    if (blockStyle3.right)
                    {
                        num2 |= 2;
                    }
                    else
                    {
                        blockStyle3.Clear();
                    }
                }
            }
            Framing.BlockStyle blockStyle4 = default(Framing.BlockStyle);
            if (blockStyle.right)
            {
                Tile tileSafely3 = Framing.GetTileSafely(i + 1, j);
                if (tileSafely3.active() && TileID.Sets.GemsparkFramingTypes[(int)tileSafely3.type] == num)
                {
                    blockStyle4 = Framing.FindBlockStyle(tileSafely3);
                    if (blockStyle4.left)
                    {
                        num2 |= 4;
                    }
                    else
                    {
                        blockStyle4.Clear();
                    }
                }
            }
            Framing.BlockStyle blockStyle5 = default(Framing.BlockStyle);
            if (blockStyle.bottom)
            {
                Tile tileSafely4 = Framing.GetTileSafely(i, j + 1);
                if (tileSafely4.active() && TileID.Sets.GemsparkFramingTypes[(int)tileSafely4.type] == num)
                {
                    blockStyle5 = Framing.FindBlockStyle(tileSafely4);
                    if (blockStyle5.top)
                    {
                        num2 |= 8;
                    }
                    else
                    {
                        blockStyle5.Clear();
                    }
                }
            }
            if (blockStyle2.left && blockStyle3.top)
            {
                Tile tileSafely5 = Framing.GetTileSafely(i - 1, j - 1);
                if (tileSafely5.active() && TileID.Sets.GemsparkFramingTypes[(int)tileSafely5.type] == num)
                {
                    Framing.BlockStyle blockStyle6 = Framing.FindBlockStyle(tileSafely5);
                    if (blockStyle6.right && blockStyle6.bottom)
                    {
                        num2 |= 16;
                    }
                }
            }
            if (blockStyle2.right && blockStyle4.top)
            {
                Tile tileSafely6 = Framing.GetTileSafely(i + 1, j - 1);
                if (tileSafely6.active() && TileID.Sets.GemsparkFramingTypes[(int)tileSafely6.type] == num)
                {
                    Framing.BlockStyle blockStyle7 = Framing.FindBlockStyle(tileSafely6);
                    if (blockStyle7.left && blockStyle7.bottom)
                    {
                        num2 |= 32;
                    }
                }
            }
            if (blockStyle5.left && blockStyle3.bottom)
            {
                Tile tileSafely7 = Framing.GetTileSafely(i - 1, j + 1);
                if (tileSafely7.active() && TileID.Sets.GemsparkFramingTypes[(int)tileSafely7.type] == num)
                {
                    Framing.BlockStyle blockStyle8 = Framing.FindBlockStyle(tileSafely7);
                    if (blockStyle8.right && blockStyle8.top)
                    {
                        num2 |= 64;
                    }
                }
            }
            if (blockStyle5.right && blockStyle4.bottom)
            {
                Tile tileSafely8 = Framing.GetTileSafely(i + 1, j + 1);
                if (tileSafely8.active() && TileID.Sets.GemsparkFramingTypes[(int)tileSafely8.type] == num)
                {
                    Framing.BlockStyle blockStyle9 = Framing.FindBlockStyle(tileSafely8);
                    if (blockStyle9.left && blockStyle9.top)
                    {
                        num2 |= 128;
                    }
                }
            }
            if (resetFrame)
            {
                centerTile.frameNumber((byte)WorldGen.genRand.Next(0, 3));
            }
            Point16 point = Framing.selfFrame8WayLookup[num2][(int)centerTile.frameNumber()];

            centerTile.frameX = point.X;
            centerTile.frameY = point.Y;
        }
Beispiel #3
0
 public static Tile GetTileSafely(Vector2 position)
 {
     position /= 16f;
     return(Framing.GetTileSafely((int)position.X, (int)position.Y));
 }
        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) == 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;
                    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() && Main.tileCut[tileSafely.type])
                        {
                            WorldGen.KillTile(num6 + 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 void DrawPreview(SpriteBatch sb, TileObjectPreviewData op, Vector2 position)
        {
            Point16        coordinates = op.Coordinates;
            Texture2D      texture     = Main.tileTexture[op.Type];
            TileObjectData tileData    = TileObjectData.GetTileData(op.Type, op.Style, op.Alternate);
            int            num         = 0;
            int            num2        = 0;
            int            num3        = tileData.CalculatePlacementStyle(op.Style, op.Alternate, op.Random);
            int            num4        = 0;
            int            num5        = tileData.DrawYOffset;

            if (tileData.StyleWrapLimit > 0)
            {
                num4  = num3 / tileData.StyleWrapLimit;
                num3 %= tileData.StyleWrapLimit;
            }
            if (tileData.StyleHorizontal)
            {
                num  = tileData.CoordinateFullWidth * num3;
                num2 = tileData.CoordinateFullHeight * num4;
            }
            else
            {
                num  = tileData.CoordinateFullWidth * num4;
                num2 = tileData.CoordinateFullHeight * num3;
            }
            for (int i = 0; i < op.Size.X; i++)
            {
                int x    = num + (i - op.ObjectStart.X) * (tileData.CoordinateWidth + tileData.CoordinatePadding);
                int num6 = num2;
                for (int j = 0; j < op.Size.Y; j++)
                {
                    int num7 = coordinates.X + i;
                    int num8 = coordinates.Y + j;
                    if (j == 0 && tileData.DrawStepDown != 0)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num7, num8 - 1);
                        if (WorldGen.SolidTile(tileSafely))
                        {
                            num5 += tileData.DrawStepDown;
                        }
                    }
                    Color color;
                    switch (op[i, j])
                    {
                    case 2:
                        color = Color.Red * 0.7f;
                        break;

                    case 1:
                        color = Color.White;
                        break;

                    default:
                        continue;
                    }
                    color *= 0.5f;
                    if (i >= op.ObjectStart.X && i < op.ObjectStart.X + tileData.Width && j >= op.ObjectStart.Y && j < op.ObjectStart.Y + tileData.Height)
                    {
                        SpriteEffects spriteEffects = SpriteEffects.None;
                        if (tileData.DrawFlipHorizontal && i % 2 == 1)
                        {
                            spriteEffects |= SpriteEffects.FlipHorizontally;
                        }
                        if (tileData.DrawFlipVertical && j % 2 == 1)
                        {
                            spriteEffects |= SpriteEffects.FlipVertically;
                        }
                        sb.Draw(sourceRectangle: new Rectangle(x, num6, tileData.CoordinateWidth, tileData.CoordinateHeights[j - op.ObjectStart.Y]), texture: texture, position: new Vector2(num7 * 16 - (int)(position.X + (float)(tileData.CoordinateWidth - 16) / 2f), num8 * 16 - (int)position.Y + num5), color: color, rotation: 0f, origin: Vector2.Zero, scale: 1f, effects: spriteEffects, layerDepth: 0f);
                        num6 += tileData.CoordinateHeights[j - op.ObjectStart.Y] + tileData.CoordinatePadding;
                    }
                }
            }
        }
        public static void DrawPreview(SpriteBatch sb, TileObjectPreviewData op, Vector2 position)
        {
            var coordinates    = op.Coordinates;
            var texture        = Main.tileTexture[(int)op.Type];
            var tileData       = TileObjectData.GetTileData((int)op.Type, (int)op.Style, op.Alternate);
            var placementStyle = tileData.CalculatePlacementStyle((int)op.Style, op.Alternate, op.Random);
            var num1           = 0;
            var drawYoffset    = tileData.DrawYOffset;

            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;
            }

            for (var index1 = 0; index1 < (int)op.Size.X; ++index1)
            {
                var x = num2 + (index1 - (int)op.ObjectStart.X) *
                        (tileData.CoordinateWidth + tileData.CoordinatePadding);
                var y = num3;
                for (var index2 = 0; index2 < (int)op.Size.Y; ++index2)
                {
                    var i    = (int)coordinates.X + index1;
                    var num4 = (int)coordinates.Y + index2;
                    if (index2 == 0 && tileData.DrawStepDown != 0 &&
                        WorldGen.SolidTile(Framing.GetTileSafely(i, num4 - 1)))
                    {
                        drawYoffset += tileData.DrawStepDown;
                    }
                    Color color1;
                    switch (op[index1, index2])
                    {
                    case 1:
                        color1 = Color.White;
                        break;

                    case 2:
                        color1 = Color.Red * 0.7f;
                        break;

                    default:
                        continue;
                    }

                    var color2 = color1 * 0.5f;
                    if (index1 >= (int)op.ObjectStart.X && index1 < (int)op.ObjectStart.X + tileData.Width &&
                        (index2 >= (int)op.ObjectStart.Y && index2 < (int)op.ObjectStart.Y + tileData.Height))
                    {
                        var effects = SpriteEffects.None;
                        if (tileData.DrawFlipHorizontal && index1 % 2 == 1)
                        {
                            effects |= SpriteEffects.FlipHorizontally;
                        }
                        if (tileData.DrawFlipVertical && index2 % 2 == 1)
                        {
                            effects |= SpriteEffects.FlipVertically;
                        }
                        var rectangle = new Rectangle(x, y, tileData.CoordinateWidth,
                                                      tileData.CoordinateHeights[index2 - (int)op.ObjectStart.Y]);
                        sb.Draw(texture,
                                new Vector2(
                                    (float)(i * 16 - (int)((double)position.X +
                                                           (double)(tileData.CoordinateWidth - 16) / 2.0)),
                                    (float)(num4 * 16 - (int)position.Y + drawYoffset)), new Rectangle?(rectangle),
                                color2, 0.0f, Vector2.Zero, 1f, effects, 0.0f);
                        y += tileData.CoordinateHeights[index2 - (int)op.ObjectStart.Y] + tileData.CoordinatePadding;
                    }
                }
            }
        }
        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)
                    {
                        _ = tileData2.Origin.X;
                        _ = 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);
        }
        public static bool CanPlace(int x, int y, int type, int style, int dir, out TileObject objectData,
                                    bool onlyCheck = false)
        {
            var tileData1 = TileObjectData.GetTileData(type, style, 0);

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

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

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

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

            while (alternate < num4)
            {
                ++alternate;
                var tileData2 = TileObjectData.GetTileData(type, style, alternate);
                if (tileData2.Direction == TileObjectDirection.None ||
                    (tileData2.Direction != TileObjectDirection.PlaceLeft || dir != 1) &&
                    (tileData2.Direction != TileObjectDirection.PlaceRight || dir != -1))
                {
                    var num8 = x - (int)tileData2.Origin.X;
                    var 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);
                    }
                    var rectangle = new Rectangle(0, 0, tileData2.Width, tileData2.Height);
                    var X         = 0;
                    var Y         = 0;
                    if (tileData2.AnchorTop.tileCount != 0)
                    {
                        if (rectangle.Y == 0)
                        {
                            rectangle.Y = -1;
                            ++rectangle.Height;
                            ++Y;
                        }

                        var checkStart = tileData2.AnchorTop.checkStart;
                        if (checkStart < rectangle.X)
                        {
                            rectangle.Width += rectangle.X - checkStart;
                            X          += rectangle.X - checkStart;
                            rectangle.X = checkStart;
                        }

                        var num10 = checkStart + tileData2.AnchorTop.tileCount - 1;
                        var num11 = rectangle.X + rectangle.Width - 1;
                        if (num10 > num11)
                        {
                            rectangle.Width += num10 - num11;
                        }
                    }

                    if (tileData2.AnchorBottom.tileCount != 0)
                    {
                        if (rectangle.Y + rectangle.Height == tileData2.Height)
                        {
                            ++rectangle.Height;
                        }
                        var checkStart = tileData2.AnchorBottom.checkStart;
                        if (checkStart < rectangle.X)
                        {
                            rectangle.Width += rectangle.X - checkStart;
                            X          += rectangle.X - checkStart;
                            rectangle.X = checkStart;
                        }

                        var num10 = checkStart + tileData2.AnchorBottom.tileCount - 1;
                        var num11 = rectangle.X + rectangle.Width - 1;
                        if (num10 > num11)
                        {
                            rectangle.Width += num10 - num11;
                        }
                    }

                    if (tileData2.AnchorLeft.tileCount != 0)
                    {
                        if (rectangle.X == 0)
                        {
                            rectangle.X = -1;
                            ++rectangle.Width;
                            ++X;
                        }

                        var 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;
                        }

                        var num10 = checkStart + tileData2.AnchorLeft.tileCount - 1;
                        if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            num10 += 2;
                        }
                        var num11 = rectangle.Y + rectangle.Height - 1;
                        if (num10 > num11)
                        {
                            rectangle.Height += num10 - num11;
                        }
                    }

                    if (tileData2.AnchorRight.tileCount != 0)
                    {
                        if (rectangle.X + rectangle.Width == tileData2.Width)
                        {
                            ++rectangle.Width;
                        }
                        var 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;
                        }

                        var num10 = checkStart + tileData2.AnchorRight.tileCount - 1;
                        if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            num10 += 2;
                        }
                        var num11 = rectangle.Y + rectangle.Height - 1;
                        if (num10 > num11)
                        {
                            rectangle.Height += num10 - num11;
                        }
                    }

                    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);
                    }

                    var num12 = 0.0f;
                    var num13 = (float)(tileData2.Width * tileData2.Height);
                    var num14 = 0.0f;
                    var num15 = 0.0f;
                    for (var index1 = 0; index1 < tileData2.Width; ++index1)
                    {
                        for (var index2 = 0; index2 < tileData2.Height; ++index2)
                        {
                            var tileSafely = Framing.GetTileSafely(num8 + index1, num9 + index2);
                            var flag2      = !tileData2.LiquidPlace(tileSafely);
                            var flag3      = false;
                            if (tileData2.AnchorWall)
                            {
                                ++num15;
                                if (!tileData2.isValidWallAnchor((int)tileSafely.wall))
                                {
                                    flag3 = true;
                                }
                                else
                                {
                                    ++num14;
                                }
                            }

                            var 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;
                                }
                                ++num12;
                            }
                        }
                    }

                    var anchorBottom = tileData2.AnchorBottom;
                    if (anchorBottom.tileCount != 0)
                    {
                        num15 += (float)anchorBottom.tileCount;
                        var height = tileData2.Height;
                        for (var index = 0; index < anchorBottom.tileCount; ++index)
                        {
                            var num10      = anchorBottom.checkStart + index;
                            var tileSafely = Framing.GetTileSafely(num8 + num10, num9 + height);
                            var 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])
                                    {
                                        var 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;
                                }
                                ++num14;
                            }
                        }
                    }

                    var anchorTop = tileData2.AnchorTop;
                    if (anchorTop.tileCount != 0)
                    {
                        num15 += (float)anchorTop.tileCount;
                        var num10 = -1;
                        for (var index = 0; index < anchorTop.tileCount; ++index)
                        {
                            var num11      = anchorTop.checkStart + index;
                            var tileSafely = Framing.GetTileSafely(num8 + num11, num9 + num10);
                            var 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;
                                }
                                ++num14;
                            }
                        }
                    }

                    var anchorRight = tileData2.AnchorRight;
                    if (anchorRight.tileCount != 0)
                    {
                        num15 += (float)anchorRight.tileCount;
                        var width = tileData2.Width;
                        for (var index = 0; index < anchorRight.tileCount; ++index)
                        {
                            var num10       = anchorRight.checkStart + index;
                            var tileSafely1 = Framing.GetTileSafely(num8 + width, num9 + num10);
                            var 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 &&
                                    tileSafely1.type == (ushort)5)
                                {
                                    flag2 = true;
                                    if (index == 0)
                                    {
                                        ++num15;
                                        var tileSafely2 = Framing.GetTileSafely(num8 + width, num9 + num10 - 1);
                                        if (tileSafely2.nactive() && tileSafely2.type == (ushort)5)
                                        {
                                            ++num14;
                                            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)
                                    {
                                        ++num15;
                                        var tileSafely2 = Framing.GetTileSafely(num8 + width, num9 + num10 + 1);
                                        if (tileSafely2.nactive() && tileSafely2.type == (ushort)5)
                                        {
                                            ++num14;
                                            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;
                                }
                                ++num14;
                            }
                        }
                    }

                    var anchorLeft = tileData2.AnchorLeft;
                    if (anchorLeft.tileCount != 0)
                    {
                        num15 += (float)anchorLeft.tileCount;
                        var num10 = -1;
                        for (var index = 0; index < anchorLeft.tileCount; ++index)
                        {
                            var num11       = anchorLeft.checkStart + index;
                            var tileSafely1 = Framing.GetTileSafely(num8 + num10, num9 + num11);
                            var 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 &&
                                    tileSafely1.type == (ushort)5)
                                {
                                    flag2 = true;
                                    if (index == 0)
                                    {
                                        ++num15;
                                        var tileSafely2 = Framing.GetTileSafely(num8 + num10, num9 + num11 - 1);
                                        if (tileSafely2.nactive() && tileSafely2.type == (ushort)5)
                                        {
                                            ++num14;
                                            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)
                                    {
                                        ++num15;
                                        var tileSafely2 = Framing.GetTileSafely(num8 + num10, num9 + num11 + 1);
                                        if (tileSafely2.nactive() && tileSafely2.type == (ushort)5)
                                        {
                                            ++num14;
                                            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;
                                }
                                ++num14;
                            }
                        }
                    }

                    if (tileData2.HookCheck.hook != null)
                    {
                        if (tileData2.HookCheck.processedCoordinates)
                        {
                            var x1 = (int)tileData2.Origin.X;
                            var y1 = (int)tileData2.Origin.Y;
                        }

                        if (tileData2.HookCheck.hook(x, y, type, style, dir) == tileData2.HookCheck.badReturn &&
                            tileData2.HookCheck.badResponse == 0)
                        {
                            num14 = 0.0f;
                            num12 = 0.0f;
                            TileObject.objectPreview.AllInvalid();
                        }
                    }

                    var num16 = num14 / num15;
                    var num17 = num12 / num13;
                    if ((double)num17 == 1.0 && (double)num15 == 0.0)
                    {
                        num16 = 1f;
                        num17 = 1f;
                    }

                    if ((double)num16 == 1.0 && (double)num17 == 1.0)
                    {
                        num5           = 1f;
                        num6           = 1f;
                        num7           = alternate;
                        tileObjectData = tileData2;
                        break;
                    }

                    if ((double)num16 > (double)num5 ||
                        (double)num16 == (double)num5 && (double)num17 > (double)num6)
                    {
                        TileObjectPreviewData.placementCache.CopyFrom(TileObject.objectPreview);
                        num5           = num16;
                        num6           = num17;
                        tileObjectData = tileData2;
                        num7           = alternate;
                    }
                }
            }

            var num18 = -1;

            if (flag1)
            {
                if (TileObjectPreviewData.randomCache == null)
                {
                    TileObjectPreviewData.randomCache = new TileObjectPreviewData();
                }
                var flag2 = false;
                if ((int)TileObjectPreviewData.randomCache.Type == type)
                {
                    var coordinates = TileObjectPreviewData.randomCache.Coordinates;
                    var objectStart = TileObjectPreviewData.randomCache.ObjectStart;
                    var num8        = (int)coordinates.X + (int)objectStart.X;
                    var num9        = (int)coordinates.Y + (int)objectStart.Y;
                    var num10       = x - (int)tileData1.Origin.X;
                    var num11       = y - (int)tileData1.Origin.Y;
                    if (num8 != num10 || num9 != num11)
                    {
                        flag2 = true;
                    }
                }
                else
                {
                    flag2 = true;
                }

                num18 = !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 = num18;
                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    = num18;
            }

            if ((double)num5 == 1.0)
            {
                return((double)num6 == 1.0);
            }
            return(false);
        }
        public static bool Place(TileObject toBePlaced)
        {
            var 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
            {
                var type           = (ushort)toBePlaced.type;
                var placementStyle =
                    tileData.CalculatePlacementStyle(toBePlaced.style, toBePlaced.alternate, toBePlaced.random);
                var 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;
                }

                var xCoord = toBePlaced.xCoord;
                var yCoord = toBePlaced.yCoord;
                for (var index1 = 0; index1 < tileData.Width; ++index1)
                {
                    for (var index2 = 0; index2 < tileData.Height; ++index2)
                    {
                        var tileSafely = Framing.GetTileSafely(xCoord + index1, yCoord + index2);
                        if (tileSafely.active() && Main.tileCut[(int)tileSafely.type])
                        {
                            WorldGen.KillTile(xCoord + index1, yCoord + index2, false, false, false);
                        }
                    }
                }

                for (var index1 = 0; index1 < tileData.Width; ++index1)
                {
                    var num4 = num2 + index1 * (tileData.CoordinateWidth + tileData.CoordinatePadding);
                    var num5 = num3;
                    for (var index2 = 0; index2 < tileData.Height; ++index2)
                    {
                        var 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)
            {
                var anchorData = tileData.AnchorBottom;
                if (anchorData.tileCount != 0 && (anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    var num = toBePlaced.xCoord + anchorData.checkStart;
                    var j   = toBePlaced.yCoord + tileData.Height;
                    for (var index = 0; index < anchorData.tileCount; ++index)
                    {
                        var 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)
                {
                    var num = toBePlaced.xCoord + anchorData.checkStart;
                    var j   = toBePlaced.yCoord - 1;
                    for (var index = 0; index < anchorData.tileCount; ++index)
                    {
                        var 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)
                {
                    var i   = toBePlaced.xCoord + tileData.Width;
                    var num = toBePlaced.yCoord + anchorData.checkStart;
                    for (var index = 0; index < anchorData.tileCount; ++index)
                    {
                        var 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)
                {
                    var i   = toBePlaced.xCoord - 1;
                    var num = toBePlaced.yCoord + anchorData.checkStart;
                    for (var index = 0; index < anchorData.tileCount; ++index)
                    {
                        var 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 #10
0
 public static Tile GetTileSafely(Point pt)
 {
     return(Framing.GetTileSafely(pt.X, pt.Y));
 }
Beispiel #11
0
 public static Tile GetTileSafely(Point16 pt)
 {
     return(Framing.GetTileSafely((int)pt.X, (int)pt.Y));
 }
Beispiel #12
0
        public static void SelfFrame8Way(int i, int j, Tile centerTile, bool resetFrame)
        {
            if (!centerTile.active())
            {
                return;
            }
            Framing.BlockStyle blockStyle1 = Framing.FindBlockStyle(centerTile);
            int index = 0;

            Framing.BlockStyle blockStyle2 = new Framing.BlockStyle();
            if (blockStyle1.top)
            {
                Tile tileSafely = Framing.GetTileSafely(i, j - 1);
                if (tileSafely.active() && Framing.WillItBlend(centerTile.type, tileSafely.type))
                {
                    blockStyle2 = Framing.FindBlockStyle(tileSafely);
                    if (blockStyle2.bottom)
                    {
                        index |= 1;
                    }
                    else
                    {
                        blockStyle2.Clear();
                    }
                }
            }
            Framing.BlockStyle blockStyle3 = new Framing.BlockStyle();
            if (blockStyle1.left)
            {
                Tile tileSafely = Framing.GetTileSafely(i - 1, j);
                if (tileSafely.active() && Framing.WillItBlend(centerTile.type, tileSafely.type))
                {
                    blockStyle3 = Framing.FindBlockStyle(tileSafely);
                    if (blockStyle3.right)
                    {
                        index |= 2;
                    }
                    else
                    {
                        blockStyle3.Clear();
                    }
                }
            }
            Framing.BlockStyle blockStyle4 = new Framing.BlockStyle();
            if (blockStyle1.right)
            {
                Tile tileSafely = Framing.GetTileSafely(i + 1, j);
                if (tileSafely.active() && Framing.WillItBlend(centerTile.type, tileSafely.type))
                {
                    blockStyle4 = Framing.FindBlockStyle(tileSafely);
                    if (blockStyle4.left)
                    {
                        index |= 4;
                    }
                    else
                    {
                        blockStyle4.Clear();
                    }
                }
            }
            Framing.BlockStyle blockStyle5 = new Framing.BlockStyle();
            if (blockStyle1.bottom)
            {
                Tile tileSafely = Framing.GetTileSafely(i, j + 1);
                if (tileSafely.active() && Framing.WillItBlend(centerTile.type, tileSafely.type))
                {
                    blockStyle5 = Framing.FindBlockStyle(tileSafely);
                    if (blockStyle5.top)
                    {
                        index |= 8;
                    }
                    else
                    {
                        blockStyle5.Clear();
                    }
                }
            }
            if (blockStyle2.left && blockStyle3.top)
            {
                Tile tileSafely = Framing.GetTileSafely(i - 1, j - 1);
                if (tileSafely.active() && Framing.WillItBlend(centerTile.type, tileSafely.type))
                {
                    Framing.BlockStyle blockStyle6 = Framing.FindBlockStyle(tileSafely);
                    if (blockStyle6.right && blockStyle6.bottom)
                    {
                        index |= 16;
                    }
                }
            }
            if (blockStyle2.right && blockStyle4.top)
            {
                Tile tileSafely = Framing.GetTileSafely(i + 1, j - 1);
                if (tileSafely.active() && Framing.WillItBlend(centerTile.type, tileSafely.type))
                {
                    Framing.BlockStyle blockStyle6 = Framing.FindBlockStyle(tileSafely);
                    if (blockStyle6.left && blockStyle6.bottom)
                    {
                        index |= 32;
                    }
                }
            }
            if (blockStyle5.left && blockStyle3.bottom)
            {
                Tile tileSafely = Framing.GetTileSafely(i - 1, j + 1);
                if (tileSafely.active() && Framing.WillItBlend(centerTile.type, tileSafely.type))
                {
                    Framing.BlockStyle blockStyle6 = Framing.FindBlockStyle(tileSafely);
                    if (blockStyle6.right && blockStyle6.top)
                    {
                        index |= 64;
                    }
                }
            }
            if (blockStyle5.right && blockStyle4.bottom)
            {
                Tile tileSafely = Framing.GetTileSafely(i + 1, j + 1);
                if (tileSafely.active() && Framing.WillItBlend(centerTile.type, tileSafely.type))
                {
                    Framing.BlockStyle blockStyle6 = Framing.FindBlockStyle(tileSafely);
                    if (blockStyle6.left && blockStyle6.top)
                    {
                        index |= 128;
                    }
                }
            }
            if (resetFrame)
            {
                centerTile.frameNumber((byte)WorldGen.genRand.Next(0, 3));
            }
            Point16 point16 = Framing.selfFrame8WayLookup[index][(int)centerTile.frameNumber()];

            centerTile.frameX = point16.X;
            centerTile.frameY = point16.Y;
        }
Beispiel #13
0
        public void DrawFreshAnimations(SpriteBatch spriteBatch)
        {
            for (int index = 0; index < this.data.Length; ++index)
            {
                ++this.data[index].animationTimeElapsed;
            }
            if (!Main.SettingsEnabled_MinersWobble)
            {
                return;
            }
            int     num1      = 1;
            Vector2 vector2_1 = new Vector2((float)Main.offScreenRange);

            if (Main.drawToScreen)
            {
                vector2_1 = Vector2.Zero;
            }
            vector2_1 = Vector2.Zero;
            for (int index = 0; index < this.data.Length; ++index)
            {
                if (this.data[index].type == num1)
                {
                    int damage = this.data[index].damage;
                    if (damage >= 20)
                    {
                        int x = this.data[index].X;
                        int y = this.data[index].Y;
                        if (WorldGen.InWorld(x, y, 0))
                        {
                            bool flag1;
                            if ((flag1 = Main.tile[x, y] != null) && num1 == 1)
                            {
                                flag1 = flag1 && Main.tile[x, y].active() && Main.tileSolid[(int)Main.tile[x, y].type];
                            }
                            if (flag1 && num1 == 2)
                            {
                                flag1 = flag1 && (int)Main.tile[x, y].wall != 0;
                            }
                            if (flag1)
                            {
                                bool flag2 = false;
                                bool flag3 = false;
                                if ((int)Main.tile[x, y].type == 10)
                                {
                                    flag2 = false;
                                }
                                else if (Main.tileSolid[(int)Main.tile[x, y].type] && !Main.tileSolidTop[(int)Main.tile[x, y].type])
                                {
                                    flag2 = true;
                                }
                                else if ((int)Main.tile[x, y].type == 5)
                                {
                                    flag3 = true;
                                    int num2 = (int)Main.tile[x, y].frameX / 22;
                                    int num3 = (int)Main.tile[x, y].frameY / 22;
                                    if (num3 < 9)
                                    {
                                        flag2 = (num2 != 1 && num2 != 2 || (num3 < 6 || num3 > 8)) && ((num2 != 3 || num3 > 2) && ((num2 != 4 || num3 < 3 || num3 > 5) && (num2 != 5 || num3 < 6 || num3 > 8)));
                                    }
                                }
                                else if ((int)Main.tile[x, y].type == 72)
                                {
                                    flag3 = true;
                                    if ((int)Main.tile[x, y].frameX <= 34)
                                    {
                                        flag2 = true;
                                    }
                                }
                                if (flag2 && (int)Main.tile[x, y].slope() == 0 && !Main.tile[x, y].halfBrick())
                                {
                                    int num2 = 0;
                                    if (damage >= 80)
                                    {
                                        num2 = 3;
                                    }
                                    else if (damage >= 60)
                                    {
                                        num2 = 2;
                                    }
                                    else if (damage >= 40)
                                    {
                                        num2 = 1;
                                    }
                                    else if (damage >= 20)
                                    {
                                        num2 = 0;
                                    }
                                    Rectangle rectangle = new Rectangle(this.data[index].crackStyle * 18, num2 * 18, 16, 16);
                                    rectangle.Inflate(-2, -2);
                                    if (flag3)
                                    {
                                        rectangle.X = (4 + this.data[index].crackStyle / 2) * 18;
                                    }
                                    int animationTimeElapsed = this.data[index].animationTimeElapsed;
                                    if ((double)animationTimeElapsed < 10.0)
                                    {
                                        float   num3     = (float)animationTimeElapsed / 10f;
                                        float   num4     = 1f;
                                        Color   color1   = Lighting.GetColor(x, y);
                                        float   rotation = 0.0f;
                                        Vector2 zero     = Vector2.Zero;
                                        float   num5     = num3;
                                        float   num6     = 0.5f;
                                        float   num7     = num5 % num6 * 2f;
                                        if ((int)((double)num5 / (double)num6) % 2 == 1)
                                        {
                                            num7 = 1f - num7;
                                        }
                                        num4 = (float)((double)num7 * 0.449999988079071 + 1.0);
                                        Tile      tileSafely = Framing.GetTileSafely(x, y);
                                        Tile      tile       = tileSafely;
                                        Texture2D texture    = !Main.canDrawColorTile(tileSafely.type, (int)tileSafely.color()) ? Main.tileTexture[(int)tileSafely.type] : (Texture2D)Main.tileAltTexture[(int)tileSafely.type, (int)tileSafely.color()];
                                        Vector2   origin     = new Vector2(8f);
                                        Vector2   vector2_2  = new Vector2(1f);
                                        float     num8       = (float)((double)num7 * 0.200000002980232 + 1.0);
                                        Color     color2     = color1 * 0.8f;
                                        Vector2   scale      = num8 * vector2_2;
                                        Vector2   position   = (new Vector2((float)(x * 16 - (int)Main.screenPosition.X), (float)(y * 16 - (int)Main.screenPosition.Y)) + vector2_1 + origin + zero).Floor();
                                        spriteBatch.Draw(texture, position, new Rectangle?(new Rectangle((int)tile.frameX, (int)tile.frameY, 16, 16)), color2, rotation, origin, scale, SpriteEffects.None, 0.0f);
                                        color2.A = (byte)180;
                                        spriteBatch.Draw(Main.tileCrackTexture, position, new Rectangle?(rectangle), color2, rotation, origin, scale, SpriteEffects.None, 0.0f);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #14
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 #15
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 (TileID.Sets.Platforms[tileSafely.type])
                                {
                                    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 && !TileID.Sets.Platforms[tileSafely.type] && 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] || TileID.Sets.Platforms[tileSafely.type] && (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 (single6 == 1f && single4 == 0f)
                {
                    single5 = 1f;
                    single6 = 1f;
                }
                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);
        }
        public void DrawFreshAnimations(SpriteBatch spriteBatch)
        {
            for (int i = 0; i < data.Length; i++)
            {
                data[i].animationTimeElapsed++;
            }
            if (!Main.SettingsEnabled_MinersWobble)
            {
                return;
            }
            int     num    = 1;
            Vector2 vector = new Vector2(Main.offScreenRange);

            if (Main.drawToScreen)
            {
                vector = Vector2.Zero;
            }
            vector = Vector2.Zero;
            for (int j = 0; j < data.Length; j++)
            {
                if (data[j].type != num)
                {
                    continue;
                }
                int damage = data[j].damage;
                if (damage < 20)
                {
                    continue;
                }
                int x = data[j].X;
                int y = data[j].Y;
                if (!WorldGen.InWorld(x, y))
                {
                    continue;
                }
                bool flag = Main.tile[x, y] != null;
                if (flag && num == 1)
                {
                    flag = flag && Main.tile[x, y].active() && Main.tileSolid[Main.tile[x, y].type];
                }
                if (flag && num == 2)
                {
                    flag = flag && Main.tile[x, y].wall != 0;
                }
                if (!flag)
                {
                    continue;
                }
                bool flag2 = false;
                bool flag3 = false;
                if (Main.tile[x, y].type == 10)
                {
                    flag2 = false;
                }
                else if (Main.tileSolid[Main.tile[x, y].type] && !Main.tileSolidTop[Main.tile[x, y].type])
                {
                    flag2 = true;
                }
                else if (WorldGen.IsTreeType(Main.tile[x, y].type))
                {
                    flag3 = true;
                    int num2 = Main.tile[x, y].frameX / 22;
                    int num3 = Main.tile[x, y].frameY / 22;
                    if (num3 < 9)
                    {
                        flag2 = ((num2 != 1 && num2 != 2) || num3 < 6 || num3 > 8) && (num2 != 3 || num3 > 2) && (num2 != 4 || num3 < 3 || num3 > 5) && ((num2 != 5 || num3 < 6 || num3 > 8) ? true : false);
                    }
                }
                else if (Main.tile[x, y].type == 72)
                {
                    flag3 = true;
                    if (Main.tile[x, y].frameX <= 34)
                    {
                        flag2 = true;
                    }
                }
                if (!flag2 || Main.tile[x, y].slope() != 0 || Main.tile[x, y].halfBrick())
                {
                    continue;
                }
                int num4 = 0;
                if (damage >= 80)
                {
                    num4 = 3;
                }
                else if (damage >= 60)
                {
                    num4 = 2;
                }
                else if (damage >= 40)
                {
                    num4 = 1;
                }
                else if (damage >= 20)
                {
                    num4 = 0;
                }
                Rectangle value = new Rectangle(data[j].crackStyle * 18, num4 * 18, 16, 16);
                value.Inflate(-2, -2);
                if (flag3)
                {
                    value.X = (4 + data[j].crackStyle / 2) * 18;
                }
                int animationTimeElapsed = data[j].animationTimeElapsed;
                if (!((float)animationTimeElapsed >= 10f))
                {
                    float   num5     = (float)animationTimeElapsed / 10f;
                    Color   color    = Lighting.GetColor(x, y);
                    float   rotation = 0f;
                    Vector2 zero     = Vector2.Zero;
                    float   num6     = 0.5f;
                    float   num7     = num5 % num6;
                    num7 *= 1f / num6;
                    if ((int)(num5 / num6) % 2 == 1)
                    {
                        num7 = 1f - num7;
                    }
                    Tile      tileSafely = Framing.GetTileSafely(x, y);
                    Tile      tile       = tileSafely;
                    Texture2D texture2D  = Main.instance.TilePaintSystem.TryGetTileAndRequestIfNotReady(tileSafely.type, 0, tileSafely.color());
                    if (texture2D != null)
                    {
                        Vector2 vector2     = new Vector2(8f);
                        Vector2 value2      = new Vector2(1f);
                        float   scaleFactor = num7 * 0.2f + 1f;
                        float   num8        = 1f - num7;
                        num8   = 1f;
                        color *= num8 * num8 * 0.8f;
                        Vector2 scale    = scaleFactor * value2;
                        Vector2 position = (new Vector2(x * 16 - (int)Main.screenPosition.X, y * 16 - (int)Main.screenPosition.Y) + vector + vector2 + zero);
                        spriteBatch.Draw(texture2D, position, new Rectangle(tile.frameX, tile.frameY, 16, 16), color, rotation, vector2, scale, SpriteEffects.None, 0f);
                        color.A = 180;
                        spriteBatch.Draw(TextureAssets.TileCrack.Value, position, value, color, rotation, vector2, scale, SpriteEffects.None, 0f);
                    }
                }
            }
        }