diff options
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric/citresewn/pack')
3 files changed, 112 insertions, 0 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ActiveCITs.java new file mode 100644 index 0000000..4d48fdc --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ActiveCITs.java @@ -0,0 +1,46 @@ +package shcm.shsupercm.fabric.citresewn.pack; + +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.resource.ResourceManager; +import net.minecraft.util.profiler.Profiler; +import shcm.shsupercm.fabric.citresewn.util.Disposable; + +public class ActiveCITs implements Disposable { 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 static ActiveCITs load(ResourceManager resourceManager, Profiler profiler) { + profiler.push("citresewn:disposing"); + if (active != null) { + active.dispose(); + active = null; + } + profiler.pop(); + + ActiveCITs active = new ActiveCITs(); + + profiler.push("citresewn:load_global_properties"); + PackParser.loadGlobalProperties(resourceManager, active.globalProperties); + active.globalProperties.callHandlers(); + profiler.pop(); + + return ActiveCITs.active = active; + } + + @Override + public void dispose() { + for (Disposable disposable : FabricLoader.getInstance().getEntrypoints("citresewn:dispose", Disposable.class)) + disposable.dispose(); + + + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java new file mode 100644 index 0000000..7775b66 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java @@ -0,0 +1,54 @@ +package shcm.shsupercm.fabric.citresewn.pack; + +import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.api.entrypoint.EntrypointContainer; +import net.minecraft.util.Identifier; +import net.minecraft.util.InvalidIdentifierException; +import shcm.shsupercm.fabric.citresewn.format.PropertyGroup; +import shcm.shsupercm.fabric.citresewn.format.PropertyKey; +import shcm.shsupercm.fabric.citresewn.format.PropertyValue; +import shcm.shsupercm.fabric.citresewn.registry.api.GlobalPropertiesHandler; + +import java.io.IOException; +import java.io.InputStream; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; + +public class GlobalProperties extends PropertyGroup { + public GlobalProperties() { + super(new Identifier("citresewn", "global_properties")); + } + + @Override + public String getExtension() { + return ""; + } + + @Override + public PropertyGroup load(Identifier identifier, InputStream is) throws IOException, InvalidIdentifierException { + PropertyGroup group = PropertyGroup.tryParseGroup(identifier, is); + if (group != null) + for (Map.Entry<PropertyKey, Set<PropertyValue>> entry : group.properties.entrySet()) + this.properties.computeIfAbsent(entry.getKey(), key -> new LinkedHashSet<>()).addAll(entry.getValue()); + + return this; + } + + public void callHandlers() { + for (EntrypointContainer<GlobalPropertiesHandler> container : FabricLoader.getInstance().getEntrypointContainers("citresewn:cit_global_properties", GlobalPropertiesHandler.class)) { + String containerNamespace = container.getProvider().getMetadata().getId(); + if (containerNamespace.equals("citresewn-defaults")) + containerNamespace = "citresewn"; + + for (Map.Entry<PropertyKey, Set<PropertyValue>> entry : properties.entrySet()) + if (entry.getKey().namespace().equals(containerNamespace)) { + PropertyValue value = null; + for (PropertyValue v : entry.getValue()) + value = v; + + container.getEntrypoint().globalProperty(entry.getKey().path(), value); + } + } + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java new file mode 100644 index 0000000..79ffc70 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java @@ -0,0 +1,12 @@ +package shcm.shsupercm.fabric.citresewn.pack; + +import net.minecraft.resource.ResourceManager; + +public class PackParser { + public static void loadGlobalProperties(ResourceManager resourceManager, GlobalProperties globalProperties) { + resourceManager.streamResourcePacks().forEachOrdered(resourcePack -> { + //todo + + }); + } +} |