Add RecipeChoice.ExactChoice API for NBT matches on ingredients

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2019-01-02 15:56:21 +11:00
parent 1336c4afb9
commit 5aff480181
5 changed files with 71 additions and 32 deletions

View File

@@ -1,20 +1,18 @@
--- a/net/minecraft/server/ShapelessRecipes.java
+++ b/net/minecraft/server/ShapelessRecipes.java
@@ -5,6 +5,13 @@
@@ -5,6 +5,11 @@
import com.google.gson.JsonParseException;
import it.unimi.dsi.fastutil.ints.IntList;
import java.util.Iterator;
+// CraftBukkit start
+import java.util.ArrayList;
+import java.util.List;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
+import org.bukkit.craftbukkit.inventory.CraftShapelessRecipe;
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
+// CraftBukkit end
public class ShapelessRecipes implements IRecipe {
@@ -20,6 +27,26 @@
@@ -20,6 +25,20 @@
this.ingredients = nonnulllist;
}
@@ -26,13 +24,7 @@
+ recipe.setGroup(this.group);
+
+ for (RecipeItemStack list : this.ingredients) {
+ list.buildChoices();
+
+ List<org.bukkit.Material> choices = new ArrayList<>(list.choices.length);
+ for (ItemStack i : list.choices) {
+ choices.add(CraftMagicNumbers.getMaterial(i.getItem()));
+ }
+ recipe.addIngredient(new org.bukkit.inventory.RecipeChoice.MaterialChoice(choices));
+ recipe.addIngredient(CraftRecipe.toBukkit(list));
+ }
+ return recipe;
+ }