From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sat, 4 Dec 2021 17:04:47 -0800
Subject: [PATCH] Forward CraftEntity in teleport command


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 396ee5a8aa57e7c2e9a14606d37cae3c02dc4283..18294d7cdb4619bb128c626ef567622bae187c8d 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -3177,6 +3177,13 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
     }
 
     public void restoreFrom(Entity original) {
+        // Paper start
+        CraftEntity bukkitEntity = original.bukkitEntity;
+        if (bukkitEntity != null) {
+            bukkitEntity.setHandle(this);
+            this.bukkitEntity = bukkitEntity;
+        }
+        // Paper end
         CompoundTag nbttagcompound = original.saveWithoutId(new CompoundTag());
 
         nbttagcompound.remove("Dimension");
@@ -3258,10 +3265,10 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
                     if (worldserver.getTypeKey() == LevelStem.END) { // CraftBukkit
                         ServerLevel.makeObsidianPlatform(worldserver, this); // CraftBukkit
                     }
-                    // CraftBukkit start - Forward the CraftEntity to the new entity
-                    this.getBukkitEntity().setHandle(entity);
-                    entity.bukkitEntity = this.getBukkitEntity();
-                    // CraftBukkit end
+                    // // CraftBukkit start - Forward the CraftEntity to the new entity // Paper - moved to Entity#restoreFrom
+                    // this.getBukkitEntity().setHandle(entity);
+                    // entity.bukkitEntity = this.getBukkitEntity();
+                    // // CraftBukkit end
                 }
 
                 this.removeAfterChangingDimensions();
