diff options
author | md_5 <git@md-5.net> | 2018-09-01 11:04:48 +1000 |
---|---|---|
committer | md_5 <git@md-5.net> | 2018-09-01 11:04:48 +1000 |
commit | 4c219e2a1206225cff4b34669c00106b1c312991 (patch) | |
tree | 8af1f563fddea26ab13ad7f0207b9848fde52577 /src | |
parent | 6304ccd95fc9498960e99f96b59479dfc08b3c8d (diff) | |
download | craftbukkit-4c219e2a1206225cff4b34669c00106b1c312991.tar craftbukkit-4c219e2a1206225cff4b34669c00106b1c312991.tar.gz craftbukkit-4c219e2a1206225cff4b34669c00106b1c312991.tar.lz craftbukkit-4c219e2a1206225cff4b34669c00106b1c312991.tar.xz craftbukkit-4c219e2a1206225cff4b34669c00106b1c312991.zip |
Expand Recipe API to allow multiple Materials per slot
Diffstat (limited to 'src')
3 files changed, 22 insertions, 11 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java index d3e03e24..eec606b2 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java @@ -1,7 +1,18 @@ package org.bukkit.craftbukkit.inventory; +import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Recipe; +import org.bukkit.inventory.RecipeChoice; public interface CraftRecipe extends Recipe { + void addToCraftingManager(); + + default net.minecraft.server.RecipeItemStack toNMS(RecipeChoice bukkit) { + if (bukkit instanceof RecipeChoice.MaterialChoice) { + return new net.minecraft.server.RecipeItemStack(((RecipeChoice.MaterialChoice) bukkit).getChoices().stream().map((mat) -> new net.minecraft.server.RecipeItemStack.StackProvider(CraftItemStack.asNMSCopy(new ItemStack(mat))))); + } else { + throw new IllegalArgumentException("Unknown recipe stack instance " + bukkit); + } + } } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapedRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapedRecipe.java index f83593cb..9e313cc4 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapedRecipe.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapedRecipe.java @@ -1,7 +1,6 @@ package org.bukkit.craftbukkit.inventory; import java.util.Map; -import java.util.stream.Stream; import net.minecraft.server.MinecraftServer; import net.minecraft.server.NonNullList; @@ -11,6 +10,7 @@ import net.minecraft.server.ShapedRecipes; import org.bukkit.NamespacedKey; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.RecipeChoice; import org.bukkit.inventory.ShapedRecipe; public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe { @@ -34,11 +34,11 @@ public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe { ret.setGroup(recipe.getGroup()); String[] shape = recipe.getShape(); ret.shape(shape); - Map<Character, ItemStack> ingredientMap = recipe.getIngredientMap(); + Map<Character, RecipeChoice> ingredientMap = recipe.getChoiceMap(); for (char c : ingredientMap.keySet()) { - ItemStack stack = ingredientMap.get(c); + RecipeChoice stack = ingredientMap.get(c); if (stack != null) { - ret.setIngredient(c, stack.getType(), stack.getDurability()); + ret.setIngredient(c, stack); } } return ret; @@ -46,14 +46,14 @@ public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe { public void addToCraftingManager() { String[] shape = this.getShape(); - Map<Character, ItemStack> ingred = this.getIngredientMap(); + Map<Character, org.bukkit.inventory.RecipeChoice> ingred = this.getChoiceMap(); int width = shape[0].length(); NonNullList<RecipeItemStack> data = NonNullList.a(shape.length * width, RecipeItemStack.a); for (int i = 0; i < shape.length; i++) { String row = shape[i]; for (int j = 0; j < row.length(); j++) { - data.set(i * width + j, new RecipeItemStack(Stream.of(new RecipeItemStack.StackProvider(CraftItemStack.asNMSCopy(ingred.get(row.charAt(j))))))); + data.set(i * width + j, toNMS(ingred.get(row.charAt(j)))); } } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java index 28582da1..8e3446fc 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java @@ -1,7 +1,6 @@ package org.bukkit.craftbukkit.inventory; import java.util.List; -import java.util.stream.Stream; import net.minecraft.server.MinecraftServer; import net.minecraft.server.NonNullList; @@ -11,6 +10,7 @@ import net.minecraft.server.ShapelessRecipes; import org.bukkit.NamespacedKey; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.RecipeChoice; import org.bukkit.inventory.ShapelessRecipe; public class CraftShapelessRecipe extends ShapelessRecipe implements CraftRecipe { @@ -32,17 +32,17 @@ public class CraftShapelessRecipe extends ShapelessRecipe implements CraftRecipe } CraftShapelessRecipe ret = new CraftShapelessRecipe(recipe.getKey(), recipe.getResult()); ret.setGroup(recipe.getGroup()); - for (ItemStack ingred : recipe.getIngredientList()) { - ret.addIngredient(ingred.getType(), ingred.getDurability()); + for (RecipeChoice ingred : recipe.getChoiceList()) { + ret.addIngredient(ingred); } return ret; } public void addToCraftingManager() { - List<ItemStack> ingred = this.getIngredientList(); + List<org.bukkit.inventory.RecipeChoice> ingred = this.getChoiceList(); NonNullList<RecipeItemStack> data = NonNullList.a(ingred.size(), RecipeItemStack.a); for (int i = 0; i < ingred.size(); i++) { - data.set(i, new RecipeItemStack(Stream.of(new RecipeItemStack.StackProvider(CraftItemStack.asNMSCopy(ingred.get(i)))))); + data.set(i, toNMS(ingred.get(i))); } MinecraftServer.getServer().getCraftingManager().a(new ShapelessRecipes(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), CraftItemStack.asNMSCopy(this.getResult()), data)); |