Add predicate to recipe's ExactChoice ingredient

This commit is contained in:
William Blake Galbreath
2025-01-05 12:23:28 -08:00
committed by granny
parent 97d90df5da
commit 32db32c5ae
4 changed files with 42 additions and 60 deletions

View File

@@ -0,0 +1,36 @@
--- a/src/main/java/org/bukkit/inventory/RecipeChoice.java
+++ b/src/main/java/org/bukkit/inventory/RecipeChoice.java
@@ -191,6 +_,7 @@
public static class ExactChoice implements RecipeChoice {
private List<ItemStack> choices;
+ private Predicate<ItemStack> predicate; // Purpur - Add predicate to recipe's ExactChoice ingredient
public ExactChoice(@NotNull ItemStack stack) {
this(Arrays.asList(stack));
@@ -241,6 +_,7 @@
@Override
public boolean test(@NotNull ItemStack t) {
+ 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;
@@ -249,6 +_,17 @@
return false;
}
+
+ // Purpur start - Add predicate to recipe's ExactChoice ingredient
+ @org.jetbrains.annotations.Nullable
+ public Predicate<ItemStack> getPredicate() {
+ return predicate;
+ }
+
+ public void setPredicate(@org.jetbrains.annotations.Nullable Predicate<ItemStack> predicate) {
+ this.predicate = predicate;
+ }
+ // Purpur end - Add predicate to recipe's ExactChoice ingredient
@Override
public int hashCode() {