aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/shcm/shsupercm/fabric/citresewn
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2022-03-25 11:51:59 +0300
committerSHsuperCM <shsupercm@gmail.com>2022-03-25 11:51:59 +0300
commit0484498863626dc57d55d381b7b394b5cc9234c2 (patch)
treec2329a89ac1ebdae17822b88a8c2ab5429d4086f /src/main/java/shcm/shsupercm/fabric/citresewn
parent162f9b7cf8ae24c950673a32e695e59e4e807f39 (diff)
downloadCITResewn-0484498863626dc57d55d381b7b394b5cc9234c2.tar.gz
CITResewn-0484498863626dc57d55d381b7b394b5cc9234c2.tar.bz2
CITResewn-0484498863626dc57d55d381b7b394b5cc9234c2.zip
Cleanup with built in conditions
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric/citresewn')
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITRegistry.java2
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ConstantCondition.java40
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/core/WeightCondition.java (renamed from src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/WeightCondition.java)8
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java2
4 files changed, 34 insertions, 18 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 bf7c2ca..a33f331 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITRegistry.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITRegistry.java
@@ -92,7 +92,7 @@ public final class CITRegistry { private CITRegistry(){}
CITConditionContainer<? extends CITCondition> conditionContainer = CONDITIONS.get(key);
if (conditionContainer == null) {
logWarnLoading(properties.messageWithDescriptorOf("Unknown condition type \"" + key.toString() + "\"", value.position()));
- return new ConstantCondition(false);
+ return ConstantCondition.FALSE;
}
CITCondition condition = conditionContainer.createCondition.get();
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 5bc9354..ed967c1 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
@@ -9,23 +9,43 @@ 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 {
+public abstract class ConstantCondition extends CITCondition {
/**
- * What testing contexts will always result in.
+ * Constant condition that always tests positive.
*/
- public final boolean value;
+ public static final ConstantCondition TRUE = new ConstantCondition(true) {
+ @Override
+ public boolean test(CITContext context) {
+ return true;
+ }
+ };
- public ConstantCondition(boolean value) {
- this.value = value;
+ /**
+ * Constant condition that always tests negative.
+ */
+ public static final ConstantCondition FALSE = new ConstantCondition(false) {
+ @Override
+ public boolean test(CITContext context) {
+ return false;
+ }
+ };
+
+ /**
+ * @return constant condition for the given boolean value
+ */
+ public static ConstantCondition of(boolean value) {
+ return value ? TRUE : FALSE;
}
- @Override
- public void load(PropertyValue value, PropertyGroup properties) throws CITParsingException {
+ /**
+ * What testing contexts will always result in.
+ */
+ public final boolean value;
+ private ConstantCondition(boolean value) {
+ this.value = value;
}
@Override
- public boolean test(CITContext context) {
- return value;
- }
+ public void load(PropertyValue value, PropertyGroup properties) throws CITParsingException { }
}
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/core/WeightCondition.java
index a53e019..cb728c9 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/core/WeightCondition.java
@@ -1,12 +1,8 @@
-package shcm.shsupercm.fabric.citresewn.cit.builtin.conditions;
+package shcm.shsupercm.fabric.citresewn.cit.builtin.conditions.core;
import io.shcm.shsupercm.fabric.fletchingtable.api.Entrypoint;
import shcm.shsupercm.fabric.citresewn.api.CITConditionContainer;
-import shcm.shsupercm.fabric.citresewn.ex.CITParsingException;
-import shcm.shsupercm.fabric.citresewn.cit.CITCondition;
-import shcm.shsupercm.fabric.citresewn.cit.CITContext;
-import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup;
-import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue;
+import shcm.shsupercm.fabric.citresewn.cit.builtin.conditions.IntegerCondition;
/**
* Internal condition used to determine the priority CITs get tested in.<br>
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 cd85af1..ad1b9ba 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java
@@ -6,7 +6,7 @@ import net.minecraft.resource.ResourcePack;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import shcm.shsupercm.fabric.citresewn.CITResewn;
-import shcm.shsupercm.fabric.citresewn.cit.builtin.conditions.WeightCondition;
+import shcm.shsupercm.fabric.citresewn.cit.builtin.conditions.core.WeightCondition;
import shcm.shsupercm.fabric.citresewn.ex.CITParsingException;
import shcm.shsupercm.fabric.citresewn.cit.CIT;
import shcm.shsupercm.fabric.citresewn.cit.CITCondition;