Asynchronous fetch preview textures

This commit is contained in:
Sollace 2018-07-26 16:00:33 +02:00
parent b12567b033
commit 1ea7ed0c6b
3 changed files with 23 additions and 6 deletions

View file

@ -88,7 +88,7 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
private Class<? extends GuiSkins> skinsClass = null;
public static PreviewTextureManager getPreviewTextureManager(GameProfile profile) {
return new PreviewTextureManager(INSTANCE.getGatewayServer().getPreviewTextures(profile));
return new PreviewTextureManager(profile);
}
private HDSkinManager() {

View file

@ -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) {

View file

@ -1,8 +1,10 @@
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;
@ -10,6 +12,7 @@ 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 +22,26 @@ import javax.annotation.Nullable;
*/
public class PreviewTextureManager {
private final Map<Type, MinecraftProfileTexture> textures;
private final GameProfile profile;
PreviewTextureManager(Map<Type, MinecraftProfileTexture> textures) {
this.textures = textures;
private Map<Type, MinecraftProfileTexture> textures = null;
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
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;
}