From 5531bfb71d3547f12423ed2967c6160e17ed5ee0 Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Thu, 9 May 2024 14:10:19 +0100 Subject: [PATCH 1/4] chore: ported to 1.20.6 No Forge support at this time; Fabric & NeoForge only --- build.gradle | 16 ++--- common/build.gradle | 3 +- .../mods/ftbfiltersystem/FTBFilterSystem.java | 4 +- .../ftbfiltersystem/FilterSystemAPIImpl.java | 6 ++ .../ftbfiltersystem/FilterSystemCommands.java | 70 ++++++++++++++++--- .../api/FTBFilterSystemAPI.java | 6 ++ .../api/NumericComparison.java | 45 ++++++------ .../api/client/FilterScreenFactory.java | 1 + .../gui/AbstractComparisonConfigScreen.java | 20 +++--- .../api/client/gui/AbstractFilterScreen.java | 2 + .../client/gui/widget/CustomCheckbox.java | 2 +- .../api/event/FilterRegistrationEvent.java | 3 + .../client/ClientFilterRegistrationEvent.java | 5 +- .../api/filter/AbstractComparisonFilter.java | 12 ++++ .../api/filter/SmartFilter.java | 2 +- .../client/FTBFilterSystemClient.java | 2 +- .../client/SelectionPanel.java | 2 +- .../gui/AbstractItemEditorConfigScreen.java | 2 +- ...Screen.java => ComponentConfigScreen.java} | 43 ++++++++---- .../client/gui/DurabilityConfigScreen.java | 1 + .../client/gui/ExpressionConfigScreen.java | 3 +- .../client/gui/FilterScreen.java | 19 +++-- .../client/gui/FoodValueConfigScreen.java | 1 + .../client/gui/ItemConfigScreen.java | 5 +- .../client/gui/ItemTagConfigScreen.java | 7 +- .../client/gui/MaxCountConfigScreen.java | 1 + .../client/gui/ModConfigScreen.java | 7 +- .../client/gui/StackSizeConfigScreen.java | 1 + .../gui/widget/CustomSelectionList.java | 4 +- .../client/gui/widget/ItemWidget.java | 3 +- .../ftbfiltersystem/filter/BlockFilter.java | 3 +- .../{NbtFilter.java => ComponentFilter.java} | 48 ++++++++----- .../filter/DurabilityFilter.java | 2 +- .../filter/FoodValueFilter.java | 10 +-- .../ftbfiltersystem/filter/ItemFilter.java | 4 +- .../ftbfiltersystem/filter/ItemTagFilter.java | 4 +- .../filter/MaxStackSizeFilter.java | 5 +- .../ftbfiltersystem/filter/ModFilter.java | 3 +- .../filter/StackSizeFilter.java | 1 - .../filter/compound/AndFilter.java | 2 +- .../filter/compound/NotFilter.java | 4 +- .../filter/compound/OnlyOneFilter.java | 2 +- .../filter/compound/OrFilter.java | 2 +- .../integration/jei/JEIIntegration.java | 8 +-- .../network/FTBFilterSystemNet.java | 23 ++++-- .../network/SyncFilterMessage.java | 65 +++++++---------- .../registry/FilterRegistry.java | 1 - .../registry/ModDataComponents.java | 21 ++++++ .../ftbfiltersystem/registry/ModItems.java | 6 +- .../registry/item/SmartFilterItem.java | 13 ++-- .../ftbfiltersystem/util/FilterCache.java | 4 ++ .../ftbfiltersystem/util/PlatformUtil.java | 2 +- .../assets/ftbfiltersystem/lang/en_us.json | 17 +++-- .../ftbfiltersystem/recipes/smart_filter.json | 4 +- fabric/build.gradle | 3 +- .../mixin/PatchedDataComponentMapAccess.java | 15 ++++ .../util/fabric/PlatformUtilImpl.java | 10 ++- .../resources/ftbfiltersystem.mixins.json | 1 + gradle.properties | 15 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- neoforge/build.gradle | 5 +- ...orge.java => FTBFilterSystemNeoForge.java} | 4 +- .../util/neoforge/PlatformUtilImpl.java | 5 +- .../{mods.toml => neoforge.mods.toml} | 0 settings.gradle | 4 +- 65 files changed, 395 insertions(+), 221 deletions(-) rename common/src/main/java/dev/ftb/mods/ftbfiltersystem/{ => api}/client/gui/AbstractComparisonConfigScreen.java (88%) rename common/src/main/java/dev/ftb/mods/ftbfiltersystem/{ => api}/client/gui/widget/CustomCheckbox.java (98%) rename common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/{NBTConfigScreen.java => ComponentConfigScreen.java} (52%) rename common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/{NbtFilter.java => ComponentFilter.java} (53%) create mode 100644 common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/ModDataComponents.java create mode 100644 fabric/src/main/java/dev/ftb/mods/ftbfiltersystem/fabric/mixin/PatchedDataComponentMapAccess.java rename neoforge/src/main/java/dev/ftb/mods/ftbfiltersystem/neoforge/{FTBFilterSystemForge.java => FTBFilterSystemNeoForge.java} (85%) rename neoforge/src/main/resources/META-INF/{mods.toml => neoforge.mods.toml} (100%) diff --git a/build.gradle b/build.gradle index 0cbd3f2..6dd3bb4 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ import me.modmuss50.mpp.ReleaseType plugins { id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "1.5-SNAPSHOT" apply false + id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false id "me.modmuss50.mod-publish-plugin" version "0.4.5" } @@ -38,7 +38,7 @@ allprojects { tasks.withType(JavaCompile) { options.encoding = "UTF-8" - options.release = 17 + options.release = 21 } java { @@ -111,12 +111,12 @@ publishMods { } } - curseforge("forge") { - from curseOptions - modLoaders.add("forge") - file = project(":forge").tasks.remapJar.archiveFile - displayName = "[FORGE] FTB Filter System ${mod_version} MC ${minecraft_version}" - } +// curseforge("forge") { +// from curseOptions +// modLoaders.add("forge") +// file = project(":forge").tasks.remapJar.archiveFile +// displayName = "[FORGE] FTB Filter System ${mod_version} MC ${minecraft_version}" +// } curseforge("neoforge") { from curseOptions diff --git a/common/build.gradle b/common/build.gradle index a3898b9..f373a60 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -13,7 +13,8 @@ dependencies { // Remove the next line if you don't want to depend on the API modApi "dev.architectury:architectury:${rootProject.architectury_version}" - modCompileOnly("mezz.jei:jei-${rootProject.minecraft_version}-common-api:${rootProject.jei_version}") +// modCompileOnly("mezz.jei:jei-${rootProject.minecraft_version}-common-api:${rootProject.jei_version}") + modCompileOnly("mezz.jei:jei-1.20.4-common-api:${rootProject.jei_version}") } tasks.register("buildApi", Jar) { diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/FTBFilterSystem.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/FTBFilterSystem.java index 073eaf4..5dbba44 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/FTBFilterSystem.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/FTBFilterSystem.java @@ -15,6 +15,7 @@ import dev.ftb.mods.ftbfiltersystem.filter.compound.OrFilter; import dev.ftb.mods.ftbfiltersystem.network.FTBFilterSystemNet; import dev.ftb.mods.ftbfiltersystem.registry.FilterRegistry; +import dev.ftb.mods.ftbfiltersystem.registry.ModDataComponents; import dev.ftb.mods.ftbfiltersystem.registry.ModItems; import net.minecraft.server.MinecraftServer; import org.apache.logging.log4j.LogManager; @@ -38,6 +39,7 @@ public FTBFilterSystem() { FilterRegistrationEvent.REGISTER.register(this::registerBuiltinFilters); ModItems.TABS.register(); ModItems.ITEMS.register(); + ModDataComponents.COMPONENT_TYPES.register(); EnvExecutor.runInEnv(Env.CLIENT, () -> FTBFilterSystemClient.INSTANCE::init); @@ -62,7 +64,7 @@ private void registerBuiltinFilters(FTBFilterSystemRegistry reg) { reg.register(ItemTagFilter.ID, ItemTagFilter::fromString, ItemTagFilter::new); reg.register(MaxStackSizeFilter.ID, MaxStackSizeFilter::fromString, MaxStackSizeFilter::new); reg.register(ModFilter.ID, ModFilter::fromString, ModFilter::new); - reg.register(NbtFilter.ID, NbtFilter::fromString, NbtFilter::new); + reg.register(ComponentFilter.ID, ComponentFilter::fromString, ComponentFilter::new); reg.register(StackSizeFilter.ID, StackSizeFilter::fromString, StackSizeFilter::new); reg.register(AndFilter.ID, AndFilter::fromString, AndFilter::new); 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 9f4dd1f..5c945a6 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/FilterSystemAPIImpl.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/FilterSystemAPIImpl.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Optional; public enum FilterSystemAPIImpl implements FTBFilterSystemAPI.API { @@ -32,6 +33,11 @@ public boolean isFilterItem(ItemStack stack) { return stack.getItem() instanceof SmartFilterItem; } + @Override + public Item filterItem() { + return Objects.requireNonNull(ModItems.SMART_FILTER.get()); + } + @Override public boolean doesFilterMatch(ItemStack filterStack, ItemStack toMatch) { try { diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/FilterSystemCommands.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/FilterSystemCommands.java index 3d5d0e0..ad2f8d5 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/FilterSystemCommands.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/FilterSystemCommands.java @@ -5,16 +5,19 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import dev.ftb.mods.ftbfiltersystem.api.filter.DumpedFilter; import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI; 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.util.FilterCache; import dev.ftb.mods.ftbfiltersystem.util.FilterParser; import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; +import net.minecraft.core.component.TypedDataComponent; +import net.minecraft.nbt.NbtOps; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.world.item.ItemStack; @@ -27,6 +30,8 @@ public class FilterSystemCommands { = new DynamicCommandExceptionType(object -> Component.translatable("ftbfiltersystem.message.parse_failed", object)); public static final SimpleCommandExceptionType NOT_A_FILTER = new SimpleCommandExceptionType(Component.translatable("ftbfiltersystem.message.not_a_filter")); + public static final SimpleCommandExceptionType NOT_CONFIGURED + = new SimpleCommandExceptionType(Component.translatable("ftbfiltersystem.message.not_configured")); public static final SimpleCommandExceptionType NO_OFFHAND_ITEM = new SimpleCommandExceptionType(Component.translatable("ftbfiltersystem.message.no_offhand_item")); @@ -54,16 +59,29 @@ public static void registerCommands(CommandDispatcher dispat .then(literal("try_match") .executes(ctx -> tryMatch(ctx.getSource())) ) - .then(literal("dump_nbt") + .then(literal("dump_components") + .requires(ctx -> ctx.hasPermission(2)) + .executes(ctx -> dumpComponents(ctx.getSource(), false)) + .then(literal("all") + .executes(ctx -> dumpComponents(ctx.getSource(), true)) + ) + ) + .then(literal("cache") .requires(ctx -> ctx.hasPermission(2)) - .executes(ctx -> dumpNbt(ctx.getSource())) + .then(literal("clear") + .executes(ctx -> clearCache(ctx.getSource())) + ) ) ); } private static int tryParseCommand(CommandSourceStack source, String string) throws CommandSyntaxException { try { - for (DumpedFilter entry : FTBFilterSystemAPI.api().dump(FilterParser.parse(string))) { + SmartFilter parsed = FilterParser.parse(string); + if (parsed == null) { + throw new FilterException("can't parse: " + string); + } + for (DumpedFilter entry : FTBFilterSystemAPI.api().dump(parsed)) { source.sendSuccess(() -> { MutableComponent txt = entry.filter().getDisplayName().copy().withStyle(ChatFormatting.AQUA); if (!(entry.filter() instanceof SmartFilter.Compound)) { @@ -81,6 +99,9 @@ private static int tryParseCommand(CommandSourceStack source, String string) thr private static int tryShowFilter(CommandSourceStack source, boolean prettyPrint) throws CommandSyntaxException { String filterString = SmartFilterItem.getFilterString(getHeldFilter(source)); + if (filterString.isEmpty()) { + throw NOT_CONFIGURED.create(); + } if (prettyPrint) { return tryParseCommand(source, filterString); } else { @@ -91,7 +112,8 @@ private static int tryShowFilter(CommandSourceStack source, boolean prettyPrint) private static int trySetFilter(CommandSourceStack source, String string) throws CommandSyntaxException { try { - SmartFilterItem.setFilter(getHeldFilter(source), FilterParser.parse(string).toString()); + SmartFilter parsed = FilterParser.parse(string); + SmartFilterItem.setFilter(getHeldFilter(source), parsed.toString()); return 1; } catch (FilterException e) { source.sendFailure(Component.literal(e.getMessage()).withStyle(ChatFormatting.RED)); @@ -115,19 +137,47 @@ public static int tryMatch(CommandSourceStack source) throws CommandSyntaxExcept } } - private static int dumpNbt(CommandSourceStack source) throws CommandSyntaxException { + private static int dumpComponents(CommandSourceStack source, boolean all) throws CommandSyntaxException { ItemStack stack = source.getPlayerOrException().getMainHandItem(); - if (stack.hasTag()) { - source.sendSuccess(() -> Component.literal("NBT dump:").withStyle(ChatFormatting.YELLOW), false); - source.sendSuccess(() -> Component.literal(stack.getTag().toString()), false); + if (!stack.getComponents().isEmpty()) { + int amount = stack.getComponents().size(); + source.sendSuccess(() -> Component.translatable("ftbfiltersystem.message.components_header", amount, stack.getItem().getDescription()) + .withStyle(ChatFormatting.YELLOW), false); + if (!all) { + source.sendSuccess(() -> Component.translatable("ftbfiltersystem.message.non_default_components") + .withStyle(ChatFormatting.YELLOW, ChatFormatting.ITALIC), false); + } + stack.getComponents().forEach(tc -> { + if (all || !tc.value().equals(stack.getItem().components().get(tc.type()))) { + source.sendSuccess(() -> Component.empty() + .append(Component.literal(tc.type().toString()).withStyle(ChatFormatting.AQUA)) + .append(": ") + .append(encodeComponent(tc)), + false); + } + }); return 1; } else { - source.sendFailure(Component.literal("No NBT").withStyle(ChatFormatting.RED)); + source.sendFailure(Component.translatable("ftbfiltersystem.message.components_header_none").withStyle(ChatFormatting.GOLD)); return 0; } } + private static Component encodeComponent(TypedDataComponent tc) { + try { + return Component.literal(tc.encodeValue(NbtOps.INSTANCE).getOrThrow().toString()); + } catch (IllegalStateException ignored) { + return Component.literal("(encoding failed)").withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC); + } + } + + private static int clearCache(CommandSourceStack source) { + FilterCache.INSTANCE.clear(); + source.sendSuccess(() -> Component.translatable("ftbfiltersystem.message.cache_cleared"), false); + return 1; + } + // --------------------------------------------------------------------------------------------- // supporting methods 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 3d3ac33..70dc49d 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 @@ -112,6 +112,12 @@ public interface API { */ boolean isFilterItem(ItemStack stack); + /** + * {@return the Smart Filter item} May be useful for mods which wish to add capabilities and/or components + * to the Smart Filter. Do not call this before registration has completed. + */ + Item filterItem(); + /** * Check if the given filter stack matches the given item stack * . diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/NumericComparison.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/NumericComparison.java index 2aa3d57..bb5a3a8 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/NumericComparison.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/NumericComparison.java @@ -9,17 +9,26 @@ import java.util.Optional; import java.util.function.IntPredicate; -public class NumericComparison implements IntPredicate { - private final ComparisonOp op; - private final int value; - private final boolean percentage; - - public NumericComparison(ComparisonOp op, int value, boolean percentage) { - this.op = op; - this.value = value; - this.percentage = percentage; - } - +/** + * A comparison object, which is retrieved from a + * {@link dev.ftb.mods.ftbfiltersystem.api.filter.AbstractComparisonFilter comparison filter}. Effectively just an + * integer predicate. + * + * @param op the comparison operator + * @param value the value to compare + * @param percentage true if this is a percentage comparison + */ +public record NumericComparison(ComparisonOp op, int value, boolean percentage) implements IntPredicate { + /** + * Create a new comparison from the given string. The expected format is {@code {OP}{VAL}[%]}, where OP is a + * comparison operator (see {@link ComparisonOp}, and VAL is an integer quantity. See the {@link #toString()} + * for an illustration of the reverse process. + * + * @param str the str to parse + * @param allowPercentages true if this comparison should allow percentage comparisons + * @return a new NumericComparison object + * @throws FilterException if the input is any way invalid + */ public static NumericComparison fromString(String str, boolean allowPercentages) throws FilterException { boolean pct = false; if (str.endsWith("%")) { @@ -64,18 +73,6 @@ public boolean test(int toCheck) { return op.test(toCheck, value); } - public boolean isPercentage() { - return percentage; - } - - public int getValue() { - return value; - } - - public ComparisonOp getOp() { - return op; - } - public enum ComparisonOp { EQ("=", (v1, v2) -> v1 == v2), NE("!=", (v1, v2) -> v1 != v2), @@ -87,7 +84,7 @@ public enum ComparisonOp { private final String str; private final ValuePredicate predicate; - private static final Map map = Util.make(new HashMap<>(), + private static final Map map = Util.make(new HashMap<>(), map -> Arrays.stream(values()).forEach(op -> map.put(op.str, op)) ); diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/client/FilterScreenFactory.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/client/FilterScreenFactory.java index 800f62f..d4a8e13 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/client/FilterScreenFactory.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/client/FilterScreenFactory.java @@ -4,6 +4,7 @@ import dev.ftb.mods.ftbfiltersystem.api.client.gui.AbstractFilterScreen; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; +@FunctionalInterface public interface FilterScreenFactory { AbstractFilterConfigScreen createScreen(T filter, AbstractFilterScreen parentScreen); } diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/AbstractComparisonConfigScreen.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/client/gui/AbstractComparisonConfigScreen.java similarity index 88% rename from common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/AbstractComparisonConfigScreen.java rename to common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/client/gui/AbstractComparisonConfigScreen.java index 99d8a1c..407c306 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/AbstractComparisonConfigScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/client/gui/AbstractComparisonConfigScreen.java @@ -1,13 +1,10 @@ -package dev.ftb.mods.ftbfiltersystem.client.gui; +package dev.ftb.mods.ftbfiltersystem.api.client.gui; import com.mojang.blaze3d.platform.InputConstants; import dev.ftb.mods.ftbfiltersystem.api.NumericComparison; -import dev.ftb.mods.ftbfiltersystem.api.client.gui.AbstractFilterConfigScreen; -import dev.ftb.mods.ftbfiltersystem.api.client.gui.AbstractFilterScreen; +import dev.ftb.mods.ftbfiltersystem.api.client.gui.widget.CustomCheckbox; import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractComparisonFilter; -import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractCompoundFilter; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; -import dev.ftb.mods.ftbfiltersystem.client.gui.widget.CustomCheckbox; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.CycleButton; import net.minecraft.client.gui.components.EditBox; @@ -20,6 +17,13 @@ import java.util.function.BiFunction; +/** + * Base screen class for all comparison filters - see {@link AbstractComparisonFilter}. You can extend this class; + * typical implementations are extremely simple, needing only a constructor which satisfies the + * {@link dev.ftb.mods.ftbfiltersystem.api.client.FilterScreenFactory} interface contract. + * + * @param the filter implementation type + */ public abstract class AbstractComparisonConfigScreen extends AbstractFilterConfigScreen { private final BiFunction comparisonFactory; protected CycleButton opBtn; @@ -42,7 +46,7 @@ protected void init() { opBtn = rowHelper.addChild(CycleButton.builder(NumericComparison.ComparisonOp::getDisplayName) .withValues(NumericComparison.ComparisonOp.values()) - .withInitialValue(filter.getComparison().getOp()) + .withInitialValue(filter.getComparison().op()) .displayOnlyValue() .create(0, 0, 20, font.lineHeight + 8, Component.empty(), (btn, val) -> {})); @@ -54,7 +58,7 @@ protected void init() { rowHelper.addChild(Button.builder(Component.literal("+"), b -> adjustVal(1)).size(12, 12).build(), LayoutSettings.defaults().alignVerticallyMiddle().paddingLeft(2)); - numBox.setValue(Integer.toString(filter.getComparison().getValue())); + numBox.setValue(Integer.toString(filter.getComparison().value())); numBox.setResponder(str -> adjustVal(0)); numBox.setFilter(str -> isValidNumber(str) || str.isEmpty()); @@ -62,7 +66,7 @@ protected void init() { rowHelper.addChild(SpacerElement.height(5), 5); MutableComponent txt = Component.translatable("ftbfiltersystem.gui.percentage"); pctCheckBox = rowHelper.addChild(new CustomCheckbox(0, 0, font.width(txt), 20, - txt, filter.getComparison().isPercentage()), 5); + txt, filter.getComparison().percentage()), 5); } layout.arrangeElements(); diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/client/gui/AbstractFilterScreen.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/client/gui/AbstractFilterScreen.java index b6a461c..3b816bd 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/client/gui/AbstractFilterScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/client/gui/AbstractFilterScreen.java @@ -3,11 +3,13 @@ import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.ApiStatus; /** * Base class for the top-level editor GUI, passed as a parameter when constructing a * {@link AbstractFilterConfigScreen}. Do not extend this class yourself. */ +@ApiStatus.NonExtendable public abstract class AbstractFilterScreen extends Screen { protected AbstractFilterScreen(Component component) { super(component); diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/widget/CustomCheckbox.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/client/gui/widget/CustomCheckbox.java similarity index 98% rename from common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/widget/CustomCheckbox.java rename to common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/client/gui/widget/CustomCheckbox.java index e725719..09b09bf 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/widget/CustomCheckbox.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/client/gui/widget/CustomCheckbox.java @@ -1,4 +1,4 @@ -package dev.ftb.mods.ftbfiltersystem.client.gui.widget; +package dev.ftb.mods.ftbfiltersystem.api.client.gui.widget; import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.ChatFormatting; diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/event/FilterRegistrationEvent.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/event/FilterRegistrationEvent.java index db189e1..c85f310 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/event/FilterRegistrationEvent.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/event/FilterRegistrationEvent.java @@ -4,6 +4,9 @@ import dev.architectury.event.EventFactory; import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemRegistry; +/** + * Fired when filters are being registered; use this event to register your custom filters. + */ public interface FilterRegistrationEvent { Event REGISTER = EventFactory.createLoop(); diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/event/client/ClientFilterRegistrationEvent.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/event/client/ClientFilterRegistrationEvent.java index cd9dd78..ffe46ca 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/event/client/ClientFilterRegistrationEvent.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/event/client/ClientFilterRegistrationEvent.java @@ -2,9 +2,12 @@ import dev.architectury.event.Event; import dev.architectury.event.EventFactory; -import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemRegistry; import dev.ftb.mods.ftbfiltersystem.api.client.FTBFilterSystemClientAPI; +/** + * Fired when filters are being registered on the client; use this event to register configuration screens for your + * custom filters. + */ public interface ClientFilterRegistrationEvent { Event REGISTER = EventFactory.createLoop(); diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/filter/AbstractComparisonFilter.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/filter/AbstractComparisonFilter.java index 4e0e1aa..505b91c 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/filter/AbstractComparisonFilter.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/filter/AbstractComparisonFilter.java @@ -3,6 +3,9 @@ import dev.ftb.mods.ftbfiltersystem.api.NumericComparison; import net.minecraft.world.item.ItemStack; +/** + * Base class for all simple comparison filters; those filters which compare a single integer property. + */ public abstract class AbstractComparisonFilter extends AbstractSmartFilter { protected final NumericComparison comparison; @@ -15,8 +18,17 @@ public NumericComparison getComparison() { return comparison; } + /** + * Retrieve the actual value to be compared from the given itemstack + * @param stack the stack to check + * @return the value to be compared + */ protected abstract int getValueToCompare(ItemStack stack); + /** + * Does this filter allow the comparison value to alternately be specified as a percentage of the maximum amount? + * @return true to allow percentage comparisons, false otherwise + */ public boolean allowsPercentage() { return false; } diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/filter/SmartFilter.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/filter/SmartFilter.java index f7bcabe..4e27c26 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/filter/SmartFilter.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/api/filter/SmartFilter.java @@ -9,7 +9,7 @@ import java.util.function.Predicate; /** - * Represent a filter object, which can be used to test item stacks for specific properties. Smart filters may be + * Represents a filter object, which can be used to test item stacks for specific properties. Smart filters may be * compound (see {@link AbstractCompoundFilter}) and represent a hierarchy of filters. * * @apiNote Implementations should extend {@link AbstractSmartFilter} or {@link AbstractCompoundFilter} rather than diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/FTBFilterSystemClient.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/FTBFilterSystemClient.java index c90b19c..6fe918e 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/FTBFilterSystemClient.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/FTBFilterSystemClient.java @@ -46,7 +46,7 @@ private void registerClientFilters(FTBFilterSystemClientAPI api) { api.registerFilterScreenFactory(FoodValueFilter.ID, FoodValueConfigScreen::new); api.registerFilterScreenFactory(ItemTagFilter.ID, ItemTagConfigScreen::new); api.registerFilterScreenFactory(ModFilter.ID, ModConfigScreen::new); - api.registerFilterScreenFactory(NbtFilter.ID, NBTConfigScreen::new); + api.registerFilterScreenFactory(ComponentFilter.ID, ComponentConfigScreen::new); api.registerFilterScreenFactory(CustomFilter.ID, CustomConfigScreen::new); api.registerFilterScreenFactory(ExpressionFilter.ID, ExpressionConfigScreen::new); } diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/SelectionPanel.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/SelectionPanel.java index 5e4aefe..33ec488 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/SelectionPanel.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/SelectionPanel.java @@ -118,7 +118,7 @@ public void positionAndRender(GuiGraphics guiGraphics, int topEdge, int rightEdg layout.setPosition(bounds.getX(), bounds.getY()); GuiUtil.drawPanel(guiGraphics, GuiUtil.outsetRect(bounds, 3), 0xFFD6D6D6, 0xFF404040, GuiUtil.BorderStyle.PLAIN, 1); - guiGraphics.vLine(xBase + compoundButtons.get(0).getWidth() + 5, topEdge, topEdge + layout.getHeight(), 0xFFA0A0A0); + guiGraphics.vLine(xBase + compoundButtons.getFirst().getWidth() + 5, topEdge, topEdge + layout.getHeight(), 0xFFA0A0A0); visitWidgets(w -> w.render(guiGraphics, mouseX, mouseY, partialTick)); } diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/AbstractItemEditorConfigScreen.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/AbstractItemEditorConfigScreen.java index 41a302d..f027b64 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/AbstractItemEditorConfigScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/AbstractItemEditorConfigScreen.java @@ -99,7 +99,7 @@ public SearchItemWidget(int row, int col) { protected void handleClick(boolean doubleClick) { if (inventoryChecker().test(getStack()) && minecraft.player.hasPermissions(2)) { editBox.setValue(serialize(getStack())); - customHoverName = getStack().hasCustomHoverName() ? getStack().getHoverName() : null; + customHoverName = getStack().getHoverName(); AbstractItemEditorConfigScreen.this.setFocused(editBox); AbstractItemEditorConfigScreen.this.onItemWidgetClicked(); } diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/NBTConfigScreen.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ComponentConfigScreen.java similarity index 52% rename from common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/NBTConfigScreen.java rename to common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ComponentConfigScreen.java index d992c98..5fb464d 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/NBTConfigScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ComponentConfigScreen.java @@ -2,20 +2,26 @@ import dev.ftb.mods.ftbfiltersystem.api.FilterException; import dev.ftb.mods.ftbfiltersystem.api.client.gui.AbstractFilterScreen; -import dev.ftb.mods.ftbfiltersystem.client.gui.widget.CustomCheckbox; -import dev.ftb.mods.ftbfiltersystem.filter.NbtFilter; +import dev.ftb.mods.ftbfiltersystem.api.client.gui.widget.CustomCheckbox; +import dev.ftb.mods.ftbfiltersystem.filter.ComponentFilter; +import dev.ftb.mods.ftbfiltersystem.util.PlatformUtil; +import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Rect2i; +import net.minecraft.core.component.DataComponentMap; +import net.minecraft.core.component.DataComponents; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtOps; +import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Nullable; -import java.util.Objects; import java.util.function.Predicate; -public class NBTConfigScreen extends AbstractItemEditorConfigScreen implements GhostDropReceiver { +public class ComponentConfigScreen extends AbstractItemEditorConfigScreen implements GhostDropReceiver { private CustomCheckbox fuzzyCB; - public NBTConfigScreen(NbtFilter filter, AbstractFilterScreen parentScreen) { + public ComponentConfigScreen(ComponentFilter filter, AbstractFilterScreen parentScreen) { super(filter, parentScreen, 320, 176); } @@ -26,7 +32,11 @@ protected void init() { Component str = Component.translatable("ftbfiltersystem.gui.fuzzy_match"); fuzzyCB = addRenderableWidget(new CustomCheckbox(leftPos + 180, topPos + 110, font.width(str), 20, str, filter.isFuzzyMatch())); - editBox.setValue(filter.getTag().toString()); + try { + Tag tag = DataComponentMap.CODEC.encodeStart(NbtOps.INSTANCE, filter.getComponentMap()).getOrThrow(); + editBox.setValue(tag.toString()); + } catch (IllegalStateException ignored) { + } } @Override @@ -35,7 +45,7 @@ protected void doScheduledUpdate() { setStatus(true, Component.empty(), null); } else { try { - NbtFilter.fromString(filter.getParent(), editBox.getValue()); + ComponentFilter.fromString(filter.getParent(), editBox.getValue()); setStatus(true, Component.translatable("ftbfiltersystem.gui.nbt_ok"), null); } catch (FilterException e) { setStatus(false, Component.translatable("ftbfiltersystem.gui.nbt_bad"), e.getMessage()); @@ -44,10 +54,10 @@ protected void doScheduledUpdate() { } @Override - protected @Nullable NbtFilter makeNewFilter() { + protected @Nullable ComponentFilter makeNewFilter() { try { - String str = NbtFilter.getNBTPrefix(fuzzyCB.selected()) + editBox.getValue(); - return NbtFilter.fromString(filter.getParent(), str); + String str = ComponentFilter.getPrefixStr(fuzzyCB.selected()) + editBox.getValue(); + return ComponentFilter.fromString(filter.getParent(), str); } catch (FilterException e) { return null; } @@ -55,12 +65,16 @@ protected void doScheduledUpdate() { @Override protected Predicate inventoryChecker() { - return ItemStack::hasTag; + return PlatformUtil::hasComponentPatch; } @Override protected String serialize(ItemStack stack) { - return Objects.requireNonNull(stack.getTag()).toString(); + Tag res = stack.save(Minecraft.getInstance().level.registryAccess(), new CompoundTag()); + if (res instanceof CompoundTag c && c.contains("components")) { + return c.get("components").toString(); + } + return ""; } @Override @@ -68,11 +82,12 @@ public Rect2i getGhostDropRegion() { return new Rect2i(editBox.getX(), editBox.getY(), editBox.getWidth(), editBox.getHeight()); } + @SuppressWarnings("UnreachableCode") @Override public void receiveGhostDrop(ItemStack stack) { - if (stack.hasTag()) { + if (PlatformUtil.hasComponentPatch(stack)) { editBox.setValue(serialize(stack)); - customHoverName = stack.hasCustomHoverName() ? stack.getHoverName() : null; + customHoverName = stack.getOrDefault(DataComponents.CUSTOM_NAME, null); setFocused(editBox); } } diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/DurabilityConfigScreen.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/DurabilityConfigScreen.java index 35199e0..998f649 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/DurabilityConfigScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/DurabilityConfigScreen.java @@ -1,5 +1,6 @@ package dev.ftb.mods.ftbfiltersystem.client.gui; +import dev.ftb.mods.ftbfiltersystem.api.client.gui.AbstractComparisonConfigScreen; import dev.ftb.mods.ftbfiltersystem.api.client.gui.AbstractFilterScreen; import dev.ftb.mods.ftbfiltersystem.filter.DurabilityFilter; diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ExpressionConfigScreen.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ExpressionConfigScreen.java index 7cd001a..6e8d19a 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ExpressionConfigScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ExpressionConfigScreen.java @@ -51,8 +51,7 @@ protected void onItemWidgetClicked() { @Override protected Predicate inventoryChecker() { - return stack -> stack.hasTag() && FTBFilterSystemAPI.api().isFilterItem(stack) - && !FTBFilterSystemClient.isPlayerHolding(stack); + return stack -> FTBFilterSystemAPI.api().isFilterItem(stack) && !FTBFilterSystemClient.isPlayerHolding(stack); } @Override 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 c2a7cde..14139a9 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 @@ -1,6 +1,7 @@ package dev.ftb.mods.ftbfiltersystem.client.gui; import com.mojang.blaze3d.platform.InputConstants; +import dev.architectury.networking.NetworkManager; import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI; import dev.ftb.mods.ftbfiltersystem.api.client.Textures; import dev.ftb.mods.ftbfiltersystem.api.client.gui.AbstractFilterScreen; @@ -32,6 +33,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Optional; public class FilterScreen extends AbstractFilterScreen { private static SelectionPanel selectionPanel = null; @@ -74,7 +76,6 @@ protected void init() { filterList = new FilterList(minecraft, topPos + 20, getListWidth(), getListHeight()); filterList.setX(leftPos + 8); - filterList.setRenderBackground(false); addWidget(filterList); titleEditBtn = addRenderableWidget(new ImageButton(leftPos, topPos + 3, 16, 16, @@ -139,7 +140,9 @@ private boolean canAddMoreFilters(SmartFilter filter) { } private void applyChanges() { - new SyncFilterMessage(filter.toString(), newTitle == null ? null : newTitle.getString(), interactionHand).sendToServer(); + NetworkManager.sendToServer(new SyncFilterMessage( + filter.toString(), newTitle == null ? Optional.empty() : Optional.of(newTitle.getString()), interactionHand) + ); onClose(); @@ -232,9 +235,9 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partia super.render(guiGraphics, mouseX, mouseY, partialTick); if (guiHeight > 0) { - GuiUtil.drawPanel(guiGraphics, new Rect2i(leftPos + 7, topPos + 20, getListWidth() + 2, getListHeight()), + GuiUtil.drawPanel(guiGraphics, new Rect2i(leftPos + 7, topPos + 19, getListWidth() + 2, getListHeight() + 1), 0xFFA0A0A0, 0xFFA0A0A0, GuiUtil.BorderStyle.INSET, 1); - filterList.render(guiGraphics, mouseX, mouseY, partialTick); + filterList.renderWidget(guiGraphics, mouseX, mouseY, partialTick); Component displayTitle = newTitle == null ? title : newTitle; guiGraphics.drawString(font, displayTitle,leftPos + 8, topPos + 7, 0x404040, false); @@ -372,6 +375,10 @@ public FilterList(Minecraft minecraft, int y, int width, int height) { addChildren(); } + @Override + protected void renderListBackground(GuiGraphics guiGraphics) { + } + private void addChildren() { List entries = new ArrayList<>(); @@ -479,6 +486,10 @@ protected void renderSelection(GuiGraphics guiGraphics, int pTop, int pWidth, in 0xFF4663AC, GuiUtil.BorderStyle.PLAIN, 1); } + @Override + protected void renderListSeparators(GuiGraphics guiGraphics) { + } + private void findAndSelect(SmartFilter filter) { children().stream().filter(entry -> entry.dumpedFilter.filter() == filter) .findFirst() diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/FoodValueConfigScreen.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/FoodValueConfigScreen.java index b39f6df..a5eace2 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/FoodValueConfigScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/FoodValueConfigScreen.java @@ -1,5 +1,6 @@ package dev.ftb.mods.ftbfiltersystem.client.gui; +import dev.ftb.mods.ftbfiltersystem.api.client.gui.AbstractComparisonConfigScreen; import dev.ftb.mods.ftbfiltersystem.api.client.gui.AbstractFilterScreen; import dev.ftb.mods.ftbfiltersystem.filter.FoodValueFilter; diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ItemConfigScreen.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ItemConfigScreen.java index 8be6233..2fb1777 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ItemConfigScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ItemConfigScreen.java @@ -19,6 +19,7 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.flag.FeatureFlags; import net.minecraft.world.item.CreativeModeTabs; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import org.jetbrains.annotations.Nullable; @@ -32,8 +33,6 @@ import java.util.stream.Collectors; public class ItemConfigScreen extends AbstractFilterConfigScreen implements GhostDropReceiver { - private static final ResourceLocation SCROLL_TEXTURE = new ResourceLocation("textures/gui/container/creative_inventory/tabs.png"); - private static final int SEARCH_ROWS = 4; private static final int SEARCH_COLS = 9; @@ -270,7 +269,7 @@ static class SearchEntry implements Predicate { List l; try { Minecraft mc = Minecraft.getInstance(); - l = stack.getTooltipLines(mc.player, mc.options.advancedItemTooltips ? TooltipFlag.Default.ADVANCED : TooltipFlag.Default.NORMAL).stream() + l = stack.getTooltipLines(Item.TooltipContext.of(mc.level), mc.player, mc.options.advancedItemTooltips ? TooltipFlag.Default.ADVANCED : TooltipFlag.Default.NORMAL).stream() .map(Component::getString) .collect(Collectors.toList()); } catch (Exception ignored) { diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ItemTagConfigScreen.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ItemTagConfigScreen.java index db296ac..0b2fa58 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ItemTagConfigScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ItemTagConfigScreen.java @@ -41,11 +41,8 @@ protected void init() { updateSearchEntries(); -// itemTagList = new ItemTagList(minecraft, getListWidth() + 8, getListHeight(), topPos + 32, topPos + 35 + getListHeight()); itemTagList = new ItemTagList(minecraft,topPos + 32, getListWidth(), getListHeight()); itemTagList.setX(leftPos + 8); - itemTagList.setRenderBackground(false); -// itemTagList.setRenderTopAndBottom(false); addWidget(itemTagList); itemTagList.children().stream() @@ -104,6 +101,10 @@ public ItemTagList(Minecraft minecraft, int y, int width, int height) { super(minecraft, width, height, y, ELEMENT_HEIGHT); } + @Override + protected void renderListBackground(GuiGraphics guiGraphics) { + } + @Override protected List buildChildrenList() { return matchingTags.stream().map(ItemTagEntry::new).toList(); diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/MaxCountConfigScreen.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/MaxCountConfigScreen.java index da7d5a6..bebf139 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/MaxCountConfigScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/MaxCountConfigScreen.java @@ -1,5 +1,6 @@ package dev.ftb.mods.ftbfiltersystem.client.gui; +import dev.ftb.mods.ftbfiltersystem.api.client.gui.AbstractComparisonConfigScreen; import dev.ftb.mods.ftbfiltersystem.api.client.gui.AbstractFilterScreen; import dev.ftb.mods.ftbfiltersystem.filter.MaxStackSizeFilter; diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ModConfigScreen.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ModConfigScreen.java index 68a4eef..58b5799 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ModConfigScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/ModConfigScreen.java @@ -39,11 +39,8 @@ protected void init() { updateSearchEntries(); -// modList = new ModList(minecraft, getListWidth() + 8, getListHeight(), topPos + 32, topPos + 35 + getListHeight()); modList = new ModList(minecraft, topPos + 32, getListWidth(), getListHeight()); modList.setX(leftPos + 8); - modList.setRenderBackground(false); -// modList.setRenderTopAndBottom(false); addWidget(modList); modList.children().stream() @@ -120,6 +117,10 @@ public ModList(Minecraft minecraft, int y, int width, int height) { super(minecraft, width, height, y, ELEMENT_HEIGHT); } + @Override + protected void renderListBackground(GuiGraphics guiGraphics) { + } + @Override protected List buildChildrenList() { return matchingModData.stream().map(ModEntry::new).toList(); diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/StackSizeConfigScreen.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/StackSizeConfigScreen.java index bbd23f6..43cfa59 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/StackSizeConfigScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/StackSizeConfigScreen.java @@ -1,5 +1,6 @@ package dev.ftb.mods.ftbfiltersystem.client.gui; +import dev.ftb.mods.ftbfiltersystem.api.client.gui.AbstractComparisonConfigScreen; import dev.ftb.mods.ftbfiltersystem.api.client.gui.AbstractFilterScreen; import dev.ftb.mods.ftbfiltersystem.filter.StackSizeFilter; diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/widget/CustomSelectionList.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/widget/CustomSelectionList.java index 4cf8cda..78c2488 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/widget/CustomSelectionList.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/widget/CustomSelectionList.java @@ -45,12 +45,12 @@ public void updateWidgetNarration(NarrationElementOutput narrationElementOutput) } @Override - protected void renderList(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { + protected void renderListItems(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { int w = getMaxScroll() > 0 ? width - 6 : width; GuiUtil.drawPanel(guiGraphics, new Rect2i(getX(), getY(), w, height + 4), 0xFFA0A0A0, 0xFFA0A0A0, GuiUtil.BorderStyle.INSET, 1); - super.renderList(guiGraphics, mouseX, mouseY, partialTick); + super.renderListItems(guiGraphics, mouseX, mouseY, partialTick); } @Override diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/widget/ItemWidget.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/widget/ItemWidget.java index 67b4fdd..4f822d8 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/widget/ItemWidget.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/widget/ItemWidget.java @@ -7,6 +7,7 @@ import net.minecraft.client.gui.components.Tooltip; import net.minecraft.client.gui.narration.NarrationElementOutput; import net.minecraft.network.chat.Component; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import org.jetbrains.annotations.NotNull; @@ -65,7 +66,7 @@ private void updateTooltip() { setTooltip(null); } else { TooltipFlag.Default flag = Minecraft.getInstance().options.advancedItemTooltips ? TooltipFlag.ADVANCED : TooltipFlag.NORMAL; - stack.getTooltipLines(Minecraft.getInstance().player, flag).stream() + stack.getTooltipLines(Item.TooltipContext.of(Minecraft.getInstance().level), Minecraft.getInstance().player, flag).stream() .reduce((c1, c2) -> c1.copy().append("\n").append(c2)) .ifPresent(c -> setTooltip(Tooltip.create(c))); } diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/BlockFilter.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/BlockFilter.java index e13cd0f..666a338 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/BlockFilter.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/BlockFilter.java @@ -1,8 +1,7 @@ package dev.ftb.mods.ftbfiltersystem.filter; -import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractCompoundFilter; -import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractSmartFilter; import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI; +import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractSmartFilter; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.BlockItem; diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/NbtFilter.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ComponentFilter.java similarity index 53% rename from common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/NbtFilter.java rename to common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ComponentFilter.java index da7c3fe..2c50158 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/NbtFilter.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ComponentFilter.java @@ -5,32 +5,35 @@ import dev.ftb.mods.ftbfiltersystem.api.FilterException; import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractSmartFilter; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; -import dev.ftb.mods.ftbfiltersystem.util.NBTUtil; +import dev.ftb.mods.ftbfiltersystem.util.PlatformUtil; +import net.minecraft.core.component.DataComponentMap; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtOps; +import net.minecraft.nbt.Tag; import net.minecraft.nbt.TagParser; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class NbtFilter extends AbstractSmartFilter { - public static final ResourceLocation ID = FTBFilterSystemAPI.rl("nbt"); - protected final CompoundTag tag; +public class ComponentFilter extends AbstractSmartFilter { + public static final ResourceLocation ID = FTBFilterSystemAPI.rl("component"); + protected final DataComponentMap map; private final boolean fuzzyMatch; - public NbtFilter(@Nullable SmartFilter.Compound parent) { - this(parent, true, new CompoundTag()); + public ComponentFilter(@Nullable SmartFilter.Compound parent) { + this(parent, true, DataComponentMap.EMPTY); } - public NbtFilter(SmartFilter.Compound parent, boolean fuzzyMatch, CompoundTag tag) { + public ComponentFilter(SmartFilter.Compound parent, boolean fuzzyMatch, DataComponentMap map) { super(parent); this.fuzzyMatch = fuzzyMatch; - this.tag = tag; + this.map = map; } @NotNull - public static String getNBTPrefix(boolean fuzzy) { + public static String getPrefixStr(boolean fuzzy) { return fuzzy ? "fuzzy:" : "strict:"; } @@ -41,36 +44,43 @@ public ResourceLocation getId() { @Override public boolean test(ItemStack stack) { - return tag.isEmpty() ? - stack.getTag() == null || stack.getTag().isEmpty() : - (fuzzyMatch ? fuzzyMatch(stack.getTag()) : tag.equals(stack.getTag())); + //noinspection UnreachableCode + return PlatformUtil.hasComponentPatch(stack) ? + (fuzzyMatch ? fuzzyMatch(stack.getComponents()) : stack.getComponents().equals(map)) : + map.isEmpty(); } - private boolean fuzzyMatch(CompoundTag toMatch) { - return tag != null && NBTUtil.compareNbt(tag, toMatch, true, true); + private boolean fuzzyMatch(DataComponentMap toMatch) { + return map.stream().allMatch(tc -> toMatch.has(tc.type()) && toMatch.get(tc.type()).equals(tc.value())); } @Override public String getStringArg() { - return getNBTPrefix(fuzzyMatch) + tag.toString(); + try { + Tag tag = DataComponentMap.CODEC.encodeStart(NbtOps.INSTANCE, map).getOrThrow(); + return getPrefixStr(fuzzyMatch) + tag.toString(); + } catch (IllegalStateException e) { + return ""; + } } - public CompoundTag getTag() { - return tag; + public DataComponentMap getComponentMap() { + return map; } public boolean isFuzzyMatch() { return fuzzyMatch; } - public static NbtFilter fromString(SmartFilter.Compound parent, String str) { + public static ComponentFilter fromString(SmartFilter.Compound parent, String str) { try { boolean fuzzy = true; if (str.startsWith("strict:") || str.startsWith("fuzzy:")) { fuzzy = str.startsWith("fuzzy:"); str = str.substring(str.indexOf(':') + 1); } - return new NbtFilter(parent, fuzzy, parseNBT(str)); + DataComponentMap map = DataComponentMap.CODEC.parse(NbtOps.INSTANCE, parseNBT(str)).getOrThrow(FilterException::new); + return new ComponentFilter(parent, fuzzy, map); } catch (CommandSyntaxException e) { throw new FilterException("invalid NBT tag: " + str, e); } diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/DurabilityFilter.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/DurabilityFilter.java index 8c2708c..3ce0c65 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/DurabilityFilter.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/DurabilityFilter.java @@ -27,7 +27,7 @@ public ResourceLocation getId() { protected int getValueToCompare(ItemStack stack) { if (stack.getMaxDamage() != 0) { int durability = stack.getMaxDamage() - stack.getDamageValue(); - return comparison.isPercentage() ? + return comparison.percentage() ? (int) (durability * 100L / stack.getMaxDamage()) : // long arithmetic for int overflow avoidance durability; } else { diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/FoodValueFilter.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/FoodValueFilter.java index ee75caa..0d12c8b 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/FoodValueFilter.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/FoodValueFilter.java @@ -1,11 +1,10 @@ package dev.ftb.mods.ftbfiltersystem.filter; -import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractComparisonFilter; -import dev.ftb.mods.ftbfiltersystem.api.NumericComparison; -import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractCompoundFilter; import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI; +import dev.ftb.mods.ftbfiltersystem.api.NumericComparison; +import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractComparisonFilter; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; -import dev.ftb.mods.ftbfiltersystem.util.PlatformUtil; +import net.minecraft.core.component.DataComponents; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; @@ -27,7 +26,8 @@ public ResourceLocation getId() { @Override protected int getValueToCompare(ItemStack stack) { - return PlatformUtil.getFoodValue(stack); + //noinspection DataFlowIssue + return stack.has(DataComponents.FOOD) ? stack.get(DataComponents.FOOD).nutrition() : 0; } public static FoodValueFilter fromString(SmartFilter.Compound parent, String str) { diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ItemFilter.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ItemFilter.java index 43552d8..ca60dbe 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ItemFilter.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ItemFilter.java @@ -1,7 +1,7 @@ package dev.ftb.mods.ftbfiltersystem.filter; -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.FilterException; import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractSmartFilter; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; import net.minecraft.core.registries.BuiltInRegistries; diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ItemTagFilter.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ItemTagFilter.java index c888999..cba830d 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ItemTagFilter.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ItemTagFilter.java @@ -1,7 +1,7 @@ package dev.ftb.mods.ftbfiltersystem.filter; -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.FilterException; import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractSmartFilter; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; import net.minecraft.ResourceLocationException; diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/MaxStackSizeFilter.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/MaxStackSizeFilter.java index c36a295..31eda77 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/MaxStackSizeFilter.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/MaxStackSizeFilter.java @@ -1,9 +1,8 @@ package dev.ftb.mods.ftbfiltersystem.filter; -import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractComparisonFilter; -import dev.ftb.mods.ftbfiltersystem.api.NumericComparison; -import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractCompoundFilter; import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI; +import dev.ftb.mods.ftbfiltersystem.api.NumericComparison; +import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractComparisonFilter; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ModFilter.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ModFilter.java index 557a75a..6b9494b 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ModFilter.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ModFilter.java @@ -1,8 +1,7 @@ package dev.ftb.mods.ftbfiltersystem.filter; -import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractCompoundFilter; -import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractSmartFilter; import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI; +import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractSmartFilter; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/StackSizeFilter.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/StackSizeFilter.java index c26221b..66ccb12 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/StackSizeFilter.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/StackSizeFilter.java @@ -3,7 +3,6 @@ import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI; import dev.ftb.mods.ftbfiltersystem.api.NumericComparison; import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractComparisonFilter; -import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractCompoundFilter; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/compound/AndFilter.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/compound/AndFilter.java index 980def6..5214f38 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/compound/AndFilter.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/compound/AndFilter.java @@ -1,7 +1,7 @@ package dev.ftb.mods.ftbfiltersystem.filter.compound; -import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractCompoundFilter; import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI; +import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractCompoundFilter; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/compound/NotFilter.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/compound/NotFilter.java index 6076520..7805832 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/compound/NotFilter.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/compound/NotFilter.java @@ -1,8 +1,8 @@ package dev.ftb.mods.ftbfiltersystem.filter.compound; -import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractCompoundFilter; import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI; +import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractCompoundFilter; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; @@ -27,7 +27,7 @@ public int maxChildren() { @Override public boolean test(ItemStack stack) { - return !getChildren().isEmpty() && !getChildren().get(0).test(stack); + return !getChildren().isEmpty() && !getChildren().getFirst().test(stack); } public static NotFilter fromString(SmartFilter.Compound parent, String str) { diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/compound/OnlyOneFilter.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/compound/OnlyOneFilter.java index acc1e5a..083e719 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/compound/OnlyOneFilter.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/compound/OnlyOneFilter.java @@ -1,8 +1,8 @@ package dev.ftb.mods.ftbfiltersystem.filter.compound; -import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractCompoundFilter; import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI; +import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractCompoundFilter; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/compound/OrFilter.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/compound/OrFilter.java index f4448e0..8585997 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/compound/OrFilter.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/compound/OrFilter.java @@ -1,8 +1,8 @@ package dev.ftb.mods.ftbfiltersystem.filter.compound; -import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractCompoundFilter; import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI; +import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractCompoundFilter; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/integration/jei/JEIIntegration.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/integration/jei/JEIIntegration.java index 154fe56..b005a2f 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/integration/jei/JEIIntegration.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/integration/jei/JEIIntegration.java @@ -1,14 +1,13 @@ package dev.ftb.mods.ftbfiltersystem.integration.jei; import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI; -import dev.ftb.mods.ftbfiltersystem.client.gui.NBTConfigScreen; +import dev.ftb.mods.ftbfiltersystem.client.gui.ComponentConfigScreen; import dev.ftb.mods.ftbfiltersystem.client.gui.ItemConfigScreen; import dev.ftb.mods.ftbfiltersystem.client.gui.ModConfigScreen; import mezz.jei.api.IModPlugin; import mezz.jei.api.JeiPlugin; import mezz.jei.api.registration.IGuiHandlerRegistration; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; @JeiPlugin public class JEIIntegration implements IModPlugin { @@ -24,8 +23,9 @@ public void registerGuiHandlers(IGuiHandlerRegistration registration) { registration.addGuiScreenHandler(ItemConfigScreen.class, new FFSScreenHandler<>()); registration.addGhostIngredientHandler(ItemConfigScreen.class, new FFSGhostHandler<>()); - registration.addGuiScreenHandler(NBTConfigScreen.class, new FFSScreenHandler<>()); - registration.addGhostIngredientHandler(NBTConfigScreen.class, new FFSGhostHandler<>(ItemStack::hasTag)); + registration.addGuiScreenHandler(ComponentConfigScreen.class, new FFSScreenHandler<>()); +// registration.addGhostIngredientHandler(NBTConfigScreen.class, new FFSGhostHandler<>(ItemStack::hasTag)); + registration.addGhostIngredientHandler(ComponentConfigScreen.class, new FFSGhostHandler<>(s -> false)); registration.addGuiScreenHandler(ModConfigScreen.class, new FFSScreenHandler<>()); registration.addGhostIngredientHandler(ModConfigScreen.class, new FFSGhostHandler<>()); diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/network/FTBFilterSystemNet.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/network/FTBFilterSystemNet.java index de9918a..eb439a8 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/network/FTBFilterSystemNet.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/network/FTBFilterSystemNet.java @@ -1,14 +1,25 @@ package dev.ftb.mods.ftbfiltersystem.network; -import dev.architectury.networking.simple.MessageType; -import dev.architectury.networking.simple.SimpleNetworkManager; -import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI; +import dev.architectury.networking.NetworkManager; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; public interface FTBFilterSystemNet { - SimpleNetworkManager NET = SimpleNetworkManager.create(FTBFilterSystemAPI.MOD_ID); + static void init() { + NetworkManager.registerReceiver(NetworkManager.c2s(), SyncFilterMessage.TYPE, SyncFilterMessage.STREAM_CODEC, SyncFilterMessage::handle); + } - MessageType SYNC_FILTER = NET.registerC2S("sync_filter", SyncFilterMessage::new); + static > StreamCodec enumCodec(Class enumClass) { + return new StreamCodec<>() { + @Override + public V decode(B buf) { + return buf.readEnum(enumClass); + } - static void init() { + @Override + public void encode(B buf, V value) { + buf.writeEnum(value); + } + }; } } diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/network/SyncFilterMessage.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/network/SyncFilterMessage.java index a4ede3b..af8f0aa 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/network/SyncFilterMessage.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/network/SyncFilterMessage.java @@ -1,66 +1,53 @@ package dev.ftb.mods.ftbfiltersystem.network; import dev.architectury.networking.NetworkManager; -import dev.architectury.networking.simple.BaseC2SMessage; -import dev.architectury.networking.simple.MessageType; import dev.ftb.mods.ftbfiltersystem.FTBFilterSystem; +import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI; import dev.ftb.mods.ftbfiltersystem.api.FilterException; import dev.ftb.mods.ftbfiltersystem.registry.item.SmartFilterItem; import dev.ftb.mods.ftbfiltersystem.util.FilterParser; +import net.minecraft.core.component.DataComponents; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.world.InteractionHand; import net.minecraft.world.item.ItemStack; -import org.jetbrains.annotations.Nullable; import java.util.Optional; -public class SyncFilterMessage extends BaseC2SMessage { - private final String filterStr; - private final @Nullable String newTitle; - private final InteractionHand hand; +public record SyncFilterMessage(String filterStr, Optional newTitle, InteractionHand hand) implements CustomPacketPayload { + public static final Type TYPE = new Type<>(FTBFilterSystemAPI.rl("sync_filter")); - public SyncFilterMessage(String filterStr, @Nullable String newTitle, InteractionHand hand) { - this.filterStr = filterStr; - this.newTitle = newTitle; - this.hand = hand; - } - - public SyncFilterMessage(FriendlyByteBuf buf) { - filterStr = buf.readUtf(); - newTitle = buf.readNullable(FriendlyByteBuf::readUtf); - hand = buf.readEnum(InteractionHand.class); - } + public static StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.STRING_UTF8, SyncFilterMessage::filterStr, + ByteBufCodecs.STRING_UTF8.apply(ByteBufCodecs::optional), SyncFilterMessage::newTitle, + FTBFilterSystemNet.enumCodec(InteractionHand.class), SyncFilterMessage::hand, + SyncFilterMessage::new + ); - @Override - public MessageType getType() { - return FTBFilterSystemNet.SYNC_FILTER; - } - - @Override - public void write(FriendlyByteBuf buf) { - buf.writeUtf(filterStr); - buf.writeNullable(newTitle, FriendlyByteBuf::writeUtf); - buf.writeEnum(hand); - } - - @Override - public void handle(NetworkManager.PacketContext context) { - ItemStack stack = context.getPlayer().getItemInHand(hand); + public static void handle(SyncFilterMessage message, NetworkManager.PacketContext context) { + ItemStack stack = context.getPlayer().getItemInHand(message.hand); if (stack.getItem() instanceof SmartFilterItem) { try { - SmartFilterItem.setFilter(stack, FilterParser.parse(filterStr).toString()); - if (newTitle != null) { - if (newTitle.isEmpty()) { - stack.resetHoverName(); + SmartFilterItem.setFilter(stack, FilterParser.parse(message.filterStr).toString()); + message.newTitle.ifPresent(title -> { + if (title.isEmpty()) { + stack.remove(DataComponents.CUSTOM_NAME); } else { - stack.setHoverName(Component.literal(newTitle)); + stack.set(DataComponents.CUSTOM_NAME, Component.literal(title)); } - } + }); } catch (FilterException e) { FTBFilterSystem.LOGGER.error("received filter sync message with bad filter data from client {}: {}", context.getPlayer().getGameProfile().getName(), e.getMessage()); } } } + + @Override + public Type type() { + return TYPE; + } } diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/FilterRegistry.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/FilterRegistry.java index 56f9c9b..44126eb 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/FilterRegistry.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/FilterRegistry.java @@ -1,6 +1,5 @@ package dev.ftb.mods.ftbfiltersystem.registry; -import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractCompoundFilter; import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemRegistry; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; import net.minecraft.resources.ResourceLocation; diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/ModDataComponents.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/ModDataComponents.java new file mode 100644 index 0000000..efab728 --- /dev/null +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/ModDataComponents.java @@ -0,0 +1,21 @@ +package dev.ftb.mods.ftbfiltersystem.registry; + +import com.mojang.serialization.Codec; +import dev.architectury.registry.registries.DeferredRegister; +import dev.architectury.registry.registries.RegistrySupplier; +import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.core.registries.Registries; +import net.minecraft.network.codec.ByteBufCodecs; + +public class ModDataComponents { + public static final DeferredRegister> COMPONENT_TYPES + = DeferredRegister.create(FTBFilterSystemAPI.MOD_ID, Registries.DATA_COMPONENT_TYPE); + + public static final RegistrySupplier> FILTER_STRING + = COMPONENT_TYPES.register(FTBFilterSystemAPI.rl("filter"), () -> DataComponentType.builder() + .persistent(Codec.STRING) + .networkSynchronized(ByteBufCodecs.STRING_UTF8) + .build() + ); +} diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/ModItems.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/ModItems.java index 0fd4a36..dbaba0e 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/ModItems.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/ModItems.java @@ -24,15 +24,13 @@ public class ModItems { public static final RegistrySupplier SMART_FILTER = ITEMS.register("smart_filter", SmartFilterItem::new); public static Item.Properties defaultProps() { - return new Item.Properties().arch$tab(CREATIVE_TAB); + return new Item.Properties(); } private static CreativeModeTab buildDefaultTab() { return CreativeTabRegistry.create(builder -> builder.title(Component.translatable(FTBFilterSystemAPI.MOD_ID)) .icon(() -> new ItemStack(ModItems.SMART_FILTER.get())) - .displayItems((params, output) -> { - output.accept(new ItemStack(ModItems.SMART_FILTER.get())); - }) + .displayItems((params, output) -> output.accept(new ItemStack(ModItems.SMART_FILTER.get()))) ); } } diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/item/SmartFilterItem.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/item/SmartFilterItem.java index 88c9fe8..32c1c93 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/item/SmartFilterItem.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/item/SmartFilterItem.java @@ -5,6 +5,7 @@ import dev.ftb.mods.ftbfiltersystem.api.FilterException; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; import dev.ftb.mods.ftbfiltersystem.client.FTBFilterSystemClient; +import dev.ftb.mods.ftbfiltersystem.registry.ModDataComponents; import dev.ftb.mods.ftbfiltersystem.registry.ModItems; import dev.ftb.mods.ftbfiltersystem.util.FilterParser; import net.minecraft.ChatFormatting; @@ -16,19 +17,17 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; -import org.jetbrains.annotations.Nullable; import java.util.List; public class SmartFilterItem extends Item { - private static final String FILTER_TAG_NAME = "ftbfiltersystem:filter"; - public SmartFilterItem() { super(ModItems.defaultProps()); +// .component(ModDataComponents.FILTER_STRING.get(), "")); } public static String getFilterString(ItemStack filterStack) { - return filterStack.hasTag() ? filterStack.getTag().getString(FILTER_TAG_NAME) : ""; + return filterStack.getOrDefault(ModDataComponents.FILTER_STRING.get(), ""); } public static SmartFilter getFilter(ItemStack filterStack) throws FilterException { @@ -36,7 +35,7 @@ public static SmartFilter getFilter(ItemStack filterStack) throws FilterExceptio } public static void setFilter(ItemStack filterStack, String string) { - filterStack.getOrCreateTag().putString(FILTER_TAG_NAME, string); + filterStack.set(ModDataComponents.FILTER_STRING.get(), string); } @Override @@ -55,8 +54,8 @@ public InteractionResultHolder use(Level level, Player player, Intera } @Override - public void appendHoverText(ItemStack itemStack, @Nullable Level level, List list, TooltipFlag tooltipFlag) { - if (level == null || level.isClientSide && !FTBFilterSystemClient.shouldShowItemTooltip()) { + public void appendHoverText(ItemStack itemStack, TooltipContext context, List list, TooltipFlag tooltipFlag) { + if (context.registries() == null || !FTBFilterSystemClient.shouldShowItemTooltip()) { return; // avoids spurious tooltips in places like FTB Quests where a filter could be a matching display item } list.add(Component.translatable("item.ftbfiltersystem.smart_filter.tooltip.1").withStyle(ChatFormatting.GRAY)); diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/util/FilterCache.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/util/FilterCache.java index 4c1adfb..5c015f1 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/util/FilterCache.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/util/FilterCache.java @@ -30,4 +30,8 @@ public SmartFilter getOrCreateFilter(String filterStr) throws FilterException { return filter; } } + + public void clear() { + cache.clear(); + } } diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/util/PlatformUtil.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/util/PlatformUtil.java index feefad5..3c8f382 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/util/PlatformUtil.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/util/PlatformUtil.java @@ -5,7 +5,7 @@ public class PlatformUtil { @ExpectPlatform - public static int getFoodValue(ItemStack stack) { + public static boolean hasComponentPatch(ItemStack stack) { throw new AssertionError(); } } 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 2c910b8..820cec3 100644 --- a/common/src/main/resources/assets/ftbfiltersystem/lang/en_us.json +++ b/common/src/main/resources/assets/ftbfiltersystem/lang/en_us.json @@ -5,10 +5,15 @@ "item.ftbfiltersystem.smart_filter.tooltip.2": "Sneak + Right-click: Test filter with item in off hand", "ftbfiltersystem.message.parse_failed": "Filter parse failure: %s", "ftbfiltersystem.message.not_a_filter": "You must hold a Smart Filter in your main hand", + "ftbfiltersystem.message.not_configured": "This Smart Filter has no filter configured", "ftbfiltersystem.message.no_offhand_item": "Hold an item to be tested in your off hand", "ftbfiltersystem.message.matched": "Filter matches: %s", "ftbfiltersystem.message.not_matched": "Filter does not match: %s", "ftbfiltersystem.message.changes_saved": "Filter has been updated!", + "ftbfiltersystem.message.cache_cleared": "Cleared compiled filter cache", + "ftbfiltersystem.message.components_header": "%s data component(s) on %s:", + "ftbfiltersystem.message.components_header_none": "No data components", + "ftbfiltersystem.message.non_default_components": "Showing non-default components only", "ftbfiltersystem.gui.add": "Add...", "ftbfiltersystem.gui.delete": "Delete", "ftbfiltersystem.gui.configure": "Configure...", @@ -26,7 +31,7 @@ "ftbfiltersystem.gui.changes_made.question": "Close the editor without saving?", "ftbfiltersystem.gui.compound": "Compound Filters", "ftbfiltersystem.gui.basic": "Basic Filters", - "ftbfiltersystem.gui.fuzzy_match": "Fuzzy NBT Match?", + "ftbfiltersystem.gui.fuzzy_match": "Fuzzy Component Match?", "ftbfiltersystem.gui.custom_name": "Custom Name", "filter.ftbfiltersystem.and.name": "All Of", "filter.ftbfiltersystem.and.tooltip": "Compound filter: this filter matches if ALL of its child filters match.", @@ -38,14 +43,14 @@ "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.component.name": "Item Component", + "filter.ftbfiltersystem.component.tooltip": "Matches item data components on an item.\nSupports exact (all components must match) and fuzzy matches (only match components in the filter).\nIf you have admin permissions, items in your inventory which have (non-default) component data can be clicked to copy their current data into the text editor, serialized as SNBT.", "filter.ftbfiltersystem.durability.name": "Durability", "filter.ftbfiltersystem.durability.tooltip": "Matches an item based on its remaining durability.\nNon-damageable items are considered to have a durability of 0.", "filter.ftbfiltersystem.food_value.name": "Food Value", "filter.ftbfiltersystem.food_value.tooltip": "Matches an item based on its nutritional value (half-shanks of food restored)\nNon-food items have a nutritional value of 0", - "filter.ftbfiltersystem.fuzzy_nbt.name": "Fuzzy NBT", - "filter.ftbfiltersystem.fuzzy_nbt.tooltip": "Matches NBT on an item, but only the NBT fields specified here will be checked. Fields in the item's NBT not specified here are ignored.\nIf you have admin permissions, items in your inventory which have NBT can be clicked to copy their current NBT tag into the text editor.", "filter.ftbfiltersystem.item.name": "Item", - "filter.ftbfiltersystem.item.tooltip": "Matches against a specific item.\nNBT is not checked here (see NBT and Fuzzy NBT filters)\nItems can be picked from Creative or Inventory item lists.\nUse the textfield to filter item ID's to limit the displayed items.", + "filter.ftbfiltersystem.item.tooltip": "Matches against a specific item.\nItem component data is not checked here (see Component Filter)\nItems can be picked from Creative or Inventory item lists.\nUse the textfield to filter item ID's to limit the displayed items.", "filter.ftbfiltersystem.item_tag.name": "Item Tag", "filter.ftbfiltersystem.item_tag.tooltip": "Matches against an item tag; items which are in the tag will be matched.\nUse the textfield to filter displayed item tags.", "filter.ftbfiltersystem.stack_size.name": "Stack Size", @@ -54,11 +59,9 @@ "filter.ftbfiltersystem.max_stack_size.tooltip": "Matches against an item's maximum stack size.\nUnstackable items have a maximum stack size of 1.", "filter.ftbfiltersystem.mod.name": "Mod", "filter.ftbfiltersystem.mod.tooltip": "Matches against the mod which adds the item.\nVanilla items are in the Minecraft 'mod'.", - "filter.ftbfiltersystem.nbt.name": "NBT", - "filter.ftbfiltersystem.nbt.tooltip": "Matches NBT on an item.\nAn exact match is required.\nIf you have admin permissions, items in your inventory which have NBT can be clicked to copy their current NBT tag into the text editor.", "filter.ftbfiltersystem.custom.name": "Custom", "filter.ftbfiltersystem.custom.tooltip": "Advanced filter intended for modders and modpack makers.\nFires a CustomFilterEvent when a match is attempted; set the event result to indicate a successful or failed match.\nUse the textfield to provide freeform text data which is passed to the event as the 'data' parameter.", "filter.ftbfiltersystem.expression.name": "Expression", "filter.ftbfiltersystem.expression.tooltip": "Allows a literal filter expression to be entered or loaded from a Filter item in your inventory.\nIt is optional (but recommended!) to assign a custom name, for clarity.", - "filter.ftbfiltersystem.root.name": "All Of (Root)" + "filter.ftbfiltersystem.root.name": "Root (All Of)" } \ No newline at end of file diff --git a/common/src/main/resources/data/ftbfiltersystem/recipes/smart_filter.json b/common/src/main/resources/data/ftbfiltersystem/recipes/smart_filter.json index 90684bc..ef5b92f 100644 --- a/common/src/main/resources/data/ftbfiltersystem/recipes/smart_filter.json +++ b/common/src/main/resources/data/ftbfiltersystem/recipes/smart_filter.json @@ -1,5 +1,6 @@ { "type": "minecraft:crafting_shaped", + "category": "misc", "key": { "P": { "item": "minecraft:paper" @@ -17,6 +18,7 @@ "TST" ], "result": { - "item": "ftbfiltersystem:smart_filter" + "count": 1, + "id": "ftbfiltersystem:smart_filter" } } \ No newline at end of file diff --git a/fabric/build.gradle b/fabric/build.gradle index bab86fa..19c91c0 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -25,7 +25,8 @@ dependencies { // Remove the next line if you don't want to depend on the API modApi "dev.architectury:architectury-fabric:${rootProject.architectury_version}" - modCompileOnly("mezz.jei:jei-${rootProject.minecraft_version}-fabric-api:${rootProject.jei_version}") +// modCompileOnly("mezz.jei:jei-${rootProject.minecraft_version}-fabric-api:${rootProject.jei_version}") + modCompileOnly("mezz.jei:jei-1.20.4-fabric-api:${rootProject.jei_version}") common(project(path: ":common", configuration: "namedElements")) { transitive false } shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false } diff --git a/fabric/src/main/java/dev/ftb/mods/ftbfiltersystem/fabric/mixin/PatchedDataComponentMapAccess.java b/fabric/src/main/java/dev/ftb/mods/ftbfiltersystem/fabric/mixin/PatchedDataComponentMapAccess.java new file mode 100644 index 0000000..67d2672 --- /dev/null +++ b/fabric/src/main/java/dev/ftb/mods/ftbfiltersystem/fabric/mixin/PatchedDataComponentMapAccess.java @@ -0,0 +1,15 @@ +package dev.ftb.mods.ftbfiltersystem.fabric.mixin; + +import it.unimi.dsi.fastutil.objects.Reference2ObjectMap; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.core.component.PatchedDataComponentMap; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Optional; + +@Mixin(PatchedDataComponentMap.class) +public interface PatchedDataComponentMapAccess { + @Accessor + Reference2ObjectMap, Optional> getPatch(); +} diff --git a/fabric/src/main/java/dev/ftb/mods/ftbfiltersystem/util/fabric/PlatformUtilImpl.java b/fabric/src/main/java/dev/ftb/mods/ftbfiltersystem/util/fabric/PlatformUtilImpl.java index e7fad1c..3bd82fa 100644 --- a/fabric/src/main/java/dev/ftb/mods/ftbfiltersystem/util/fabric/PlatformUtilImpl.java +++ b/fabric/src/main/java/dev/ftb/mods/ftbfiltersystem/util/fabric/PlatformUtilImpl.java @@ -1,9 +1,15 @@ package dev.ftb.mods.ftbfiltersystem.util.fabric; +import dev.ftb.mods.ftbfiltersystem.fabric.mixin.PatchedDataComponentMapAccess; +import net.minecraft.core.component.PatchedDataComponentMap; import net.minecraft.world.item.ItemStack; +@SuppressWarnings("unused") public class PlatformUtilImpl { - public static int getFoodValue(ItemStack stack) { - return stack.getItem().getFoodProperties() == null ? 0 : stack.getItem().getFoodProperties().getNutrition(); + public static boolean hasComponentPatch(ItemStack stack) { + if (stack.getComponents() instanceof PatchedDataComponentMap) { + return !((PatchedDataComponentMapAccess) stack.getComponents()).getPatch().isEmpty(); + } + return false; } } diff --git a/fabric/src/main/resources/ftbfiltersystem.mixins.json b/fabric/src/main/resources/ftbfiltersystem.mixins.json index faf8e68..b588cca 100644 --- a/fabric/src/main/resources/ftbfiltersystem.mixins.json +++ b/fabric/src/main/resources/ftbfiltersystem.mixins.json @@ -4,6 +4,7 @@ "compatibilityLevel": "JAVA_17", "minVersion": "0.8", "client": [ + "PatchedDataComponentMapAccess" ], "mixins": [ ], diff --git a/gradle.properties b/gradle.properties index 0fab96a..a20c5b1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,21 +1,22 @@ org.gradle.jvmargs=-Xmx2048M -minecraft_version=1.20.4 -enabled_platforms=fabric,forge,neoforge +minecraft_version=1.20.6 +#enabled_platforms=fabric,forge,neoforge +enabled_platforms=fabric,neoforge archives_base_name=ftb-filter-system -mod_version=2.0.1 +mod_version=2.1.0 maven_group=dev.ftb.mods curseforge_id=943925 -architectury_version=11.1.17 +architectury_version=12.0.28 -fabric_loader_version=0.15.7 -fabric_api_version=0.96.4+1.20.4 +fabric_loader_version=0.15.10 +fabric_api_version=0.97.8+1.20.6 forge_version=49.0.31 -neoforge_version=20.4.196 +neoforge_version=20.6.48-beta neoforge_loader_version=1 jei_version=17.3.0.49 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 744c64d..20db9ad 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/neoforge/build.gradle b/neoforge/build.gradle index 3a118df..fa412e9 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -30,7 +30,8 @@ dependencies { // Remove the next line if you don't want to depend on the API modApi "dev.architectury:architectury-neoforge:${rootProject.architectury_version}" - modCompileOnly("mezz.jei:jei-${rootProject.minecraft_version}-forge-api:${rootProject.jei_version}") +// modCompileOnly("mezz.jei:jei-${rootProject.minecraft_version}-forge-api:${rootProject.jei_version}") + modCompileOnly("mezz.jei:jei-1.20.4-forge-api:${rootProject.jei_version}") common(project(path: ":common", configuration: "namedElements")) { transitive false } shadowCommon(project(path: ":common", configuration: "transformProductionNeoForge")) { transitive = false } @@ -41,7 +42,7 @@ apply from: "https://raw.githubusercontent.com/FTBTeam/mods-meta/main/gradle/ext processResources { inputs.property "version", project.version - filesMatching("META-INF/mods.toml") { + filesMatching("META-INF/neoforge.mods.toml") { expand "version": project.version, "archversion": project.architectury_version, "neoforgeversion": project.neoforge_version, diff --git a/neoforge/src/main/java/dev/ftb/mods/ftbfiltersystem/neoforge/FTBFilterSystemForge.java b/neoforge/src/main/java/dev/ftb/mods/ftbfiltersystem/neoforge/FTBFilterSystemNeoForge.java similarity index 85% rename from neoforge/src/main/java/dev/ftb/mods/ftbfiltersystem/neoforge/FTBFilterSystemForge.java rename to neoforge/src/main/java/dev/ftb/mods/ftbfiltersystem/neoforge/FTBFilterSystemNeoForge.java index 7e9fc7f..13aa7b6 100644 --- a/neoforge/src/main/java/dev/ftb/mods/ftbfiltersystem/neoforge/FTBFilterSystemForge.java +++ b/neoforge/src/main/java/dev/ftb/mods/ftbfiltersystem/neoforge/FTBFilterSystemNeoForge.java @@ -5,8 +5,8 @@ import net.neoforged.fml.common.Mod; @Mod(FTBFilterSystemAPI.MOD_ID) -public class FTBFilterSystemForge { - public FTBFilterSystemForge() { +public class FTBFilterSystemNeoForge { + public FTBFilterSystemNeoForge() { // Submit our event bus to let architectury register our content on the right time // EventBuses.registerModEventBus(FTBFilterSystemAPI.MOD_ID, FMLJavaModLoadingContext.get().getModEventBus()); new FTBFilterSystem(); diff --git a/neoforge/src/main/java/dev/ftb/mods/ftbfiltersystem/util/neoforge/PlatformUtilImpl.java b/neoforge/src/main/java/dev/ftb/mods/ftbfiltersystem/util/neoforge/PlatformUtilImpl.java index 479acd8..2ec16da 100644 --- a/neoforge/src/main/java/dev/ftb/mods/ftbfiltersystem/util/neoforge/PlatformUtilImpl.java +++ b/neoforge/src/main/java/dev/ftb/mods/ftbfiltersystem/util/neoforge/PlatformUtilImpl.java @@ -2,8 +2,9 @@ import net.minecraft.world.item.ItemStack; +@SuppressWarnings("unused") public class PlatformUtilImpl { - public static int getFoodValue(ItemStack stack) { - return stack.getItem().isEdible() ? stack.getItem().getFoodProperties(stack, null).getNutrition() : 0; + public static boolean hasComponentPatch(ItemStack stack) { + return !stack.isComponentsPatchEmpty(); } } diff --git a/neoforge/src/main/resources/META-INF/mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml similarity index 100% rename from neoforge/src/main/resources/META-INF/mods.toml rename to neoforge/src/main/resources/META-INF/neoforge.mods.toml diff --git a/settings.gradle b/settings.gradle index b2c2e45..9895669 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,6 +7,6 @@ pluginManagement { } } -include("common", "fabric", "forge", "neoforge") +include("common", "fabric", /*"forge",*/ "neoforge") -rootProject.name = "FTB-Filter-System-1.20.4" +rootProject.name = "FTB-Filter-System-1.20.6" From 1a31d581f310baaffba17ee7bf5a34cc59638c01 Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Thu, 9 May 2024 14:17:54 +0100 Subject: [PATCH 2/4] ci: update JDK version 17 -> 21 --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ec67c57..a3fef84 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,6 +18,7 @@ jobs: with: curse-publish-task: "" maven-snapshots: true + java-version: 21 secrets: ftb-maven-token: ${{ secrets.FTB_MAVEN_TOKEN }} saps-token: ${{ secrets.SAPS_TOKEN }} \ No newline at end of file From 31c437a8f30fc93ddd939128107d1e5559c24fc8 Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Mon, 13 May 2024 10:31:21 +0100 Subject: [PATCH 3/4] fix: more robust validation for filter text --- .../ftbfiltersystem/FilterSystemCommands.java | 18 +++++++++++------- .../gui/AbstractItemEditorConfigScreen.java | 4 +--- .../filter/ExpressionFilter.java | 7 ++++--- .../registry/item/SmartFilterItem.java | 2 ++ .../ftbfiltersystem/util/FilterParser.java | 9 ++++++++- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/FilterSystemCommands.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/FilterSystemCommands.java index ad2f8d5..26b52ab 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/FilterSystemCommands.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/FilterSystemCommands.java @@ -127,13 +127,17 @@ public static int tryMatch(CommandSourceStack source) throws CommandSyntaxExcept throw NO_OFFHAND_ITEM.create(); } - SmartFilter filter = FilterParser.parse(SmartFilterItem.getFilterString(getHeldFilter(source))); - if (filter.test(offhandItem)) { - source.sendSuccess(() -> TICK_MARK.copy().append(Component.translatable("ftbfiltersystem.message.matched", offhandItem.getDisplayName())), false); - return 1; - } else { - source.sendSuccess(() -> X_MARK.copy().append(Component.translatable("ftbfiltersystem.message.not_matched", offhandItem.getDisplayName())), false); - return 0; + try { + SmartFilter filter = FilterParser.parse(SmartFilterItem.getFilterString(getHeldFilter(source))); + if (filter.test(offhandItem)) { + source.sendSuccess(() -> TICK_MARK.copy().append(Component.translatable("ftbfiltersystem.message.matched", offhandItem.getDisplayName())), false); + return 1; + } else { + source.sendSuccess(() -> X_MARK.copy().append(Component.translatable("ftbfiltersystem.message.not_matched", offhandItem.getDisplayName())), false); + return 0; + } + } catch (FilterException e) { + throw PARSE_FAILED.create(e.getMessage()); } } diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/AbstractItemEditorConfigScreen.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/AbstractItemEditorConfigScreen.java index f027b64..50a383c 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/AbstractItemEditorConfigScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/gui/AbstractItemEditorConfigScreen.java @@ -30,7 +30,6 @@ public AbstractItemEditorConfigScreen(T filter, AbstractFilterScreen parentScree private CustomStringWidget statusLine; private final List itemWidgets = new ArrayList<>(); protected Component customHoverName = null; -// protected Component statusMsg = Component.empty(); @Override protected void init() { @@ -74,8 +73,6 @@ public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPar super.render(guiGraphics, pMouseX, pMouseY, pPartialTick); guiGraphics.renderOutline(leftPos + 7, topPos + 109, 164, 74, 0xFFA0A0A0); -// int w = font.width(statusMsg); -// guiGraphics.drawString(font, statusMsg, leftPos + guiWidth - (w + 8), topPos + 98, 0x404040, false); } protected abstract Predicate inventoryChecker(); @@ -89,6 +86,7 @@ protected void setStatus(boolean ok, Component message, String detail) { } protected abstract String serialize(ItemStack stack); + private class SearchItemWidget extends ItemWidget { public SearchItemWidget(int row, int col) { diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ExpressionFilter.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ExpressionFilter.java index 6723c41..1afb8e8 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ExpressionFilter.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/filter/ExpressionFilter.java @@ -1,6 +1,7 @@ package dev.ftb.mods.ftbfiltersystem.filter; import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI; +import dev.ftb.mods.ftbfiltersystem.api.FilterException; import dev.ftb.mods.ftbfiltersystem.api.filter.AbstractSmartFilter; import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; import dev.ftb.mods.ftbfiltersystem.util.FilterParser; @@ -15,11 +16,11 @@ public class ExpressionFilter extends AbstractSmartFilter { private final String customName; private final SmartFilter parsedExpression; - public ExpressionFilter(SmartFilter.Compound parent) { + public ExpressionFilter(SmartFilter.Compound parent) throws FilterException { this(parent, ""); } - public ExpressionFilter(SmartFilter.Compound parent, String expression) { + public ExpressionFilter(SmartFilter.Compound parent, String expression) throws FilterException { super(parent); String[] parts = expression.split("/", 2); @@ -52,7 +53,7 @@ public Component getDisplayArg() { return customName.isEmpty() ? super.getDisplayArg() : Component.literal(customName); } - public static ExpressionFilter fromString(SmartFilter.Compound parent, String str) { + public static ExpressionFilter fromString(SmartFilter.Compound parent, String str) throws FilterException { return new ExpressionFilter(parent, str); } diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/item/SmartFilterItem.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/item/SmartFilterItem.java index 32c1c93..bedd445 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/item/SmartFilterItem.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/item/SmartFilterItem.java @@ -17,6 +17,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -30,6 +31,7 @@ public static String getFilterString(ItemStack filterStack) { return filterStack.getOrDefault(ModDataComponents.FILTER_STRING.get(), ""); } + @NotNull public static SmartFilter getFilter(ItemStack filterStack) throws FilterException { return FilterParser.parse(getFilterString(filterStack)); } diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/util/FilterParser.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/util/FilterParser.java index 7ba4dc2..4cac7ba 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/util/FilterParser.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/util/FilterParser.java @@ -6,15 +6,22 @@ import dev.ftb.mods.ftbfiltersystem.filter.compound.RootFilter; import dev.ftb.mods.ftbfiltersystem.registry.FilterRegistry; import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; public class FilterParser { + @NotNull public static SmartFilter parse(String str) throws FilterException { - return FilterCache.INSTANCE.getOrCreateFilter(str); + SmartFilter filter = FilterCache.INSTANCE.getOrCreateFilter(str); + if (filter == null) { + throw new FilterException("invalid filter: " + str); + } + return filter; } + @NotNull static SmartFilter parseRaw(String str) throws FilterException { RootFilter root = new RootFilter(); root.getChildren().addAll(parseFilterList(root, str)); From 379d6b2b3704749adde8b8eee1857264e9ebaa93 Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Wed, 5 Jun 2024 15:34:41 +0100 Subject: [PATCH 4/4] build: updated deps & changelog --- .../java/dev/ftb/mods/ftbfiltersystem/registry/ModItems.java | 3 +-- .../mods/ftbfiltersystem/registry/item/SmartFilterItem.java | 5 +++-- gradle.properties | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/ModItems.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/ModItems.java index dbaba0e..9622cda 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/ModItems.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/ModItems.java @@ -15,14 +15,13 @@ public class ModItems { public static final DeferredRegister ITEMS = DeferredRegister.create(FTBFilterSystemAPI.MOD_ID, Registries.ITEM); + public static final RegistrySupplier SMART_FILTER = ITEMS.register("smart_filter", SmartFilterItem::new); public static final DeferredRegister TABS = DeferredRegister.create(FTBFilterSystemAPI.MOD_ID, Registries.CREATIVE_MODE_TAB); public static final RegistrySupplier CREATIVE_TAB = RegistrarManager.get(FTBFilterSystemAPI.MOD_ID) .get(Registries.CREATIVE_MODE_TAB) .register(new ResourceLocation(FTBFilterSystemAPI.MOD_ID, "default"), ModItems::buildDefaultTab); - public static final RegistrySupplier SMART_FILTER = ITEMS.register("smart_filter", SmartFilterItem::new); - public static Item.Properties defaultProps() { return new Item.Properties(); } diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/item/SmartFilterItem.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/item/SmartFilterItem.java index bedd445..625a040 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/item/SmartFilterItem.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/item/SmartFilterItem.java @@ -23,8 +23,9 @@ public class SmartFilterItem extends Item { public SmartFilterItem() { - super(ModItems.defaultProps()); -// .component(ModDataComponents.FILTER_STRING.get(), "")); + super(ModItems.defaultProps() + .component(ModDataComponents.FILTER_STRING.get(), "") + ); } public static String getFilterString(ItemStack filterStack) { diff --git a/gradle.properties b/gradle.properties index a20c5b1..3261652 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,14 +9,14 @@ mod_version=2.1.0 maven_group=dev.ftb.mods curseforge_id=943925 -architectury_version=12.0.28 +architectury_version=12.1.3 fabric_loader_version=0.15.10 fabric_api_version=0.97.8+1.20.6 forge_version=49.0.31 -neoforge_version=20.6.48-beta +neoforge_version=20.6.100-beta neoforge_loader_version=1 jei_version=17.3.0.49