aboutsummaryrefslogtreecommitdiff
path: root/defaults/src/main/java/shcm
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2022-02-13 07:20:35 +0200
committerSHsuperCM <shsupercm@gmail.com>2022-02-13 07:20:35 +0200
commita48789c45fb474a953df65e342a3bad27fd89870 (patch)
tree73c6b32f5dc8cf488afb606d789e73ce8f0a32aa /defaults/src/main/java/shcm
parent207048093b7727ff1dec581e6cb523a7a3086c59 (diff)
downloadCITResewn-a48789c45fb474a953df65e342a3bad27fd89870.tar.gz
CITResewn-a48789c45fb474a953df65e342a3bad27fd89870.tar.bz2
CITResewn-a48789c45fb474a953df65e342a3bad27fd89870.zip
Implemented items condition
Diffstat (limited to 'defaults/src/main/java/shcm')
-rw-r--r--defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/conditions/ConditionItems.java54
-rw-r--r--defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeItem.java (renamed from defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/types/TypeItem.java)2
2 files changed, 55 insertions, 1 deletions
diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/conditions/ConditionItems.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/conditions/ConditionItems.java
new file mode 100644
index 0000000..e010a58
--- /dev/null
+++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/conditions/ConditionItems.java
@@ -0,0 +1,54 @@
+package shcm.shsupercm.fabric.citresewn.defaults.cit.conditions;
+
+import io.shcm.shsupercm.fabric.fletchingtable.api.Entrypoint;
+import net.minecraft.item.Item;
+import net.minecraft.util.Identifier;
+import net.minecraft.util.InvalidIdentifierException;
+import net.minecraft.util.registry.Registry;
+import shcm.shsupercm.fabric.citresewn.api.CITConditionContainer;
+import shcm.shsupercm.fabric.citresewn.ex.CITParsingException;
+import shcm.shsupercm.fabric.citresewn.pack.cit.CITCondition;
+import shcm.shsupercm.fabric.citresewn.pack.cit.CITContext;
+import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup;
+import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+public class ConditionItems extends CITCondition {
+ @Entrypoint(CITConditionContainer.ENTRYPOINT)
+ public static final CITConditionContainer<ConditionItems> CONTAINER = new CITConditionContainer<>(ConditionItems.class, ConditionItems::new,
+ "items", "matchItems");
+
+ public Item[] items = new Item[0];
+
+ @Override
+ public void load(PropertyValue value, PropertyGroup properties) throws CITParsingException {
+ Set<Item> items = new LinkedHashSet<>();
+
+ for (String entry : value.value().split(" "))
+ if (!entry.isEmpty())
+ try {
+ Identifier identifier = new Identifier(entry);
+ if (Registry.ITEM.containsId(identifier))
+ items.add(Registry.ITEM.get(identifier));
+ else {
+ items.add(null);
+ warn(identifier + " is not in the item registry", value, properties);
+ }
+ } catch (InvalidIdentifierException e) {
+ throw new CITParsingException("Invalid item identifier \"" + entry + "\"", properties, value.position());
+ }
+
+ this.items = items.toArray(new Item[0]);
+ }
+
+ @Override
+ public boolean test(CITContext context) {
+ for (Item item : this.items)
+ if (context.stack.getItem() == item)
+ return true;
+
+ return false;
+ }
+}
diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/types/TypeItem.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeItem.java
index 855b90e..58460aa 100644
--- a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/types/TypeItem.java
+++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeItem.java
@@ -1,4 +1,4 @@
-package shcm.shsupercm.fabric.citresewn.defaults.types;
+package shcm.shsupercm.fabric.citresewn.defaults.cit.types;
import io.shcm.shsupercm.fabric.fletchingtable.api.Entrypoint;
import shcm.shsupercm.fabric.citresewn.api.CITTypeContainer;