From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Paul Sauve <paul@technove.co>
Date: Sat, 31 Oct 2020 18:51:38 -0500
Subject: [PATCH] Simpler ShapelessRecipes comparison for Vanilla

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.

Airplane
Copyright (C) 2020 Technove LLC

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

diff --git a/src/main/java/net/minecraft/server/ShapelessRecipes.java b/src/main/java/net/minecraft/server/ShapelessRecipes.java
index ecd63281912ae0ed93c5eb5ccb4249833cb23ab1..97825ec914709ca037159c46ecee218a6013ff58 100644
--- a/src/main/java/net/minecraft/server/ShapelessRecipes.java
+++ b/src/main/java/net/minecraft/server/ShapelessRecipes.java
@@ -18,8 +18,16 @@ public class ShapelessRecipes implements RecipeCrafting {
     private final String group;
     private final ItemStack result;
     private final NonNullList<RecipeItemStack> ingredients;
+    private final boolean isBukkit; // Airplane
 
+    // Airplane start - add isBukkit constructor param
     public ShapelessRecipes(MinecraftKey minecraftkey, String s, ItemStack itemstack, NonNullList<RecipeItemStack> nonnulllist) {
+        this(minecraftkey, s, itemstack, nonnulllist, false);
+    }
+
+    public ShapelessRecipes(MinecraftKey minecraftkey, String s, ItemStack itemstack, NonNullList<RecipeItemStack> nonnulllist, boolean isBukkit) {
+        this.isBukkit = isBukkit;
+        // Airplane end
         this.key = minecraftkey;
         this.group = s;
         this.result = itemstack;
@@ -61,6 +69,28 @@ public class ShapelessRecipes implements RecipeCrafting {
     }
 
     public boolean a(InventoryCrafting inventorycrafting, World world) {
+        // Airplane start
+        if (!this.isBukkit) {
+            java.util.List<RecipeItemStack> ingredients = com.google.common.collect.Lists.newArrayList(this.ingredients.toArray(new RecipeItemStack[0]));
+
+            inventory: for (int index = 0; index < inventorycrafting.getSize(); index++) {
+                ItemStack itemStack = inventorycrafting.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();
+        }
+        // Airplane end
+
         AutoRecipeStackManager autorecipestackmanager = new AutoRecipeStackManager();
         int i = 0;
 
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java
index 4aba511fe8078164bf1467b39645dd9bf6a931e7..56b781e438f0cf1c12dd55eb37356601e47de47f 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java
@@ -44,6 +44,6 @@ public class CraftShapelessRecipe extends ShapelessRecipe implements CraftRecipe
             data.set(i, toNMS(ingred.get(i), true));
         }
 
-        MinecraftServer.getServer().getCraftingManager().addRecipe(new ShapelessRecipes(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), CraftItemStack.asNMSCopy(this.getResult()), data));
+        MinecraftServer.getServer().getCraftingManager().addRecipe(new ShapelessRecipes(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), CraftItemStack.asNMSCopy(this.getResult()), data, true)); // Airplane
     }
 }
