From 32db32c5aeb0e117fb4a5960bb703e63d3ec5b6d Mon Sep 17 00:00:00 2001 From: William Blake Galbreath Date: Sun, 5 Jan 2025 12:23:28 -0800 Subject: [PATCH] Add predicate to recipe's ExactChoice ingredient --- ...e-to-recipe-s-ExactChoice-ingredient.patch | 42 ------------------- .../bukkit/inventory/RecipeChoice.java.patch | 28 +++++-------- .../world/item/crafting/Ingredient.java.patch | 22 ++++++++++ .../inventory/CraftRecipe.java.patch | 10 +++++ 4 files changed, 42 insertions(+), 60 deletions(-) delete mode 100644 patches/server/0089-Add-predicate-to-recipe-s-ExactChoice-ingredient.patch rename patches/api/0018-Add-predicate-to-recipe-s-ExactChoice-ingredient.patch => purpur-api/paper-patches/files/src/main/java/org/bukkit/inventory/RecipeChoice.java.patch (52%) create mode 100644 purpur-server/minecraft-patches/sources/net/minecraft/world/item/crafting/Ingredient.java.patch create mode 100644 purpur-server/paper-patches/files/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java.patch diff --git a/patches/server/0089-Add-predicate-to-recipe-s-ExactChoice-ingredient.patch b/patches/server/0089-Add-predicate-to-recipe-s-ExactChoice-ingredient.patch deleted file mode 100644 index e59729518..000000000 --- a/patches/server/0089-Add-predicate-to-recipe-s-ExactChoice-ingredient.patch +++ /dev/null @@ -1,42 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: William Blake Galbreath -Date: Sat, 3 Oct 2020 17:40:52 -0500 -Subject: [PATCH] Add predicate to recipe's ExactChoice ingredient - - -diff --git a/net/minecraft/world/item/crafting/Ingredient.java b/net/minecraft/world/item/crafting/Ingredient.java -index 0b0054b3d5d56ba24e1aee0e3ab56ea5b01a82a8..2e3a834643d56543418e9b9beb9d3448bf059d22 100644 ---- a/net/minecraft/world/item/crafting/Ingredient.java -+++ b/net/minecraft/world/item/crafting/Ingredient.java -@@ -45,6 +45,7 @@ public final class Ingredient implements StackedContents.IngredientInfo itemStacks; // Paper - Improve exact choice recipe ingredients -+ public Predicate predicate; // Purpur - - public boolean isExact() { - return this.itemStacks != null; -@@ -100,6 +101,11 @@ public final class Ingredient implements StackedContents.IngredientInfo CraftItemType.bukkitToMinecraft(mat))); - } else if (bukkit instanceof RecipeChoice.ExactChoice) { - stack = Ingredient.ofStacks(((RecipeChoice.ExactChoice) bukkit).getChoices().stream().map((mat) -> CraftItemStack.asNMSCopy(mat)).toList()); -+ stack.predicate = ((RecipeChoice.ExactChoice) bukkit).getPredicate(); // Purpur - // Paper start - support "empty" choices - legacy method that spigot might incorrectly call - // Their impl of Ingredient.of() will error, ingredients need at least one entry. - // Callers running into this exception may have passed an incorrect empty() recipe choice to a non-empty slot or diff --git a/patches/api/0018-Add-predicate-to-recipe-s-ExactChoice-ingredient.patch b/purpur-api/paper-patches/files/src/main/java/org/bukkit/inventory/RecipeChoice.java.patch similarity index 52% rename from patches/api/0018-Add-predicate-to-recipe-s-ExactChoice-ingredient.patch rename to purpur-api/paper-patches/files/src/main/java/org/bukkit/inventory/RecipeChoice.java.patch index e358db980..177eef71b 100644 --- a/patches/api/0018-Add-predicate-to-recipe-s-ExactChoice-ingredient.patch +++ b/purpur-api/paper-patches/files/src/main/java/org/bukkit/inventory/RecipeChoice.java.patch @@ -1,34 +1,27 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: William Blake Galbreath -Date: Fri, 2 Oct 2020 17:43:24 -0500 -Subject: [PATCH] Add predicate to recipe's ExactChoice ingredient - - -diff --git a/src/main/java/org/bukkit/inventory/RecipeChoice.java b/src/main/java/org/bukkit/inventory/RecipeChoice.java -index 922bb69b5f218e489a6dd5e0f207743c1f1d3d35..9b3e292be334d21eb978373f434bf3811ec4af2b 100644 --- a/src/main/java/org/bukkit/inventory/RecipeChoice.java +++ b/src/main/java/org/bukkit/inventory/RecipeChoice.java -@@ -191,6 +191,7 @@ public interface RecipeChoice extends Predicate, Cloneable { +@@ -191,6 +_,7 @@ public static class ExactChoice implements RecipeChoice { private List choices; -+ private Predicate predicate; // Purpur ++ private Predicate predicate; // Purpur - Add predicate to recipe's ExactChoice ingredient public ExactChoice(@NotNull ItemStack stack) { this(Arrays.asList(stack)); -@@ -241,6 +242,7 @@ public interface RecipeChoice extends Predicate, Cloneable { +@@ -241,6 +_,7 @@ @Override public boolean test(@NotNull ItemStack t) { -+ if (predicate != null) return predicate.test(t); // Purpur ++ if (predicate != null) return predicate.test(t); // Purpur - Add predicate to recipe's ExactChoice ingredient for (ItemStack match : choices) { if (t.isSimilar(match)) { return true; -@@ -250,6 +252,17 @@ public interface RecipeChoice extends Predicate, Cloneable { +@@ -249,6 +_,17 @@ + return false; } - -+ // Purpur start ++ ++ // Purpur start - Add predicate to recipe's ExactChoice ingredient + @org.jetbrains.annotations.Nullable + public Predicate getPredicate() { + return predicate; @@ -37,8 +30,7 @@ index 922bb69b5f218e489a6dd5e0f207743c1f1d3d35..9b3e292be334d21eb978373f434bf381 + public void setPredicate(@org.jetbrains.annotations.Nullable Predicate predicate) { + this.predicate = predicate; + } -+ // Purpur end -+ ++ // Purpur end - Add predicate to recipe's ExactChoice ingredient + @Override public int hashCode() { - int hash = 7; diff --git a/purpur-server/minecraft-patches/sources/net/minecraft/world/item/crafting/Ingredient.java.patch b/purpur-server/minecraft-patches/sources/net/minecraft/world/item/crafting/Ingredient.java.patch new file mode 100644 index 000000000..188d2cfb2 --- /dev/null +++ b/purpur-server/minecraft-patches/sources/net/minecraft/world/item/crafting/Ingredient.java.patch @@ -0,0 +1,22 @@ +--- a/net/minecraft/world/item/crafting/Ingredient.java ++++ b/net/minecraft/world/item/crafting/Ingredient.java +@@ -36,6 +_,7 @@ + // CraftBukkit start + @javax.annotation.Nullable + private java.util.Set itemStacks; // Paper - Improve exact choice recipe ingredients ++ public Predicate predicate; // Purpur - Add predicate to recipe's ExactChoice ingredient + + public boolean isExact() { + return this.itemStacks != null; +@@ -87,6 +_,11 @@ + if (this.isExact()) { + return this.itemStacks.contains(stack); // Paper - Improve exact choice recipe ingredients (hashing FTW!) + } ++ // Purpur start - Add predicate to recipe's ExactChoice ingredient ++ if (predicate != null) { ++ return predicate.test(stack.asBukkitCopy()); ++ } ++ // Purpur end - Add predicate to recipe's ExactChoice ingredient + // CraftBukkit end + return stack.is(this.values); + } diff --git a/purpur-server/paper-patches/files/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java.patch b/purpur-server/paper-patches/files/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java.patch new file mode 100644 index 000000000..b3042e1f5 --- /dev/null +++ b/purpur-server/paper-patches/files/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java.patch @@ -0,0 +1,10 @@ +--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java ++++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java +@@ -36,6 +_,7 @@ + stack = Ingredient.of(((RecipeChoice.MaterialChoice) bukkit).getChoices().stream().map((mat) -> CraftItemType.bukkitToMinecraft(mat))); + } else if (bukkit instanceof RecipeChoice.ExactChoice) { + stack = Ingredient.ofStacks(((RecipeChoice.ExactChoice) bukkit).getChoices().stream().map((mat) -> CraftItemStack.asNMSCopy(mat)).toList()); ++ stack.predicate = ((RecipeChoice.ExactChoice) bukkit).getPredicate(); // Purpur - Add predicate to recipe's ExactChoice ingredient + // Paper start - support "empty" choices - legacy method that spigot might incorrectly call + // Their impl of Ingredient.of() will error, ingredients need at least one entry. + // Callers running into this exception may have passed an incorrect empty() recipe choice to a non-empty slot or