diff options
author | SHsuperCM <shsupercm@gmail.com> | 2022-03-04 19:20:40 +0200 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2022-03-04 19:20:40 +0200 |
commit | b8b6fff68c3f24a1f4df9de0ea4170cfc3b0f619 (patch) | |
tree | f54986b0ce77aa3a993bf32b0951bc752787d66f /src/main/java/shcm/shsupercm/fabric/citresewn/pack | |
parent | d0bceef6b9287184f3d97c68f0429c86538d68eb (diff) | |
download | CITResewn-b8b6fff68c3f24a1f4df9de0ea4170cfc3b0f619.tar.gz CITResewn-b8b6fff68c3f24a1f4df9de0ea4170cfc3b0f619.tar.bz2 CITResewn-b8b6fff68c3f24a1f4df9de0ea4170cfc3b0f619.zip |
Documentation (4/44, 0/35)
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric/citresewn/pack')
-rw-r--r-- | src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java | 11 | ||||
-rw-r--r-- | src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java | 41 |
2 files changed, 49 insertions, 3 deletions
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 456faab..6788b1d 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java @@ -2,6 +2,7 @@ package shcm.shsupercm.fabric.citresewn.pack; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.entrypoint.EntrypointContainer; +import net.minecraft.resource.ResourceManager; import net.minecraft.util.Identifier; import net.minecraft.util.InvalidIdentifierException; import shcm.shsupercm.fabric.citresewn.CITResewn; @@ -16,6 +17,10 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; +/** + * Property group representation of the global cit.properties file. + * @see PackParser#loadGlobalProperties(ResourceManager, GlobalProperties) + */ public class GlobalProperties extends PropertyGroup { public GlobalProperties() { super("global_properties", new Identifier("citresewn", "global_properties")); @@ -36,6 +41,12 @@ public class GlobalProperties extends PropertyGroup { return this; } + /** + * Calls all {@link CITGlobalProperties} handler entrypoints for every global property they're associated with.<br> + * Global properties are matched to their entrypoints by mod id and it's the handler responsibility to filter the properties. + * + * @see CITGlobalProperties + */ public void callHandlers() { for (EntrypointContainer<CITGlobalProperties> container : FabricLoader.getInstance().getEntrypointContainers(CITGlobalProperties.ENTRYPOINT, CITGlobalProperties.class)) { String containerNamespace = container.getProvider().getMetadata().getId(); 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 794977d..eab7e46 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java @@ -25,14 +25,29 @@ import java.util.Set; import java.util.function.Consumer; import java.util.function.Function; -public class PackParser { +/** + * Utility parsing methods for packs. + */ +public final class PackParser { private PackParser() {} + /** + * Possible CIT roots in resourcepacks ordered in ascending order of priority. + */ private static final String[] ROOTS = new String[] { "mcpatcher", "optifine", "citresewn" }; + + /** + * Gets all resourcepacks from {@link GroupResourcePack} or null if not a group or Fabric API is not present. + */ 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) { + /** + * Iterates over each loaded pack taking into account grouped packs. + * @param resourceManager the manager that contains the packs + * @param run resourcepack pack consumer + */ + public static void forEachPack(ResourceManager resourceManager, Consumer<ResourcePack> run) { resourceManager.streamResourcePacks().forEachOrdered(pack -> { List<ResourcePack> grouped = PARSE_FAPI_GROUPS.apply(pack); if (grouped != null) @@ -43,6 +58,14 @@ public class PackParser { }); } + /** + * Loads a merged global property group from loaded packs making sure to respect order. + * + * @see GlobalProperties#callHandlers() + * @param resourceManager the manager that contains the packs + * @param globalProperties global property group to parse into + * @return globalProperties + */ public static GlobalProperties loadGlobalProperties(ResourceManager resourceManager, GlobalProperties globalProperties) { forEachPack(resourceManager, pack -> { for (String root : ROOTS) { @@ -59,7 +82,12 @@ public class PackParser { return globalProperties; } - public static List<CIT<?>> loadCITs(ResourceManager resourceManager) { + /** + * Attempts parsing all CITs out of all loaded packs. + * @param resourceManager the manager that contains the packs + * @return unordered list of successfully parsed CITs + */ + public static List<CIT<?>> parseCITs(ResourceManager resourceManager) { List<CIT<?>> cits = new ArrayList<>(); for (String root : ROOTS) @@ -78,6 +106,13 @@ public class PackParser { return cits; } + /** + * Attempts parsing a CIT from a property group. + * @param properties property group representation of the CIT + * @param resourceManager the manager that contains the the property group, used to resolve relative assets + * @return the successfully parsed CIT + * @throws CITParsingException if the CIT failed parsing for any reason + */ public static CIT<?> parseCIT(PropertyGroup properties, ResourceManager resourceManager) throws CITParsingException { CITType citType = CITRegistry.parseType(properties); |