Terraria.Player.Teleport C# (CSharp) Method

Teleport() public method

public Teleport ( Vector2 newPos, int Style, int extraInfo ) : void
newPos Vector2
Style int
extraInfo int
return void
        public void Teleport(Vector2 newPos, int Style = 0, int extraInfo = 0)
        {
            try
            {
                this.grappling[0] = -1;
                this.grapCount = 0;
                for (int index = 0; index < 1000; ++index)
                {
                    if (Main.projectile[index].active && Main.projectile[index].owner == this.whoAmI && Main.projectile[index].aiStyle == 7)
                        Main.projectile[index].Kill();
                }
                int extraInfo1 = 0;
                if (Style == 4)
                    extraInfo1 = this.lastPortalColorIndex;
                Main.TeleportEffect(this.getRect(), Style, extraInfo1);
                this.position = newPos;
                this.fallStart = (int)((double)this.position.Y / 16.0);
                if (this.whoAmI == Main.myPlayer)
                {
                    Main.BlackFadeIn = (int)byte.MaxValue;
                    Lighting.BlackOut();
                    Main.screenLastPosition = Main.screenPosition;
                    Main.screenPosition.X = this.position.X + (float)(this.width / 2) - (float)(Main.screenWidth / 2);
                    Main.screenPosition.Y = this.position.Y + (float)(this.height / 2) - (float)(Main.screenHeight / 2);
                    if (Main.mapTime < 5)
                        Main.mapTime = 5;
                    Main.quickBG = 10;
                    Main.maxQ = true;
                    Main.renderNow = true;
                }
                if (Style == 4)
                {
                    this.lastPortalColorIndex = extraInfo;
                    extraInfo1 = this.lastPortalColorIndex;
                    this.justGotOutOfPortal = true;
                    this.gravity = 0.0f;
                }
                for (int index = 0; index < 3; ++index)
                    this.UpdateSocialShadow();
                this.oldPosition = this.position;
                Main.TeleportEffect(this.getRect(), Style, extraInfo1);
                this.teleportTime = 1f;
                this.teleportStyle = Style;
            }
            catch
            {
            }
        }

Usage Example

        public void OnPlayerPreUpdate(Player player)
        {
            if (player.whoAmI != Main.myPlayer) return;

            if (player.inventory[player.selectedItem].type == ItemID.CellPhone)
            {
                if (Main.mouseItem.type == ItemID.CellPhone) return; // don't allow it to be on your cursor

                if (Main.mouseLeft && Main.mouseLeftRelease)
                {
                    if (mode == Mode.Home) return;

                    player.mouseInterface = true;
                    Main.mouseLeftRelease = false;
                    if (mode == Mode.LeftOcean)
                    {
                        // left ocean
                        player.Teleport(new Vector2(200 * 16, (float)(Main.worldSurface / 2f) * 16f), 3);
                        if (!Main.tile[(int)(player.position.X / 16f), (int)(player.position.Y / 16f) + 3].active())
                        {
                            while (!Main.tile[(int)(player.position.X / 16f), (int)(player.position.Y / 16f) + 4].active())
                            {
                                player.position.Y += 16f;
                            }
                        }
                        else
                        {
                            while (Main.tile[(int)(player.position.X / 16f), (int)(player.position.Y / 16f) + 4].active())
                            {
                                player.position.Y -= 16f;
                            }
                        }
                        player.fallStart = (int)(player.position.Y / 16f);
                        if (Main.netMode == 1) NetMessage.SendTileSquare(player.whoAmI, 200, (int)Main.worldSurface / 2, 10);
                    }
                    else if (mode == Mode.RightOcean)
                    {
                        // right ocean
                        player.Teleport(new Vector2((Main.maxTilesX - 200) * 16, (float)(Main.worldSurface / 2f) * 16f), 3);
                        if (!Main.tile[(int)(player.position.X / 16f), (int)(player.position.Y / 16f) + 3].active())
                        {
                            while (!Main.tile[(int)(player.position.X / 16f), (int)(player.position.Y / 16f) + 4].active())
                            {
                                player.position.Y += 16f;
                            }
                        }
                        else
                        {
                            while (Main.tile[(int)(player.position.X / 16f), (int)(player.position.Y / 16f) + 4].active())
                            {
                                player.position.Y -= 16f;
                            }
                        }
                        player.fallStart = (int)(player.position.Y / 16f);
                        if (Main.netMode == 1) NetMessage.SendTileSquare(player.whoAmI, Main.maxTilesX - 200, (int)Main.worldSurface / 2, 10);
                    }
                    else if (mode == Mode.Hell)
                    {
                        // hell
                        player.Teleport(new Vector2((Main.maxTilesX / 2) * 16, (float)(Main.maxTilesY - 180) * 16f), 3);
                        if (!Main.tile[(int)(player.position.X / 16f), (int)(player.position.Y / 16f) + 3].active())
                        {
                            while (!Main.tile[(int)(player.position.X / 16f), (int)(player.position.Y / 16f) + 4].active())
                            {
                                player.position.Y += 16f;
                                if ((int)(player.position.Y / 16f) > Main.maxTilesY)
                                {
                                    player.position.Y = (float)(Main.maxTilesY * 16) - 130f;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            while (Main.tile[(int)(player.position.X / 16f), (int)(player.position.Y / 16f) + 4].active())
                            {
                                player.position.Y -= 16f;
                            }
                        }
                        player.fallStart = (int)(player.position.Y / 16f);
                        if (Main.netMode == 1) NetMessage.SendTileSquare(player.whoAmI, Main.maxTilesX / 2, (int)Main.maxTilesY - 180, 10);
                    }
                    else if (mode == Mode.Random)
                    {
                        if (Main.netMode == 0)
                        {
                            player.TeleportationPotion();
                        }
                        else if (Main.netMode == 1 && player.whoAmI == Main.myPlayer)
                        {
                            NetMessage.SendData(73, -1, -1, "", 0, 0f, 0f, 0f, 0);
                        }
                    }
                    for (int num91 = 0; num91 < 70; num91++)
                    {
                        Dust.NewDust(player.position, player.width, player.height, 15, 0f, 0f, 150, default(Color), 1.5f);
                    }
                }
            }
        }
Player