From e4de4d51eefa32cba7ffe74e842aa11be33f791a Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Wed, 2 Jan 2019 15:56:17 +1100 Subject: [PATCH] Add RecipeChoice.ExactChoice API for NBT matches on ingredients By: md_5 --- .../org/bukkit/inventory/RecipeChoice.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/paper-api/src/main/java/org/bukkit/inventory/RecipeChoice.java b/paper-api/src/main/java/org/bukkit/inventory/RecipeChoice.java index 8f18ddac29..5d254ca829 100644 --- a/paper-api/src/main/java/org/bukkit/inventory/RecipeChoice.java +++ b/paper-api/src/main/java/org/bukkit/inventory/RecipeChoice.java @@ -108,4 +108,44 @@ public interface RecipeChoice extends Predicate, Cloneable { return "MaterialChoice{" + "choices=" + choices + '}'; } } + + /** + * Represents a choice that will be valid only if a stack is exactly matched + * (aside from stack size). + *
+ * Not valid for shapeless recipes + * + * @deprecated draft API + */ + @Deprecated + public static class ExactChoice implements RecipeChoice { + + private ItemStack stack; + + public ExactChoice(ItemStack stack) { + Preconditions.checkArgument(stack != null, "stack"); + this.stack = stack; + } + + @Override + public ItemStack getItemStack() { + return stack; + } + + @Override + public ExactChoice clone() { + try { + ExactChoice clone = (ExactChoice) super.clone(); + clone.stack = stack.clone(); + return clone; + } catch (CloneNotSupportedException ex) { + throw new AssertionError(ex); + } + } + + @Override + public boolean test(ItemStack t) { + return stack.equals(t); + } + } }