aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2022-02-05 12:17:49 +0200
committerSHsuperCM <shsupercm@gmail.com>2022-02-05 12:17:49 +0200
commitb8572ff143d1d7f4d37472bcd1b15340aaaceea5 (patch)
tree3c6959f847b226de2b927903a9a3219e98452c88 /src/main/java
parentfcd73195b483075c962986994f32dc53dd2f91cd (diff)
downloadCITResewn-b8572ff143d1d7f4d37472bcd1b15340aaaceea5.tar.gz
CITResewn-b8572ff143d1d7f4d37472bcd1b15340aaaceea5.tar.bz2
CITResewn-b8572ff143d1d7f4d37472bcd1b15340aaaceea5.zip
Implemented internal global properties and improved property context
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/api/GlobalPropertiesHandler.java2
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/mixin/GroupResourcePackAccessor.java14
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java9
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java44
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertiesGroupAdapter.java2
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyGroup.java4
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyValue.java9
7 files changed, 75 insertions, 9 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/api/GlobalPropertiesHandler.java b/src/main/java/shcm/shsupercm/fabric/citresewn/api/GlobalPropertiesHandler.java
index 9955823..ac8228a 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/api/GlobalPropertiesHandler.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/GlobalPropertiesHandler.java
@@ -6,5 +6,5 @@ import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue;
public interface GlobalPropertiesHandler {
String ENTRYPOINT = "citresewn:global_property";
- void globalProperty(String key, PropertyValue value);
+ void globalProperty(String key, PropertyValue value) throws Exception;
}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/GroupResourcePackAccessor.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/GroupResourcePackAccessor.java
new file mode 100644
index 0000000..72af871
--- /dev/null
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/GroupResourcePackAccessor.java
@@ -0,0 +1,14 @@
+package shcm.shsupercm.fabric.citresewn.mixin;
+
+import net.fabricmc.fabric.impl.resource.loader.GroupResourcePack;
+import net.minecraft.resource.ResourcePack;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+import java.util.List;
+
+@Mixin(GroupResourcePack.class)
+public interface GroupResourcePackAccessor {
+ @Accessor
+ List<ResourcePack> getPacks();
+}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java
index 39d551a..d4f89f0 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java
@@ -4,6 +4,7 @@ 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.CITResewn;
import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup;
import shcm.shsupercm.fabric.citresewn.pack.format.PropertyKey;
import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue;
@@ -47,7 +48,13 @@ public class GlobalProperties extends PropertyGroup {
for (PropertyValue value : entry.getValue())
lastValue = value;
- container.getEntrypoint().globalProperty(entry.getKey().path(), lastValue);
+ if (lastValue != null)
+ try {
+ container.getEntrypoint().globalProperty(entry.getKey().path(), lastValue);
+ } catch (Exception e) {
+ CITResewn.logErrorLoading("Errored while parsing global properties: Line " + lastValue.position() + " of " + lastValue.propertiesIdentifier() + " in " + lastValue.packName());
+ e.printStackTrace();
+ }
}
}
}
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 79ffc70..463d34a 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java
@@ -1,12 +1,50 @@
package shcm.shsupercm.fabric.citresewn.pack;
+import net.fabricmc.fabric.impl.resource.loader.GroupResourcePack;
+import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.resource.ResourceManager;
+import net.minecraft.resource.ResourceNotFoundException;
+import net.minecraft.resource.ResourcePack;
+import net.minecraft.resource.ResourceType;
+import net.minecraft.util.Identifier;
+import shcm.shsupercm.fabric.citresewn.CITResewn;
+import shcm.shsupercm.fabric.citresewn.mixin.GroupResourcePackAccessor;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.function.Consumer;
+import java.util.function.Function;
public class PackParser {
- public static void loadGlobalProperties(ResourceManager resourceManager, GlobalProperties globalProperties) {
- resourceManager.streamResourcePacks().forEachOrdered(resourcePack -> {
- //todo
+ private static final String[] ROOTS = new String[] { "mcpatcher", "optifine", "citresewn" };
+ private static final Function<ResourcePack, List<ResourcePack>> PARSE_FAPI_GROUPS =
+ FabricLoader.getInstance().isModLoaded("fabric-resource-loader-v0") ?
+ parentPack -> parentPack instanceof GroupResourcePack ? ((GroupResourcePackAccessor) parentPack).getPacks() : null
+ : parentPack -> null;
+
+ private static void forEachPack(ResourceManager resourceManager, Consumer<ResourcePack> run) {
+ resourceManager.streamResourcePacks().forEachOrdered(pack -> {
+ List<ResourcePack> grouped = PARSE_FAPI_GROUPS.apply(pack);
+ if (grouped != null)
+ for (ResourcePack subPack : grouped)
+ run.accept(subPack);
+ else
+ run.accept(pack);
+ });
+ }
+ public static void loadGlobalProperties(ResourceManager resourceManager, GlobalProperties globalProperties) {
+ forEachPack(resourceManager, pack -> {
+ for (String root : ROOTS) {
+ Identifier identifier = new Identifier("minecraft", root + "/cit.properties");
+ try {
+ globalProperties.load(pack.getName(), identifier, pack.open(ResourceType.CLIENT_RESOURCES, identifier));
+ } catch (ResourceNotFoundException ignored) {
+ } catch (IOException e) {
+ CITResewn.logErrorLoading("Errored while loading global properties: " + identifier + " in " + pack.getName());
+ e.printStackTrace();
+ }
+ }
});
}
}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertiesGroupAdapter.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertiesGroupAdapter.java
index 896e81e..bfa4091 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertiesGroupAdapter.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertiesGroupAdapter.java
@@ -95,7 +95,7 @@ public class PropertiesGroupAdapter extends PropertyGroup {
int pos = linePos - multilineSkip;
multilineSkip = 0;
- this.put(pos, key, keyMetadata, "=", builder.toString());
+ this.put(pos, packName, identifier, key, keyMetadata, "=", builder.toString());
}
}
return this;
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyGroup.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyGroup.java
index 8fcb135..3864569 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyGroup.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyGroup.java
@@ -21,11 +21,11 @@ public abstract class PropertyGroup {
public abstract PropertyGroup load(String packName, Identifier identifier, InputStream is) throws IOException, InvalidIdentifierException;
- protected void put(int position, String key, String keyMetadata, String delimiter, String value) throws InvalidIdentifierException {
+ protected void put(int position, String packName, Identifier propertiesIdentifier, String key, String keyMetadata, String delimiter, String value) throws InvalidIdentifierException {
Objects.requireNonNull(key);
Objects.requireNonNull(value);
- this.properties.computeIfAbsent(PropertyKey.of(key), id -> new LinkedHashSet<>()).add(new PropertyValue(keyMetadata, value, delimiter, position));
+ this.properties.computeIfAbsent(PropertyKey.of(key), id -> new LinkedHashSet<>()).add(new PropertyValue(keyMetadata, value, delimiter, position, propertiesIdentifier, packName));
}
public Set<PropertyValue> get(String namespace, String... pathAliases) {
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyValue.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyValue.java
index 9a0c4e3..0294cb2 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyValue.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyValue.java
@@ -1,4 +1,11 @@
package shcm.shsupercm.fabric.citresewn.pack.format;
-public record PropertyValue(String keyMetadata, String value, String delimiter, int position) {
+import net.minecraft.util.Identifier;
+
+public record PropertyValue(String keyMetadata,
+ String value,
+ String delimiter,
+ int position,
+ Identifier propertiesIdentifier,
+ String packName) {
}