From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Sun, 25 Jun 2023 13:57:30 -0700
Subject: [PATCH] Sync vehicle position to player position on player data load

This allows the player to be re-positioned before logging into
the world without causing thread checks to trip on Folia.

diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index df0c10880c5aea110a4eade57d257d3a46e8c180..ca3770e9f77e583dfa6cef8ca884eaf6a43f5ffa 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -775,8 +775,18 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
     public void loadAndSpawnParentVehicle(Optional<CompoundTag> tag) {
         if (tag.isPresent() && tag.get().contains("RootVehicle", 10) && this.level() instanceof ServerLevel serverLevel) {
             CompoundTag compound = tag.get().getCompound("RootVehicle");
+            Vec3 playerPos = this.position(); // Paper - force sync root vehicle to player position
             Entity entity = EntityType.loadEntityRecursive(
-                compound.getCompound("Entity"), serverLevel, EntitySpawnReason.LOAD, entity2 -> !serverLevel.addWithUUID(entity2, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.MOUNT) ? null : entity2 // Paper - Entity#getEntitySpawnReason
+                // Paper start - force sync root vehicle to player position
+                compound.getCompound("Entity"), serverLevel, EntitySpawnReason.LOAD, entity2 -> {
+                        // Paper start - force sync root vehicle to player position
+                        if (entity2.distanceToSqr(ServerPlayer.this) > (5.0 * 5.0)) {
+                            entity2.setPosRaw(playerPos.x, playerPos.y, playerPos.z, true);
+                        }
+                        // Paper end - force sync root vehicle to player position
+                    return !serverLevel.addWithUUID(entity2, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.MOUNT) ? null : entity2; // Paper - Entity#getEntitySpawnReason
+                }
+                // Paper end - force sync root vehicle to player position
             );
             if (entity == null) {
                 return;
