From 9e707e4af98d66ea054389f9778cef1e91aa7ed3 Mon Sep 17 00:00:00 2001 From: Matthew Messinger Date: Tue, 17 Nov 2015 00:10:21 -0500 Subject: [PATCH] Fix hd skins a bit more --- .../voxelmodpack/hdskins/HDSkinManager.java | 64 +++++++++++++------ .../voxelmodpack/hdskins/gui/GuiSkins.java | 3 +- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/voxelmodpack/hdskins/HDSkinManager.java b/src/main/java/com/voxelmodpack/hdskins/HDSkinManager.java index 3f705fa5..c776c266 100644 --- a/src/main/java/com/voxelmodpack/hdskins/HDSkinManager.java +++ b/src/main/java/com/voxelmodpack/hdskins/HDSkinManager.java @@ -32,6 +32,7 @@ import net.minecraft.client.resources.DefaultPlayerSkin; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StringUtils; +import net.minecraft.world.World; public final class HDSkinManager { private static String gatewayUrl = "skinmanager.voxelmodpack.com"; @@ -79,33 +80,59 @@ public final class HDSkinManager { if (mc.theWorld == null) { return null; } - Collection playersInfo = mc.getNetHandler().func_175106_d(); - String uuid; + return findPlayer(mc, hash); + + } + + private static String findPlayer(Minecraft mc, String hash) { + String uuid = findNetworkPlayer(mc, hash); + if (uuid == null) { + uuid = findWorldPlayers(mc.theWorld, hash); + } + if (uuid == null) { + uuid = findSkullPlayers(hash); + } + return uuid; + } + + private static String findNetworkPlayer(Minecraft mc, String hash) { + Collection playersInfo = mc.getNetHandler().getPlayerInfoMap(); // players for (NetworkPlayerInfo player : playersInfo) { GameProfile profile = player.getGameProfile(); - Map textures = getTexturesForProfile(mc, profile); + Map textures = getTexturesForProfile(profile); storeTexturesForProfile(profile, textures); - uuid = findUUID(profile, textures, hash); + String uuid = findUUID(profile, textures, hash); if (uuid != null) return uuid; } + return null; + } + + private static String findWorldPlayers(World world, String hash) { @SuppressWarnings("unchecked") - List players = mc.theWorld.playerEntities; + List players = world.playerEntities; for (EntityPlayer player : players) { GameProfile profile = player.getGameProfile(); - Map textures = getTexturesForProfile(mc, profile); + Map textures = getTexturesForProfile(profile); storeTexturesForProfile(profile, textures); - uuid = findUUID(profile, textures, hash); + String uuid = findUUID(profile, textures, hash); if (uuid != null) return uuid; } + return null; + } + + private static String findSkullPlayers(String hash) { // skulls for (Entry> e : getSkinsCache().asMap().entrySet()) { GameProfile profile = e.getKey(); + // stupid plugineers.. + if (profile.getId() == null) + continue; Map textures = e.getValue(); storeTexturesForProfile(profile, textures); - uuid = findUUID(profile, textures, hash); + String uuid = findUUID(profile, textures, hash); if (uuid != null) return uuid; } @@ -133,12 +160,13 @@ public final class HDSkinManager { } } - private static Map getTexturesForProfile(Minecraft minecraft, GameProfile profile) { + private static Map getTexturesForProfile(GameProfile profile) { LiteLoaderLogger.debug("Get textures for " + profile.getId(), new Object[0]); Map cached = getCachedTexturesForId(trimUUID(profile.getId())); if (cached != null) { return cached; } + Minecraft minecraft = Minecraft.getMinecraft(); MinecraftSessionService sessionService = minecraft.getSessionService(); Map textures = null; @@ -148,7 +176,8 @@ public final class HDSkinManager { textures = sessionService.getTextures(profile, false); } - if ((textures == null || textures.isEmpty()) && profile.getId().equals(minecraft.getSession().getProfile().getId())) { + if ((textures == null || textures.isEmpty()) + && profile.getId().equals(minecraft.getSession().getProfile().getId())) { textures = sessionService.getTextures(sessionService.fillProfileProperties(profile, false), false); } @@ -201,19 +230,18 @@ public final class HDSkinManager { public static PreviewTexture getPreviewTexture(ResourceLocation skinResource, GameProfile profile) { TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); Object skinTexture = textureManager.getTexture(skinResource); + if (skinTexture == null) { - Map textures = getTexturesForProfile(Minecraft.getMinecraft(), profile); + Map textures = getTexturesForProfile(profile); MinecraftProfileTexture skin = textures.get(Type.SKIN); - if (skin == null) { - throw new RuntimeException("Could not get player skin URL from profile"); + if (skin != null) { + String url = skin.getUrl(); + skinTexture = new PreviewTexture(url, DefaultPlayerSkin.getDefaultSkin(profile.getId()), new ImageBufferDownloadHD()); + textureManager.loadTexture(skinResource, (ITextureObject) skinTexture); } - - String url = skin.getUrl(); - skinTexture = new PreviewTexture(url, DefaultPlayerSkin.getDefaultSkin(profile.getId()), new ImageBufferDownloadHD()); - textureManager.loadTexture(skinResource, (ITextureObject) skinTexture); } - return (PreviewTexture) skinTexture; + } public static void clearSkinCache() { diff --git a/src/main/java/com/voxelmodpack/hdskins/gui/GuiSkins.java b/src/main/java/com/voxelmodpack/hdskins/gui/GuiSkins.java index 206136f3..6d8bbb21 100644 --- a/src/main/java/com/voxelmodpack/hdskins/gui/GuiSkins.java +++ b/src/main/java/com/voxelmodpack/hdskins/gui/GuiSkins.java @@ -642,8 +642,7 @@ public class GuiSkins extends GuiScreen implements IUploadCompleteCallback, IOpe GL11.glEnable(GL11.GL_DEPTH_TEST); } - public void renderPlayerModel(EntityPlayerModel thePlayer, float xPosition, float yPosition, float scale, - @SuppressWarnings("unused") float mouseX, float mouseY, float partialTick) { + public void renderPlayerModel(EntityPlayerModel thePlayer, float xPosition, float yPosition, float scale, float mouseX, float mouseY, float partialTick) { GL11.glEnable(GL.GL_COLOR_MATERIAL); pushMatrix(); translate(xPosition, yPosition, 300.0F);