From 2a996961c3ee7543aaadad8df3ffb40b11dd0b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=96=E5=AD=90?= Date: Sun, 29 Sep 2024 17:58:51 +0800 Subject: [PATCH] Compatible with ID-based dynamic resources When there is a dynamic resource address, the client crashes directly. This is clearly not what players want to see. --- .../java/glowredman/txloader/TXResourcePack.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/glowredman/txloader/TXResourcePack.java b/src/main/java/glowredman/txloader/TXResourcePack.java index 1b64caa..463799a 100644 --- a/src/main/java/glowredman/txloader/TXResourcePack.java +++ b/src/main/java/glowredman/txloader/TXResourcePack.java @@ -8,6 +8,7 @@ import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.InvalidPathException; import java.util.HashSet; import java.util.Set; @@ -37,7 +38,18 @@ public InputStream getInputStream(ResourceLocation rl) throws IOException { @Override public boolean resourceExists(ResourceLocation rl) { - return Files.exists(this.getResourcePath(rl)); + try { + return Files.exists(this.getResourcePath(rl)); + } catch (InvalidPathException e) { + /* + * Some mods load resources dynamically by id. + * (example: java.nio.file.InvalidPathException: Illegal char <:> at index 30: textures/blocks/bw_(extrautils:golden_bag)_n.png.mcmeta) + */ + if(rl.getResourcePath().contains(":")) { + return false; + } + throw e; + } } @SuppressWarnings("rawtypes")