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");
return 0;
}
Player player = EntityPlayerMPFake.createFake(playerName, source.getServer(), pos, facing.y, facing.x, dimType, mode, flying);
if (player == null)
{
EntityPlayerMPFake.createFake(playerName, source.getServer(), pos, facing.y, facing.x, dimType, mode, flying, () -> {
Messenger.m(source, "rb Player " + playerName + " doesn't exist and cannot spawn in online mode. " +
"Turn the server offline to spawn non-existing players");
return 0;
}
});
return 1;
}
@@ -31,7 +31,8 @@ import net.minecraft.world.phys.Vec3;
import carpet.fakes.ServerPlayerInterface;
import carpet.utils.Messenger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
@SuppressWarnings("EntityConstructor")
public class EntityPlayerMPFake extends ServerPlayer
@@ -39,7 +40,7 @@ public class EntityPlayerMPFake extends ServerPlayer
public Runnable fixStartingPosition = () -> {};
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
ServerLevel worldIn = server.getLevel(dimensionId);
@@ -55,31 +56,37 @@ public class EntityPlayerMPFake extends ServerPlayer
{
if (!CarpetSettings.allowSpawningOfflinePlayers)
{
return null;
onError.run();
return;
} else {
gameprofile = new GameProfile(UUIDUtil.createOfflinePlayerUUID(username), username);
}
}
if (gameprofile.getProperties().containsKey("textures"))
{
AtomicReference<GameProfile> result = new AtomicReference<>();
//SkullBlockEntity.updateGameprofile(gameprofile, result::set);
//gameprofile = result.get();
}
EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, gameprofile, false);
instance.fixStartingPosition = () -> instance.moveTo(pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance, 0);
instance.teleportTo(worldIn, pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
instance.setHealth(20.0F);
instance.unsetRemoved();
instance.setMaxUpStep(0.6F);
instance.gameMode.changeGameModeForPlayer(gamemode);
server.getPlayerList().broadcastAll(new ClientboundRotateHeadPacket(instance, (byte) (instance.yHeadRot * 256 / 360)), dimensionId);//instance.dimension);
server.getPlayerList().broadcastAll(new ClientboundTeleportEntityPacket(instance), dimensionId);//instance.dimension);
//instance.world.getChunkManager(). updatePosition(instance);
instance.entityData.set(DATA_PLAYER_MODE_CUSTOMISATION, (byte) 0x7f); // show all model layers (incl. capes)
instance.getAbilities().flying = flying;
return instance;
GameProfile finalGP = gameprofile;
fetchGameProfile(gameprofile.getName()).thenAccept(p -> {
GameProfile current = finalGP;
if (p.isPresent())
{
current = p.get();
}
EntityPlayerMPFake instance = new EntityPlayerMPFake(server, worldIn, current, false);
instance.fixStartingPosition = () -> instance.moveTo(pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance, 0);
instance.teleportTo(worldIn, pos.x, pos.y, pos.z, (float) yaw, (float) pitch);
instance.setHealth(20.0F);
instance.unsetRemoved();
instance.setMaxUpStep(0.6F);
instance.gameMode.changeGameModeForPlayer(gamemode);
server.getPlayerList().broadcastAll(new ClientboundRotateHeadPacket(instance, (byte) (instance.yHeadRot * 256 / 360)), dimensionId);//instance.dimension);
server.getPlayerList().broadcastAll(new ClientboundTeleportEntityPacket(instance), dimensionId);//instance.dimension);
//instance.world.getChunkManager(). updatePosition(instance);
instance.entityData.set(DATA_PLAYER_MODE_CUSTOMISATION, (byte) 0x7f); // show all model layers (incl. capes)
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)
+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/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/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;