mirror of
https://github.com/PaperMC/Paper.git
synced 2025-07-31 20:22:05 -07:00
add predicate recipe choice only for potion mixes (#9486)
This commit is contained in:
@@ -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<ItemStack> 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<ItemStack> 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
|
||||
|
Reference in New Issue
Block a user