diff --git a/src/main/java/net/coderbot/iris/texture/pbr/PBRType.java b/src/main/java/net/coderbot/iris/texture/pbr/PBRType.java index ec5d3fb2e..633f109b7 100644 --- a/src/main/java/net/coderbot/iris/texture/pbr/PBRType.java +++ b/src/main/java/net/coderbot/iris/texture/pbr/PBRType.java @@ -4,6 +4,9 @@ import net.minecraft.util.ResourceLocation; import org.apache.commons.io.FilenameUtils; import org.jetbrains.annotations.Nullable; +import java.net.URI; +import java.net.URISyntaxException; + public enum PBRType { NORMAL("_n", 0x7F7FFFFF), SPECULAR("_s", 0x00000000); @@ -26,17 +29,37 @@ public enum PBRType { return defaultValue; } - public ResourceLocation appendToFileLocation(ResourceLocation location) { - String path = location.getResourcePath(); - String newPath; - int extensionIndex = FilenameUtils.indexOfExtension(path); - if (extensionIndex != -1) { - newPath = path.substring(0, extensionIndex) + suffix + path.substring(extensionIndex); - } else { - newPath = path + suffix; - } - return new ResourceLocation(location.getResourceDomain(), newPath); - } + public ResourceLocation appendToFileLocation(ResourceLocation location) { + String domain = location.getResourceDomain(); + String path = location.getResourcePath(); + String newPath; + + try { + URI uri = new URI(null, null, path, null); + String cleanPath = uri.getPath(); + + int extensionIndex = FilenameUtils.indexOfExtension(cleanPath); + if (extensionIndex != -1) { + newPath = cleanPath.substring(0, extensionIndex) + suffix + cleanPath.substring(extensionIndex); + } else { + newPath = cleanPath + suffix; + } + + URI newUri = new URI(null, null, newPath, null); + newPath = newUri.getPath(); + + } catch (URISyntaxException e) { + String fallback = path.replace(':', '/'); + int extensionIndex = FilenameUtils.indexOfExtension(fallback); + if (extensionIndex != -1) { + newPath = fallback.substring(0, extensionIndex) + suffix + fallback.substring(extensionIndex); + } else { + newPath = fallback + suffix; + } + } + + return new ResourceLocation(domain, newPath); + } /** * Returns the PBR type corresponding to the suffix of the given file location. diff --git a/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java b/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java index 6c3f8c9d9..86e1370ce 100644 --- a/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java +++ b/src/main/java/net/coderbot/iris/texture/pbr/loader/AtlasPBRLoader.java @@ -103,7 +103,11 @@ public class AtlasPBRLoader implements PBRTextureLoader { NativeImage nativeImage = NativeImage.read(resource.getInputStream()); AnimationMetadataSection animationMetadata = (AnimationMetadataSection) resource.getMetadata("animation"); if (animationMetadata == null) { - animationMetadata = new AnimationMetadataSection(Lists.newArrayList(), -1, -1, -1); + final IResource resourceOriginal = resourceManager.getResource(imageLocation); + animationMetadata = (AnimationMetadataSection) resourceOriginal.getMetadata("animation"); + if (animationMetadata == null) { + animationMetadata = new AnimationMetadataSection(Lists.newArrayList(), -1, -1, -1); + } } final Pair frameSize = this.getFrameSize(nativeImage.getWidth(), nativeImage.getHeight(), animationMetadata);