diff options
author | SHsuperCM <shsupercm@gmail.com> | 2022-02-13 07:52:10 +0200 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2022-02-13 07:52:10 +0200 |
commit | 49318a4452f629274e96001700006e0b4a1464a5 (patch) | |
tree | e887cce1cec886e17247b2a99029e79b0255b0e7 /src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java | |
parent | 8823e77b989ab1035fa8813120177dd3a95ce863 (diff) | |
download | CITResewn-49318a4452f629274e96001700006e0b4a1464a5.tar.gz CITResewn-49318a4452f629274e96001700006e0b4a1464a5.tar.bz2 CITResewn-49318a4452f629274e96001700006e0b4a1464a5.zip |
Moved some stuff around
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java')
-rw-r--r-- | src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java new file mode 100644 index 0000000..d24faf8 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java @@ -0,0 +1,66 @@ +package shcm.shsupercm.fabric.citresewn.cit; + +import net.fabricmc.loader.api.FabricLoader; +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.pack.GlobalProperties; +import shcm.shsupercm.fabric.citresewn.pack.PackParser; + +import java.util.*; + +public class ActiveCITs implements CITDisposable { private ActiveCITs() {} + private static ActiveCITs active = null; + + public static ActiveCITs getActive() { + return active; + } + + public static boolean isActive() { + return active != null; + } + + public final GlobalProperties globalProperties = new GlobalProperties(); + + public final Map<Class<? extends CITType>, List<CIT>> cits = new IdentityHashMap<>(); + + public static ActiveCITs load(ResourceManager resourceManager, Profiler profiler) { + profiler.push("citresewn:disposing"); + if (active != null) { + active.dispose(); + active = null; + } + + ActiveCITs active = new ActiveCITs(); + + profiler.swap("citresewn:load_global_properties"); + PackParser.loadGlobalProperties(resourceManager, active.globalProperties); + active.globalProperties.callHandlers(); + + profiler.swap("citresewn:load_cits"); + for (CIT cit : PackParser.loadCITs(resourceManager)) + active.cits.computeIfAbsent(cit.type.getClass(), type -> new ArrayList<>()).add(cit); + for (Map.Entry<Class<? extends CITType>, List<CIT>> entry : active.cits.entrySet()) { + entry.getValue().sort(Comparator.<CIT>comparingInt(cit -> cit.weight).reversed().thenComparing(cit -> cit.propertiesIdentifier.toString())); + for (CITTypeContainer<? extends CITType> typeContainer : CITRegistry.TYPES.values()) + if (typeContainer.type == entry.getKey()) { + typeContainer.load(entry.getValue()); + break; + } + } + + profiler.pop(); + + return ActiveCITs.active = active; + } + + @Override + public void dispose() { + for (CITDisposable disposable : FabricLoader.getInstance().getEntrypoints(CITDisposable.ENTRYPOINT, CITDisposable.class)) + disposable.dispose(); + + for (CITTypeContainer<? extends CITType> typeContainer : CITRegistry.TYPES.values()) + typeContainer.dispose(); + } +} |