mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-12-02 08:48:00 +01:00
Asynchronously fetch preview textures
java.io.FileNotFoundException: minecraft:skins/preview_${profile.getname()}.png ... Seriously?
This commit is contained in:
parent
d483e460c3
commit
946231f57d
4 changed files with 28 additions and 11 deletions
|
@ -87,7 +87,7 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
|
||||||
private Class<? extends GuiSkins> skinsClass = null;
|
private Class<? extends GuiSkins> skinsClass = null;
|
||||||
|
|
||||||
public static PreviewTextureManager getPreviewTextureManager(GameProfile profile) {
|
public static PreviewTextureManager getPreviewTextureManager(GameProfile profile) {
|
||||||
return new PreviewTextureManager(INSTANCE.getGatewayServer().getPreviewTextures(profile));
|
return new PreviewTextureManager(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private HDSkinManager() {
|
private HDSkinManager() {
|
||||||
|
|
|
@ -19,8 +19,8 @@ public class LocalTexture {
|
||||||
|
|
||||||
private final TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();
|
private final TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();
|
||||||
|
|
||||||
private DynamicTexture local;
|
private volatile DynamicTexture local;
|
||||||
private PreviewTexture remote;
|
private volatile PreviewTexture remote;
|
||||||
|
|
||||||
private ResourceLocation remoteResource;
|
private ResourceLocation remoteResource;
|
||||||
private ResourceLocation localResource;
|
private ResourceLocation localResource;
|
||||||
|
@ -33,7 +33,7 @@ public class LocalTexture {
|
||||||
this.blank = blank;
|
this.blank = blank;
|
||||||
this.type = type;
|
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);
|
remoteResource = new ResourceLocation(file);
|
||||||
textureManager.deleteTexture(remoteResource);
|
textureManager.deleteTexture(remoteResource);
|
||||||
|
@ -76,7 +76,9 @@ public class LocalTexture {
|
||||||
public void setRemote(PreviewTextureManager ptm, SkinAvailableCallback callback) {
|
public void setRemote(PreviewTextureManager ptm, SkinAvailableCallback callback) {
|
||||||
clearRemote();
|
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) {
|
public void setLocal(File file) {
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
package com.voxelmodpack.hdskins;
|
package com.voxelmodpack.hdskins;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
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.renderer.IImageBuffer;
|
||||||
import net.minecraft.client.resources.SkinManager.SkinAvailableCallback;
|
import net.minecraft.client.resources.SkinManager.SkinAvailableCallback;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -19,14 +21,26 @@ import javax.annotation.Nullable;
|
||||||
*/
|
*/
|
||||||
public class PreviewTextureManager {
|
public class PreviewTextureManager {
|
||||||
|
|
||||||
private final Map<Type, MinecraftProfileTexture> textures;
|
private final GameProfile profile;
|
||||||
|
|
||||||
PreviewTextureManager(Map<Type, MinecraftProfileTexture> textures) {
|
private Map<Type, MinecraftProfileTexture> textures = null;
|
||||||
this.textures = textures;
|
|
||||||
|
PreviewTextureManager(GameProfile profile) {
|
||||||
|
this.profile = profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<PreviewTexture> getPreviewTexture(ResourceLocation location, Type type, ResourceLocation def, @Nullable SkinAvailableCallback callback) {
|
||||||
|
return CallableFutures.asyncFailableFuture(() ->
|
||||||
|
loadPreviewTexture(location, type, def, callback)
|
||||||
|
, HDSkinManager.skinUploadExecutor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@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)) {
|
if (!textures.containsKey(type)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +55,7 @@ public class PreviewTextureManager {
|
||||||
|
|
||||||
PreviewTexture skinTexture = new PreviewTexture(texture, def, buffer);
|
PreviewTexture skinTexture = new PreviewTexture(texture, def, buffer);
|
||||||
|
|
||||||
Minecraft.getMinecraft().getTextureManager().loadTexture(location, skinTexture);
|
TextureLoader.loadTexture(location, skinTexture);
|
||||||
|
|
||||||
return skinTexture;
|
return skinTexture;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ public class CallableFutures {
|
||||||
try {
|
try {
|
||||||
ret.complete(call.call());
|
ret.complete(call.call());
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
ret.completeExceptionally(e);
|
ret.completeExceptionally(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue