From 2d99c1b5773eb4067bb873e21c409a9a2399ab3d Mon Sep 17 00:00:00 2001 From: SHsuperCM Date: Tue, 22 Feb 2022 17:11:14 +0200 Subject: Cleaned/fixed some stuff up --- .../shcm/shsupercm/fabric/citresewn/cit/CIT.java | 12 +++++++---- .../fabric/citresewn/cit/CITRegistry.java | 4 ++-- .../builtin/conditions/AlwaysFailCondition.java | 19 ---------------- .../cit/builtin/conditions/ConstantCondition.java | 25 ++++++++++++++++++++++ .../cit/builtin/conditions/WeightCondition.java | 5 ----- 5 files changed, 35 insertions(+), 30 deletions(-) delete mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/AlwaysFailCondition.java create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ConstantCondition.java diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CIT.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CIT.java index 7cc5724..3bc708f 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CIT.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CIT.java @@ -18,10 +18,14 @@ public class CIT { } public boolean test(CITContext context) { - for (CITCondition condition : conditions) - if (!condition.test(context)) - return false; + try { + for (CITCondition condition : conditions) + if (!condition.test(context)) + return false; - return true; + return true; + } catch (Exception ignored) { + return false; + } } } 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 326ec76..ff38ef8 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITRegistry.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITRegistry.java @@ -4,7 +4,7 @@ import net.fabricmc.loader.api.FabricLoader; import net.minecraft.util.Identifier; import shcm.shsupercm.fabric.citresewn.api.CITConditionContainer; import shcm.shsupercm.fabric.citresewn.api.CITTypeContainer; -import shcm.shsupercm.fabric.citresewn.cit.builtin.conditions.AlwaysFailCondition; +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.format.PropertyGroup; @@ -45,7 +45,7 @@ public class CITRegistry { CITConditionContainer conditionContainer = CONDITIONS.get(key); if (conditionContainer == null) { logWarnLoading(CITParsingException.descriptionOf("Unknown condition type \"" + key.toString() + "\"", properties, value.position())); - return new AlwaysFailCondition(); + return new ConstantCondition(false); } CITCondition condition = conditionContainer.createCondition.get(); diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/AlwaysFailCondition.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/AlwaysFailCondition.java deleted file mode 100644 index 5c32d97..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/AlwaysFailCondition.java +++ /dev/null @@ -1,19 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.cit.builtin.conditions; - -import shcm.shsupercm.fabric.citresewn.cit.CITCondition; -import shcm.shsupercm.fabric.citresewn.cit.CITContext; -import shcm.shsupercm.fabric.citresewn.ex.CITParsingException; -import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; -import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; - -public class AlwaysFailCondition extends CITCondition { - @Override - public void load(PropertyValue value, PropertyGroup properties) throws CITParsingException { - - } - - @Override - public boolean test(CITContext context) { - return false; - } -} 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 new file mode 100644 index 0000000..081c2d8 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/builtin/conditions/ConstantCondition.java @@ -0,0 +1,25 @@ +package shcm.shsupercm.fabric.citresewn.cit.builtin.conditions; + +import shcm.shsupercm.fabric.citresewn.cit.CITCondition; +import shcm.shsupercm.fabric.citresewn.cit.CITContext; +import shcm.shsupercm.fabric.citresewn.ex.CITParsingException; +import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; +import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; + +public class ConstantCondition extends CITCondition { + public final boolean value; + + public ConstantCondition(boolean value) { + this.value = value; + } + + @Override + public void load(PropertyValue value, PropertyGroup properties) throws CITParsingException { + + } + + @Override + public boolean test(CITContext context) { + return value; + } +} 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 6ad3783..2e887d6 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 @@ -24,9 +24,4 @@ public class WeightCondition extends IntegerCondition { public void setWeight(int weight) { this.min = weight; } - - @Override - protected int getValue(CITContext context) { - return 0; - } } -- cgit