diff options
author | SHsuperCM <shsupercm@gmail.com> | 2022-02-17 15:53:59 +0200 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2022-02-17 16:01:52 +0200 |
commit | ee4412ffa26ff2bfc7b649c9e0554367cf2cdb2e (patch) | |
tree | c862b1eb53d7babc49105262027ea94157687475 /defaults/src/main/java | |
parent | 748dc6de2373a9bda3886a804735c872502a942c (diff) | |
download | CITResewn-ee4412ffa26ff2bfc7b649c9e0554367cf2cdb2e.tar.gz CITResewn-ee4412ffa26ff2bfc7b649c9e0554367cf2cdb2e.tar.bz2 CITResewn-ee4412ffa26ff2bfc7b649c9e0554367cf2cdb2e.zip |
Updated api usage of items condition
Diffstat (limited to 'defaults/src/main/java')
-rw-r--r-- | defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/conditions/ConditionItems.java | 50 |
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; + } + } } |