Expand Recipe API to allow multiple Materials per slot

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2018-09-01 11:04:48 +10:00
parent d7b09a3270
commit b4f00b45eb
5 changed files with 46 additions and 21 deletions

View File

@@ -1,17 +1,20 @@
--- a/net/minecraft/server/ShapelessRecipes.java
+++ b/net/minecraft/server/ShapelessRecipes.java
@@ -5,6 +5,10 @@
@@ -5,6 +5,13 @@
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.CraftShapelessRecipe;
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
+// CraftBukkit end
public class ShapelessRecipes implements IRecipe {
@@ -20,6 +24,22 @@
@@ -20,6 +27,26 @@
this.ingredients = nonnulllist;
}
@@ -24,8 +27,12 @@
+
+ for (RecipeItemStack list : this.ingredients) {
+ list.buildChoices();
+ net.minecraft.server.ItemStack stack = list.choices[0];
+ recipe.addIngredient(org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(stack.getItem()), (list.choices.length) > 1 ? 32767 : 0);
+
+ 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));
+ }
+ return recipe;
+ }
@@ -34,7 +41,7 @@
public MinecraftKey getKey() {
return this.key;
}
@@ -127,11 +147,11 @@
@@ -127,11 +154,11 @@
packetdataserializer.a(shapelessrecipes.result);
}