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.
This commit is contained in:
Lexi
2022-10-15 15:20:12 -04:00
parent 254a07415d
commit 11281d0789
2 changed files with 72 additions and 3 deletions

View File

@@ -3,7 +3,10 @@ From: Aikar <aikar@aikar.co>
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<RecipeChoice> 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)
}
/**