aboutsummaryrefslogtreecommitdiff
path: root/defaults/src/main/java/shcm/shsupercm/fabric
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2022-02-17 15:18:13 +0200
committerSHsuperCM <shsupercm@gmail.com>2022-02-17 15:18:13 +0200
commit748dc6de2373a9bda3886a804735c872502a942c (patch)
treea21c7cb9b53eaaf21602aaeee27e22477a15af35 /defaults/src/main/java/shcm/shsupercm/fabric
parenta50fd46a00b56a15161ae3288cf2ad55d9badc17 (diff)
downloadCITResewn-748dc6de2373a9bda3886a804735c872502a942c.tar.gz
CITResewn-748dc6de2373a9bda3886a804735c872502a942c.tar.bz2
CITResewn-748dc6de2373a9bda3886a804735c872502a942c.zip
Implemented hand condition
Diffstat (limited to 'defaults/src/main/java/shcm/shsupercm/fabric')
-rw-r--r--defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/conditions/ConditionHand.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/conditions/ConditionHand.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/conditions/ConditionHand.java
new file mode 100644
index 0000000..5325e28
--- /dev/null
+++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/conditions/ConditionHand.java
@@ -0,0 +1,56 @@
+package shcm.shsupercm.fabric.citresewn.defaults.cit.conditions;
+
+import io.shcm.shsupercm.fabric.fletchingtable.api.Entrypoint;
+import shcm.shsupercm.fabric.citresewn.api.CITConditionContainer;
+import shcm.shsupercm.fabric.citresewn.cit.CITContext;
+import shcm.shsupercm.fabric.citresewn.cit.builtin.conditions.EnumCondition;
+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 ConditionHand extends EnumCondition<ConditionHand.Hand> {
+ @Entrypoint(CITConditionContainer.ENTRYPOINT)
+ public static final CITConditionContainer<ConditionHand> CONTAINER = new CITConditionContainer<>(ConditionHand.class, ConditionHand::new,
+ "hand");
+
+ public ConditionHand() {
+ super(ConditionHand.Hand::values);
+ }
+
+ @Override
+ protected Hand getValue(CITContext context) {
+ if (context.entity.getMainHandStack() == context.stack)
+ return Hand.MAINHAND;
+ if (context.entity.getOffHandStack() == context.stack)
+ return Hand.OFFHAND;
+
+ return null;
+ }
+
+ @Override
+ public boolean test(CITContext context) {
+ Hand hand = getValue(context);
+ return this.value == hand || (this.value == Hand.ANY && hand != null);
+ }
+
+ protected enum Hand implements EnumCondition.Aliased {
+ MAINHAND {
+ @Override
+ public String[] getAliases() {
+ return new String[] { "main", "mainhand", "main_hand" };
+ }
+ },
+ OFFHAND {
+ @Override
+ public String[] getAliases() {
+ return new String[] { "off", "offhand", "off_hand" };
+ }
+ },
+ ANY {
+ @Override
+ public String[] getAliases() {
+ return new String[] { "any", "either", "*" };
+ }
+ }
+ }
+}