diff --git a/patches/api/Custom-Potion-Mixes.patch b/patches/api/Custom-Potion-Mixes.patch index 1d75dff628..b8f85f8381 100644 --- a/patches/api/Custom-Potion-Mixes.patch +++ b/patches/api/Custom-Potion-Mixes.patch @@ -12,11 +12,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @@ -0,0 +0,0 @@ +package io.papermc.paper.potion; + ++import java.util.function.Predicate; +import org.bukkit.Keyed; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.RecipeChoice; +import org.jetbrains.annotations.ApiStatus; ++import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; @@ -79,6 +81,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return this.ingredient; + } + ++ /** ++ * Create a {@link RecipeChoice} based on a Predicate. These RecipeChoices are only ++ * valid for {@link PotionMix}, not anywhere else RecipeChoices may be used. ++ * ++ * @param stackPredicate a predicate for an itemstack. ++ * @return a new RecipeChoice ++ */ ++ @Contract(value = "_ -> new", pure = true) ++ public static @NotNull RecipeChoice createPredicateChoice(@NotNull Predicate stackPredicate) { ++ return new PredicateRecipeChoice(stackPredicate); ++ } ++ + @Override + public String toString() { + return "PotionMix{" + @@ -101,6 +115,45 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return Objects.hash(this.key, this.result, this.input, this.ingredient); + } +} +diff --git a/src/main/java/io/papermc/paper/potion/PredicateRecipeChoice.java b/src/main/java/io/papermc/paper/potion/PredicateRecipeChoice.java +new file mode 100644 +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/potion/PredicateRecipeChoice.java +@@ -0,0 +0,0 @@ ++package io.papermc.paper.potion; ++ ++import java.util.function.Predicate; ++import org.bukkit.inventory.ItemStack; ++import org.bukkit.inventory.RecipeChoice; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.checkerframework.framework.qual.DefaultQualifier; ++import org.jetbrains.annotations.ApiStatus; ++ ++@ApiStatus.Internal ++@DefaultQualifier(NonNull.class) ++record PredicateRecipeChoice(Predicate itemStackPredicate) implements RecipeChoice, Cloneable { ++ ++ @Override ++ @Deprecated ++ public ItemStack getItemStack() { ++ throw new UnsupportedOperationException("PredicateRecipeChoice does not support this"); ++ } ++ ++ @Override ++ public RecipeChoice clone() { ++ try { ++ return (PredicateRecipeChoice) super.clone(); ++ } catch (CloneNotSupportedException ex) { ++ throw new AssertionError(ex); ++ } ++ } ++ ++ @Override ++ public boolean test(final ItemStack itemStack) { ++ return this.itemStackPredicate.test(itemStack); ++ } ++} diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/Bukkit.java diff --git a/patches/server/Custom-Potion-Mixes.patch b/patches/server/Custom-Potion-Mixes.patch index 9f65367b82..e65eda9622 100644 --- a/patches/server/Custom-Potion-Mixes.patch +++ b/patches/server/Custom-Potion-Mixes.patch @@ -12,15 +12,23 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @@ -0,0 +0,0 @@ +package io.papermc.paper.potion; + ++import java.util.function.Predicate; +import net.minecraft.world.item.ItemStack; -+import net.minecraft.world.item.crafting.Ingredient; +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.inventory.CraftRecipe; ++import org.bukkit.inventory.RecipeChoice; + -+public record PaperPotionMix(ItemStack result, Ingredient input, Ingredient ingredient) { ++public record PaperPotionMix(ItemStack result, Predicate input, Predicate ingredient) { + + public PaperPotionMix(PotionMix potionMix) { -+ this(CraftItemStack.asNMSCopy(potionMix.getResult()), CraftRecipe.toIngredient(potionMix.getInput(), true), CraftRecipe.toIngredient(potionMix.getIngredient(), true)); ++ this(CraftItemStack.asNMSCopy(potionMix.getResult()), convert(potionMix.getInput()), convert(potionMix.getIngredient())); ++ } ++ ++ static Predicate convert(final RecipeChoice choice) { ++ if (choice instanceof PredicateRecipeChoice predicateRecipeChoice) { ++ return stack -> predicateRecipeChoice.test(CraftItemStack.asBukkitCopy(stack)); ++ } ++ return CraftRecipe.toIngredient(choice, true); + } +} diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java