aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/shcm/shsupercm/fabric/citresewn/pack
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2022-01-22 17:54:26 +0200
committerSHsuperCM <shsupercm@gmail.com>2022-01-22 17:54:26 +0200
commitb16f0e068ba375d0b21456811a0ae5f68a77eba0 (patch)
tree8711f21b9826372c6c41bf6bd54c6d76957f1595 /src/main/java/shcm/shsupercm/fabric/citresewn/pack
parentffd25dce4e101c478e13867ebb5995f07cd68039 (diff)
downloadCITResewn-b16f0e068ba375d0b21456811a0ae5f68a77eba0.tar.gz
CITResewn-b16f0e068ba375d0b21456811a0ae5f68a77eba0.tar.bz2
CITResewn-b16f0e068ba375d0b21456811a0ae5f68a77eba0.zip
Implemented global properties api and started pack parsing/active cits
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric/citresewn/pack')
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/ActiveCITs.java46
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java54
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java12
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
+
+ });
+ }
+}