From 11281d078906f0a1beacb3ae6cc60643181d1dac Mon Sep 17 00:00:00 2001 From: Lexi Date: Sat, 15 Oct 2022 15:20:12 -0400 Subject: [PATCH] Avoid usages of RecipeChoice#getItemStack() (#8453) Replaces some internal usages of this method with RecipeChoice#test(ItemStack) and deprecates every other method still utilizing this legacy method. --- ...-ItemStack-Recipe-API-helper-methods.patch | 27 +++++++++-- .../api/Fix-Spigot-annotation-mistakes.patch | 48 +++++++++++++++++++ 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/patches/api/Add-ItemStack-Recipe-API-helper-methods.patch b/patches/api/Add-ItemStack-Recipe-API-helper-methods.patch index bd9733467f..ba4113dbd7 100644 --- a/patches/api/Add-ItemStack-Recipe-API-helper-methods.patch +++ b/patches/api/Add-ItemStack-Recipe-API-helper-methods.patch @@ -3,7 +3,10 @@ From: Aikar Date: Tue, 28 Jan 2014 19:13:57 -0500 Subject: [PATCH] Add ItemStack Recipe API helper methods -Allows using ExactChoice Recipes with easier methodss +Allows using ExactChoice Recipes with easier methods + +Redirects some of upstream's APIs to these new methods to avoid +usage of magic values and the deprecated RecipeChoice#getItemStack diff --git a/src/main/java/org/bukkit/inventory/ShapedRecipe.java b/src/main/java/org/bukkit/inventory/ShapedRecipe.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 @@ -55,8 +58,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public ShapelessRecipe removeIngredient(int count, @NotNull ItemStack item) { + Iterator iterator = ingredients.iterator(); + while (count > 0 && iterator.hasNext()) { -+ ItemStack stack = iterator.next().getItemStack(); -+ if (stack.equals(item)) { ++ RecipeChoice choice = iterator.next(); ++ if (choice.test(item)) { + iterator.remove(); + count--; + } @@ -68,3 +71,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 /** * Removes an ingredient from the list. * +@@ -0,0 +0,0 @@ public class ShapelessRecipe implements Recipe, Keyed { + */ + @NotNull + public ShapelessRecipe removeIngredient(@NotNull Material ingredient) { +- return removeIngredient(ingredient, 0); ++ return removeIngredient(new ItemStack(ingredient)); // Paper - avoid using deprecated methods (magic values; RecipeChoice#getItemStack) + } + + /** +@@ -0,0 +0,0 @@ public class ShapelessRecipe implements Recipe, Keyed { + */ + @NotNull + public ShapelessRecipe removeIngredient(int count, @NotNull Material ingredient) { +- return removeIngredient(count, ingredient, 0); ++ return removeIngredient(count, new ItemStack(ingredient)); // Paper - avoid using deprecated methods (magic values; RecipeChoice#getItemStack) + } + + /** diff --git a/patches/api/Fix-Spigot-annotation-mistakes.patch b/patches/api/Fix-Spigot-annotation-mistakes.patch index b7439dd186..96df183310 100644 --- a/patches/api/Fix-Spigot-annotation-mistakes.patch +++ b/patches/api/Fix-Spigot-annotation-mistakes.patch @@ -524,6 +524,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 public MaterialData getTypeAndData(int x, int y, int z); /** +diff --git a/src/main/java/org/bukkit/inventory/CookingRecipe.java b/src/main/java/org/bukkit/inventory/CookingRecipe.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/inventory/CookingRecipe.java ++++ b/src/main/java/org/bukkit/inventory/CookingRecipe.java +@@ -0,0 +0,0 @@ public abstract class CookingRecipe implements Recipe, + * Get the input material. + * + * @return The input material. ++ * @deprecated Use {@link #getInputChoice()} instead for more complete data. + */ ++ @Deprecated // Paper + @NotNull + public ItemStack getInput() { + return this.ingredient.getItemStack(); diff --git a/src/main/java/org/bukkit/inventory/CraftingInventory.java b/src/main/java/org/bukkit/inventory/CraftingInventory.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/inventory/CraftingInventory.java @@ -730,6 +744,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 public ShapedRecipe setIngredient(char key, @NotNull MaterialData ingredient) { return setIngredient(key, ingredient.getItemType(), ingredient.getData()); } +@@ -0,0 +0,0 @@ public class ShapedRecipe implements Recipe, Keyed { + * Get a copy of the ingredients map. + * + * @return The mapping of character to ingredients. ++ * @deprecated Use {@link #getChoiceMap()} instead for more complete data. + */ ++ @Deprecated // Paper + @NotNull + public Map getIngredientMap() { + HashMap result = new HashMap(); diff --git a/src/main/java/org/bukkit/inventory/ShapelessRecipe.java b/src/main/java/org/bukkit/inventory/ShapelessRecipe.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/inventory/ShapelessRecipe.java @@ -778,6 +802,30 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 public ShapelessRecipe removeIngredient(int count, @NotNull MaterialData ingredient) { return removeIngredient(count, ingredient.getItemType(), ingredient.getData()); } +@@ -0,0 +0,0 @@ public class ShapelessRecipe implements Recipe, Keyed { + * Get the list of ingredients used for this recipe. + * + * @return The input list ++ * @deprecated Use {@link #getChoiceList()} instead for more complete data. + */ ++ @Deprecated // Paper + @NotNull + public List getIngredientList() { + ArrayList result = new ArrayList(ingredients.size()); +diff --git a/src/main/java/org/bukkit/inventory/StonecuttingRecipe.java b/src/main/java/org/bukkit/inventory/StonecuttingRecipe.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/inventory/StonecuttingRecipe.java ++++ b/src/main/java/org/bukkit/inventory/StonecuttingRecipe.java +@@ -0,0 +0,0 @@ public class StonecuttingRecipe implements Recipe, Keyed { + * Get the input material. + * + * @return The input material. ++ * @deprecated Use {@link #getInputChoice()} instead for more complete data. + */ ++ @Deprecated // Paper + @NotNull + public ItemStack getInput() { + return this.ingredient.getItemStack(); diff --git a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java