testserver/patches/server/0480-Fix-Entity-Teleportati...

84 lines
5.0 KiB
Diff
Raw Normal View History

2021-06-11 12:02:28 +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/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index da6a0171bd63ac68635de1c23fc9eafa732503bd..214771e661ca3303af167fda3b623d83f0f63055 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -760,7 +760,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2022-06-08 06:06:17 +00:00
return;
}
2021-06-14 14:41:34 +00:00
- this.player.absMoveTo(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot());
2022-06-08 06:06:17 +00:00
+ this.player.moveTo(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot()); // Paper - use proper moveTo for teleportation
2021-06-11 12:02:28 +00:00
this.lastGoodX = this.awaitingPositionFromClient.x;
this.lastGoodY = this.awaitingPositionFromClient.y;
this.lastGoodZ = this.awaitingPositionFromClient.z;
@@ -1676,7 +1676,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
// CraftBukkit end
this.awaitingTeleportTime = this.tickCount;
- this.player.absMoveTo(d0, d1, d2, f, f1);
2022-06-08 06:06:17 +00:00
+ this.player.moveTo(d0, d1, d2, f, f1); // Paper - use proper moveTo for teleportation
this.player.connection.send(new ClientboundPlayerPositionPacket(d0 - d3, d1 - d4, d2 - d5, f - f2, f1 - f3, set, this.awaitingTeleport, flag));
}
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
2022-11-03 21:03:31 +00:00
index 1582da75f92aed598c1c076af7b94af7ab48d10a..5a43e57d2e2146d324685808cfe980178bde03a2 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -158,6 +158,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
2021-06-11 12:02:28 +00:00
// CraftBukkit start
private static final int CURRENT_LEVEL = 2;
+ public boolean preserveMotion = true; // Paper - keep initial motion on first setPositionRotation
static boolean isLevelAtLeast(CompoundTag tag, int level) {
return tag.contains("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level;
}
@@ -1716,6 +1717,13 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
2021-06-11 12:02:28 +00:00
}
public void moveTo(double x, double y, double z, float yaw, float pitch) {
+ // Paper - cancel entity velocity if teleported
+ if (!preserveMotion) {
+ this.deltaMovement = Vec3.ZERO;
+ } else {
+ this.preserveMotion = false;
+ }
+ // Paper end
2021-06-14 14:41:34 +00:00
this.setPosRaw(x, y, z);
this.setYRot(yaw);
this.setXRot(pitch);
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/net/minecraft/world/level/BaseSpawner.java b/src/main/java/net/minecraft/world/level/BaseSpawner.java
2022-11-03 21:03:31 +00:00
index 763b4049060b294345ef8a796c0f5b52575d644c..8d403b4a6db98cc5c3851d5f2c485560cf8b412f 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/level/BaseSpawner.java
+++ b/src/main/java/net/minecraft/world/level/BaseSpawner.java
2022-06-08 06:06:17 +00:00
@@ -163,6 +163,7 @@ public abstract class BaseSpawner {
2021-06-14 14:41:34 +00:00
return;
}
2021-06-11 12:02:28 +00:00
2021-06-14 14:41:34 +00:00
+ entity.preserveMotion = true; // Paper - preserve entity motion from tag
2022-06-08 06:06:17 +00:00
entity.moveTo(entity.getX(), entity.getY(), entity.getZ(), randomsource.nextFloat() * 360.0F, 0.0F);
2021-06-14 14:41:34 +00:00
if (entity instanceof Mob) {
Mob entityinsentient = (Mob) entity;
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
2022-11-03 21:03:31 +00:00
index ceb7123362ba85df825a50c035a399174b6634dc..52ccc5cb9c5512b30ce863062de85219adb801ae 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -561,7 +561,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
2021-06-11 12:02:28 +00:00
}
// entity.setLocation() throws no event, and so cannot be cancelled
2021-06-14 14:41:34 +00:00
- this.entity.absMoveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
2022-06-08 06:06:17 +00:00
+ entity.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); // Paper - use proper moveTo, as per vanilla teleporting
2021-06-11 12:02:28 +00:00
// SPIGOT-619: Force sync head rotation also
2021-06-14 14:41:34 +00:00
this.entity.setYHeadRot(location.getYaw());