aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2022-03-04 19:20:40 +0200
committerSHsuperCM <shsupercm@gmail.com>2022-03-04 19:20:40 +0200
commitb8b6fff68c3f24a1f4df9de0ea4170cfc3b0f619 (patch)
treef54986b0ce77aa3a993bf32b0951bc752787d66f
parentd0bceef6b9287184f3d97c68f0429c86538d68eb (diff)
downloadCITResewn-b8b6fff68c3f24a1f4df9de0ea4170cfc3b0f619.tar.gz
CITResewn-b8b6fff68c3f24a1f4df9de0ea4170cfc3b0f619.tar.bz2
CITResewn-b8b6fff68c3f24a1f4df9de0ea4170cfc3b0f619.zip
Documentation (4/44, 0/35)
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java17
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/CITResewnCommand.java30
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java2
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/GlobalProperties.java11
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java41
5 files changed, 91 insertions, 10 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java
index 79e49aa..7d4be88 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java
@@ -8,6 +8,9 @@ import org.apache.logging.log4j.Logger;
import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig;
import shcm.shsupercm.fabric.citresewn.cit.CITRegistry;
+/**
+ * Main initializer for CIT Resewn. Contains various internal utilities(just logging for now).
+ */
public class CITResewn implements ClientModInitializer {
public static final Logger LOG = LogManager.getLogger("CITResewn");
@Entrypoint(Entrypoint.CLIENT)
@@ -21,16 +24,30 @@ public class CITResewn implements ClientModInitializer {
CITResewnCommand.register();
}
+ /**
+ * Logs an info line in CIT Resewn's name.
+ * @param message log message
+ */
public static void info(String message) {
LOG.info("[citresewn] " + message);
}
+ /**
+ * Logs a warning line in CIT Resewn's name if enabled in config.
+ * @see CITResewnConfig#mute_warns
+ * @param message warn message
+ */
public static void logWarnLoading(String message) {
if (CITResewnConfig.INSTANCE.mute_warns)
return;
LOG.error("[citresewn] " + message);
}
+ /**
+ * Logs an error line in CIT Resewn's name if enabled in config.
+ * @see CITResewnConfig#mute_errors
+ * @param message error message
+ */
public static void logErrorLoading(String message) {
if (CITResewnConfig.INSTANCE.mute_errors)
return;
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewnCommand.java b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewnCommand.java
index 01c08bf..6583cd8 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewnCommand.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewnCommand.java
@@ -24,12 +24,27 @@ import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.arg
import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.literal;
import static net.minecraft.text.Text.of;
+/**
+ * Logic for the /citresewn client command. Only enabled when Fabric API is present.<br>
+ * Structure:
+ * <pre>
+ * /citresewn - General info command
+ * /citresewn config - Opens the config gui(only when Cloth Config is present)
+ * /citresewn analyze pack &lt;pack&gt; - Displays data for the given loaded cit pack.
+ * </pre>
+ */
public class CITResewnCommand {
+ /**
+ * @see shcm.shsupercm.fabric.citresewn.mixin.ChatScreenMixin
+ */
public static boolean openConfig = false;
- public static void register() {
+ /**
+ * Registers
+ */
+ static void register() {
ClientCommandManager.DISPATCHER.register(literal("citresewn")
- .executes(context -> {
+ .executes(context -> { //citresewn
context.getSource().sendFeedback(of("CIT Resewn v" + FabricLoader.getInstance().getModContainer("citresewn").orElseThrow().getMetadata().getVersion() + ":"));
context.getSource().sendFeedback(of(" Registered: " + CITRegistry.TYPES.values().stream().distinct().count() + " types and " + CITRegistry.CONDITIONS.values().stream().distinct().count() + " conditions"));
@@ -43,15 +58,15 @@ public class CITResewnCommand {
return 1;
})
.then(literal("config")
- .executes(context -> {
+ .executes(context -> { //citresewn config
openConfig = true;
return 1;
}))
.then(literal("analyze")
.then(literal("pack")
- .then(argument("pack", new CITPackArgument())
- .executes(context -> {
+ .then(argument("pack", new LoadedCITPackArgument())
+ .executes(context -> { //citresewn analyze <pack>
final String pack = context.getArgument("pack", String.class);
if (ActiveCITs.isActive()) {
context.getSource().sendFeedback(of("Analyzed CIT data of \"" + pack + "\u00a7r\":"));
@@ -102,7 +117,10 @@ public class CITResewnCommand {
);
}
- private static class CITPackArgument implements ArgumentType<String> {
+ /**
+ * Greedy string argument that is limited to cit pack names loaded in {@link shcm.shsupercm.fabric.citresewn.cit.ActiveCITs}.
+ */
+ private static class LoadedCITPackArgument implements ArgumentType<String> {
@Override
public String parse(StringReader reader) throws CommandSyntaxException {
StringBuilder builder = new StringBuilder();
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java
index 2c31641..57d34c3 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/ActiveCITs.java
@@ -44,7 +44,7 @@ public class ActiveCITs implements CITDisposable { private ActiveCITs() {}
PackParser.loadGlobalProperties(resourceManager, active.globalProperties).callHandlers();
profiler.swap("citresewn:load_cits");
- List<CIT<?>> cits = PackParser.loadCITs(resourceManager);
+ List<CIT<?>> cits = PackParser.parseCITs(resourceManager);
for (CIT<?> cit : cits)
active.cits.computeIfAbsent(cit.type.getClass(), type -> new ArrayList<>()).add(cit);
for (Map.Entry<Class<? extends CITType>, List<CIT<?>>> entry : active.cits.entrySet()) {
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);