improved resource generation error handling
This commit is contained in:
@@ -74,16 +74,16 @@ public class BetterFoliageClient implements ILeafTextureRecognizer {
|
||||
MinecraftForge.EVENT_BUS.register(leafGenerator);
|
||||
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
|
||||
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
|
||||
public IResource getResource(ResourceLocation var1) throws IOException {
|
||||
return new HalfTextureResource(unwrapResource(var1), false);
|
||||
return new HalfTextureResource(unwrapResource(var1), false, getMissingResource());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -26,9 +26,14 @@ import net.minecraft.util.ResourceLocation;
|
||||
public class HalfTextureResource implements IResource {
|
||||
|
||||
/** Raw PNG data*/
|
||||
protected byte[] data = null;
|
||||
public byte[] data = null;
|
||||
|
||||
public HalfTextureResource(ResourceLocation resource, boolean bottom) {
|
||||
/** Resource to return if generation fails */
|
||||
public IResource fallbackResource;
|
||||
|
||||
public HalfTextureResource(ResourceLocation resource, boolean bottom, IResource fallbackResource) {
|
||||
this.fallbackResource = fallbackResource;
|
||||
|
||||
IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
|
||||
try {
|
||||
// load full texture
|
||||
@@ -53,7 +58,7 @@ public class HalfTextureResource implements IResource {
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() {
|
||||
return data != null ? new ByteArrayInputStream(data) : null;
|
||||
return data != null ? new ByteArrayInputStream(data) : fallbackResource.getInputStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,19 +32,16 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
public class LeafTextureGenerator extends BlockTextureGenerator implements IIconRegister {
|
||||
|
||||
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 */
|
||||
public List<ILeafTextureRecognizer> recognizers = Lists.newLinkedList();
|
||||
|
||||
public IResource getResource(ResourceLocation resourceLocation) throws IOException {
|
||||
LeafTextureResource result = new LeafTextureResource(unwrapResource(resourceLocation));
|
||||
if (result.data != null) {
|
||||
counter++;
|
||||
return result;
|
||||
}
|
||||
return getMissingResource();
|
||||
LeafTextureResource result = new LeafTextureResource(unwrapResource(resourceLocation), getMissingResource());
|
||||
if (result.data != null) counter++;
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Leaf blocks register their textures here. An extra texture will be registered in the atlas
|
||||
|
||||
@@ -31,7 +31,12 @@ public class LeafTextureResource implements IResource {
|
||||
/** Name of the default alpha mask to use */
|
||||
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();
|
||||
try {
|
||||
// load normal leaf texture
|
||||
@@ -97,7 +102,7 @@ public class LeafTextureResource implements IResource {
|
||||
}
|
||||
|
||||
public InputStream getInputStream() {
|
||||
return data != null ? new ByteArrayInputStream(data) : null;
|
||||
return data != null ? new ByteArrayInputStream(data) : fallbackResource.getInputStream();
|
||||
}
|
||||
|
||||
public boolean hasMetadata() {
|
||||
|
||||
Reference in New Issue
Block a user