Skip to content

Commit

Permalink
Replace fake client player with a draggable widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Jul 22, 2024
1 parent f570920 commit f7d6275
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 356 deletions.
268 changes: 0 additions & 268 deletions src/main/java/io/github/gaming32/worldhost/GameProfileRenderer.java

This file was deleted.

65 changes: 65 additions & 0 deletions src/main/java/io/github/gaming32/worldhost/WHPlayerSkin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package io.github.gaming32.worldhost;

import com.mojang.authlib.GameProfile;
import net.minecraft.client.resources.SkinManager;
import net.minecraft.resources.ResourceLocation;


//#if MC >= 1.20.2
import net.minecraft.client.resources.PlayerSkin;
//#else
//$$ import com.mojang.authlib.minecraft.MinecraftProfileTexture;
//$$ import java.util.UUID;
//$$ import java.util.concurrent.CompletableFuture;
//$$ import net.minecraft.client.resources.DefaultPlayerSkin;
//$$ import net.minecraft.core.UUIDUtil;
//#endif

// TODO: Remove in 1.20.2+
public record WHPlayerSkin(
ResourceLocation texture,
ResourceLocation capeTexture,
Model model
) {
//#if MC >= 1.20.2
public static WHPlayerSkin fromPlayerSkin(PlayerSkin skin) {
return new WHPlayerSkin(skin.texture(), skin.capeTexture(), Model.byName(skin.model().id()));
}
//#endif

public static WHPlayerSkin fromSkinManager(SkinManager skinManager, GameProfile profile) {
//#if MC >= 1.20.2
return fromPlayerSkin(skinManager.getInsecureSkin(profile));
//#else
//$$ final var map = skinManager.getInsecureSkinInformation(profile);
//$$ final MinecraftProfileTexture skin = map.get(MinecraftProfileTexture.Type.SKIN);
//$$ final ResourceLocation skinTexture;
//$$ final String skinModel;
//$$ if (skin != null) {
//$$ skinTexture = skinManager.registerTexture(skin, MinecraftProfileTexture.Type.SKIN);
//$$ skinModel = skin.getMetadata("model");
//$$ } else {
//$$ final UUID uuid = UUIDUtil.getOrCreatePlayerUUID(profile);
//$$ skinTexture = DefaultPlayerSkin.getDefaultSkin(uuid);
//$$ skinModel = DefaultPlayerSkin.getSkinModelName(uuid);
//$$ }
//$$ final MinecraftProfileTexture cape = map.get(MinecraftProfileTexture.Type.CAPE);
//$$ return new WHPlayerSkin(
//$$ skinTexture,
//$$ cape != null ? skinTexture.registerTexture(cape, MinecraftProfileTexture.Type.CAPE) : null,
//$$ Model.byName(skinModel)
//$$ );
//#endif
}

public enum Model {
SLIM, WIDE;

public static Model byName(String name) {
return switch (name) {
case "slim" -> SLIM;
case null, default -> WIDE;
};
}
}
}
35 changes: 4 additions & 31 deletions src/main/java/io/github/gaming32/worldhost/WorldHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.multiplayer.resolver.ServerAddress;
import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.ClickEvent;
Expand Down Expand Up @@ -97,15 +96,10 @@
//#if MC >= 1.19.2
import io.github.gaming32.worldhost.mixin.MinecraftAccessor;
//#else
//$$ import com.mojang.authlib.minecraft.MinecraftProfileTexture;
//$$ import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
//$$ import net.minecraft.world.entity.player.Player;
//#endif

//#if MC >= 1.20.2
import net.minecraft.client.resources.PlayerSkin;
//#endif

//#if FABRIC
import dev.isxander.mainmenucredits.MainMenuCredits;
import net.fabricmc.api.ClientModInitializer;
Expand Down Expand Up @@ -579,33 +573,12 @@ public static GameProfileCache getProfileCache() {
return profileCache;
}

public static CompletableFuture<ResourceLocation> getInsecureSkinLocation(GameProfile gameProfile) {
final var skinManager = Minecraft.getInstance().getSkinManager();
//#if MC >= 1.20.2
return skinManager.getOrLoad(gameProfile).thenApply(PlayerSkin::texture);
//#elseif MC >= 1.19.2
//$$ return CompletableFuture.completedFuture(skinManager.getInsecureSkinLocation(gameProfile));
//#else
//$$ final MinecraftProfileTexture texture = skinManager.getInsecureSkinInformation(gameProfile)
//$$ .get(MinecraftProfileTexture.Type.SKIN);
//$$ return CompletableFuture.completedFuture(
//$$ texture != null
//$$ ? skinManager.registerTexture(texture, MinecraftProfileTexture.Type.SKIN)
//$$ : DefaultPlayerSkin.getDefaultSkin(Player.createPlayerUUID(gameProfile))
//$$ );
//#endif
public static WHPlayerSkin getInsecureSkin(GameProfile profile) {
return WHPlayerSkin.fromSkinManager(Minecraft.getInstance().getSkinManager(), profile);
}

public static ResourceLocation getSkinLocationNow(GameProfile gameProfile) {
final ResourceLocation location = getInsecureSkinLocation(gameProfile).getNow(null);
if (location == null) {
//#if MC >= 1.20.2
return DefaultPlayerSkin.get(gameProfile).texture();
//#else
//$$ return DefaultPlayerSkin.getDefaultSkin(gameProfile.getId());
//#endif
}
return location;
public static ResourceLocation getSkinLocationNow(GameProfile profile) {
return getInsecureSkin(profile).texture();
}

public static void getMaybeAsync(GameProfileCache cache, String name, Consumer<Optional<GameProfile>> action) {
Expand Down
Loading

0 comments on commit f7d6275

Please sign in to comment.