Files
Purpur/patches/server/0091-Add-predicate-to-recipe-s-ExactChoice-ingredient.patch
2024-12-03 20:57:07 -08:00

43 lines
2.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
Date: Sat, 3 Oct 2020 17:40:52 -0500
Subject: [PATCH] Add predicate to recipe's ExactChoice ingredient
diff --git a/src/main/java/net/minecraft/world/item/crafting/Ingredient.java b/src/main/java/net/minecraft/world/item/crafting/Ingredient.java
index 0bd0935e76038e07c063bbfc61fa1a6339c23eed..e38cab89bd58a91cf91044d23900b5d83fa191f6 100644
--- a/src/main/java/net/minecraft/world/item/crafting/Ingredient.java
+++ b/src/main/java/net/minecraft/world/item/crafting/Ingredient.java
@@ -45,6 +45,7 @@ public final class Ingredient implements StackedContents.IngredientInfo<Holder<I
// CraftBukkit start
@Nullable
private List<ItemStack> itemStacks;
+ public Predicate<org.bukkit.inventory.ItemStack> predicate; // Purpur
public boolean isExact() {
return this.itemStacks != null;
@@ -102,6 +103,11 @@ public final class Ingredient implements StackedContents.IngredientInfo<Holder<I
return false;
}
+ // Purpur start
+ if (predicate != null) {
+ return predicate.test(itemstack.asBukkitCopy());
+ }
+ // Purpur end
// CraftBukkit end
return itemstack.is(this.values);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java
index 4864e2016cb1d377425297fd1c52b383632cb59e..fc0e93a936dadb0dca758207297f92a22f3955d4 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java
@@ -36,6 +36,7 @@ public interface CraftRecipe extends Recipe {
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
// 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