Fix skulls causing Pony to load before the texture is loaded.

This commit is contained in:
Matthew Messinger 2018-08-26 16:35:15 -04:00
parent d9ddd3f842
commit f54e54da40
7 changed files with 31 additions and 27 deletions

View file

@ -4,7 +4,7 @@ import net.minecraft.client.renderer.texture.DynamicTexture;
import java.awt.image.BufferedImage;
public class DynamicTextureImage extends DynamicTexture {
public class DynamicTextureImage extends DynamicTexture implements IBufferedTexture {
private BufferedImage image;
@ -13,7 +13,8 @@ public class DynamicTextureImage extends DynamicTexture {
this.image = bufferedImage;
}
public BufferedImage getImage() {
@Override
public BufferedImage getBufferedImage() {
return image;
}

View file

@ -57,7 +57,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
public final class HDSkinManager implements IResourceManagerReloadListener {
@ -215,9 +214,6 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
skins.invalidateAll();
reloadSkins();
clearListeners = clearListeners.stream()
.filter(this::onSkinCacheCleared)
.collect(Collectors.toList());
}
private void clearNetworkSkin(NetworkPlayerInfo player) {
@ -258,6 +254,7 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
if (playClient != null) {
playClient.getPlayerInfoMap().forEach(this::clearNetworkSkin);
}
clearListeners.removeIf(this::onSkinCacheCleared);
}
public void parseSkin(Type type, ResourceLocation resource, MinecraftProfileTexture texture) {

View file

@ -0,0 +1,10 @@
package com.voxelmodpack.hdskins;
import java.awt.image.BufferedImage;
import javax.annotation.Nullable;
public interface IBufferedTexture {
@Nullable
BufferedImage getBufferedImage();
}

View file

@ -30,7 +30,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.imageio.ImageIO;
public class ThreadDownloadImageETag extends SimpleTexture {
public class ThreadDownloadImageETag extends SimpleTexture implements IBufferedTexture {
private static final Logger LOGGER = LogManager.getLogger();
private static final AtomicInteger THREAD_ID = new AtomicInteger(0);
@ -84,6 +84,7 @@ public class ThreadDownloadImageETag extends SimpleTexture {
}
}
@Override
@Nullable
public BufferedImage getBufferedImage() {
return bufferedImage;

View file

@ -1,14 +1,16 @@
package com.minelittlepony.mixin;
import java.awt.image.BufferedImage;
import com.voxelmodpack.hdskins.IBufferedTexture;
import net.minecraft.client.renderer.ThreadDownloadImageData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import net.minecraft.client.renderer.ThreadDownloadImageData;
import java.awt.image.BufferedImage;
@Mixin(ThreadDownloadImageData.class)
public interface MixinThreadDownloadImageData {
public interface MixinThreadDownloadImageData extends IBufferedTexture {
@Accessor("bufferedImage")
@Override
BufferedImage getBufferedImage();
}

View file

@ -2,9 +2,7 @@ package com.minelittlepony.pony.data;
import com.google.common.base.MoreObjects;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.mixin.MixinThreadDownloadImageData;
import com.voxelmodpack.hdskins.DynamicTextureImage;
import com.voxelmodpack.hdskins.ThreadDownloadImageETag;
import com.voxelmodpack.hdskins.IBufferedTexture;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.ITextureObject;
@ -69,7 +67,7 @@ public class Pony {
}
@Nullable
private BufferedImage getBufferedImage(@Nonnull ResourceLocation resource) {
public static BufferedImage getBufferedImage(@Nonnull ResourceLocation resource) {
try {
IResource skin = Minecraft.getMinecraft().getResourceManager().getResource(resource);
BufferedImage skinImage = TextureUtil.readBufferedImage(skin.getInputStream());
@ -78,22 +76,16 @@ public class Pony {
return skinImage;
} catch (IOException ignored) { }
try {
ITextureObject texture = Minecraft.getMinecraft().getTextureManager().getTexture(resource);
if (texture instanceof MixinThreadDownloadImageData) {
return ((MixinThreadDownloadImageData) texture).getBufferedImage();
} else if (texture instanceof ThreadDownloadImageETag) {
return ((ThreadDownloadImageETag) texture).getBufferedImage();
} else if (texture instanceof DynamicTextureImage) {
return ((DynamicTextureImage) texture).getImage();
if (texture instanceof IBufferedTexture) {
return ((IBufferedTexture) texture).getBufferedImage();
}
} catch (Exception ignored) { }
return null;
}
private IPonyData checkSkin(BufferedImage bufferedimage) {
private IPonyData checkSkin(@Nullable BufferedImage bufferedimage) {
if (bufferedimage == null) return new PonyData();
MineLittlePony.logger.debug("\tStart skin check for pony #{} with image {}.", ponyId, bufferedimage);
return PonyData.parse(bufferedimage);

View file

@ -2,6 +2,7 @@ package com.minelittlepony.render.skull;
import com.minelittlepony.PonyConfig;
import com.minelittlepony.model.components.ModelDeadMau5Ears;
import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.pony.data.PonyLevel;
import com.minelittlepony.render.PonySkull;
import com.minelittlepony.render.RenderPony;
@ -41,7 +42,7 @@ public class PlayerSkullRenderer extends PonySkull {
deadMau5.setVisible("deadmau5".equals(profile.getName()));
ResourceLocation skin = HDSkinManager.INSTANCE.getTextures(profile).get(MinecraftProfileTexture.Type.SKIN);
if (skin != null) {
if (skin != null && Pony.getBufferedImage(skin) != null) {
return skin;
}