2020-09-04 01:48:44 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 25 Aug 2020 20:45:36 -0400
Subject: [PATCH] Fix Entity Teleportation and cancel velocity if teleported
Uses correct setPositionRotation for Entity teleporting instead of setLocation
as this is how Vanilla teleports entities.
Cancel any pending motion when teleported.
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
2020-12-21 07:56:22 +00:00
index bf0ef3998ff5dd71d3d6489184ece7fdce8afdd5..1f73ffbdd5b1b5906573ca4ba5c16a4f31b4c79a 100644
2020-09-04 01:48:44 +00:00
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
2020-09-19 17:19:34 +00:00
@@ -54,6 +54,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
// CraftBukkit start
private static final int CURRENT_LEVEL = 2;
+ boolean preserveMotion = true; // Paper - keep initial motion on first setPositionRotation
static boolean isLevelAtLeast(NBTTagCompound tag, int level) {
return tag.hasKey("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level;
}
2020-11-03 02:22:15 +00:00
@@ -1317,6 +1318,13 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
2020-09-04 01:48:44 +00:00
}
public void setPositionRotation(double d0, double d1, double d2, float f, float f1) {
2020-09-19 17:19:34 +00:00
+ // Paper - cancel entity velocity if teleported
+ if (!preserveMotion) {
+ this.mot = Vec3D.ORIGIN;
+ } else {
+ this.preserveMotion = false;
+ }
+ // Paper end
2020-09-04 01:48:44 +00:00
this.g(d0, d1, d2);
this.yaw = f;
this.pitch = f1;
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
2020-12-08 07:51:55 +00:00
index 8a4a7888089a10416fc0cf88007b7a958e903a4c..c0524ff9f49dffa4010bdeef301c0d7a059046d4 100644
2020-09-04 01:48:44 +00:00
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
2020-12-08 07:51:55 +00:00
@@ -542,7 +542,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
2020-09-04 01:48:44 +00:00
public void a(PacketPlayInTeleportAccept packetplayinteleportaccept) {
PlayerConnectionUtils.ensureMainThread(packetplayinteleportaccept, this, this.player.getWorldServer());
if (packetplayinteleportaccept.b() == this.teleportAwait && this.teleportPos != null) { // CraftBukkit
- this.player.setLocation(this.teleportPos.x, this.teleportPos.y, this.teleportPos.z, this.player.yaw, this.player.pitch);
+ this.player.setPositionRotation(this.teleportPos.x, this.teleportPos.y, this.teleportPos.z, this.player.yaw, this.player.pitch); // Paper - use proper setPositionRotation for teleportation
this.o = this.teleportPos.x;
this.p = this.teleportPos.y;
this.q = this.teleportPos.z;
2020-12-08 07:51:55 +00:00
@@ -1376,7 +1376,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
2020-09-04 01:48:44 +00:00
// CraftBukkit end
this.A = this.e;
- this.player.setLocation(d0, d1, d2, f, f1);
+ this.player.setPositionRotation(d0, d1, d2, f, f1); // Paper - use proper setPositionRotation for teleportation
this.player.forceCheckHighPriority(); // Paper
this.player.playerConnection.sendPacket(new PacketPlayOutPosition(d0 - d3, d1 - d4, d2 - d5, f - f2, f1 - f3, set, this.teleportAwait));
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
2020-12-21 07:56:22 +00:00
index c7636ffc952c436d7148e6e5926b0108cc628821..582ed13a9ba1748444ce4d624d83a4d7be7006f2 100644
2020-09-04 01:48:44 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
2020-12-21 07:56:22 +00:00
@@ -554,7 +554,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
2020-09-04 01:48:44 +00:00
}
// entity.setLocation() throws no event, and so cannot be cancelled
- entity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
+ entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); // Paper - use proper setPosition, as per vanilla teleporting
// SPIGOT-619: Force sync head rotation also
entity.setHeadRotation(location.getYaw());
((net.minecraft.server.WorldServer) entity.world).chunkCheck(entity); // Spigot - register to new chunk