diff options
author | SHsuperCM <shsupercm@gmail.com> | 2021-10-15 12:17:22 +0300 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2021-10-15 12:17:22 +0300 |
commit | 102697939684255827620da07266089dc20572a2 (patch) | |
tree | 00f0de6821ea83bcd0a076c16331a98ede91c2aa /src/main/java/shcm/shsupercm/fabric/citresewn/pack | |
parent | b2d3760c3cceabf4f3a06fea6c35b58bf2a3d394 (diff) | |
download | CITResewn-102697939684255827620da07266089dc20572a2.tar.gz CITResewn-102697939684255827620da07266089dc20572a2.tar.bz2 CITResewn-102697939684255827620da07266089dc20572a2.zip |
Restructured to store active effective global properties
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric/citresewn/pack')
-rw-r--r-- | src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java | 54 | ||||
-rw-r--r-- | src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java | 3 |
2 files changed, 38 insertions, 19 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 92faec0..59f1659 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java @@ -9,10 +9,10 @@ public class CITPack { public final ResourcePack resourcePack; public final Collection<CIT> cits = new ArrayList<>(); - private EnchantmentMergeMethod method = EnchantmentMergeMethod.AVERAGE; - private int cap = 8; - private float fade = 0.5f; - private boolean useGlint = true; + public EnchantmentMergeMethod method = EnchantmentMergeMethod.AVERAGE; + public Integer cap = 8; + public Float fade = 0.5f; + public Boolean useGlint = true; public CITPack(ResourcePack resourcePack) { this.resourcePack = resourcePack; @@ -20,27 +20,47 @@ public class CITPack { public void loadGlobalProperties(Properties properties) throws Exception { try { - 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)) { + this.method = properties.containsKey("method") ? CITPack.EnchantmentMergeMethod.valueOf(properties.getProperty("method").toUpperCase(Locale.ENGLISH)) : null; + + if (properties.containsKey("cap")) { + this.cap = Integer.parseInt(properties.getProperty("cap")); + if (this.cap < 0) + throw new Exception("cap cannot be negative"); + } else + this.cap = null; + + if (properties.containsKey("fade")) { + this.fade = Float.parseFloat(properties.getProperty("fade")); + if (this.fade < 0f) + throw new Exception("fade cannot be negative"); + } else + this.fade = null; + + this.useGlint = properties.containsKey("useGlint") ? switch (properties.getProperty("useGlint").toLowerCase(Locale.ENGLISH)) { case "true" -> true; case "false" -> false; default -> throw new Exception("useGlint is not a boolean"); - }; + } : null; } catch (Exception e) { - this.method = EnchantmentMergeMethod.AVERAGE; - this.cap = 8; - this.fade = 0.5f; - this.useGlint = true; + this.method = null; + this.cap = null; + this.fade = null; + this.useGlint = null; throw e; } } + public void loadGlobalProperties(CITPack properties) { + if (properties.method != null) + this.method = properties.method; + if (properties.cap != null) + this.cap = properties.cap; + if (properties.fade != null) + this.fade = properties.fade; + if (properties.useGlint != null) + this.useGlint = properties.useGlint; + } + public enum EnchantmentMergeMethod { AVERAGE, LAYERED, 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 03ea512..ee97b25 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java @@ -36,11 +36,10 @@ public final class CITParser { private CITParser() {} * @param packs packs to parse * @return a collection of parsed CITs */ - public static Collection<CIT> parseCITs(Collection<ResourcePack> packs) { + public static List<CITPack> parseCITs(Collection<ResourcePack> packs) { return packs.stream() .map(CITParser::parse) .flatMap(Collection::stream) - .flatMap(pack -> pack.cits.stream()) .collect(Collectors.toList()); } |