private void loadTexture(GameProfile profile, final Type type, final SkinAvailableCallback callback) { if (profile.getId() != null) { Map<Type, MinecraftProfileTexture> data = getProfileData(profile); final MinecraftProfileTexture texture = data.get(type); String skinDir = type.toString().toLowerCase() + "s/"; final ResourceLocation skin = new ResourceLocation("hdskins", skinDir + texture.getHash()); File file2 = new File(LiteLoader.getAssetsDirectory(), "hd/" + skinDir + texture.getHash().substring(0, 2) + "/" + texture.getHash()); final IImageBuffer imagebufferdownload = type == Type.SKIN ? new ImageBufferDownloadHD() : null; ITextureObject texObject = new ThreadDownloadImageETag(file2, texture.getUrl(), DefaultPlayerSkin.getDefaultSkinLegacy(), new IImageBuffer() { @Nonnull @Override public BufferedImage parseUserSkin(@Nonnull BufferedImage image) { BufferedImage image1 = image; if (imagebufferdownload != null) { image1 = imagebufferdownload.parseUserSkin(image); } return image1 == null ? image : image1; } @Override public void skinAvailable() { if (imagebufferdownload != null) { imagebufferdownload.skinAvailable(); } callback.skinAvailable(type, skin, texture); } }); // schedule texture loading on the main thread. TextureLoader.loadTexture(skin, texObject); } }
@Nullable public static PreviewTexture getPreviewTexture(ResourceLocation skinResource, GameProfile profile, Type type, ResourceLocation def, @Nullable final SkinAvailableCallback callback) { TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); MinecraftProfileTexture url = INSTANCE.getGatewayServer().getPreviewTexture(type, profile).orElse(null); if (url == null) return null; IImageBuffer buffer = new ImageBufferDownloadHD(); PreviewTexture skinTexture = new PreviewTexture(url.getUrl(), def, type == Type.SKIN ? new IImageBuffer() { @Override @Nullable public BufferedImage parseUserSkin(BufferedImage image) { return buffer.parseUserSkin(image); } @Override public void skinAvailable() { if (callback != null) { callback.skinAvailable(type, skinResource, new MinecraftProfileTexture(url.getUrl(), Maps.newHashMap())); } } } : null); textureManager.loadTexture(skinResource, skinTexture); return skinTexture; }
public boolean addUUID(String uuid, SkinAvailableCallback callback) { if (callbacks.size() < 100 && !running) { callbacks.put(uuid, callback); return true; } else { return false; } }