From 6654b5399c201adf2f0319c88935040fae97dfd2 Mon Sep 17 00:00:00 2001 From: Crystal0404 Date: Tue, 14 Oct 2025 18:25:45 +0800 Subject: [PATCH] place the player before loading the data --- .../java/carpet/patches/EntityPlayerMPFake.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/carpet/patches/EntityPlayerMPFake.java b/src/main/java/carpet/patches/EntityPlayerMPFake.java index 72714a5f..21c5aa47 100644 --- a/src/main/java/carpet/patches/EntityPlayerMPFake.java +++ b/src/main/java/carpet/patches/EntityPlayerMPFake.java @@ -2,11 +2,8 @@ package carpet.patches; import carpet.CarpetSettings; import com.mojang.authlib.GameProfile; -import com.mojang.authlib.properties.PropertyMap; import net.minecraft.core.BlockPos; import net.minecraft.core.UUIDUtil; -import net.minecraft.core.component.DataComponents; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.DisconnectionDetails; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.contents.TranslatableContents; @@ -22,8 +19,6 @@ import net.minecraft.server.level.ClientInformation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.CommonListenerCookie; -import net.minecraft.server.players.CachedUserNameToIdResolver; -import net.minecraft.server.players.NameAndId; import net.minecraft.server.players.OldUsersConverter; import net.minecraft.util.ProblemReporter; import net.minecraft.world.damagesource.DamageSource; @@ -36,7 +31,6 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.component.ResolvableProfile; import net.minecraft.world.level.GameType; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.SkullBlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.portal.TeleportTransition; import net.minecraft.world.level.storage.TagValueInput; @@ -104,9 +98,10 @@ public class EntityPlayerMPFake extends ServerPlayer } EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, current, ClientInformation.createDefault(), false); - loadPlayerData(instance); instance.fixStartingPosition = () -> instance.snapTo(pos.x, pos.y, pos.z, (float) yaw, (float) pitch); server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance, new CommonListenerCookie(current, 0, instance.clientInformation(), false)); + loadPlayerData(instance); + instance.stopRiding(); // otherwise the created fake player will be on the vehicle instance.teleportTo(worldIn, pos.x, pos.y, pos.z, Set.of(), (float) yaw, (float) pitch, true); instance.setHealth(20.0F); instance.unsetRemoved(); @@ -132,7 +127,7 @@ public class EntityPlayerMPFake extends ServerPlayer { Optional optional = player.level().getServer().getPlayerList().loadPlayerData(player.nameAndId()).map((compoundTag) -> TagValueInput.create(scopedCollector, player.registryAccess(), compoundTag)); optional.ifPresent( valueInput -> { - player.readAdditionalSaveData(valueInput); + player.load(valueInput); player.loadAndSpawnEnderPearls(valueInput); player.loadAndSpawnParentVehicle(valueInput); }); @@ -147,8 +142,8 @@ public class EntityPlayerMPFake extends ServerPlayer GameProfile gameprofile = player.getGameProfile(); EntityPlayerMPFake playerShadow = new EntityPlayerMPFake(server, worldIn, gameprofile, player.clientInformation(), true); playerShadow.setChatSession(player.getChatSession()); - loadPlayerData(playerShadow); server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), playerShadow, new CommonListenerCookie(gameprofile, 0, player.clientInformation(), true)); + loadPlayerData(playerShadow); playerShadow.setHealth(player.getHealth()); playerShadow.connection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot()); @@ -179,7 +174,7 @@ public class EntityPlayerMPFake extends ServerPlayer private EntityPlayerMPFake(MinecraftServer server, ServerLevel worldIn, GameProfile profile, ClientInformation cli, boolean shadow) { super(server, worldIn, profile, cli); - isAShadow = shadow; + this.isAShadow = shadow; } @Override