From 5cc35a8e234f5048a46eb2d6abd6f8ce266e808a Mon Sep 17 00:00:00 2001 From: kerudion <119808157+kerudion@users.noreply.github.com> Date: Tue, 28 Jan 2025 16:11:25 -0800 Subject: [PATCH] Fix flickering with teleportAsync Fixes flickering of entities without passengers when teleporting them with teleportAsync. We do not need to untrack/track the entity when there are no passengers, so we should not. --- .../minecraft/world/entity/Entity.java.patch | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/folia-server/minecraft-patches/sources/net/minecraft/world/entity/Entity.java.patch b/folia-server/minecraft-patches/sources/net/minecraft/world/entity/Entity.java.patch index 5cf56e2..71d5214 100644 --- a/folia-server/minecraft-patches/sources/net/minecraft/world/entity/Entity.java.patch +++ b/folia-server/minecraft-patches/sources/net/minecraft/world/entity/Entity.java.patch @@ -200,7 +200,7 @@ if (!this.level().paperConfig().scoreboards.allowNonPlayerEntitiesOnScoreboards && !(this instanceof Player)) { return null; } // Paper - Perf: Disable Scoreboards for non players by default return this.level().getScoreboard().getPlayersTeam(this.getScoreboardName()); } -@@ -3726,8 +_,782 @@ +@@ -3726,8 +_,789 @@ this.portalProcess = entity.portalProcess; } @@ -589,25 +589,32 @@ + ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkX(pos), ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkZ(pos) + ) + ) { ++ boolean hasPassengers = !this.passengers.isEmpty(); + EntityTreeNode passengerTree = this.detachPassengers(); -+ // Note: The client does not accept position updates for controlled entities. So, we must -+ // perform a lot of tracker updates here to make it all work out. + -+ // first, clear the tracker -+ passengerTree.clearTracker(); ++ if (hasPassengers) { ++ // Note: The client does not accept position updates for controlled entities. So, we must ++ // perform a lot of tracker updates here to make it all work out. ++ ++ // first, clear the tracker ++ passengerTree.clearTracker(); ++ } ++ + for (EntityTreeNode entity : passengerTree.getFullTree()) { + entity.root.teleportSyncSameRegion(pos, yaw, pitch, velocity); + } + -+ passengerTree.restore(); -+ // re-add to the tracker once the tree is restored -+ passengerTree.addTracker(); ++ if (hasPassengers) { ++ passengerTree.restore(); ++ // re-add to the tracker once the tree is restored ++ passengerTree.addTracker(); + -+ // adjust entities to final position -+ passengerTree.adjustRiders(true); ++ // adjust entities to final position ++ passengerTree.adjustRiders(true); + -+ // the tracker clear/add logic is only used in the same region, as the other logic -+ // performs add/remove from world logic which will also perform add/remove tracker logic ++ // the tracker clear/add logic is only used in the same region, as the other logic ++ // performs add/remove from world logic which will also perform add/remove tracker logic ++ } + + if (teleportComplete != null) { + teleportComplete.accept(this);