diff options
Diffstat (limited to 'src/main')
17 files changed, 196 insertions, 25 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITCondition.java index b5c1996..fd00ac6 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITCondition.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITCondition.java @@ -22,6 +22,6 @@ public abstract class CITCondition { public abstract boolean test(CITContext context); protected void warn(String message, PropertyValue value, PropertyGroup properties) { - CITResewn.logWarnLoading("Warning: " + CITParsingException.descriptionOf(message, properties, value.position())); + CITResewn.logWarnLoading("Warning: " + properties.messageWithDescriptorOf(message, value.position())); } } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITRegistry.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITRegistry.java index 47f79fe..d8454a0 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITRegistry.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITRegistry.java @@ -56,7 +56,7 @@ public class CITRegistry { public static CITCondition parseCondition(PropertyKey key, PropertyValue value, PropertyGroup properties) throws CITParsingException { CITConditionContainer<? extends CITCondition> conditionContainer = CONDITIONS.get(key); if (conditionContainer == null) { - logWarnLoading(CITParsingException.descriptionOf("Unknown condition type \"" + key.toString() + "\"", properties, value.position())); + logWarnLoading(properties.messageWithDescriptorOf("Unknown condition type \"" + key.toString() + "\"", value.position())); return new ConstantCondition(false); } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITType.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITType.java index c3bb134..b35d26c 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITType.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITType.java @@ -16,7 +16,7 @@ public abstract class CITType { public abstract void load(List<CITCondition> conditions, PropertyGroup properties, ResourceManager resourceManager) throws CITParsingException; protected void warn(String message, PropertyValue value, PropertyGroup properties) { - CITResewn.logWarnLoading("Warning: " + CITParsingException.descriptionOf(message, properties, value == null ? -1 : value.position())); + CITResewn.logWarnLoading("Warning: " + properties.messageWithDescriptorOf(message, value == null ? -1 : value.position())); } /** diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/ex/CITParsingException.java b/src/main/java/shcm/shsupercm/fabric/citresewn/ex/CITParsingException.java index 811d16b..f897ba7 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/ex/CITParsingException.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/ex/CITParsingException.java @@ -2,16 +2,16 @@ package shcm.shsupercm.fabric.citresewn.ex; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; +/** + * Thrown if errored while parsing the properties of a {@link PropertyGroup}. + * @see PropertyGroup#messageWithDescriptorOf(String, int) + */ public class CITParsingException extends Exception { public CITParsingException(String message, PropertyGroup propertyGroup, int position, Throwable throwable) { - super("Errored while parsing CIT: " + descriptionOf(message, propertyGroup, position), throwable); + super("Errored while parsing CIT: " + propertyGroup.messageWithDescriptorOf(message, position), throwable); } public CITParsingException(String message, PropertyGroup propertyGroup, int position) { - super("Errored while parsing CIT: " + descriptionOf(message, propertyGroup, position)); - } - - public static String descriptionOf(String message, PropertyGroup propertyGroup, int position) { - return message + (position != -1 ? " @L" + position : "") + " in " + propertyGroup.identifier.toString() + " from " + propertyGroup.packName; + super("Errored while parsing CIT: " + propertyGroup.messageWithDescriptorOf(message, position)); } } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/ex/UnknownCITTypeException.java b/src/main/java/shcm/shsupercm/fabric/citresewn/ex/UnknownCITTypeException.java index eacbc69..23f9c82 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/ex/UnknownCITTypeException.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/ex/UnknownCITTypeException.java @@ -2,6 +2,9 @@ package shcm.shsupercm.fabric.citresewn.ex; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; +/** + * Thrown when a property group contains an unrecognized value associated with the "type" key. + */ public class UnknownCITTypeException extends CITParsingException { public UnknownCITTypeException(PropertyGroup propertyGroup, int position) { super("Unknown type", propertyGroup, position); diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ChatScreenMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ChatScreenMixin.java index 5bacbde..c79143b 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ChatScreenMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ChatScreenMixin.java @@ -9,14 +9,23 @@ import net.minecraft.text.Text; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArg; +import shcm.shsupercm.fabric.citresewn.CITResewnCommand; import shcm.shsupercm.fabric.citresewn.config.CITResewnConfigScreenFactory; import static shcm.shsupercm.fabric.citresewn.CITResewnCommand.openConfig; +/** + * Opens the config screen when running the "/citresewn config" command. + * @see CITResewnCommand#openConfig + */ @Mixin(ChatScreen.class) public class ChatScreenMixin { + /** + * If {@link CITResewnCommand#openConfig} is true, changes the screen that's opened when the chat is closed to the config screen. + * @see CITResewnCommand#openConfig + */ @ModifyArg(method = "keyPressed", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;setScreen(Lnet/minecraft/client/gui/screen/Screen;)V")) - public Screen redirectConfigScreen(Screen original) { + public Screen citresewn$redirectConfigScreen(Screen original) { if (openConfig) { openConfig = false; return FabricLoader.getInstance().isModLoaded("cloth-config2") ? diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/GroupResourcePackAccessor.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/GroupResourcePackAccessor.java index 72af871..8263be8 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/GroupResourcePackAccessor.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/GroupResourcePackAccessor.java @@ -4,9 +4,15 @@ 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 shcm.shsupercm.fabric.citresewn.pack.PackParser; import java.util.List; +/** + * Access for individual packs in a grouped resourcepack.<br> + * Used by Fabric API to bundle all mods' resources into a single pack. + * @see PackParser#forEachPack + */ @Mixin(GroupResourcePack.class) public interface GroupResourcePackAccessor { @Accessor 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 ea1d5ab..df11ac9 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java @@ -10,8 +10,15 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import shcm.shsupercm.fabric.citresewn.cit.ActiveCITs; +/** + * Initializes the (re)loading of active cits in the resource manager. + * @see ActiveCITs + */ @Mixin(ModelLoader.class) public class ModelLoaderMixin { + /** + * @see ActiveCITs#load(ResourceManager, Profiler) + */ @Inject(method = "<init>", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/util/profiler/Profiler;push(Ljava/lang/String;)V")) private void citresewn$loadCITs(ResourceManager resourceManager, BlockColors blockColors, Profiler profiler, int i, CallbackInfo ci) { diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/AbstractFileResourcePackMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/AbstractFileResourcePackMixin.java index 9ad7992..b241fff 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/AbstractFileResourcePackMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/AbstractFileResourcePackMixin.java @@ -14,33 +14,43 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import shcm.shsupercm.fabric.citresewn.config.BrokenPaths; import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import java.util.zip.ZipFile; +/** + * Adds a resourcepack compatibility error message when broken paths are enabled and are detected in a pack. + * @see BrokenPaths + * @see ResourcePackCompatibilityMixin + */ @Mixin(AbstractFileResourcePack.class) public abstract class AbstractFileResourcePackMixin implements ResourcePack { @Shadow @Final protected File base; @SuppressWarnings({"unchecked", "ConstantConditions", "EqualsBetweenInconvertibleTypes"}) @Inject(method = "parseMetadata(Lnet/minecraft/resource/metadata/ResourceMetadataReader;)Ljava/lang/Object;", cancellable = true, at = @At("RETURN")) - public <T extends PackResourceMetadata> void parseMetadata(ResourceMetadataReader<T> metaReader, CallbackInfoReturnable<T> cir) { + public <T extends PackResourceMetadata> void citresewn$brokenpaths$parseMetadata(ResourceMetadataReader<T> metaReader, CallbackInfoReturnable<T> cir) { if (cir.getReturnValue() != null) try { if (this.getClass().equals(ZipResourcePack.class)) { try (ZipFile zipFile = new ZipFile(base)) { zipFile.stream() .forEach(entry -> { - if (entry.getName().startsWith("assets")) + if (entry.getName().startsWith("assets") && !entry.getName().endsWith(".DS_Store")) new Identifier("minecraft", entry.getName()); }); } } else if (this.getClass().equals(DirectoryResourcePack.class)) { final Path assets = new File(base, "assets").toPath(); Files.walk(assets) - .forEach(path -> new Identifier("minecraft", assets.relativize(path).toString().replace('\\', '/'))); + .forEach(fullPath -> { + String path = assets.relativize(fullPath).toString().replace('\\', '/'); + if (!path.endsWith(".DS_Store")) + new Identifier("minecraft", path); + }); } } catch (InvalidIdentifierException e) { cir.setReturnValue((T) new PackResourceMetadata(cir.getReturnValue().getDescription(), Integer.MAX_VALUE - 53)); diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/IdentifierMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/IdentifierMixin.java index 0be08f9..0bc36c3 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/IdentifierMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/IdentifierMixin.java @@ -6,13 +6,19 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import shcm.shsupercm.fabric.citresewn.CITResewn; +import shcm.shsupercm.fabric.citresewn.config.BrokenPaths; import static shcm.shsupercm.fabric.citresewn.config.BrokenPaths.processingBrokenPaths; +/** + * Applies broken paths logic when active. + * @see BrokenPaths + * @see ReloadableResourceManagerImplMixin + */ @Mixin(Identifier.class) public class IdentifierMixin { @Inject(method = "isPathValid", cancellable = true, at = @At("RETURN")) - private static void processBrokenPaths(String path, CallbackInfoReturnable<Boolean> cir) { + private static void citresewn$brokenpaths$processBrokenPaths(String path, CallbackInfoReturnable<Boolean> cir) { if (!processingBrokenPaths) return; diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/ReloadableResourceManagerImplMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/ReloadableResourceManagerImplMixin.java index 3f54be3..1d94285 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/ReloadableResourceManagerImplMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/ReloadableResourceManagerImplMixin.java @@ -12,6 +12,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import shcm.shsupercm.fabric.citresewn.CITResewn; +import shcm.shsupercm.fabric.citresewn.config.BrokenPaths; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -19,12 +20,17 @@ import java.util.concurrent.Executor; import static shcm.shsupercm.fabric.citresewn.config.BrokenPaths.processingBrokenPaths; +/** + * Starts/Stops broken paths logic. + * @see BrokenPaths + * @see IdentifierMixin + */ @Mixin(ReloadableResourceManagerImpl.class) public class ReloadableResourceManagerImplMixin { @Shadow @Final private ResourceType type; @Inject(method = "reload", at = @At("RETURN")) - public void onReload(Executor prepareExecutor, Executor applyExecutor, CompletableFuture<Unit> initialStage, List<ResourcePack> packs, CallbackInfoReturnable<ResourceReload> cir) { + public void citresewn$brokenpaths$onReload(Executor prepareExecutor, Executor applyExecutor, CompletableFuture<Unit> initialStage, List<ResourcePack> packs, CallbackInfoReturnable<ResourceReload> cir) { if (processingBrokenPaths = this.type == ResourceType.CLIENT_RESOURCES) { CITResewn.LOG.error("[citresewn] Caution! Broken paths is enabled!"); cir.getReturnValue().whenComplete().thenRun(() -> processingBrokenPaths = false); diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/ResourcePackCompatibilityMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/ResourcePackCompatibilityMixin.java index f187a56..813eb3d 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/ResourcePackCompatibilityMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/ResourcePackCompatibilityMixin.java @@ -7,7 +7,13 @@ import org.spongepowered.asm.mixin.gen.Invoker; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import shcm.shsupercm.fabric.citresewn.config.BrokenPaths; +/** + * Adds a resourcepack compatibility error message when broken paths are enabled and are detected in a pack. + * @see BrokenPaths + * @see AbstractFileResourcePackMixin + */ @Mixin(ResourcePackCompatibility.class) public abstract class ResourcePackCompatibilityMixin { private static final ResourcePackCompatibility BROKEN_PATHS = ResourcePackCompatibility("BROKEN_PATHS", -1, "broken_paths"); @@ -19,7 +25,7 @@ public abstract class ResourcePackCompatibilityMixin { } @Inject(method = "from(ILnet/minecraft/resource/ResourceType;)Lnet/minecraft/resource/ResourcePackCompatibility;", cancellable = true, at = @At("HEAD")) - private static void redirectBrokenPathsCompatibility(int packVersion, ResourceType type, CallbackInfoReturnable<ResourcePackCompatibility> cir) { + private static void citresewn$brokenpaths$redirectBrokenPathsCompatibility(int packVersion, ResourceType type, CallbackInfoReturnable<ResourcePackCompatibility> cir) { if (packVersion == Integer.MAX_VALUE - 53) cir.setReturnValue(BROKEN_PATHS); } 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 4912a71..0375079 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 @@ -1,6 +1,7 @@ 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; @@ -18,7 +19,7 @@ public class PropertiesGroupAdapter extends PropertyGroup { } @Override - public PropertyGroup load(String packName, Identifier identifier, InputStream is) throws IOException { + 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; 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 1f21ed5..8d185fd 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 @@ -7,9 +7,29 @@ import java.io.IOException; import java.io.InputStream; import java.util.*; +/** + * Storage agnostic map of keys and values.<br> + * Keys are stored as {@link PropertyKey}s holding the mod id of the property type.<br> + * A key can have multiple values associated with it as they are stored in an ordered set. + * + * @see PropertyKey + * @see PropertyValue + * @see PropertiesGroupAdapter + */ public abstract class PropertyGroup { + /** + * The internal map that backs this property group. + */ public final Map<PropertyKey, Set<PropertyValue>> properties = new LinkedHashMap<>(); + + /** + * This group's location in its resourcepack. + */ public final Identifier identifier; + + /** + * The file name of the resourcepack that this property group is in. + */ public final String packName; protected PropertyGroup(String packName, Identifier identifier) { @@ -17,17 +37,63 @@ public abstract class PropertyGroup { this.identifier = identifier; } + /** + * Tries to parse a group out of a stream. + * @see #load(String, Identifier, InputStream) + * @see #getExtension() + * @see PropertiesGroupAdapter + * @param packName {@link #packName} + * @param identifier {@link #identifier}, needed for extension matching + * @param is a stream containing properties as specified by implementation + * @return the parsed group or null if could not match an adapter + * @throws IOException if errored while parsing the group + */ + 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); + } + + /** + * @return file suffix for this property group's implementation + */ public abstract String getExtension(); + /** + * Reads the given input stream into the group. + * @param packName {@link #packName} + * @param identifier {@link #identifier} + * @param is a stream containing properties as specified by implementation + * @return this + * @throws IOException if errored while reading the stream + * @throws InvalidIdentifierException if encountered a malformed {@link Identifier} while reading + */ public abstract PropertyGroup load(String packName, Identifier identifier, InputStream is) throws IOException, InvalidIdentifierException; - protected void put(int position, String packName, Identifier propertiesIdentifier, String key, String keyMetadata, PropertySeparator separator, String value) throws InvalidIdentifierException { + /** + * Adds the given value to the group. + * @param position implementation specific interpretation of the value's position in the group, has no effect on internal order + * @param packName the value's resourcepack file name + * @param propertiesIdentifier the value's property group location identifier + * @param key the value's key name + * @param keyMetadata nullable, implementation specific metadata for this value's key + * @param separator implementation specific connection between the key and the value + * @param value string representation of the value to be parsed by the group's user + */ + protected void put(int position, String packName, Identifier propertiesIdentifier, String key, String keyMetadata, PropertySeparator separator, String value) { Objects.requireNonNull(key); Objects.requireNonNull(value); this.properties.computeIfAbsent(PropertyKey.of(key), id -> new LinkedHashSet<>()).add(new PropertyValue(keyMetadata, value, separator, position, propertiesIdentifier, packName)); } + /** + * @param namespace the key's namespace(should be the value type's modid by convention) + * @param pathAliases all key name aliases to check for + * @return all values associated with the given key by alias>insertion order + */ public Set<PropertyValue> get(String namespace, String... pathAliases) { Set<PropertyValue> values = new LinkedHashSet<>(); @@ -40,6 +106,12 @@ public abstract class PropertyGroup { return values; } + /** + * @see #getLastWithoutMetadataOrDefault(String, String, String...) + * @param namespace the key's namespace(should be the value type's modid by convention) + * @param pathAliases all key name aliases to check for + * @return the last value associated with the key(by insertion order) that has a null key metadata or null if the key is not present in the group + */ public PropertyValue getLastWithoutMetadata(String namespace, String... pathAliases) { PropertyValue value = null; for (PropertyValue next : get(namespace, pathAliases)) @@ -49,6 +121,13 @@ public abstract class PropertyGroup { return value; } + /** + * @see #getLastWithoutMetadata(String, String...) + * @param defaultValue the dummy value to return if not present in the group + * @param namespace the key's namespace(should be the value type's modid by convention) + * @param pathAliases all key name aliases to check for + * @return the last value associated with the key(by insertion order) that has a null key metadata or the wrapped default value if the key is not present in the group + */ public PropertyValue getLastWithoutMetadataOrDefault(String defaultValue, String namespace, String... pathAliases) { PropertyValue property = getLastWithoutMetadata(namespace, pathAliases); if (property == null) @@ -57,15 +136,22 @@ public abstract class PropertyGroup { return property; } + /** + * @see #getExtension() + * @see #identifier + * @return the name of this group without its path or extension + */ public String stripName() { return identifier.getPath().substring(identifier.getPath().lastIndexOf('/') + 1, identifier.getPath().length() - getExtension().length()); } - 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); + /** + * Compiles a message with attached info on a value's origin. + * @param message message to add descriptor to + * @param position implementation specific position of + * @return the formatted message + */ + public String messageWithDescriptorOf(String message, int position) { + return message + (position != -1 ? " @L" + position : "") + " in " + this.identifier.toString() + " from " + this.packName; } } 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 index 37a698d..7bc2cdc 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyKey.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertyKey.java @@ -1,6 +1,18 @@ package shcm.shsupercm.fabric.citresewn.pack.format; +import net.minecraft.util.Identifier; + +/** + * Namespace/path pair of strings. Similar to {@link Identifier} but without validity restrictions. + * @see Identifier + */ public record PropertyKey(String namespace, String path) { + /** + * Attempts to split a given string into a namespace and path by the first occurrence of a colon.<br> + * If a namespace cannot be extracted from the given string, "citresewn" is set instead. + * @param key key to parse + * @return parsed property key + */ public static PropertyKey of(String key) { String[] split = new String[] {"citresewn", key}; int i = key.indexOf(':'); diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertySeparator.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertySeparator.java index 612d83f..ce4ebab 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertySeparator.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/format/PropertySeparator.java @@ -1,8 +1,18 @@ package shcm.shsupercm.fabric.citresewn.pack.format; +/** + * Marker for the connection between a {@link PropertyKey} and its {@link PropertyValue}. + */ public enum PropertySeparator { - EQUALS("="); + /** + * Marks either a check for equality or an action to set a value. + */ + EQUALS("=") + ; + /** + * String representation of the separator. + */ public final String separator; PropertySeparator(String separator) { 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 fe126d7..f41119f 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 @@ -2,6 +2,15 @@ package shcm.shsupercm.fabric.citresewn.pack.format; import net.minecraft.util.Identifier; +/** + * Wrapped representation of a property group's value with additional attached metadata. + * @param keyMetadata nullable, implementation specific metadata for this value's key + * @param value string representation of the value to be parsed by the group's user + * @param separator implementation specific connection between the key and the value + * @param position implementation specific interpretation of the value's position in the group, has no effect on internal order + * @param propertiesIdentifier the value's property group location identifier + * @param packName the value's resourcepack file name + */ public record PropertyValue(String keyMetadata, String value, PropertySeparator separator, |