aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0414-Fix-Custom-Shapeless-Custom-Crafting-Recipes.patch
blob: c45c2db214355c4f3a82d1b93ae0567a3596c546 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
From 8076fb34e182a4674a5f985fe2327491f6294e39 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Fri, 18 Jan 2019 00:08:15 -0500
Subject: [PATCH] Fix Custom Shapeless Custom Crafting Recipes

Mojang implemented Shapeless different than Shaped

This made the Bukkit RecipeChoice API not work for Shapeless.

This reimplements vanilla logic using the same test logic as Shaped

diff --git a/src/main/java/net/minecraft/server/ShapelessRecipes.java b/src/main/java/net/minecraft/server/ShapelessRecipes.java
index 819b4ac2d..ea4083a45 100644
--- a/src/main/java/net/minecraft/server/ShapelessRecipes.java
+++ b/src/main/java/net/minecraft/server/ShapelessRecipes.java
@@ -62,18 +62,47 @@ public class ShapelessRecipes implements IRecipe {
             AutoRecipeStackManager autorecipestackmanager = new AutoRecipeStackManager();
             int i = 0;
 
+            // Paper start
+            java.util.List<ItemStack> providedItems = new java.util.ArrayList<>();
+            co.aikar.util.Counter<ItemStack> matchedProvided = new co.aikar.util.Counter<>();
+            co.aikar.util.Counter<RecipeItemStack> matchedIngredients = new co.aikar.util.Counter<>();
+            // Paper end
             for (int j = 0; j < iinventory.n(); ++j) {
                 for (int k = 0; k < iinventory.U_(); ++k) {
                     ItemStack itemstack = iinventory.getItem(k + j * iinventory.U_());
 
                     if (!itemstack.isEmpty()) {
-                        ++i;
-                        autorecipestackmanager.b(new ItemStack(itemstack.getItem()));
+                        // Paper start
+                        itemstack = itemstack.cloneItemStack();
+                        providedItems.add(itemstack);
+                        for (RecipeItemStack ingredient : ingredients) {
+                            if (ingredient.test(itemstack)) {
+                                matchedProvided.increment(itemstack);
+                                matchedIngredients.increment(ingredient);
+                            }
+                        }
+                        // Paper end
                     }
                 }
             }
-
-            return i == this.ingredients.size() && autorecipestackmanager.a(this, (IntList) null);
+            // Paper start
+            java.util.List<RecipeItemStack> ingredients = new java.util.ArrayList<>(this.ingredients);
+            providedItems.sort(java.util.Comparator.comparingInt((ItemStack c) -> (int) matchedProvided.getCount(c)).reversed());
+            ingredients.sort(java.util.Comparator.comparingInt((RecipeItemStack c) -> (int) matchedIngredients.getCount(c)));
+
+            PROVIDED:
+            for (ItemStack provided : providedItems) {
+                for (Iterator<RecipeItemStack> itIngredient = ingredients.iterator(); itIngredient.hasNext(); ) {
+                    RecipeItemStack ingredient = itIngredient.next();
+                    if (ingredient.test(provided)) {
+                        itIngredient.remove();
+                        continue PROVIDED;
+                    }
+                }
+                return false;
+            }
+            return ingredients.isEmpty();
+            // Paper end
         }
     }
 
-- 
2.21.0