From d5e4cfdad93267d7c3f574451a4ee7e0b4ef4098 Mon Sep 17 00:00:00 2001 From: SHsuperCM Date: Fri, 4 Mar 2022 10:59:46 +0200 Subject: Fixed cit parsing with config not enabled --- .../shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java | 17 +++++++++++++---- .../shsupercm/fabric/citresewn/pack/PackParser.java | 3 ++- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'src/main') diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java index c7ca38c..2c31641 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java @@ -5,6 +5,7 @@ import net.minecraft.resource.ResourceManager; import net.minecraft.util.profiler.Profiler; import shcm.shsupercm.fabric.citresewn.api.CITDisposable; import shcm.shsupercm.fabric.citresewn.api.CITTypeContainer; +import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; import shcm.shsupercm.fabric.citresewn.pack.GlobalProperties; import shcm.shsupercm.fabric.citresewn.pack.PackParser; @@ -32,14 +33,19 @@ public class ActiveCITs implements CITDisposable { private ActiveCITs() {} active = null; } + if (!CITResewnConfig.INSTANCE.enabled) { + profiler.pop(); + return null; + } + ActiveCITs active = new ActiveCITs(); profiler.swap("citresewn:load_global_properties"); - PackParser.loadGlobalProperties(resourceManager, active.globalProperties); - active.globalProperties.callHandlers(); + PackParser.loadGlobalProperties(resourceManager, active.globalProperties).callHandlers(); profiler.swap("citresewn:load_cits"); - for (CIT cit : PackParser.loadCITs(resourceManager)) + List> cits = PackParser.loadCITs(resourceManager); + for (CIT cit : cits) active.cits.computeIfAbsent(cit.type.getClass(), type -> new ArrayList<>()).add(cit); for (Map.Entry, List>> entry : active.cits.entrySet()) { entry.getValue().sort(Comparator.>comparingInt(cit -> cit.weight).reversed().thenComparing(cit -> cit.propertiesIdentifier.toString())); @@ -52,7 +58,10 @@ public class ActiveCITs implements CITDisposable { private ActiveCITs() {} profiler.pop(); - return ActiveCITs.active = active; + if (!cits.isEmpty()) + ActiveCITs.active = active; + + return ActiveCITs.active; } @Override diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java index 163435b..794977d 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java @@ -43,7 +43,7 @@ public class PackParser { }); } - public static void loadGlobalProperties(ResourceManager resourceManager, GlobalProperties globalProperties) { + public static GlobalProperties loadGlobalProperties(ResourceManager resourceManager, GlobalProperties globalProperties) { forEachPack(resourceManager, pack -> { for (String root : ROOTS) { Identifier identifier = new Identifier("minecraft", root + "/cit.properties"); @@ -56,6 +56,7 @@ public class PackParser { } } }); + return globalProperties; } public static List> loadCITs(ResourceManager resourceManager) { -- cgit