aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2022-03-06 17:07:48 +0200
committerSHsuperCM <shsupercm@gmail.com>2022-03-06 17:07:48 +0200
commit526a5f1da2354d328be10c4d6d2f58b3b73e0d20 (patch)
tree1e911f85783395436db570a465bd78a8e6f7fc39 /src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin
parentbb9dcef4b53d201cf4bcac3bf88d2042a1ce226c (diff)
downloadCITResewn-526a5f1da2354d328be10c4d6d2f58b3b73e0d20.tar.gz
CITResewn-526a5f1da2354d328be10c4d6d2f58b3b73e0d20.tar.bz2
CITResewn-526a5f1da2354d328be10c4d6d2f58b3b73e0d20.zip
Documentation (44/44, 0/35)
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin')
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/BooleanCondition.java13
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ConstantCondition.java6
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/DoubleCondition.java27
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/EnumCondition.java27
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/FloatCondition.java27
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/IdentifierCondition.java13
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/IntegerCondition.java27
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ListCondition.java39
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/LongCondition.java27
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/WeightCondition.java5
10 files changed, 199 insertions, 12 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/BooleanCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/BooleanCondition.java
index 62f1da1..989318f 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/BooleanCondition.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/BooleanCondition.java
@@ -6,11 +6,22 @@ import shcm.shsupercm.fabric.citresewn.ex.CITParsingException;
import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup;
import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue;
+/**
+ * Common condition parser for booleans.
+ */
public abstract class BooleanCondition extends CITCondition {
+ /**
+ * Parsed boolean.
+ */
protected boolean value;
+ /**
+ * Converts the given context to a boolean to compare the parsed value to.
+ * @param context context to retrieve the compared value from
+ * @return the boolean value associated with the given context
+ */
protected boolean getValue(CITContext context) {
- throw new AssertionError();
+ throw new AssertionError("Not implemented by this condition");
}
@Override
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ConstantCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ConstantCondition.java
index 081c2d8..5bc9354 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ConstantCondition.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ConstantCondition.java
@@ -6,7 +6,13 @@ import shcm.shsupercm.fabric.citresewn.ex.CITParsingException;
import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup;
import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue;
+/**
+ * Common condition type with no parsing for constant true/false testing output.
+ */
public class ConstantCondition extends CITCondition {
+ /**
+ * What testing contexts will always result in.
+ */
public final boolean value;
public ConstantCondition(boolean value) {
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/DoubleCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/DoubleCondition.java
index 0f392d4..44bb906 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/DoubleCondition.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/DoubleCondition.java
@@ -8,10 +8,23 @@ import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue;
import static java.lang.Double.*;
+/**
+ * Common condition parser for doubles with optional support for ranges, negatives and percentages.
+ */
public abstract class DoubleCondition extends CITCondition {
+ /**
+ * Whether this condition should accept given ranges/negatives/percentages.
+ */
protected final boolean supportsRanges, supportsNegatives, supportsPercentages;
+ /**
+ * If ranges are accepted, parsed minimum/maximum double. If not, minimum is the parsed value.
+ */
protected double min, max;
+
+ /**
+ * Whether the parsed value is a range/percentage.
+ */
protected boolean range = false, percentage = false;
protected DoubleCondition(boolean supportsRanges, boolean supportsNegatives, boolean supportsPercentages) {
@@ -20,12 +33,22 @@ public abstract class DoubleCondition extends CITCondition {
this.supportsPercentages = supportsPercentages;
}
+ /**
+ * Converts the given context to a double to compare the parsed value to.
+ * @param context context to retrieve the compared value from
+ * @return the double value associated with the given context
+ */
protected double getValue(CITContext context) {
- throw new AssertionError();
+ throw new AssertionError("Not implemented by this condition");
}
+ /**
+ * Converts the given context to a max double to be used when percentages are enabled.
+ * @param context context to retrieve the max value from
+ * @return the max double value associated with the given context
+ */
protected double getPercentageTotalValue(CITContext context) {
- throw new AssertionError();
+ throw new AssertionError("Not implemented by this condition");
}
@Override
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/EnumCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/EnumCondition.java
index 56f5fb7..ed69fed 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/EnumCondition.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/EnumCondition.java
@@ -8,14 +8,33 @@ import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue;
import java.util.function.Supplier;
+/**
+ * Common condition parser for enum values.
+ * @see EnumCondition.Aliased
+ */
public abstract class EnumCondition<T extends Enum<? extends EnumCondition.Aliased>> extends CITCondition {
+ /**
+ * Fetches the all of the enum's parsable values.
+ */
protected final Supplier<T[]> values;
+
+ /**
+ * Should letter casing be ignored when parsing the enum value. (default true)
+ */
protected final boolean ignoreCase;
+ /**
+ * Parsed enum value.
+ */
protected T value;
+ /**
+ * Converts the given context to an enum value to compare the parsed value to.
+ * @param context context to retrieve the compared value from
+ * @return the enum value associated with the given context
+ */
protected T getValue(CITContext context) {
- throw new AssertionError();
+ throw new AssertionError("Not implemented by this condition");
}
protected EnumCondition(Supplier<T[]> values, boolean ignoreCase) {
@@ -44,7 +63,13 @@ public abstract class EnumCondition<T extends Enum<? extends EnumCondition.Alias
return getValue(context) == this.value;
}
+ /**
+ * Gives implementing enums the ability to have multiple aliased names for parsing.
+ */
public interface Aliased {
+ /**
+ * @return all possible names for this enum value
+ */
default String[] getAliases() {
return new String[] { ((Enum<?>) this).name() };
}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/FloatCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/FloatCondition.java
index afc3954..aadaa76 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/FloatCondition.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/FloatCondition.java
@@ -8,10 +8,23 @@ import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue;
import static java.lang.Float.*;
+/**
+ * Common condition parser for floats with optional support for ranges, negatives and percentages.
+ */
public abstract class FloatCondition extends CITCondition {
+ /**
+ * Whether this condition should accept given ranges/negatives/percentages.
+ */
protected final boolean supportsRanges, supportsNegatives, supportsPercentages;
+ /**
+ * If ranges are accepted, parsed minimum/maximum float. If not, minimum is the parsed value.
+ */
protected float min, max;
+
+ /**
+ * Whether the parsed value is a range/percentage.
+ */
protected boolean range = false, percentage = false;
protected FloatCondition(boolean supportsRanges, boolean supportsNegatives, boolean supportsPercentages) {
@@ -20,12 +33,22 @@ public abstract class FloatCondition extends CITCondition {
this.supportsPercentages = supportsPercentages;
}
+ /**
+ * Converts the given context to a float to compare the parsed value to.
+ * @param context context to retrieve the compared value from
+ * @return the float value associated with the given context
+ */
protected float getValue(CITContext context) {
- throw new AssertionError();
+ throw new AssertionError("Not implemented by this condition");
}
+ /**
+ * Converts the given context to a max float to be used when percentages are enabled.
+ * @param context context to retrieve the max value from
+ * @return the max float value associated with the given context
+ */
protected float getPercentageTotalValue(CITContext context) {
- throw new AssertionError();
+ throw new AssertionError("Not implemented by this condition");
}
@Override
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/IdentifierCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/IdentifierCondition.java
index 0df5330..4d04b76 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/IdentifierCondition.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/IdentifierCondition.java
@@ -8,11 +8,22 @@ import shcm.shsupercm.fabric.citresewn.ex.CITParsingException;
import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup;
import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue;
+/**
+ * Common condition parser for identifiers.
+ */
public abstract class IdentifierCondition extends CITCondition {
+ /**
+ * Parsed identifier.
+ */
protected Identifier value;
+ /**
+ * Converts the given context to an identifier to compare the parsed value to.
+ * @param context context to retrieve the compared value from
+ * @return the identifier value associated with the given context
+ */
protected Identifier getValue(CITContext context) {
- throw new AssertionError();
+ throw new AssertionError("Not implemented by this condition");
}
@Override
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/IntegerCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/IntegerCondition.java
index 13c87c6..80937f5 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/IntegerCondition.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/IntegerCondition.java
@@ -8,10 +8,23 @@ import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue;
import static java.lang.Integer.*;
+/**
+ * Common condition parser for integers with optional support for ranges, negatives and percentages.
+ */
public abstract class IntegerCondition extends CITCondition {
+ /**
+ * Whether this condition should accept given ranges/negatives/percentages.
+ */
protected final boolean supportsRanges, supportsNegatives, supportsPercentages;
+ /**
+ * If ranges are accepted, parsed minimum/maximum integers. If not, minimum is the parsed value.
+ */
protected int min, max;
+
+ /**
+ * Whether the parsed value is a range/percentage.
+ */
protected boolean range = false, percentage = false;
protected IntegerCondition(boolean supportsRanges, boolean supportsNegatives, boolean supportsPercentages) {
@@ -20,12 +33,22 @@ public abstract class IntegerCondition extends CITCondition {
this.supportsPercentages = supportsPercentages;
}
+ /**
+ * Converts the given context to an integer to compare the parsed value to.
+ * @param context context to retrieve the compared value from
+ * @return the integer value associated with the given context
+ */
protected int getValue(CITContext context) {
- throw new AssertionError();
+ throw new AssertionError("Not implemented by this condition");
}
+ /**
+ * Converts the given context to a max integer to be used when percentages are enabled.
+ * @param context context to retrieve the max value from
+ * @return the max integer value associated with the given context
+ */
protected int getPercentageTotalValue(CITContext context) {
- throw new AssertionError();
+ throw new AssertionError("Not implemented by this condition");
}
@Override
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ListCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ListCondition.java
index 3b9a264..e264b27 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ListCondition.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ListCondition.java
@@ -12,14 +12,39 @@ import java.util.List;
import java.util.function.Supplier;
import java.util.regex.Pattern;
+/**
+ * Common condition parser for multiple values separated by any regex expression.
+ */
public abstract class ListCondition<T extends CITCondition> extends CITCondition {
- private static final Pattern PATTERN_WHITESPACE = Pattern.compile("\\p{Zs}+");
+ /**
+ * Regex pattern for any amount of whitespace.
+ */
+ public static final Pattern PATTERN_WHITESPACE = Pattern.compile("\\p{Zs}+");
+ /**
+ * Enum class type associated with this condition.
+ */
private final Class<T> conditionType;
+
+ /**
+ * Determines how testing the conditions should work(either in OR checks or AND checks).
+ * @see ListCondition.Type
+ */
protected final Type listType;
+
+ /**
+ * Regex pattern to use to separate given input into conditions.
+ */
protected final Pattern delimiter;
+
+ /**
+ * Constructor for new parsed conditions.
+ */
protected final Supplier<T> conditionSupplier;
+ /**
+ * Parsed conditions.
+ */
protected T[] conditions;
protected ListCondition(Class<T> conditionType, Type listType, Pattern delimiter, Supplier<T> conditionSupplier) {
@@ -52,7 +77,13 @@ public abstract class ListCondition<T extends CITCondition> extends CITCondition
return listType.test(conditions, context);
}
+ /**
+ * Provides OR and AND gates for all of the list's conditions.
+ */
public enum Type {
+ /**
+ * Testing passes if any of the conditions pass and fails otherwise.
+ */
OR {
@Override
public boolean test(CITCondition[] conditions, CITContext context) {
@@ -63,6 +94,9 @@ public abstract class ListCondition<T extends CITCondition> extends CITCondition
return false;
}
},
+ /**
+ * Testing passes if all of the conditions pass and fails otherwise.
+ */
AND {
@Override
public boolean test(CITCondition[] conditions, CITContext context) {
@@ -74,6 +108,9 @@ public abstract class ListCondition<T extends CITCondition> extends CITCondition
}
};
+ /**
+ * Tests the given context against all of the conditions.
+ */
public abstract boolean test(CITCondition[] conditions, CITContext context);
}
}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/LongCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/LongCondition.java
index 97f58b5..da68bd8 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/LongCondition.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/LongCondition.java
@@ -8,10 +8,23 @@ import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue;
import static java.lang.Long.*;
+/**
+ * Common condition parser for longs with optional support for ranges, negatives and percentages.
+ */
public abstract class LongCondition extends CITCondition {
+ /**
+ * Whether this condition should accept given ranges/negatives/percentages.
+ */
protected final boolean supportsRanges, supportsNegatives, supportsPercentages;
+ /**
+ * If ranges are accepted, parsed minimum/maximum longs. If not, minimum is the parsed value.
+ */
protected long min, max;
+
+ /**
+ * Whether the parsed value is a range/percentage.
+ */
protected boolean range = false, percentage = false;
protected LongCondition(boolean supportsRanges, boolean supportsNegatives, boolean supportsPercentages) {
@@ -20,12 +33,22 @@ public abstract class LongCondition extends CITCondition {
this.supportsPercentages = supportsPercentages;
}
+ /**
+ * Converts the given context to a long to compare the parsed value to.
+ * @param context context to retrieve the compared value from
+ * @return the long value associated with the given context
+ */
protected long getValue(CITContext context) {
- throw new AssertionError();
+ throw new AssertionError("Not implemented by this condition");
}
+ /**
+ * Converts the given context to a max long to be used when percentages are enabled.
+ * @param context context to retrieve the max value from
+ * @return the max llong value associated with the given context
+ */
protected long getPercentageTotalValue(CITContext context) {
- throw new AssertionError();
+ throw new AssertionError("Not implemented by this condition");
}
@Override
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/WeightCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/WeightCondition.java
index 2e887d6..a53e019 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/WeightCondition.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/WeightCondition.java
@@ -8,6 +8,11 @@ import shcm.shsupercm.fabric.citresewn.cit.CITContext;
import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup;
import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue;
+/**
+ * Internal condition used to determine the priority CITs get tested in.<br>
+ * Weights default to 0 and higher weights get chosen over lower weights.<br>
+ * When two conflicting CITs have the same weight, their path in the resourcepack is used as a tie breaker.
+ */
public class WeightCondition extends IntegerCondition {
@Entrypoint(CITConditionContainer.ENTRYPOINT)
public static final CITConditionContainer<WeightCondition> CONTAINER = new CITConditionContainer<>(WeightCondition.class, WeightCondition::new,