From 15cf2048f4779e08d89453d6c170f061691120b2 Mon Sep 17 00:00:00 2001 From: rasmus123d <59487370+RasmusKD@users.noreply.github.com> Date: Sun, 16 Aug 2026 15:27:44 +0200 Subject: [PATCH] Optional type-only matching for meta-less pipe filters The filter comparison rejects any item whose meta differs from the filter entry, so a plain 'potion' filter never catches brewed potions, and enchanted books and renamed items slip past every plain filter into overflow. Filtering on exact meta instead means spelling out every enchant and potion variant on a sign, which is not practical. With 'filters-match-type' enabled, a filter entry that carries no item meta matches on type alone, so every variant of an item sorts into that item's chest. Filter entries that do specify meta still compare it exactly. Off by default, which keeps the strict comparison unchanged. --- .../sk89q/craftbook/mechanics/pipe/Pipes.java | 3 +++ .../com/sk89q/craftbook/util/ItemUtil.java | 23 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sk89q/craftbook/mechanics/pipe/Pipes.java b/src/main/java/com/sk89q/craftbook/mechanics/pipe/Pipes.java index 3b6c9f4aa..8eeae7f2a 100644 --- a/src/main/java/com/sk89q/craftbook/mechanics/pipe/Pipes.java +++ b/src/main/java/com/sk89q/craftbook/mechanics/pipe/Pipes.java @@ -526,5 +526,8 @@ public void loadConfiguration (YAMLProcessor config, String path) { config.setComment(path + "require-sign", "Requires pipes to have a [Pipe] sign connected to them. This is the only way to require permissions to make pipes."); pipeRequireSign = config.getBoolean(path + "require-sign", false); + + config.setComment(path + "filters-match-type", "When a filter entry has no item meta, match by item type alone so potions, enchanted books and renamed items are caught by plain filters instead of passing through. Filters that specify meta still compare it exactly."); + ItemUtil.setLooseFilterMatching(config.getBoolean(path + "filters-match-type", false)); } } \ No newline at end of file diff --git a/src/main/java/com/sk89q/craftbook/util/ItemUtil.java b/src/main/java/com/sk89q/craftbook/util/ItemUtil.java index bb549c62b..998fd59bf 100644 --- a/src/main/java/com/sk89q/craftbook/util/ItemUtil.java +++ b/src/main/java/com/sk89q/craftbook/util/ItemUtil.java @@ -91,7 +91,7 @@ public static boolean doesItemPassFilters(ItemStack stack, Set inclus if(!ItemUtil.isStackValid(fil)) continue; - if(ItemUtil.areItemsIdentical(fil, stack)) { + if(ItemUtil.matchesFilter(fil, stack)) { passesFilters = true; break; } else @@ -105,7 +105,7 @@ public static boolean doesItemPassFilters(ItemStack stack, Set inclus if(!ItemUtil.isStackValid(fil)) continue; - if(ItemUtil.areItemsIdentical(fil, stack)) { + if(ItemUtil.matchesFilter(fil, stack)) { passesFilters = false; break; } @@ -371,6 +371,25 @@ public static boolean areItemMetaIdentical(ItemMeta meta, ItemMeta meta2, boolea return true; } + /** + * When enabled, filter entries that carry no item meta match on type alone, so a + * plain 'potion' filter also catches brewed potions, enchanted books and renamed + * items instead of letting them pass through. Filter entries that do specify meta + * always compare it exactly. Configured by the Pipes mechanic; off by default, + * which keeps the strict comparison below. + */ + private static boolean looseFilterMatching = false; + + public static void setLooseFilterMatching(boolean loose) { + looseFilterMatching = loose; + } + + public static boolean matchesFilter(ItemStack filter, ItemStack stack) { + if (looseFilterMatching && !filter.hasItemMeta()) + return areBaseItemsIdentical(filter, stack); + return areItemsIdentical(filter, stack); + } + public static boolean areItemsIdentical(ItemStack item, ItemStack item2) { if(!isStackValid(item) || !isStackValid(item2)) {