slightly more robust leaf texture generation
This commit is contained in:
@@ -14,6 +14,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent.Post;
|
||||
@@ -39,19 +40,31 @@ public class LeafTextureGenerator extends BlockTextureGenerator implements IIcon
|
||||
}
|
||||
|
||||
public IResource getResource(ResourceLocation resourceLocation) throws IOException {
|
||||
ResourceLocation original = unwrapResource(resourceLocation);
|
||||
IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
|
||||
ResourceLocation originalNoDirs = unwrapResource(resourceLocation);
|
||||
ResourceLocation originalWithDirs = new ResourceLocation(originalNoDirs.getResourceDomain(), "textures/blocks/" + originalNoDirs.getResourcePath());
|
||||
|
||||
// check for provided texture
|
||||
ResourceLocation handDrawnLocation = new ResourceLocation(nonGeneratedDomain, String.format("textures/blocks/%s/%s", original.getResourceDomain(), original.getResourcePath()));
|
||||
ResourceLocation handDrawnLocation = new ResourceLocation(nonGeneratedDomain, String.format("textures/blocks/%s/%s", originalNoDirs.getResourceDomain(), originalNoDirs.getResourcePath()));
|
||||
if (Utils.resourceExists(handDrawnLocation)) {
|
||||
nonGeneratedCounter++;
|
||||
return Minecraft.getMinecraft().getResourceManager().getResource(handDrawnLocation);
|
||||
return resourceManager.getResource(handDrawnLocation);
|
||||
}
|
||||
|
||||
// Don't alter ShaderMod normal and specular maps
|
||||
if (originalWithDirs.getResourcePath().toLowerCase().endsWith("_n.png") || originalWithDirs.getResourcePath().toLowerCase().endsWith("_s.png")) {
|
||||
resourceManager.getResource(originalWithDirs);
|
||||
}
|
||||
|
||||
// generate our own
|
||||
LeafTextureResource result = new LeafTextureResource(original, getMissingResource());
|
||||
if (result.data != null) counter++;
|
||||
return result;
|
||||
if (!Utils.resourceExists(originalWithDirs)) return getMissingResource();
|
||||
LeafTextureResource result = new LeafTextureResource(resourceManager.getResource(originalWithDirs));
|
||||
if (result.data != null) {
|
||||
counter++;
|
||||
return result;
|
||||
} else {
|
||||
return getMissingResource();
|
||||
}
|
||||
}
|
||||
|
||||
/** Leaf blocks register their textures here. An extra texture will be registered in the atlas
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
@@ -31,23 +30,10 @@ public class LeafTextureResource implements IResource {
|
||||
/** Name of the default alpha mask to use */
|
||||
public static String defaultMask = "rough";
|
||||
|
||||
/** Resource to return if generation fails */
|
||||
public IResource fallbackResource;
|
||||
|
||||
public LeafTextureResource(ResourceLocation resLeaf, IResource fallbackResource) {
|
||||
this.fallbackResource = fallbackResource;
|
||||
|
||||
IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
|
||||
public LeafTextureResource(IResource resLeaf) {
|
||||
try {
|
||||
ResourceLocation origResource = new ResourceLocation(resLeaf.getResourceDomain(), "textures/blocks/" + resLeaf.getResourcePath());
|
||||
if (origResource.getResourcePath().toLowerCase().endsWith("_n.png") || origResource.getResourcePath().toLowerCase().endsWith("_s.png")) {
|
||||
// Don't alter ShaderMod normal and specular maps
|
||||
fallbackResource = resourceManager.getResource(origResource);
|
||||
return;
|
||||
}
|
||||
|
||||
// load normal leaf texture
|
||||
BufferedImage origImage = ImageIO.read(resourceManager.getResource(origResource).getInputStream());
|
||||
BufferedImage origImage = ImageIO.read(resLeaf.getInputStream());
|
||||
if (origImage.getWidth() != origImage.getHeight()) return;
|
||||
int size = origImage.getWidth();
|
||||
|
||||
@@ -78,7 +64,6 @@ public class LeafTextureResource implements IResource {
|
||||
data = baos.toByteArray();
|
||||
} catch (Exception e) {
|
||||
// stop log spam with GLSL installed
|
||||
if (e instanceof FileNotFoundException) return;
|
||||
BetterFoliage.log.info(String.format("Could not create leaf texture: %s, exception: %s", resLeaf.toString(), e.getClass().getSimpleName()));
|
||||
}
|
||||
}
|
||||
@@ -108,7 +93,7 @@ public class LeafTextureResource implements IResource {
|
||||
}
|
||||
|
||||
public InputStream getInputStream() {
|
||||
return data != null ? new ByteArrayInputStream(data) : fallbackResource.getInputStream();
|
||||
return new ByteArrayInputStream(data);
|
||||
}
|
||||
|
||||
public boolean hasMetadata() {
|
||||
|
||||
Reference in New Issue
Block a user