diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java b/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java index ccc34157..12719858 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java @@ -87,7 +87,7 @@ public final class HDSkinManager implements IResourceManagerReloadListener { private Class skinsClass = null; public static PreviewTextureManager getPreviewTextureManager(GameProfile profile) { - return new PreviewTextureManager(INSTANCE.getGatewayServer().getPreviewTextures(profile)); + return new PreviewTextureManager(profile); } private HDSkinManager() { diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/LocalTexture.java b/src/hdskins/java/com/voxelmodpack/hdskins/LocalTexture.java index 6b2ee1a7..a44ade96 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/LocalTexture.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/LocalTexture.java @@ -19,8 +19,8 @@ public class LocalTexture { private final TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); - private DynamicTexture local; - private PreviewTexture remote; + private volatile DynamicTexture local; + private volatile PreviewTexture remote; private ResourceLocation remoteResource; private ResourceLocation localResource; @@ -33,7 +33,7 @@ public class LocalTexture { this.blank = blank; this.type = type; - String file = type.name().toLowerCase() + "s/preview_${profile.getName()}.png"; + String file = String.format("%ss/preview_%s.png", type.name().toLowerCase(), profile.getName()); remoteResource = new ResourceLocation(file); textureManager.deleteTexture(remoteResource); @@ -76,7 +76,9 @@ public class LocalTexture { public void setRemote(PreviewTextureManager ptm, SkinAvailableCallback callback) { clearRemote(); - remote = ptm.getPreviewTexture(remoteResource, type, blank.getBlankSkin(type), callback); + ptm.getPreviewTexture(remoteResource, type, blank.getBlankSkin(type), callback).thenAccept(texture -> { + remote = texture; + }); } public void setLocal(File file) { diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/PreviewTextureManager.java b/src/hdskins/java/com/voxelmodpack/hdskins/PreviewTextureManager.java index 4b5ccd8d..e01ee425 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/PreviewTextureManager.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/PreviewTextureManager.java @@ -1,15 +1,17 @@ package com.voxelmodpack.hdskins; import com.google.common.collect.Maps; +import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; +import com.voxelmodpack.hdskins.skins.CallableFutures; -import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IImageBuffer; import net.minecraft.client.resources.SkinManager.SkinAvailableCallback; import net.minecraft.util.ResourceLocation; import java.util.Map; +import java.util.concurrent.CompletableFuture; import javax.annotation.Nullable; @@ -19,14 +21,26 @@ import javax.annotation.Nullable; */ public class PreviewTextureManager { - private final Map textures; + private final GameProfile profile; - PreviewTextureManager(Map textures) { - this.textures = textures; + private Map textures = null; + + PreviewTextureManager(GameProfile profile) { + this.profile = profile; + } + + public CompletableFuture getPreviewTexture(ResourceLocation location, Type type, ResourceLocation def, @Nullable SkinAvailableCallback callback) { + return CallableFutures.asyncFailableFuture(() -> + loadPreviewTexture(location, type, def, callback) + , HDSkinManager.skinUploadExecutor); } @Nullable - public PreviewTexture getPreviewTexture(ResourceLocation location, Type type, ResourceLocation def, @Nullable SkinAvailableCallback callback) { + private PreviewTexture loadPreviewTexture(ResourceLocation location, Type type, ResourceLocation def, @Nullable SkinAvailableCallback callback) { + if (textures == null) { + textures = HDSkinManager.INSTANCE.getGatewayServer().getPreviewTextures(profile); + } + if (!textures.containsKey(type)) { return null; } @@ -41,7 +55,7 @@ public class PreviewTextureManager { PreviewTexture skinTexture = new PreviewTexture(texture, def, buffer); - Minecraft.getMinecraft().getTextureManager().loadTexture(location, skinTexture); + TextureLoader.loadTexture(location, skinTexture); return skinTexture; } diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/skins/CallableFutures.java b/src/hdskins/java/com/voxelmodpack/hdskins/skins/CallableFutures.java index 39a93aa7..0a529cd7 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/skins/CallableFutures.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/skins/CallableFutures.java @@ -12,6 +12,7 @@ public class CallableFutures { try { ret.complete(call.call()); } catch (Throwable e) { + e.printStackTrace(); ret.completeExceptionally(e); } });