diff options
Diffstat (limited to 'src')
10 files changed, 154 insertions, 22 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertiesGroupAdapter.java b/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertiesGroupAdapter.java index c3d91ec..51ff9d8 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertiesGroupAdapter.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertiesGroupAdapter.java @@ -20,7 +20,7 @@ public class PropertiesGroupAdapter extends PropertyGroup { } @Override - public PropertyGroup load(InputStream is) throws IOException, InvalidIdentifierException { + public PropertyGroup load(Identifier identifier, InputStream is) throws IOException, InvalidIdentifierException { try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { String line; int linePos = 0, multilineSkip = 0; diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyGroup.java b/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyGroup.java index d1894c7..969800e 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyGroup.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyGroup.java @@ -17,7 +17,7 @@ public abstract class PropertyGroup { public abstract String getExtension(); - public abstract PropertyGroup load(InputStream is) throws IOException, InvalidIdentifierException; + public abstract PropertyGroup load(Identifier identifier, InputStream is) throws IOException, InvalidIdentifierException; protected void put(int position, String key, String keyMetadata, String delimiter, String value) throws InvalidIdentifierException { Objects.requireNonNull(key); @@ -39,14 +39,10 @@ public abstract class PropertyGroup { } public static PropertyGroup tryParseGroup(Identifier identifier, InputStream is) throws IOException { - PropertyGroup group; + PropertyGroup group = null; if (identifier.getPath().endsWith(PropertiesGroupAdapter.EXTENSION)) group = new PropertiesGroupAdapter(identifier); - else - return null; - group.load(is); - - return group; + return group == null ? null : group.load(identifier, is); } } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyValue.java b/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyValue.java index ee33cc1..4998803 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyValue.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyValue.java @@ -1,17 +1,4 @@ package shcm.shsupercm.fabric.citresewn.format; -public class PropertyValue { - public final String keyMetadata; - public final String stringValue; - public final String delimiter; - public final int position; - - public Object value = null; - - public PropertyValue(String keyMetadata, String stringValue, String delimiter, int position) { - this.keyMetadata = keyMetadata; - this.stringValue = stringValue; - this.delimiter = delimiter; - this.position = position; - } +public record PropertyValue(String keyMetadata, String value, String delimiter, int position) { } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java new file mode 100644 index 0000000..e37ea6d --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java @@ -0,0 +1,22 @@ +package shcm.shsupercm.fabric.citresewn.mixin; + +import net.minecraft.client.color.block.BlockColors; +import net.minecraft.client.render.model.ModelLoader; +import net.minecraft.resource.ResourceManager; +import net.minecraft.util.profiler.Profiler; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import shcm.shsupercm.fabric.citresewn.pack.ActiveCITs; + +@Mixin(ModelLoader.class) +public class ModelLoaderMixin { + @Inject(method = "<init>", at = + @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/util/profiler/Profiler;push(Ljava/lang/String;)V")) + private void loadCITs(ResourceManager resourceManager, BlockColors blockColors, Profiler profiler, int i, CallbackInfo ci) { + profiler.push("citresewn:reloading_cits"); + ActiveCITs.load(resourceManager, profiler); + profiler.pop(); + } +} 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 + + }); + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/registry/api/GlobalPropertiesHandler.java b/src/main/java/shcm/shsupercm/fabric/citresewn/registry/api/GlobalPropertiesHandler.java new file mode 100644 index 0000000..e5a2820 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/registry/api/GlobalPropertiesHandler.java @@ -0,0 +1,8 @@ +package shcm.shsupercm.fabric.citresewn.registry.api; + +import shcm.shsupercm.fabric.citresewn.format.PropertyValue; + +@FunctionalInterface +public interface GlobalPropertiesHandler { + void globalProperty(String key, PropertyValue value); +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/util/Disposable.java b/src/main/java/shcm/shsupercm/fabric/citresewn/util/Disposable.java new file mode 100644 index 0000000..84c65b2 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/util/Disposable.java @@ -0,0 +1,6 @@ +package shcm.shsupercm.fabric.citresewn.util; + +@FunctionalInterface +public interface Disposable { + void dispose(); +} diff --git a/src/main/resources/citresewn.mixins.json b/src/main/resources/citresewn.mixins.json index 70184b7..39343fb 100644 --- a/src/main/resources/citresewn.mixins.json +++ b/src/main/resources/citresewn.mixins.json @@ -4,6 +4,7 @@ "package": "shcm.shsupercm.fabric.citresewn.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ + "ModelLoaderMixin" ], "injectors": { "defaultRequire": 1 |