diff options
author | SHsuperCM <shsupercm@gmail.com> | 2021-09-27 10:36:51 +0300 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2021-09-27 10:36:51 +0300 |
commit | 4e0a4605c51cb523a367daf0549958d37feeb133 (patch) | |
tree | 55432e4b93787a23804444342cefcd81ab238f05 /src/main | |
parent | bf9ac15fa28e5c8eac6fb3e3ea3c6ca187b3e1d2 (diff) | |
download | CITResewn-4e0a4605c51cb523a367daf0549958d37feeb133.tar.gz CITResewn-4e0a4605c51cb523a367daf0549958d37feeb133.tar.bz2 CITResewn-4e0a4605c51cb523a367daf0549958d37feeb133.zip |
Fixed some issues with global properties parsing
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java | 42 | ||||
-rw-r--r-- | src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java | 36 |
2 files changed, 42 insertions, 36 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java index ef4842e..92faec0 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java @@ -1,15 +1,9 @@ package shcm.shsupercm.fabric.citresewn.pack; import net.minecraft.resource.ResourcePack; -import net.minecraft.util.Identifier; -import shcm.shsupercm.fabric.citresewn.CITResewn; -import shcm.shsupercm.fabric.citresewn.ex.CITParseException; import shcm.shsupercm.fabric.citresewn.pack.cits.CIT; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Locale; -import java.util.Properties; +import java.util.*; public class CITPack { public final ResourcePack resourcePack; @@ -24,22 +18,26 @@ public class CITPack { this.resourcePack = resourcePack; } - public void loadProperties(Properties properties) { - method = CITPack.EnchantmentMergeMethod.valueOf(properties.getProperty("method", "average").toUpperCase(Locale.ENGLISH)); + public void loadGlobalProperties(Properties properties) throws Exception { try { - cap = Integer.parseInt(properties.getProperty("cap", "8")); - } catch (NumberFormatException e) { - CITResewn.logErrorLoading(new CITParseException(resourcePack, new Identifier("cit.properties"), "cap is not a whole number").getMessage()); - } - try { - fade = Float.parseFloat(properties.getProperty("fade", "0.5")); - } catch (NumberFormatException e) { - CITResewn.logErrorLoading(new CITParseException(resourcePack, new Identifier("cit.properties"), "fade is not a number").getMessage()); - } - switch (properties.getProperty("useGlint", "true").toLowerCase(Locale.ENGLISH)) { - case "true" -> useGlint = true; - case "false" -> useGlint = false; - default -> CITResewn.logErrorLoading(new CITParseException(resourcePack, new Identifier("cit.properties"), "useGlint is not a boolean").getMessage()); + this.method = CITPack.EnchantmentMergeMethod.valueOf(properties.getProperty("method", "average").toUpperCase(Locale.ENGLISH)); + this.cap = Integer.parseInt(properties.getProperty("cap", "8")); + if (this.cap < 0) + throw new Exception("cap cannot be negative"); + this.fade = Float.parseFloat(properties.getProperty("fade", "0.5")); + if (this.fade < 0f) + throw new Exception("fade cannot be negative"); + this.useGlint = switch (properties.getProperty("useGlint", "true").toLowerCase(Locale.ENGLISH)) { + case "true" -> true; + case "false" -> false; + default -> throw new Exception("useGlint is not a boolean"); + }; + } catch (Exception e) { + this.method = EnchantmentMergeMethod.AVERAGE; + this.cap = 8; + this.fade = 0.5f; + this.useGlint = true; + throw e; } } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java index 7313301..03ea512 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java @@ -5,9 +5,8 @@ import net.fabricmc.loader.api.FabricLoader; import net.minecraft.resource.ResourcePack; import net.minecraft.resource.ResourceType; import net.minecraft.util.Identifier; -import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import shcm.shsupercm.fabric.citresewn.CITResewn; -import shcm.shsupercm.fabric.citresewn.ex.CITLoadException; import shcm.shsupercm.fabric.citresewn.ex.CITParseException; import shcm.shsupercm.fabric.citresewn.mixin.core.GroupResourcePackAccessor; import shcm.shsupercm.fabric.citresewn.pack.cits.*; @@ -62,25 +61,34 @@ public final class CITParser { private CITParser() {} Collection<Identifier> packProperties = new ArrayList<>(); for (String namespace : resourcePack.getNamespaces(ResourceType.CLIENT_RESOURCES)) { packProperties.addAll(resourcePack.findResources(ResourceType.CLIENT_RESOURCES, namespace, "citresewn/cit", Integer.MAX_VALUE - 53, s -> s.endsWith(".properties"))); + if (resourcePack.contains(ResourceType.CLIENT_RESOURCES, new Identifier(namespace, "citresewn/cit.properties"))) + packProperties.add(new Identifier(namespace, "citresewn/cit.properties")); + packProperties.addAll(resourcePack.findResources(ResourceType.CLIENT_RESOURCES, namespace, "optifine/cit", Integer.MAX_VALUE - 53, s -> s.endsWith(".properties"))); + if (resourcePack.contains(ResourceType.CLIENT_RESOURCES, new Identifier(namespace, "optifine/cit.properties"))) + packProperties.add(new Identifier(namespace, "optifine/cit.properties")); + packProperties.addAll(resourcePack.findResources(ResourceType.CLIENT_RESOURCES, namespace, "mcpatcher/cit", Integer.MAX_VALUE - 53, s -> s.endsWith(".properties"))); + if (resourcePack.contains(ResourceType.CLIENT_RESOURCES, new Identifier(namespace, "mcpatcher/cit.properties"))) + packProperties.add(new Identifier(namespace, "mcpatcher/cit.properties")); } - boolean readCitProperties = false; + boolean readGlobalProperties = false; for (Iterator<Identifier> iterator = packProperties.iterator(); iterator.hasNext(); ) { Identifier propertiesIdentifier = iterator.next(); - if (propertiesIdentifier.getPath().substring(propertiesIdentifier.getPath().indexOf("cit/") + 4).equals("cit.properties")) { - if (!readCitProperties) { - Properties citProperties = new Properties(); - try (InputStream is = resourcePack.open(ResourceType.CLIENT_RESOURCES, propertiesIdentifier)) { - citProperties.load(is); - citPack.loadProperties(citProperties); - readCitProperties = true; - } catch (Exception e) { - CITResewn.logErrorLoading(new CITLoadException(resourcePack, propertiesIdentifier, e.getMessage()).getMessage()); - } + try { + if (StringUtils.countMatches(propertiesIdentifier.getPath(), '/') <= 2 && propertiesIdentifier.getPath().endsWith("cit.properties")) { + iterator.remove(); + if (!readGlobalProperties) + try (InputStream is = resourcePack.open(ResourceType.CLIENT_RESOURCES, propertiesIdentifier)) { + Properties citProperties = new Properties(); + citProperties.load(is); + citPack.loadGlobalProperties(citProperties); + readGlobalProperties = true; + } } - iterator.remove(); + } catch (Exception e) { + CITResewn.logErrorLoading("Skipped global properties: " + e.getMessage() + " in " + resourcePack.getName() + " -> " + propertiesIdentifier); } } |