From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> Date: Wed, 9 Jul 2025 03:06:02 +0300 Subject: [PATCH] Pufferfish: Simpler ShapelessRecipes comparison for Vanilla Original license: GPL v3 Original project: https://github.com/pufferfish-gg/Pufferfish Patch description: Paper added a fancy sorting comparison due to Bukkit recipes breaking the vanilla one, however this is far more advanced than what you need for all the vanilla recipes. diff --git a/net/minecraft/world/item/crafting/ShapelessRecipe.java b/net/minecraft/world/item/crafting/ShapelessRecipe.java index d601b54b1de2f2ae44fe2b20c8116c71a6340e45..658c950e18a5a4ff992c8720e60f505a11ab2efd 100644 --- a/net/minecraft/world/item/crafting/ShapelessRecipe.java +++ b/net/minecraft/world/item/crafting/ShapelessRecipe.java @@ -23,13 +23,21 @@ public class ShapelessRecipe implements CraftingRecipe { final List ingredients; @Nullable private PlacementInfo placementInfo; + // DivineMC start - Pufferfish: Simpler ShapelessRecipes comparison for Vanilla + private final boolean isBukkit; public ShapelessRecipe(String group, CraftingBookCategory category, ItemStack result, List ingredients) { + this(group, category, result, ingredients, false); + } + + public ShapelessRecipe(String group, CraftingBookCategory category, ItemStack result, List ingredients, boolean isBukkit) { this.group = group; this.category = category; this.result = result; this.ingredients = ingredients; + this.isBukkit = isBukkit; } + // DivineMC end - Pufferfish: Simpler ShapelessRecipes comparison for Vanilla // CraftBukkit start @Override @@ -72,6 +80,27 @@ public class ShapelessRecipe implements CraftingRecipe { @Override public boolean matches(CraftingInput input, Level level) { + // DivineMC start - Pufferfish: Simpler ShapelessRecipes comparison for Vanilla + if (!this.isBukkit) { + java.util.List ingredients = com.google.common.collect.Lists.newArrayList(this.ingredients.toArray(new Ingredient[0])); + + inventory: for (int index = 0; index < input.size(); index++) { + ItemStack itemStack = input.getItem(index); + + if (!itemStack.isEmpty()) { + for (int i = 0; i < ingredients.size(); i++) { + if (ingredients.get(i).test(itemStack)) { + ingredients.remove(i); + continue inventory; + } + } + return false; + } + } + + return ingredients.isEmpty(); + } + // DivineMC end - Pufferfish: Simpler ShapelessRecipes comparison for Vanilla // Paper start - Improve exact choice recipe ingredients & unwrap ternary if (input.ingredientCount() != this.ingredients.size()) { return false;