From a48789c45fb474a953df65e342a3bad27fd89870 Mon Sep 17 00:00:00 2001 From: SHsuperCM Date: Sun, 13 Feb 2022 07:20:35 +0200 Subject: Implemented items condition --- .../defaults/cit/conditions/ConditionItems.java | 54 ++++++++++++++++++++++ .../citresewn/defaults/cit/types/TypeItem.java | 36 +++++++++++++++ .../fabric/citresewn/defaults/types/TypeItem.java | 36 --------------- 3 files changed, 90 insertions(+), 36 deletions(-) create mode 100644 defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/conditions/ConditionItems.java create mode 100644 defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeItem.java delete mode 100644 defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/types/TypeItem.java (limited to 'defaults/src/main/java') 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 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 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/cit/types/TypeItem.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeItem.java new file mode 100644 index 0000000..58460aa --- /dev/null +++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeItem.java @@ -0,0 +1,36 @@ +package shcm.shsupercm.fabric.citresewn.defaults.cit.types; + +import io.shcm.shsupercm.fabric.fletchingtable.api.Entrypoint; +import shcm.shsupercm.fabric.citresewn.api.CITTypeContainer; +import shcm.shsupercm.fabric.citresewn.ex.CITParsingException; +import shcm.shsupercm.fabric.citresewn.pack.cit.CIT; +import shcm.shsupercm.fabric.citresewn.pack.cit.CITCondition; +import shcm.shsupercm.fabric.citresewn.pack.cit.CITType; +import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; + +import java.util.List; + +public class TypeItem extends CITType { + @Entrypoint(CITTypeContainer.ENTRYPOINT) + public static final Container CONTAINER = new Container(); + + @Override + public void load(List conditions, PropertyGroup properties) throws CITParsingException { + + } + + public static class Container extends CITTypeContainer { + public Container() { + super(TypeItem.class, TypeItem::new, "item"); + } + + @Override + public void load(List parsedCITs) { + } + + @Override + public void dispose() { + + } + } +} \ No newline at end of file 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/types/TypeItem.java deleted file mode 100644 index 855b90e..0000000 --- a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/types/TypeItem.java +++ /dev/null @@ -1,36 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.defaults.types; - -import io.shcm.shsupercm.fabric.fletchingtable.api.Entrypoint; -import shcm.shsupercm.fabric.citresewn.api.CITTypeContainer; -import shcm.shsupercm.fabric.citresewn.ex.CITParsingException; -import shcm.shsupercm.fabric.citresewn.pack.cit.CIT; -import shcm.shsupercm.fabric.citresewn.pack.cit.CITCondition; -import shcm.shsupercm.fabric.citresewn.pack.cit.CITType; -import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; - -import java.util.List; - -public class TypeItem extends CITType { - @Entrypoint(CITTypeContainer.ENTRYPOINT) - public static final Container CONTAINER = new Container(); - - @Override - public void load(List conditions, PropertyGroup properties) throws CITParsingException { - - } - - public static class Container extends CITTypeContainer { - public Container() { - super(TypeItem.class, TypeItem::new, "item"); - } - - @Override - public void load(List parsedCITs) { - } - - @Override - public void dispose() { - - } - } -} \ No newline at end of file -- cgit