From fcd73195b483075c962986994f32dc53dd2f91cd Mon Sep 17 00:00:00 2001 From: SHsuperCM Date: Sat, 5 Feb 2022 08:32:41 +0200 Subject: Moved some stuff around --- .../shsupercm/fabric/citresewn/api/Disposable.java | 8 ++ .../citresewn/api/GlobalPropertiesHandler.java | 10 ++ .../citresewn/format/PropertiesGroupAdapter.java | 103 --------------------- .../fabric/citresewn/format/PropertyGroup.java | 50 ---------- .../fabric/citresewn/format/PropertyKey.java | 14 --- .../fabric/citresewn/format/PropertyValue.java | 4 - .../fabric/citresewn/mixin/ModelLoaderMixin.java | 2 +- .../fabric/citresewn/pack/ActiveCITs.java | 2 +- .../fabric/citresewn/pack/GlobalProperties.java | 16 ++-- .../pack/format/PropertiesGroupAdapter.java | 103 +++++++++++++++++++++ .../citresewn/pack/format/PropertyGroup.java | 50 ++++++++++ .../fabric/citresewn/pack/format/PropertyKey.java | 14 +++ .../citresewn/pack/format/PropertyValue.java | 4 + .../registry/api/GlobalPropertiesHandler.java | 10 -- .../fabric/citresewn/util/Disposable.java | 8 -- 15 files changed, 199 insertions(+), 199 deletions(-) create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/api/Disposable.java create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/api/GlobalPropertiesHandler.java delete mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertiesGroupAdapter.java delete mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyGroup.java delete mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyKey.java delete mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyValue.java create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertiesGroupAdapter.java create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyGroup.java create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyKey.java create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyValue.java delete mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/registry/api/GlobalPropertiesHandler.java delete mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/util/Disposable.java (limited to 'src') diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/api/Disposable.java b/src/main/java/shcm/shsupercm/fabric/citresewn/api/Disposable.java new file mode 100644 index 0000000..85b8849 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/Disposable.java @@ -0,0 +1,8 @@ +package shcm.shsupercm.fabric.citresewn.api; + +@FunctionalInterface +public interface Disposable { + String ENTRYPOINT = "citresewn:dispose"; + + void dispose(); +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/api/GlobalPropertiesHandler.java b/src/main/java/shcm/shsupercm/fabric/citresewn/api/GlobalPropertiesHandler.java new file mode 100644 index 0000000..9955823 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/GlobalPropertiesHandler.java @@ -0,0 +1,10 @@ +package shcm.shsupercm.fabric.citresewn.api; + +import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; + +@FunctionalInterface +public interface GlobalPropertiesHandler { + String ENTRYPOINT = "citresewn:global_property"; + + void globalProperty(String key, PropertyValue value); +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertiesGroupAdapter.java b/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertiesGroupAdapter.java deleted file mode 100644 index 7501057..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertiesGroupAdapter.java +++ /dev/null @@ -1,103 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.format; - -import net.minecraft.util.Identifier; -import net.minecraft.util.InvalidIdentifierException; - -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.util.Properties; - -public class PropertiesGroupAdapter extends PropertyGroup { - public static final String EXTENSION = ".properties"; - - protected PropertiesGroupAdapter(String packName, Identifier identifier) { - super(packName, identifier); - } - - @Override - public String getExtension() { - return EXTENSION; - } - - @Override - public PropertyGroup load(String packName, 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; - while ((line = reader.readLine()) != null) { - linePos++; - line = line.stripLeading(); - if (line.isEmpty() || line.startsWith("#") || line.startsWith("!")) - continue; - - while (line.endsWith("\\")) { - String nextLine = reader.readLine(); - linePos++; - multilineSkip++; - if (nextLine == null) - nextLine = ""; - nextLine = nextLine.stripLeading(); - - if (nextLine.startsWith("#") || nextLine.startsWith("!")) - continue; - - line = line.substring(0, line.length() - 1) + "\\n" + nextLine; - } - - StringBuilder builder = new StringBuilder(); - - String key = null, keyMetadata = null; - - for (int i = 0; i < line.length(); i++) { - char c = line.charAt(i); - - if (c == '\\') { // escape - c = switch (c = line.charAt(++i)) { - case 'n' -> '\n'; - case 'r' -> '\r'; - case 'f' -> '\f'; - case 't' -> '\t'; - case 'u' -> { - if (i + 4 >= line.length()) - yield c; - - //todo implement manually - java.util.Properties properties = new Properties(); - properties.load(new StringReader("k=\\u" + line.charAt(i + 1) + line.charAt(i + 2) + line.charAt(i + 3) + line.charAt(i + 4))); - String k = properties.getProperty("k"); - if (k.length() == 1) { - i += 4; - yield k.charAt(0); - } - yield c; - } - - default -> c; - }; - - } else if (key == null && c == '=') { - key = builder.toString().stripTrailing(); - int metadataIndex = key.indexOf('.'); - if (metadataIndex >= 0) { - keyMetadata = key.substring(metadataIndex + 1); - key = key.substring(0, metadataIndex); - } - - builder = new StringBuilder(); - for (i++; i < line.length() && Character.isWhitespace(line.charAt(i)); i++); - i--; - continue; - } - - - builder.append(c); - } - - int pos = linePos - multilineSkip; - multilineSkip = 0; - this.put(pos, key, keyMetadata, "=", builder.toString()); - } - } - return this; - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyGroup.java b/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyGroup.java deleted file mode 100644 index d2ff2a4..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyGroup.java +++ /dev/null @@ -1,50 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.format; - -import net.minecraft.util.Identifier; -import net.minecraft.util.InvalidIdentifierException; - -import java.io.IOException; -import java.io.InputStream; -import java.util.*; - -public abstract class PropertyGroup { - public final Map> properties = new LinkedHashMap<>(); - public final Identifier identifier; - public final String packName; - - protected PropertyGroup(String packName, Identifier identifier) { - this.packName = packName; - this.identifier = identifier; - } - - public abstract String getExtension(); - - 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 { - Objects.requireNonNull(key); - Objects.requireNonNull(value); - - this.properties.computeIfAbsent(PropertyKey.of(key), id -> new LinkedHashSet<>()).add(new PropertyValue(keyMetadata, value, delimiter, position)); - } - - public Set get(String namespace, String... pathAliases) { - Set values = new LinkedHashSet<>(); - - for (String path : pathAliases) { - Set possibleValues = this.properties.get(new PropertyKey(namespace, path)); - if (possibleValues != null) - values.addAll(possibleValues); - } - - return values; - } - - public static PropertyGroup tryParseGroup(String packName, Identifier identifier, InputStream is) throws IOException { - PropertyGroup group = null; - if (identifier.getPath().endsWith(PropertiesGroupAdapter.EXTENSION)) - group = new PropertiesGroupAdapter(packName, identifier); - - return group == null ? null : group.load(packName, identifier, is); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyKey.java b/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyKey.java deleted file mode 100644 index 9adcca2..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyKey.java +++ /dev/null @@ -1,14 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.format; - -public record PropertyKey(String namespace, String path) { - public static PropertyKey of(String key) { - String[] split = new String[] {"citresewn", key}; - int i = key.indexOf(':'); - if (i >= 0) { - split[1] = key.substring(i + 1); - if (i >= 1) - split[0] = key.substring(0, i); - } - return new PropertyKey(split[0], split[1]); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyValue.java b/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyValue.java deleted file mode 100644 index 4998803..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/format/PropertyValue.java +++ /dev/null @@ -1,4 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.format; - -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 index e37ea6d..f8b2979 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java @@ -14,7 +14,7 @@ import shcm.shsupercm.fabric.citresewn.pack.ActiveCITs; public class ModelLoaderMixin { @Inject(method = "", 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) { + private void citresewn$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 index 5523c84..642b950 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ActiveCITs.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ActiveCITs.java @@ -3,7 +3,7 @@ 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; +import shcm.shsupercm.fabric.citresewn.api.Disposable; public class ActiveCITs implements Disposable { private ActiveCITs() {} private static ActiveCITs active = null; 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 76f5d26..39d551a 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java @@ -4,10 +4,10 @@ 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 shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; +import shcm.shsupercm.fabric.citresewn.pack.format.PropertyKey; +import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; +import shcm.shsupercm.fabric.citresewn.api.GlobalPropertiesHandler; import java.io.IOException; import java.io.InputStream; @@ -43,11 +43,11 @@ public class GlobalProperties extends PropertyGroup { for (Map.Entry> entry : properties.entrySet()) if (entry.getKey().namespace().equals(containerNamespace)) { - PropertyValue value = null; - for (PropertyValue v : entry.getValue()) - value = v; + PropertyValue lastValue = null; + for (PropertyValue value : entry.getValue()) + lastValue = value; - container.getEntrypoint().globalProperty(entry.getKey().path(), value); + container.getEntrypoint().globalProperty(entry.getKey().path(), lastValue); } } } 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 new file mode 100644 index 0000000..896e81e --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertiesGroupAdapter.java @@ -0,0 +1,103 @@ +package shcm.shsupercm.fabric.citresewn.pack.format; + +import net.minecraft.util.Identifier; +import net.minecraft.util.InvalidIdentifierException; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.Properties; + +public class PropertiesGroupAdapter extends PropertyGroup { + public static final String EXTENSION = ".properties"; + + protected PropertiesGroupAdapter(String packName, Identifier identifier) { + super(packName, identifier); + } + + @Override + public String getExtension() { + return EXTENSION; + } + + @Override + public PropertyGroup load(String packName, 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; + while ((line = reader.readLine()) != null) { + linePos++; + line = line.stripLeading(); + if (line.isEmpty() || line.startsWith("#") || line.startsWith("!")) + continue; + + while (line.endsWith("\\")) { + String nextLine = reader.readLine(); + linePos++; + multilineSkip++; + if (nextLine == null) + nextLine = ""; + nextLine = nextLine.stripLeading(); + + if (nextLine.startsWith("#") || nextLine.startsWith("!")) + continue; + + line = line.substring(0, line.length() - 1) + "\\n" + nextLine; + } + + StringBuilder builder = new StringBuilder(); + + String key = null, keyMetadata = null; + + for (int i = 0; i < line.length(); i++) { + char c = line.charAt(i); + + if (c == '\\') { // escape + c = switch (c = line.charAt(++i)) { + case 'n' -> '\n'; + case 'r' -> '\r'; + case 'f' -> '\f'; + case 't' -> '\t'; + case 'u' -> { + if (i + 4 >= line.length()) + yield c; + + //todo implement manually + java.util.Properties properties = new Properties(); + properties.load(new StringReader("k=\\u" + line.charAt(i + 1) + line.charAt(i + 2) + line.charAt(i + 3) + line.charAt(i + 4))); + String k = properties.getProperty("k"); + if (k.length() == 1) { + i += 4; + yield k.charAt(0); + } + yield c; + } + + default -> c; + }; + + } else if (key == null && c == '=') { + key = builder.toString().stripTrailing(); + int metadataIndex = key.indexOf('.'); + if (metadataIndex >= 0) { + keyMetadata = key.substring(metadataIndex + 1); + key = key.substring(0, metadataIndex); + } + + builder = new StringBuilder(); + for (i++; i < line.length() && Character.isWhitespace(line.charAt(i)); i++); + i--; + continue; + } + + + builder.append(c); + } + + int pos = linePos - multilineSkip; + multilineSkip = 0; + this.put(pos, 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 new file mode 100644 index 0000000..8fcb135 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyGroup.java @@ -0,0 +1,50 @@ +package shcm.shsupercm.fabric.citresewn.pack.format; + +import net.minecraft.util.Identifier; +import net.minecraft.util.InvalidIdentifierException; + +import java.io.IOException; +import java.io.InputStream; +import java.util.*; + +public abstract class PropertyGroup { + public final Map> properties = new LinkedHashMap<>(); + public final Identifier identifier; + public final String packName; + + protected PropertyGroup(String packName, Identifier identifier) { + this.packName = packName; + this.identifier = identifier; + } + + public abstract String getExtension(); + + 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 { + Objects.requireNonNull(key); + Objects.requireNonNull(value); + + this.properties.computeIfAbsent(PropertyKey.of(key), id -> new LinkedHashSet<>()).add(new PropertyValue(keyMetadata, value, delimiter, position)); + } + + public Set get(String namespace, String... pathAliases) { + Set values = new LinkedHashSet<>(); + + for (String path : pathAliases) { + Set possibleValues = this.properties.get(new PropertyKey(namespace, path)); + if (possibleValues != null) + values.addAll(possibleValues); + } + + return values; + } + + public static PropertyGroup tryParseGroup(String packName, Identifier identifier, InputStream is) throws IOException { + PropertyGroup group = null; + if (identifier.getPath().endsWith(PropertiesGroupAdapter.EXTENSION)) + group = new PropertiesGroupAdapter(packName, identifier); + + return group == null ? null : group.load(packName, identifier, is); + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyKey.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyKey.java new file mode 100644 index 0000000..b861a63 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyKey.java @@ -0,0 +1,14 @@ +package shcm.shsupercm.fabric.citresewn.pack.format; + +public record PropertyKey(String namespace, String path) { + public static PropertyKey of(String key) { + String[] split = new String[] {"citresewn", key}; + int i = key.indexOf(':'); + if (i >= 0) { + split[1] = key.substring(i + 1); + if (i >= 1) + split[0] = key.substring(0, i); + } + return new PropertyKey(split[0], split[1]); + } +} 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 new file mode 100644 index 0000000..9a0c4e3 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyValue.java @@ -0,0 +1,4 @@ +package shcm.shsupercm.fabric.citresewn.pack.format; + +public record PropertyValue(String keyMetadata, String value, String delimiter, int position) { +} 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 deleted file mode 100644 index 9b1ad6f..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/registry/api/GlobalPropertiesHandler.java +++ /dev/null @@ -1,10 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.registry.api; - -import shcm.shsupercm.fabric.citresewn.format.PropertyValue; - -@FunctionalInterface -public interface GlobalPropertiesHandler { - String ENTRYPOINT = "citresewn:global_property"; - - boolean 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 deleted file mode 100644 index 7878e16..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/util/Disposable.java +++ /dev/null @@ -1,8 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.util; - -@FunctionalInterface -public interface Disposable { - String ENTRYPOINT = "citresewn:dispose"; - - void dispose(); -} -- cgit