2021-06-11 14:02:28 +02: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/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2024-04-24 15:46:45 +02:00
index 51e97ca80f25cd1e49033cfbc41b595f3fa54d66..5175475d75c393bfd5516d7dbede5200b7091b64 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2024-04-24 15:46:45 +02:00
@@ -682,7 +682,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2022-06-08 08:06:17 +02:00
return;
}
2021-06-14 16:41:34 +02:00
- this.player.absMoveTo(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot());
2024-01-20 12:50:16 +01:00
+ this.player.moveTo(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot()); // Paper - Fix Entity Teleportation and cancel velocity if teleported
2021-06-11 14:02:28 +02:00
this.lastGoodX = this.awaitingPositionFromClient.x;
this.lastGoodY = this.awaitingPositionFromClient.y;
this.lastGoodZ = this.awaitingPositionFromClient.z;
2024-04-24 15:46:45 +02:00
@@ -1589,7 +1589,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2021-11-25 10:19:05 +01:00
this.awaitingTeleportTime = this.tickCount;
2024-04-24 15:46:45 +02:00
this.player.resetCurrentImpulseContext();
2021-11-25 10:19:05 +01:00
- this.player.absMoveTo(d0, d1, d2, f, f1);
2024-01-20 12:50:16 +01:00
+ this.player.moveTo(d0, d1, d2, f, f1); // Paper - Fix Entity Teleportation and cancel velocity if teleported
2023-03-14 21:25:13 +01:00
this.player.connection.send(new ClientboundPlayerPositionPacket(d0 - d3, d1 - d4, d2 - d5, f - f2, f1 - f3, set, this.awaitingTeleport));
2021-11-25 10:19:05 +01:00
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
2024-04-24 15:46:45 +02:00
index e6422024dd4aa472156d9751dcdeb55b5e210f53..c8e4e37b706bd8cb9698ac2d13d0d8668e2d1d14 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
2024-04-24 15:46:45 +02:00
@@ -165,6 +165,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
2021-06-11 14:02:28 +02:00
// CraftBukkit start
private static final int CURRENT_LEVEL = 2;
2024-01-20 12:50:16 +01:00
+ public boolean preserveMotion = true; // Paper - Fix Entity Teleportation and cancel velocity if teleported; keep initial motion on first setPositionRotation
2021-06-11 14:02:28 +02:00
static boolean isLevelAtLeast(CompoundTag tag, int level) {
return tag.contains("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level;
}
2024-04-24 15:46:45 +02:00
@@ -1809,6 +1810,13 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
2021-06-11 14:02:28 +02:00
}
public void moveTo(double x, double y, double z, float yaw, float pitch) {
2024-01-20 23:13:41 +01:00
+ // Paper start - Fix Entity Teleportation and cancel velocity if teleported
2021-06-11 14:02:28 +02:00
+ if (!preserveMotion) {
+ this.deltaMovement = Vec3.ZERO;
+ } else {
+ this.preserveMotion = false;
+ }
2024-01-20 12:50:16 +01:00
+ // Paper end - Fix Entity Teleportation and cancel velocity if teleported
2021-06-14 16:41:34 +02:00
this.setPosRaw(x, y, z);
this.setYRot(yaw);
this.setXRot(pitch);
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/level/BaseSpawner.java b/src/main/java/net/minecraft/world/level/BaseSpawner.java
2024-04-24 15:46:45 +02:00
index b90127f9f805fdb5bb43a4b8ad2b10499b0b6b78..8efc06d29c62fa2be8515ed3359d52a6d4b807d2 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/BaseSpawner.java
+++ b/src/main/java/net/minecraft/world/level/BaseSpawner.java
2024-04-24 15:46:45 +02:00
@@ -164,6 +164,7 @@ public abstract class BaseSpawner {
2021-06-14 16:41:34 +02:00
return;
}
2021-06-11 14:02:28 +02:00
2024-01-20 12:50:16 +01:00
+ entity.preserveMotion = true; // Paper - Fix Entity Teleportation and cancel velocity if teleported; preserve entity motion from tag
2022-06-08 08:06:17 +02:00
entity.moveTo(entity.getX(), entity.getY(), entity.getZ(), randomsource.nextFloat() * 360.0F, 0.0F);
2021-06-14 16:41:34 +02:00
if (entity instanceof Mob) {
Mob entityinsentient = (Mob) entity;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
2024-04-24 15:46:45 +02:00
index 40e4b8233e27b8ebd94a89bb43b5c14808edaa68..3da47cf8968c1917e2f216a410eece51a693dfb2 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
@@ -238,7 +238,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
2021-06-11 14:02:28 +02:00
}
// entity.setLocation() throws no event, and so cannot be cancelled
2021-06-14 16:41:34 +02:00
- this.entity.absMoveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
2022-06-08 08:06:17 +02:00
+ entity.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); // Paper - use proper moveTo, as per vanilla teleporting
2021-06-11 14:02:28 +02:00
// SPIGOT-619: Force sync head rotation also
2021-06-14 16:41:34 +02:00
this.entity.setYHeadRot(location.getYaw());