mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 16:24: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;
|
package com.voxelmodpack.hdskins.util;
|
||||||
|
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||||
|
|
||||||
import org.apache.commons.lang3.reflect.FieldUtils;
|
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.awt.image.DataBufferInt;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -26,4 +31,16 @@ public class ProfileTextureUtil {
|
||||||
throw new RuntimeException("Unable to write metadata field", e);
|
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;
|
package com.minelittlepony.pony.data;
|
||||||
|
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.minelittlepony.MineLittlePony;
|
import com.minelittlepony.MineLittlePony;
|
||||||
import com.minelittlepony.ducks.IRenderPony;
|
import com.minelittlepony.ducks.IRenderPony;
|
||||||
|
import com.voxelmodpack.hdskins.resources.texture.DynamicTextureImage;
|
||||||
import com.voxelmodpack.hdskins.resources.texture.IBufferedTexture;
|
import com.voxelmodpack.hdskins.resources.texture.IBufferedTexture;
|
||||||
|
import com.voxelmodpack.hdskins.util.ProfileTextureUtil;
|
||||||
|
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
@ -52,16 +53,25 @@ public class Pony implements IPony {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferedImage skinImage = Preconditions.checkNotNull(getBufferedImage(resource), "bufferedImage: " + resource);
|
BufferedImage ponyTexture = getBufferedImage(resource);
|
||||||
return this.checkSkin(skinImage);
|
|
||||||
|
if (ponyTexture == null) {
|
||||||
|
ponyTexture = ProfileTextureUtil.getDynamicBufferedImage(16, 16, TextureUtil.MISSING_TEXTURE);
|
||||||
|
|
||||||
|
Minecraft.getMinecraft().getTextureManager().loadTexture(resource, new DynamicTextureImage(ponyTexture));
|
||||||
|
}
|
||||||
|
|
||||||
|
return checkSkin(ponyTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private IPonyData checkPonyMeta(ResourceLocation resource) {
|
private IPonyData checkPonyMeta(ResourceLocation resource) {
|
||||||
try {
|
try {
|
||||||
IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource);
|
IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource);
|
||||||
|
|
||||||
if (res.hasMetadata()) {
|
if (res.hasMetadata()) {
|
||||||
PonyData data = res.getMetadata(PonyDataSerialiser.NAME);
|
PonyData data = res.getMetadata(PonyDataSerialiser.NAME);
|
||||||
|
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -71,6 +81,7 @@ public class Pony implements IPony {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
MineLittlePony.logger.warn("Unable to read {} metadata", resource, e);
|
MineLittlePony.logger.warn("Unable to read {} metadata", resource, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue