diff options
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric/citresewn/api')
4 files changed, 95 insertions, 1 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITConditionContainer.java b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITConditionContainer.java index 56ac01f..886185c 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITConditionContainer.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITConditionContainer.java @@ -1,13 +1,37 @@ package shcm.shsupercm.fabric.citresewn.api; import shcm.shsupercm.fabric.citresewn.cit.CITCondition; +import shcm.shsupercm.fabric.citresewn.cit.CITRegistry; import java.util.function.Supplier; +/** + * Wrapper to facilitate metadata, registry and creation of condition class types. + * @see #ENTRYPOINT + * @see CITRegistry + */ public class CITConditionContainer<T extends CITCondition> { + /** + * Entrypoint for container singletons, usually kept as a static final field in the condition type's class. + */ public static final String ENTRYPOINT = "citresewn:condition"; + + /** + * Associated condition's class. + */ public final Class<T> condition; + + /** + * Method reference to the condition's constructor or any other supplier of new condition instances. + */ public final Supplier<T> createCondition; + + /** + * Possible names in property groups for the associated condition type.<br> + * Condition names are declared in groups with a mod id prefix to avoid conflicts with other 3rd party + * properties(formatted as "modid:alias").<br> + * If a modid is not declared, defaults to "citresewn" which is handled by CIT Resewn: Defaults. + */ public final String[] aliases; public CITConditionContainer(Class<T> condition, Supplier<T> createCondition, String... aliases) { diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITDisposable.java b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITDisposable.java index 240f197..dec7098 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITDisposable.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITDisposable.java @@ -1,8 +1,18 @@ package shcm.shsupercm.fabric.citresewn.api; +/** + * @see #dispose() + */ @FunctionalInterface public interface CITDisposable { + /** + * Entrypoint for any disposing method that is not covered by CIT Resewn automatically. + * @see #dispose() + */ String ENTRYPOINT = "citresewn:dispose"; + /** + * Invoked just before reloading CITs. Use to clean up and changes CIT loading made. + */ void dispose(); } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java index ada5147..a3d78ae 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java @@ -2,9 +2,24 @@ package shcm.shsupercm.fabric.citresewn.api; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; +/** + * @see #globalProperty(String, PropertyValue) + */ @FunctionalInterface public interface CITGlobalProperties { + /** + * Entrypoint for handlers of global properties. + * @see #globalProperty(String, PropertyValue) + */ String ENTRYPOINT = "citresewn:global_property"; + /** + * Invoked before CIT parsing for any global property name associated with the handler's modid.<br> + * May be called multiple times for a key to overwrite its global property with higher-priority resourcepacks.<br> + * Handlers should take care to reset back any changes global properties make by listening to CIT disposal. + * @see CITDisposable#dispose() + * @param key name of the property key stripped of its modid + * @param value the value it's been set to + */ void globalProperty(String key, PropertyValue value) throws Exception; } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java index 5aa727d..b49b4a6 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java @@ -3,17 +3,43 @@ package shcm.shsupercm.fabric.citresewn.api; import shcm.shsupercm.fabric.citresewn.cit.ActiveCITs; import shcm.shsupercm.fabric.citresewn.cit.CIT; import shcm.shsupercm.fabric.citresewn.cit.CITType; +import shcm.shsupercm.fabric.citresewn.cit.CITRegistry; import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; import java.util.List; import java.util.function.Supplier; +/** + * Wrapper to facilitate metadata, registry and creation of CIT types. + * @see #ENTRYPOINT + * @see CITRegistry + */ public abstract class CITTypeContainer<T extends CITType> implements CITDisposable { - public static final String ENTRYPOINT = "citresewn:type"; + /** + * Entrypoint for container singletons, usually kept as a static final field in the type's class. + */ + public static final String ENTRYPOINT = "citresewn:type"; + + /** + * Associated type's class. + */ public final Class<T> type; + + /** + * Method reference to the type's constructor or any other supplier of new CIT type instances. + */ public final Supplier<T> createType; + + /** + * Identifier for this type to be used in the "type=" property.<br> + * When used in property groups the type's modid must be added to avoid conflicts with other + * 3rd party types(formatted as "modid:id"). + */ public final String id; + /** + * True when the container should not have any CITs loaded. + */ protected boolean empty = true; public CITTypeContainer(Class<T> type, Supplier<T> createType, String id) { @@ -22,8 +48,16 @@ public abstract class CITTypeContainer<T extends CITType> implements CITDisposab this.id = id; } + /** + * Loads and keeps a copy of loaded CITs of this container's type. + * @param parsedCITs all loaded CITs of this container's type ordered by weight>path + */ protected abstract void load(List<CIT<T>> parsedCITs); + /** + * Loads and keeps a copy of loaded CITs of this container's type. + * @param parsedCITs all loaded CITs of this container's type ordered by weight>path + */ @SuppressWarnings("unchecked") public final void loadUntyped(List<?> parsedCITs) { if (!parsedCITs.isEmpty()) @@ -31,11 +65,22 @@ public abstract class CITTypeContainer<T extends CITType> implements CITDisposab load((List<CIT<T>>) parsedCITs); } + /** + * Unloads CITs from this container.<br> + * Override dispose() to add more logic. + * @see CITDisposable#dispose() + */ public final void unload() { dispose(); empty = true; } + /** + * @see #empty + * @see CITResewnConfig#enabled + * @see ActiveCITs#isActive() + * @return whether this container's associated type should work or not + */ public boolean active() { return !empty && CITResewnConfig.INSTANCE.enabled && ActiveCITs.isActive(); } |