Terraria.Player.SmartitemLookup C# (CSharp) Method

SmartitemLookup() public method

public SmartitemLookup ( ) : void
return void
        public void SmartitemLookup()
        {
            if (this.controlTorch && this.itemAnimation == 0)
            {
                int num1 = 0;
                int index1 = (int)(((double)Main.mouseX + (double)Main.screenPosition.X) / 16.0);
                int index2 = (int)(((double)Main.mouseY + (double)Main.screenPosition.Y) / 16.0);
                if ((double)this.gravDir == -1.0)
                    index2 = (int)(((double)Main.screenPosition.Y + (double)Main.screenHeight - (double)Main.mouseY) / 16.0);
                int num2 = -10;
                int num3 = -10;
                int num4 = -10;
                int num5 = -10;
                int num6 = -10;
                for (int index3 = 0; index3 < 50; ++index3)
                {
                    if (this.inventory[index3].pick > 0 && num2 == -10)
                        num2 = this.inventory[index3].tileBoost;
                    if (this.inventory[index3].axe > 0 && num3 == -10)
                        num3 = this.inventory[index3].tileBoost;
                    if (this.inventory[index3].hammer > 0 && num4 == -10)
                        num4 = this.inventory[index3].tileBoost;
                    if ((this.inventory[index3].itemId == 929 || this.inventory[index3].itemId == 1338 || this.inventory[index3].itemId == 1345) && num5 == -10)
                        num5 = this.inventory[index3].tileBoost;
                    if ((this.inventory[index3].itemId == 424 || this.inventory[index3].itemId == 1103) && num6 == -10)
                        num6 = this.inventory[index3].tileBoost;
                }
                int num7 = 0;
                int num8 = 0;
                if ((double)this.position.X / 16.0 >= (double)index1)
                    num7 = (int)((double)this.position.X / 16.0) - index1;
                if (((double)this.position.X + (double)this.width) / 16.0 <= (double)index1)
                    num7 = index1 - (int)(((double)this.position.X + (double)this.width) / 16.0);
                if ((double)this.position.Y / 16.0 >= (double)index2)
                    num8 = (int)((double)this.position.Y / 16.0) - index2;
                if (((double)this.position.Y + (double)this.height) / 16.0 <= (double)index2)
                    num8 = index2 - (int)(((double)this.position.Y + (double)this.height) / 16.0);
                bool flag1 = false;
                bool flag2 = false;
                try
                {
                    flag2 = (int)Main.tile[index1, index2].liquid > 0;
                    if (Main.tile[index1, index2].active())
                    {
                        int index3 = (int)Main.tile[index1, index2].type;
                        if (index3 == 219 && num7 <= num6 + Player.tileRangeX && num8 <= num6 + Player.tileRangeY)
                        {
                            num1 = 7;
                            flag1 = true;
                        }
                        else if (index3 == 209 && num7 <= num5 + Player.tileRangeX && num8 <= num5 + Player.tileRangeY)
                        {
                            num1 = 6;
                            flag1 = true;
                        }
                        else if (Main.tileHammer[index3] && num7 <= num4 + Player.tileRangeX && num8 <= num4 + Player.tileRangeY)
                        {
                            num1 = 1;
                            flag1 = true;
                        }
                        else if (Main.tileAxe[index3] && num7 <= num3 + Player.tileRangeX && num8 <= num3 + Player.tileRangeY)
                        {
                            num1 = 2;
                            flag1 = true;
                        }
                        else if (num7 <= num2 + Player.tileRangeX)
                        {
                            if (num8 <= num2 + Player.tileRangeY)
                            {
                                num1 = 3;
                                flag1 = true;
                            }
                        }
                    }
                    else if (flag2)
                    {
                        if (this.wet)
                        {
                            num1 = 4;
                            flag1 = true;
                        }
                    }
                }
                catch
                {
                }
                if (!flag1 && this.wet)
                    num1 = 4;
                if (num1 == 0 || num1 == 4)
                {
                    float num9 = Math.Abs((float)((double)Main.mouseX + (double)Main.screenPosition.X - ((double)this.position.X + (double)(this.width / 2))));
                    float num10 = Math.Abs((float)((double)Main.mouseY + (double)Main.screenPosition.Y - ((double)this.position.Y + (double)(this.height / 2)))) * 1.3f;
                    if (Math.Sqrt((double)num9 * (double)num9 + (double)num10 * (double)num10) > 200.0)
                        num1 = 5;
                }
                for (int index3 = 0; index3 < 50; ++index3)
                {
                    int index4 = this.inventory[index3].itemId;
                    if (num1 == 0)
                    {
                        if (index4 == 8 || index4 == 427 || (index4 == 428 || index4 == 429) || (index4 == 430 || index4 == 431 || (index4 == 432 || index4 == 433)) || (index4 == 523 || index4 == 974 || (index4 == 1245 || index4 == 1333) || (index4 == 2274 || index4 == 3004 || (index4 == 3045 || index4 == 3114))))
                        {
                            if (this.nonTorch == -1)
                                this.nonTorch = this.selectedItem;
                            this.selectedItem = index3;
                            break;
                        }
                        if (index4 == 282 || index4 == 286 || (index4 == 3002 || index4 == 3112))
                        {
                            if (this.nonTorch == -1)
                                this.nonTorch = this.selectedItem;
                            this.selectedItem = index3;
                        }
                    }
                    else if (num1 == 1)
                    {
                        if (this.inventory[index3].hammer > 0)
                        {
                            if (this.nonTorch == -1)
                                this.nonTorch = this.selectedItem;
                            this.selectedItem = index3;
                            break;
                        }
                    }
                    else if (num1 == 2)
                    {
                        if (this.inventory[index3].axe > 0)
                        {
                            if (this.nonTorch == -1)
                                this.nonTorch = this.selectedItem;
                            this.selectedItem = index3;
                            break;
                        }
                    }
                    else if (num1 == 3)
                    {
                        if (this.inventory[index3].pick > 0)
                        {
                            if (this.nonTorch == -1)
                                this.nonTorch = this.selectedItem;
                            this.selectedItem = index3;
                            break;
                        }
                    }
                    else if (num1 == 4)
                    {
                        if (this.inventory[index3].itemId != 282 && this.inventory[index3].itemId != 286 && (this.inventory[index3].itemId != 3002 && this.inventory[index3].itemId != 3112) && this.inventory[index3].itemId != 930 && (index4 == 8 || index4 == 427 || (index4 == 428 || index4 == 429) || (index4 == 430 || index4 == 431 || (index4 == 432 || index4 == 433)) || (index4 == 974 || index4 == 1245 || (index4 == 2274 || index4 == 3004) || (index4 == 3045 || index4 == 3114))))
                        {
                            if (this.nonTorch == -1)
                                this.nonTorch = this.selectedItem;
                            if (this.inventory[this.selectedItem].createTile != 4)
                                this.selectedItem = index3;
                        }
                        else
                        {
                            if ((index4 == 282 || index4 == 286 || (index4 == 3002 || index4 == 3112)) && flag2)
                            {
                                if (this.nonTorch == -1)
                                    this.nonTorch = this.selectedItem;
                                this.selectedItem = index3;
                                break;
                            }
                            if (index4 == 930 && flag2)
                            {
                                bool flag3 = false;
                                for (int index5 = 57; index5 >= 0; --index5)
                                {
                                    if (this.inventory[index5].ammo == this.inventory[index3].useAmmo)
                                    {
                                        flag3 = true;
                                        break;
                                    }
                                }
                                if (flag3)
                                {
                                    if (this.nonTorch == -1)
                                        this.nonTorch = this.selectedItem;
                                    this.selectedItem = index3;
                                    break;
                                }
                            }
                            else if (index4 == 1333 || index4 == 523)
                            {
                                if (this.nonTorch == -1)
                                    this.nonTorch = this.selectedItem;
                                this.selectedItem = index3;
                                break;
                            }
                        }
                    }
                    else if (num1 == 5)
                    {
                        if (index4 == 8 || index4 == 427 || (index4 == 428 || index4 == 429) || (index4 == 430 || index4 == 431 || (index4 == 432 || index4 == 433)) || (index4 == 523 || index4 == 974 || (index4 == 1245 || index4 == 1333) || (index4 == 2274 || index4 == 3004 || (index4 == 3045 || index4 == 3114))))
                        {
                            if (this.nonTorch == -1)
                                this.nonTorch = this.selectedItem;
                            if (this.inventory[this.selectedItem].createTile != 4)
                                this.selectedItem = index3;
                        }
                        else if (index4 == 930)
                        {
                            bool flag3 = false;
                            for (int index5 = 57; index5 >= 0; --index5)
                            {
                                if (this.inventory[index5].ammo == this.inventory[index3].useAmmo)
                                {
                                    flag3 = true;
                                    break;
                                }
                            }
                            if (flag3)
                            {
                                if (this.nonTorch == -1)
                                    this.nonTorch = this.selectedItem;
                                this.selectedItem = index3;
                                break;
                            }
                        }
                        else if (index4 == 282 || index4 == 286 || (index4 == 3002 || index4 == 3112))
                        {
                            if (this.nonTorch == -1)
                                this.nonTorch = this.selectedItem;
                            this.selectedItem = index3;
                            break;
                        }
                    }
                    else if (num1 == 6)
                    {
                        int num9 = 929;
                        if ((int)Main.tile[index1, index2].frameX >= 144)
                            num9 = 1345;
                        else if ((int)Main.tile[index1, index2].frameX >= 72)
                            num9 = 1338;
                        if (index4 == num9)
                        {
                            if (this.nonTorch == -1)
                                this.nonTorch = this.selectedItem;
                            this.selectedItem = index3;
                            break;
                        }
                    }
                    else if (num1 == 7 && ItemID.Sets.ExtractinatorMode[index4] >= 0)
                    {
                        if (this.nonTorch == -1)
                            this.nonTorch = this.selectedItem;
                        this.selectedItem = index3;
                        break;
                    }
                }
            }
            else
            {
                if (this.nonTorch <= -1 || this.itemAnimation != 0)
                    return;
                this.selectedItem = this.nonTorch;
                this.nonTorch = -1;
            }
        }
Player