improved resource generation error handling

This commit is contained in:
octarine-noise
2014-07-06 20:10:05 +02:00
parent 7a02179481
commit 25b1d76c9e
4 changed files with 23 additions and 16 deletions

View File

@@ -74,16 +74,16 @@ public class BetterFoliageClient implements ILeafTextureRecognizer {
MinecraftForge.EVENT_BUS.register(leafGenerator); MinecraftForge.EVENT_BUS.register(leafGenerator);
leafGenerator.recognizers.add(new BetterFoliageClient()); leafGenerator.recognizers.add(new BetterFoliageClient());
MinecraftForge.EVENT_BUS.register(new BlockTextureGenerator("bf_reed_bottom", null) { MinecraftForge.EVENT_BUS.register(new BlockTextureGenerator("bf_reed_bottom", new ResourceLocation("betterfoliage", "textures/blocks/missing_leaf.png")) {
@Override @Override
public IResource getResource(ResourceLocation var1) throws IOException { public IResource getResource(ResourceLocation var1) throws IOException {
return new HalfTextureResource(unwrapResource(var1), true); return new HalfTextureResource(unwrapResource(var1), true, getMissingResource());
} }
}); });
MinecraftForge.EVENT_BUS.register(new BlockTextureGenerator("bf_reed_top", null) { MinecraftForge.EVENT_BUS.register(new BlockTextureGenerator("bf_reed_top", new ResourceLocation("betterfoliage", "textures/blocks/missing_leaf.png")) {
@Override @Override
public IResource getResource(ResourceLocation var1) throws IOException { public IResource getResource(ResourceLocation var1) throws IOException {
return new HalfTextureResource(unwrapResource(var1), false); return new HalfTextureResource(unwrapResource(var1), false, getMissingResource());
} }
}); });

View File

@@ -26,9 +26,14 @@ import net.minecraft.util.ResourceLocation;
public class HalfTextureResource implements IResource { public class HalfTextureResource implements IResource {
/** Raw PNG data*/ /** Raw PNG data*/
protected byte[] data = null; public byte[] data = null;
/** Resource to return if generation fails */
public IResource fallbackResource;
public HalfTextureResource(ResourceLocation resource, boolean bottom, IResource fallbackResource) {
this.fallbackResource = fallbackResource;
public HalfTextureResource(ResourceLocation resource, boolean bottom) {
IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager(); IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
try { try {
// load full texture // load full texture
@@ -53,7 +58,7 @@ public class HalfTextureResource implements IResource {
@Override @Override
public InputStream getInputStream() { public InputStream getInputStream() {
return data != null ? new ByteArrayInputStream(data) : null; return data != null ? new ByteArrayInputStream(data) : fallbackResource.getInputStream();
} }
@Override @Override

View File

@@ -32,20 +32,17 @@ import cpw.mods.fml.relauncher.SideOnly;
public class LeafTextureGenerator extends BlockTextureGenerator implements IIconRegister { public class LeafTextureGenerator extends BlockTextureGenerator implements IIconRegister {
public LeafTextureGenerator() { public LeafTextureGenerator() {
super("bf_leaves_autogen", new ResourceLocation("betterfoliage", "textures/blocks/missingleaf.png")); super("bf_leaves_autogen", new ResourceLocation("betterfoliage", "textures/blocks/missing_leaf.png"));
} }
/** List of helpers which can identify leaf textures loaded by alternate means */ /** List of helpers which can identify leaf textures loaded by alternate means */
public List<ILeafTextureRecognizer> recognizers = Lists.newLinkedList(); public List<ILeafTextureRecognizer> recognizers = Lists.newLinkedList();
public IResource getResource(ResourceLocation resourceLocation) throws IOException { public IResource getResource(ResourceLocation resourceLocation) throws IOException {
LeafTextureResource result = new LeafTextureResource(unwrapResource(resourceLocation)); LeafTextureResource result = new LeafTextureResource(unwrapResource(resourceLocation), getMissingResource());
if (result.data != null) { if (result.data != null) counter++;
counter++;
return result; return result;
} }
return getMissingResource();
}
/** Leaf blocks register their textures here. An extra texture will be registered in the atlas /** Leaf blocks register their textures here. An extra texture will be registered in the atlas
* for each, with the resource domain of this generator. * for each, with the resource domain of this generator.

View File

@@ -31,7 +31,12 @@ public class LeafTextureResource implements IResource {
/** Name of the default alpha mask to use */ /** Name of the default alpha mask to use */
public static String defaultMask = "rough"; public static String defaultMask = "rough";
public LeafTextureResource(ResourceLocation resLeaf) { /** Resource to return if generation fails */
public IResource fallbackResource;
public LeafTextureResource(ResourceLocation resLeaf, IResource fallbackResource) {
this.fallbackResource = fallbackResource;
IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager(); IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
try { try {
// load normal leaf texture // load normal leaf texture
@@ -97,7 +102,7 @@ public class LeafTextureResource implements IResource {
} }
public InputStream getInputStream() { public InputStream getInputStream() {
return data != null ? new ByteArrayInputStream(data) : null; return data != null ? new ByteArrayInputStream(data) : fallbackResource.getInputStream();
} }
public boolean hasMetadata() { public boolean hasMetadata() {