Add predicate to recipe's ExactChoice ingredient (missing NMS side)

This commit is contained in:
William Blake Galbreath
2020-10-03 17:48:06 -05:00
parent d469979664
commit bd83a6b30d

View File

@@ -0,0 +1,43 @@
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/server/RecipeItemStack.java b/src/main/java/net/minecraft/server/RecipeItemStack.java
index 0f96abd0ca..f6d9294940 100644
--- a/src/main/java/net/minecraft/server/RecipeItemStack.java
+++ b/src/main/java/net/minecraft/server/RecipeItemStack.java
@@ -26,6 +26,7 @@ public final class RecipeItemStack implements Predicate<ItemStack> {
public ItemStack[] choices;
private IntList d;
public boolean exact; // CraftBukkit
+ public Predicate<org.bukkit.inventory.ItemStack> predicate; // Purpur
public RecipeItemStack(Stream<? extends RecipeItemStack.Provider> stream) {
this.b = (RecipeItemStack.Provider[]) stream.toArray((i) -> {
@@ -52,6 +53,12 @@ public final class RecipeItemStack implements Predicate<ItemStack> {
if (this.choices.length == 0) {
return itemstack.isEmpty();
} else {
+ // Purpur start
+ if (predicate != null) {
+ return predicate.test(itemstack.asBukkitCopy());
+ }
+ // Purpur end
+
ItemStack[] aitemstack = this.choices;
int i = aitemstack.length;
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java
index ef29599a89..18413e6327 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java
@@ -22,6 +22,7 @@ public interface CraftRecipe extends Recipe {
} else if (bukkit instanceof RecipeChoice.ExactChoice) {
stack = new RecipeItemStack(((RecipeChoice.ExactChoice) bukkit).getChoices().stream().map((mat) -> new net.minecraft.server.RecipeItemStack.StackProvider(CraftItemStack.asNMSCopy(mat))));
stack.exact = true;
+ stack.predicate = ((RecipeChoice.ExactChoice) bukkit).getPredicate(); // Purpur
} else {
throw new IllegalArgumentException("Unknown recipe stack instance " + bukkit);
}