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.IIconRegister;
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
import net.minecraft.client.resources.IResource;
|
import net.minecraft.client.resources.IResource;
|
||||||
|
import net.minecraft.client.resources.IResourceManager;
|
||||||
import net.minecraft.util.IIcon;
|
import net.minecraft.util.IIcon;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.client.event.TextureStitchEvent.Post;
|
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 {
|
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
|
// 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)) {
|
if (Utils.resourceExists(handDrawnLocation)) {
|
||||||
nonGeneratedCounter++;
|
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
|
// generate our own
|
||||||
LeafTextureResource result = new LeafTextureResource(original, getMissingResource());
|
if (!Utils.resourceExists(originalWithDirs)) return getMissingResource();
|
||||||
if (result.data != null) counter++;
|
LeafTextureResource result = new LeafTextureResource(resourceManager.getResource(originalWithDirs));
|
||||||
|
if (result.data != null) {
|
||||||
|
counter++;
|
||||||
return result;
|
return result;
|
||||||
|
} else {
|
||||||
|
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
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import java.awt.Graphics2D;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
@@ -31,23 +30,10 @@ 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";
|
||||||
|
|
||||||
/** Resource to return if generation fails */
|
public LeafTextureResource(IResource resLeaf) {
|
||||||
public IResource fallbackResource;
|
|
||||||
|
|
||||||
public LeafTextureResource(ResourceLocation resLeaf, IResource fallbackResource) {
|
|
||||||
this.fallbackResource = fallbackResource;
|
|
||||||
|
|
||||||
IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
|
|
||||||
try {
|
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
|
// load normal leaf texture
|
||||||
BufferedImage origImage = ImageIO.read(resourceManager.getResource(origResource).getInputStream());
|
BufferedImage origImage = ImageIO.read(resLeaf.getInputStream());
|
||||||
if (origImage.getWidth() != origImage.getHeight()) return;
|
if (origImage.getWidth() != origImage.getHeight()) return;
|
||||||
int size = origImage.getWidth();
|
int size = origImage.getWidth();
|
||||||
|
|
||||||
@@ -78,7 +64,6 @@ public class LeafTextureResource implements IResource {
|
|||||||
data = baos.toByteArray();
|
data = baos.toByteArray();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// stop log spam with GLSL installed
|
// 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()));
|
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() {
|
public InputStream getInputStream() {
|
||||||
return data != null ? new ByteArrayInputStream(data) : fallbackResource.getInputStream();
|
return new ByteArrayInputStream(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMetadata() {
|
public boolean hasMetadata() {
|
||||||
|
|||||||
Reference in New Issue
Block a user