aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/shcm/shsupercm/fabric/citresewn/api
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2022-03-18 11:35:53 +0200
committerSHsuperCM <shsupercm@gmail.com>2022-03-18 11:35:53 +0200
commitb37f3b9f93f7be977ae615cdd12179afb8ed9e53 (patch)
tree414672652720ef445a53c313fc8dd7979ea223c0 /src/main/java/shcm/shsupercm/fabric/citresewn/api
parentbcff029a6135511254ee16f615352d3279020d61 (diff)
parentd93d0cf00dc07d3e8b4534d4f6247afcc85232ef (diff)
downloadCITResewn-b37f3b9f93f7be977ae615cdd12179afb8ed9e53.tar.gz
CITResewn-b37f3b9f93f7be977ae615cdd12179afb8ed9e53.tar.bz2
CITResewn-b37f3b9f93f7be977ae615cdd12179afb8ed9e53.zip
Merge branch 'v1-rewrite'
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric/citresewn/api')
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/api/CITConditionContainer.java42
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/api/CITDisposable.java18
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java26
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java87
4 files changed, 173 insertions, 0 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
new file mode 100644
index 0000000..886185c
--- /dev/null
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITConditionContainer.java
@@ -0,0 +1,42 @@
+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) {
+ this.condition = condition;
+ this.createCondition = createCondition;
+ this.aliases = 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
new file mode 100644
index 0000000..dec7098
--- /dev/null
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITDisposable.java
@@ -0,0 +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
new file mode 100644
index 0000000..05495af
--- /dev/null
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java
@@ -0,0 +1,26 @@
+package shcm.shsupercm.fabric.citresewn.api;
+
+import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue;
+
+import javax.annotation.Nullable;
+
+/**
+ * @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>
+ * When unloading resourcepacks(usually before reloading), all keys that were invoked in the previous load will get called again with a null value to allow for disposal.
+ * @param key name of the property key stripped of its modid
+ * @param value the value it's been set to or null if resetting
+ */
+ void globalProperty(String key, @Nullable 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
new file mode 100644
index 0000000..b49b4a6
--- /dev/null
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITTypeContainer.java
@@ -0,0 +1,87 @@
+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 {
+ /**
+ * 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) {
+ this.type = type;
+ this.createType = createType;
+ 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())
+ empty = false;
+ 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();
+ }
+}