aboutsummaryrefslogtreecommitdiff
path: root/defaults/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'defaults/src/main/java')
-rw-r--r--defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/conditions/ConditionItems.java50
1 files changed, 33 insertions, 17 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
index ddd6220..73b79e0 100644
--- 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
@@ -3,42 +3,37 @@ 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.cit.CITCondition;
import shcm.shsupercm.fabric.citresewn.cit.CITContext;
+import shcm.shsupercm.fabric.citresewn.cit.builtin.conditions.IdentifierCondition;
+import shcm.shsupercm.fabric.citresewn.cit.builtin.conditions.ListCondition;
+import shcm.shsupercm.fabric.citresewn.ex.CITParsingException;
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 {
+public class ConditionItems extends ListCondition<ConditionItems.ItemCondition> {
@Entrypoint(CITConditionContainer.ENTRYPOINT)
public static final CITConditionContainer<ConditionItems> CONTAINER = new CITConditionContainer<>(ConditionItems.class, ConditionItems::new,
"items", "matchItems");
public Item[] items = new Item[0];
+ public ConditionItems() {
+ super(ItemCondition.class, ItemCondition::new);
+ }
+
@Override
public void load(PropertyValue value, PropertyGroup properties) throws CITParsingException {
+ super.load(value, properties);
+
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());
- }
+ for (ItemCondition itemCondition : this.conditions)
+ items.add(itemCondition.item);
this.items = items.toArray(new Item[0]);
}
@@ -51,4 +46,25 @@ public class ConditionItems extends CITCondition {
return false;
}
+
+ protected static class ItemCondition extends IdentifierCondition {
+ public Item item = null;
+
+ @Override
+ public void load(PropertyValue value, PropertyGroup properties) throws CITParsingException {
+ super.load(value, properties);
+
+ if (Registry.ITEM.containsId(this.value))
+ this.item = Registry.ITEM.get(this.value);
+ else {
+ this.item = null;
+ warn(this.value + " is not in the item registry", value, properties);
+ }
+ }
+
+ @Override
+ protected Identifier getValue(CITContext context) {
+ return this.value;
+ }
+ }
}