diff --git a/build.gradle b/build.gradle index 4eab20d..c796684 100644 --- a/build.gradle +++ b/build.gradle @@ -17,11 +17,12 @@ allprojects { apply from: "https://raw.githubusercontent.com/FTBTeam/mods-meta/main/gradle/git-md-changelog.gradle" base { - archivesName = rootProject.archives_base_name + archivesName = project.archives_base_name } - version = rootProject.mod_version - group = rootProject.maven_group + version = project.mod_version + group = project.maven_group + archivesBaseName = project.archives_base_name // needs to be done AFTER version is set apply from: "https://raw.githubusercontent.com/FTBTeam/mods-meta/main/gradle/publishing.gradle" diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/FilterSystemAPIImpl.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/FilterSystemAPIImpl.java index c365074..9f4dd1f 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/FilterSystemAPIImpl.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/FilterSystemAPIImpl.java @@ -1,13 +1,18 @@ package dev.ftb.mods.ftbfiltersystem; -import dev.ftb.mods.ftbfiltersystem.api.*; -import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractCompoundFilter; +import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI; +import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemRegistry; +import dev.ftb.mods.ftbfiltersystem.api.FilterException; import dev.ftb.mods.ftbfiltersystem.api.filter.DumpedFilter; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; -import dev.ftb.mods.ftbfiltersystem.registry.item.SmartFilterItem; +import dev.ftb.mods.ftbfiltersystem.filter.ItemTagFilter; import dev.ftb.mods.ftbfiltersystem.registry.FilterRegistry; +import dev.ftb.mods.ftbfiltersystem.registry.ModItems; +import dev.ftb.mods.ftbfiltersystem.registry.item.SmartFilterItem; import dev.ftb.mods.ftbfiltersystem.util.FilterParser; import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import java.util.ArrayList; @@ -29,8 +34,12 @@ public boolean isFilterItem(ItemStack stack) { @Override public boolean doesFilterMatch(ItemStack filterStack, ItemStack toMatch) { - return isFilterItem(filterStack) - && FilterParser.parse(SmartFilterItem.getFilterString(filterStack)).test(toMatch); + try { + return isFilterItem(filterStack) + && FilterParser.parse(SmartFilterItem.getFilterString(filterStack)).test(toMatch); + } catch (FilterException e) { + return false; + } } @Override @@ -48,11 +57,23 @@ public SmartFilter parseFilter(String filterStr) throws FilterException { return FilterParser.parse(filterStr); } + @Override + public SmartFilter parseFilter(ItemStack filterStack) throws FilterException { + return parseFilter(SmartFilterItem.getFilterString(filterStack)); + } + @Override public List parseFilterList(SmartFilter.Compound parent, String filterStr) throws FilterException { return FilterParser.parseFilterList(parent, filterStr); } + @Override + public ItemStack makeTagFilter(TagKey tagKey) { + ItemStack res = new ItemStack(ModItems.SMART_FILTER.get()); + SmartFilterItem.setFilter(res, ItemTagFilter.ID + "(" + tagKey.location() + ")"); + return res; + } + private List dump(SmartFilter filter, int indent, List res) { res.add(new DumpedFilter(indent, filter)); diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/FTBFilterSystemAPI.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/FTBFilterSystemAPI.java index 169c3ce..3d3ac33 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/FTBFilterSystemAPI.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/FTBFilterSystemAPI.java @@ -4,6 +4,8 @@ import dev.ftb.mods.ftbfiltersystem.api.filter.DumpedFilter; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -103,7 +105,8 @@ public interface API { FTBFilterSystemRegistry getRegistry(); /** - * Check if the given itemstack is an FTB Filter System filter + * Check if the given itemstack is an FTB Filter System filter. + * * @param stack the stack to check * @return true if it's a filter, false otherwise */ @@ -111,9 +114,10 @@ public interface API { /** * Check if the given filter stack matches the given item stack + * . * @param filterStack the filter stack, which should be a FTB Filter System filter * @param toMatch the item stack to test - * @return true if the filter stack matches, false otherwise (including if the filter stack isn't a filter) + * @return true if the filter stack matches, false otherwise (the filter stack isn't a filter, or the filter NBT is bad) */ boolean doesFilterMatch(ItemStack filterStack, ItemStack toMatch); @@ -145,6 +149,16 @@ public interface API { */ SmartFilter parseFilter(String filterStr) throws FilterException; + /** + * Create a new filter, parsed from the given serialized string. Such strings are produced by calling + * the overridden {@code toString()} on any {@link SmartFilter} implementation. + * + * @param filterStack the itemstack, which should be a valid filter item + * @return a new filter + * @throws FilterException if the item stack doesn't have valid filter NBT, or there's a problem parsing the data + */ + SmartFilter parseFilter(ItemStack filterStack) throws FilterException; + /** * Create a list of new filters, parsed from the given serialized string. Such strings are produced by calling * the overridden {@code toString()} method on any {@link SmartFilter} implementation; multiples of such strings @@ -156,5 +170,13 @@ public interface API { * @throws FilterException if there's a problem parsing the data */ List parseFilterList(@NotNull SmartFilter.Compound parent, String filterStr) throws FilterException; + + /** + * Create a simple filter which just filters on a specific item tag. + * + * @param tagKey the item tag to filter on + * @return the new filter itemstack + */ + ItemStack makeTagFilter(TagKey tagKey); } } diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/FilterScreen.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/FilterScreen.java index 0e3ffc7..9071e8a 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/FilterScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/FilterScreen.java @@ -5,7 +5,6 @@ import dev.ftb.mods.ftbfiltersystem.api.client.Textures; import dev.ftb.mods.ftbfiltersystem.api.client.gui.AbstractFilterScreen; import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractCompoundFilter; -import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractSmartFilter; import dev.ftb.mods.ftbfiltersystem.api.filter.DumpedFilter; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; import dev.ftb.mods.ftbfiltersystem.client.FTBFilterSystemClient; @@ -261,10 +260,14 @@ public boolean keyPressed(int keyCode, int scanCode, int modifier) { if (getSelectionPanel().isVisible()) { getSelectionPanel().setVisible(false); return true; - } else if (titleEditBox.canConsumeInput() && keyCode == InputConstants.KEY_ESCAPE) { - titleEditBox.setValue(newTitle == null ? title.getString() : newTitle.getString()); - showingTitleEdit = false; - return true; + } else if (titleEditBox.canConsumeInput()) { + if (keyCode == InputConstants.KEY_ESCAPE) { + titleEditBox.setValue(newTitle == null ? title.getString() : newTitle.getString()); + showingTitleEdit = false; + return true; + } else { + return titleEditBox.keyPressed(keyCode, scanCode, modifier); + } } else { closeWithConfirmation(); return true; diff --git a/common/src/main/resources/assets/ftbfiltersystem/lang/en_us.json b/common/src/main/resources/assets/ftbfiltersystem/lang/en_us.json index 02e0539..4f1b679 100644 --- a/common/src/main/resources/assets/ftbfiltersystem/lang/en_us.json +++ b/common/src/main/resources/assets/ftbfiltersystem/lang/en_us.json @@ -24,9 +24,13 @@ "ftbfiltersystem.gui.compound": "Compound Filters", "ftbfiltersystem.gui.basic": "Basic Filters", "filter.ftbfiltersystem.and.name": "All Of", + "filter.ftbfiltersystem.and.tooltip": "Compound filter: this filter matches if ALL of its child filters match.", "filter.ftbfiltersystem.or.name": "Any Of", + "filter.ftbfiltersystem.or.tooltip": "Compound filter: this filter matches if ANY of its child filters match.", "filter.ftbfiltersystem.not.name": "Not", + "filter.ftbfiltersystem.not.tooltip": "Compound filter: this filter matches if its child filter does NOT match. At most child can be added.", "filter.ftbfiltersystem.only_one.name": "Only One Of", + "filter.ftbfiltersystem.only_one.tooltip": "Compound filter: this filter matches if exactly ONE of its child filters matches.", "filter.ftbfiltersystem.block.name": "Is Block", "filter.ftbfiltersystem.block.tooltip": "Simple filter which matches if the item is a placeable block.", "filter.ftbfiltersystem.durability.name": "Durability", diff --git a/gradle.properties b/gradle.properties index 81b7426..b820131 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,9 +3,9 @@ org.gradle.jvmargs=-Xmx2048M minecraft_version=1.20.1 enabled_platforms=fabric,forge -archives_base_name=ftbfiltersystem -mod_version=1.0.0 -maven_group=dev.ftb.mods.ftbfiltersystem +archives_base_name=ftb-filter-system +mod_version=1.0.1 +maven_group=dev.ftb.mods architectury_version=9.1.12