place the player before loading the data
This commit is contained in:
1 parent
ce6664af28
commit
6654b5399c
1 file changed
+5
-10
@@ -2,11 +2,8 @@ package carpet.patches;
|
|||||||
|
|
||||||
import carpet.CarpetSettings;
|
import carpet.CarpetSettings;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.properties.PropertyMap;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.UUIDUtil;
|
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.DisconnectionDetails;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.network.chat.contents.TranslatableContents;
|
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.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.server.network.CommonListenerCookie;
|
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.server.players.OldUsersConverter;
|
||||||
import net.minecraft.util.ProblemReporter;
|
import net.minecraft.util.ProblemReporter;
|
||||||
import net.minecraft.world.damagesource.DamageSource;
|
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.item.component.ResolvableProfile;
|
||||||
import net.minecraft.world.level.GameType;
|
import net.minecraft.world.level.GameType;
|
||||||
import net.minecraft.world.level.Level;
|
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.block.state.BlockState;
|
||||||
import net.minecraft.world.level.portal.TeleportTransition;
|
import net.minecraft.world.level.portal.TeleportTransition;
|
||||||
import net.minecraft.world.level.storage.TagValueInput;
|
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);
|
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);
|
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));
|
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.teleportTo(worldIn, pos.x, pos.y, pos.z, Set.of(), (float) yaw, (float) pitch, true);
|
||||||
instance.setHealth(20.0F);
|
instance.setHealth(20.0F);
|
||||||
instance.unsetRemoved();
|
instance.unsetRemoved();
|
||||||
@@ -132,7 +127,7 @@ public class EntityPlayerMPFake extends ServerPlayer
|
|||||||
{
|
{
|
||||||
Optional<ValueInput> optional = player.level().getServer().getPlayerList().loadPlayerData(player.nameAndId()).map((compoundTag) -> TagValueInput.create(scopedCollector, player.registryAccess(), compoundTag));
|
Optional<ValueInput> optional = player.level().getServer().getPlayerList().loadPlayerData(player.nameAndId()).map((compoundTag) -> TagValueInput.create(scopedCollector, player.registryAccess(), compoundTag));
|
||||||
optional.ifPresent( valueInput -> {
|
optional.ifPresent( valueInput -> {
|
||||||
player.readAdditionalSaveData(valueInput);
|
player.load(valueInput);
|
||||||
player.loadAndSpawnEnderPearls(valueInput);
|
player.loadAndSpawnEnderPearls(valueInput);
|
||||||
player.loadAndSpawnParentVehicle(valueInput);
|
player.loadAndSpawnParentVehicle(valueInput);
|
||||||
});
|
});
|
||||||
@@ -147,8 +142,8 @@ public class EntityPlayerMPFake extends ServerPlayer
|
|||||||
GameProfile gameprofile = player.getGameProfile();
|
GameProfile gameprofile = player.getGameProfile();
|
||||||
EntityPlayerMPFake playerShadow = new EntityPlayerMPFake(server, worldIn, gameprofile, player.clientInformation(), true);
|
EntityPlayerMPFake playerShadow = new EntityPlayerMPFake(server, worldIn, gameprofile, player.clientInformation(), true);
|
||||||
playerShadow.setChatSession(player.getChatSession());
|
playerShadow.setChatSession(player.getChatSession());
|
||||||
loadPlayerData(playerShadow);
|
|
||||||
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), playerShadow, new CommonListenerCookie(gameprofile, 0, player.clientInformation(), true));
|
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), playerShadow, new CommonListenerCookie(gameprofile, 0, player.clientInformation(), true));
|
||||||
|
loadPlayerData(playerShadow);
|
||||||
|
|
||||||
playerShadow.setHealth(player.getHealth());
|
playerShadow.setHealth(player.getHealth());
|
||||||
playerShadow.connection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
|
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)
|
private EntityPlayerMPFake(MinecraftServer server, ServerLevel worldIn, GameProfile profile, ClientInformation cli, boolean shadow)
|
||||||
{
|
{
|
||||||
super(server, worldIn, profile, cli);
|
super(server, worldIn, profile, cli);
|
||||||
isAShadow = shadow;
|
this.isAShadow = shadow;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in new issue
Block a user