diff options
author | SHsuperCM <shsupercm@gmail.com> | 2022-03-05 18:44:04 +0200 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2022-03-06 05:22:00 +0200 |
commit | bb9dcef4b53d201cf4bcac3bf88d2042a1ce226c (patch) | |
tree | da5b4cd93e1514dea69495826b2a187cb7c0b946 /src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITRegistry.java | |
parent | 09792f49ee89c6b4ff37464acec4b94b3f9f370b (diff) | |
download | CITResewn-bb9dcef4b53d201cf4bcac3bf88d2042a1ce226c.tar.gz CITResewn-bb9dcef4b53d201cf4bcac3bf88d2042a1ce226c.tar.bz2 CITResewn-bb9dcef4b53d201cf4bcac3bf88d2042a1ce226c.zip |
Documentation (29/44, 0/35)
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITRegistry.java')
-rw-r--r-- | src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITRegistry.java | 54 |
1 files changed, 52 insertions, 2 deletions
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 d8454a0..bf7c2ca 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITRegistry.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITRegistry.java @@ -7,6 +7,7 @@ import shcm.shsupercm.fabric.citresewn.api.CITTypeContainer; import shcm.shsupercm.fabric.citresewn.cit.builtin.conditions.ConstantCondition; import shcm.shsupercm.fabric.citresewn.ex.CITParsingException; import shcm.shsupercm.fabric.citresewn.ex.UnknownCITTypeException; +import shcm.shsupercm.fabric.citresewn.pack.PackParser; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyKey; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; @@ -16,13 +17,38 @@ import java.util.*; import static shcm.shsupercm.fabric.citresewn.CITResewn.info; import static shcm.shsupercm.fabric.citresewn.CITResewn.logWarnLoading; -public class CITRegistry { +/** + * Holds a static registry runtime for all types and conditions. + * @see PackParser + * @see CITTypeContainer + * @see CITConditionContainer + */ +public final class CITRegistry { private CITRegistry(){} + /** + * Currently registered CIT types. + */ public static final Map<Identifier, CITTypeContainer<? extends CITType>> TYPES = new HashMap<>(); + /** + * Currently registered condition types. + */ public static final Map<PropertyKey, CITConditionContainer<? extends CITCondition>> CONDITIONS = new HashMap<>(); + /** + * Fast id lookup map for types. + * @see #idOfType(Class) + */ private static final Map<Class<? extends CITType>, Identifier> TYPE_TO_ID = new IdentityHashMap<>(); + /** + * Fast id lookup map for conditions. + * @see #idOfCondition(Class) + */ private static final Map<Class<? extends CITCondition>, PropertyKey> CONDITION_TO_ID = new IdentityHashMap<>(); + /** + * Loads all available CIT and condition types to registry. (internal use only) + * @see CITTypeContainer + * @see CITConditionContainer + */ public static void registerAll() { info("Registering CIT Conditions"); for (var entrypointContainer : FabricLoader.getInstance().getEntrypointContainers(CITConditionContainer.ENTRYPOINT, CITConditionContainer.class)) { @@ -53,6 +79,15 @@ public class CITRegistry { } } + /** + * Parses a condition from the given property.<br> + * + * @param key the condition's key in the group + * @param value the condition's value + * @param properties the containing property group + * @return the parsed condition or an always-failing {@link ConstantCondition} if unrecognized + * @throws CITParsingException if errored while parsing hte condition + */ public static CITCondition parseCondition(PropertyKey key, PropertyValue value, PropertyGroup properties) throws CITParsingException { CITConditionContainer<? extends CITCondition> conditionContainer = CONDITIONS.get(key); if (conditionContainer == null) { @@ -65,7 +100,14 @@ public class CITRegistry { return condition; } - public static CITType parseType(PropertyGroup properties) throws CITParsingException { + /** + * Parses a CIT type from the given property group.<br> + * If the group does not contain a "citresewn:type" property, defaults to "citresewn:item". + * @param properties group of properties to parse the CIT type from + * @return a new instance of the group's CIT type + * @throws UnknownCITTypeException if the given type is unrecognized in the registry + */ + public static CITType parseType(PropertyGroup properties) throws UnknownCITTypeException { Identifier type = new Identifier("citresewn", "item"); PropertyValue propertiesType = properties.getLastWithoutMetadata("citresewn", "type"); @@ -84,10 +126,18 @@ public class CITRegistry { return typeContainer.createType.get(); } + /** + * @see #TYPE_TO_ID + * @return the id of the given CIT type's class. + */ public static Identifier idOfType(Class<? extends CITType> clazz) { return TYPE_TO_ID.get(clazz); } + /** + * @see #CONDITION_TO_ID + * @return the first key of the given condition's class. + */ public static PropertyKey idOfCondition(Class<? extends CITCondition> clazz) { return CONDITION_TO_ID.get(clazz); } |