improved resource generation error handling
This commit is contained in:
@@ -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