fix player skins not showing properly

This commit is contained in:
gnembon committed 2023-08-07 20:04:40 +02:00
1 parent cd37140b85
commit 08c5c3db31
3 files changed
+35 -28

No files matched your search

@@ -293,13 +293,10 @@ public class PlayerCommand
Messenger.m(source, "rb Player " + playerName + " cannot be placed outside of the world"); Messenger.m(source, "rb Player " + playerName + " cannot be placed outside of the world");
return 0; return 0;
} }
Player player = EntityPlayerMPFake.createFake(playerName, source.getServer(), pos, facing.y, facing.x, dimType, mode, flying); EntityPlayerMPFake.createFake(playerName, source.getServer(), pos, facing.y, facing.x, dimType, mode, flying, () -> {
if (player == null)
{
Messenger.m(source, "rb Player " + playerName + " doesn't exist and cannot spawn in online mode. " + Messenger.m(source, "rb Player " + playerName + " doesn't exist and cannot spawn in online mode. " +
"Turn the server offline to spawn non-existing players"); "Turn the server offline to spawn non-existing players");
return 0; });
}
return 1; return 1;
} }
@@ -31,7 +31,8 @@ import net.minecraft.world.phys.Vec3;
import carpet.fakes.ServerPlayerInterface; import carpet.fakes.ServerPlayerInterface;
import carpet.utils.Messenger; import carpet.utils.Messenger;
import java.util.concurrent.atomic.AtomicReference; import java.util.Optional;
import java.util.concurrent.CompletableFuture;
@SuppressWarnings("EntityConstructor") @SuppressWarnings("EntityConstructor")
public class EntityPlayerMPFake extends ServerPlayer public class EntityPlayerMPFake extends ServerPlayer
@@ -39,7 +40,7 @@ public class EntityPlayerMPFake extends ServerPlayer
public Runnable fixStartingPosition = () -> {}; public Runnable fixStartingPosition = () -> {};
public boolean isAShadow; public boolean isAShadow;
public static EntityPlayerMPFake createFake(String username, MinecraftServer server, Vec3 pos, double yaw, double pitch, ResourceKey<Level> dimensionId, GameType gamemode, boolean flying) public static void createFake(String username, MinecraftServer server, Vec3 pos, double yaw, double pitch, ResourceKey<Level> dimensionId, GameType gamemode, boolean flying, Runnable onError)
{ {
//prolly half of that crap is not necessary, but it works //prolly half of that crap is not necessary, but it works
ServerLevel worldIn = server.getLevel(dimensionId); ServerLevel worldIn = server.getLevel(dimensionId);
@@ -55,31 +56,37 @@ public class EntityPlayerMPFake extends ServerPlayer
{ {
if (!CarpetSettings.allowSpawningOfflinePlayers) if (!CarpetSettings.allowSpawningOfflinePlayers)
{ {
return null; onError.run();
return;
} else { } else {
gameprofile = new GameProfile(UUIDUtil.createOfflinePlayerUUID(username), username); gameprofile = new GameProfile(UUIDUtil.createOfflinePlayerUUID(username), username);
} }
} }
if (gameprofile.getProperties().containsKey("textures")) GameProfile finalGP = gameprofile;
{ fetchGameProfile(gameprofile.getName()).thenAccept(p -> {
AtomicReference<GameProfile> result = new AtomicReference<>(); GameProfile current = finalGP;
//SkullBlockEntity.updateGameprofile(gameprofile, result::set); if (p.isPresent())
//gameprofile = result.get(); {
} current = p.get();
EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, gameprofile, false); }
instance.fixStartingPosition = () -> instance.moveTo(pos.x, pos.y, pos.z, (float) yaw, (float) pitch); EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, current, false);
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance, 0); instance.fixStartingPosition = () -> instance.moveTo(pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
instance.teleportTo(worldIn, pos.x, pos.y, pos.z, (float) yaw, (float) pitch); server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance, 0);
instance.setHealth(20.0F); instance.teleportTo(worldIn, pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
instance.unsetRemoved(); instance.setHealth(20.0F);
instance.setMaxUpStep(0.6F); instance.unsetRemoved();
instance.gameMode.changeGameModeForPlayer(gamemode); instance.setMaxUpStep(0.6F);
server.getPlayerList().broadcastAll(new ClientboundRotateHeadPacket(instance, (byte) (instance.yHeadRot * 256 / 360)), dimensionId);//instance.dimension); instance.gameMode.changeGameModeForPlayer(gamemode);
server.getPlayerList().broadcastAll(new ClientboundTeleportEntityPacket(instance), dimensionId);//instance.dimension); server.getPlayerList().broadcastAll(new ClientboundRotateHeadPacket(instance, (byte) (instance.yHeadRot * 256 / 360)), dimensionId);//instance.dimension);
//instance.world.getChunkManager(). updatePosition(instance); server.getPlayerList().broadcastAll(new ClientboundTeleportEntityPacket(instance), dimensionId);//instance.dimension);
instance.entityData.set(DATA_PLAYER_MODE_CUSTOMISATION, (byte) 0x7f); // show all model layers (incl. capes) //instance.world.getChunkManager(). updatePosition(instance);
instance.getAbilities().flying = flying; instance.entityData.set(DATA_PLAYER_MODE_CUSTOMISATION, (byte) 0x7f); // show all model layers (incl. capes)
return instance; instance.getAbilities().flying = flying;
});
}
private static CompletableFuture<Optional<GameProfile>> fetchGameProfile(final String name) {
return SkullBlockEntity.fetchGameProfile(name);
} }
public static EntityPlayerMPFake createShadow(MinecraftServer server, ServerPlayer player) public static EntityPlayerMPFake createShadow(MinecraftServer server, ServerPlayer player)
+3
View File
@@ -10,8 +10,11 @@ accessible class net/minecraft/server/MinecraftServer$ReloadableResources
accessible class net/minecraft/world/level/biome/Biome$ClimateSettings accessible class net/minecraft/world/level/biome/Biome$ClimateSettings
accessible class net/minecraft/world/level/block/entity/SculkSensorBlockEntity$VibrationUser accessible class net/minecraft/world/level/block/entity/SculkSensorBlockEntity$VibrationUser
#TODO fields and methods should be fetched via interfaces unless there is a good reason not to
accessible method net/minecraft/world/level/border/WorldBorder getListeners ()Ljava/util/List; accessible method net/minecraft/world/level/border/WorldBorder getListeners ()Ljava/util/List;
accessible method net/minecraft/server/level/DistanceManager purgeStaleTickets ()V accessible method net/minecraft/server/level/DistanceManager purgeStaleTickets ()V
#cause I don't want to deal with the interfaces until stuff is stable
accessible method net/minecraft/world/level/block/entity/SkullBlockEntity fetchGameProfile (Ljava/lang/String;)Ljava/util/concurrent/CompletableFuture;
accessible field net/minecraft/world/level/block/state/BlockBehaviour UPDATE_SHAPE_ORDER [Lnet/minecraft/core/Direction; accessible field net/minecraft/world/level/block/state/BlockBehaviour UPDATE_SHAPE_ORDER [Lnet/minecraft/core/Direction;