mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 08:14:23 +01:00
Fixed crash due to missing textures
This commit is contained in:
parent
a4216312be
commit
972a49c024
2 changed files with 31 additions and 3 deletions
|
@ -1,8 +1,13 @@
|
|||
package com.voxelmodpack.hdskins.util;
|
||||
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
|
||||
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -26,4 +31,16 @@ public class ProfileTextureUtil {
|
|||
throw new RuntimeException("Unable to write metadata field", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static BufferedImage getDynamicBufferedImage(int width, int height, DynamicTexture texture) {
|
||||
BufferedImage image = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
final int[] src = texture.getTextureData();
|
||||
|
||||
final int[] dst = ((DataBufferInt)image.getRaster().getDataBuffer()).getData();
|
||||
|
||||
System.arraycopy(src, 0, dst, 0, src.length);
|
||||
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package com.minelittlepony.pony.data;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.minelittlepony.MineLittlePony;
|
||||
import com.minelittlepony.ducks.IRenderPony;
|
||||
import com.voxelmodpack.hdskins.resources.texture.DynamicTextureImage;
|
||||
import com.voxelmodpack.hdskins.resources.texture.IBufferedTexture;
|
||||
import com.voxelmodpack.hdskins.util.ProfileTextureUtil;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -52,16 +53,25 @@ public class Pony implements IPony {
|
|||
return data;
|
||||
}
|
||||
|
||||
BufferedImage skinImage = Preconditions.checkNotNull(getBufferedImage(resource), "bufferedImage: " + resource);
|
||||
return this.checkSkin(skinImage);
|
||||
BufferedImage ponyTexture = getBufferedImage(resource);
|
||||
|
||||
if (ponyTexture == null) {
|
||||
ponyTexture = ProfileTextureUtil.getDynamicBufferedImage(16, 16, TextureUtil.MISSING_TEXTURE);
|
||||
|
||||
Minecraft.getMinecraft().getTextureManager().loadTexture(resource, new DynamicTextureImage(ponyTexture));
|
||||
}
|
||||
|
||||
return checkSkin(ponyTexture);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private IPonyData checkPonyMeta(ResourceLocation resource) {
|
||||
try {
|
||||
IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource);
|
||||
|
||||
if (res.hasMetadata()) {
|
||||
PonyData data = res.getMetadata(PonyDataSerialiser.NAME);
|
||||
|
||||
if (data != null) {
|
||||
return data;
|
||||
}
|
||||
|
@ -71,6 +81,7 @@ public class Pony implements IPony {
|
|||
} catch (IOException e) {
|
||||
MineLittlePony.logger.warn("Unable to read {} metadata", resource, e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue