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/ShapedRecipes.java
+++ b/net/minecraft/server/ShapedRecipes.java
@@ -13,6 +13,10 @@
@@ -13,6 +13,13 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
+// CraftBukkit start
+import java.util.ArrayList;
+import java.util.List;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.inventory.CraftShapedRecipe;
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
+// CraftBukkit end
public class ShapedRecipes implements IRecipe {
@@ -32,6 +36,66 @@
@@ -32,6 +39,70 @@
this.result = itemstack;
}
@@ -66,8 +69,12 @@
+ for (RecipeItemStack list : this.items) {
+ list.buildChoices();
+ if (list.choices.length > 0) {
+ net.minecraft.server.ItemStack stack = list.choices[0];
+ recipe.setIngredient(c, 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.setIngredient(c, new org.bukkit.inventory.RecipeChoice.MaterialChoice(choices));
+ }
+ c++;
+ }
@@ -78,7 +85,7 @@
public MinecraftKey getKey() {
return this.key;
}
@@ -302,11 +366,11 @@
@@ -302,11 +373,11 @@
packetdataserializer.a(shapedrecipes.result);
}