mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-29 22:13:42 +01:00
Expand Recipe API to allow multiple Materials per slot
This commit is contained in:
parent
6304ccd95f
commit
4c219e2a12
@ -1,17 +1,20 @@
|
|||||||
--- a/net/minecraft/server/ShapedRecipes.java
|
--- a/net/minecraft/server/ShapedRecipes.java
|
||||||
+++ b/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.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
+// CraftBukkit start
|
+// CraftBukkit start
|
||||||
|
+import java.util.ArrayList;
|
||||||
|
+import java.util.List;
|
||||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
+import org.bukkit.craftbukkit.inventory.CraftShapedRecipe;
|
+import org.bukkit.craftbukkit.inventory.CraftShapedRecipe;
|
||||||
|
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||||
+// CraftBukkit end
|
+// CraftBukkit end
|
||||||
|
|
||||||
public class ShapedRecipes implements IRecipe {
|
public class ShapedRecipes implements IRecipe {
|
||||||
|
|
||||||
@@ -32,6 +36,66 @@
|
@@ -32,6 +39,70 @@
|
||||||
this.result = itemstack;
|
this.result = itemstack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,8 +69,12 @@
|
|||||||
+ for (RecipeItemStack list : this.items) {
|
+ for (RecipeItemStack list : this.items) {
|
||||||
+ list.buildChoices();
|
+ list.buildChoices();
|
||||||
+ if (list.choices.length > 0) {
|
+ if (list.choices.length > 0) {
|
||||||
+ net.minecraft.server.ItemStack stack = list.choices[0];
|
+ List<org.bukkit.Material> choices = new ArrayList<>(list.choices.length);
|
||||||
+ recipe.setIngredient(c, org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(stack.getItem()), (list.choices.length) > 1 ? 32767 : 0);
|
+ for (ItemStack i : list.choices) {
|
||||||
|
+ choices.add(CraftMagicNumbers.getMaterial(i.getItem()));
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ recipe.setIngredient(c, new org.bukkit.inventory.RecipeChoice.MaterialChoice(choices));
|
||||||
+ }
|
+ }
|
||||||
+ c++;
|
+ c++;
|
||||||
+ }
|
+ }
|
||||||
@ -78,7 +85,7 @@
|
|||||||
public MinecraftKey getKey() {
|
public MinecraftKey getKey() {
|
||||||
return this.key;
|
return this.key;
|
||||||
}
|
}
|
||||||
@@ -302,11 +366,11 @@
|
@@ -302,11 +373,11 @@
|
||||||
packetdataserializer.a(shapedrecipes.result);
|
packetdataserializer.a(shapedrecipes.result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
--- a/net/minecraft/server/ShapelessRecipes.java
|
--- a/net/minecraft/server/ShapelessRecipes.java
|
||||||
+++ b/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 com.google.gson.JsonParseException;
|
||||||
import it.unimi.dsi.fastutil.ints.IntList;
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
+// CraftBukkit start
|
+// CraftBukkit start
|
||||||
|
+import java.util.ArrayList;
|
||||||
|
+import java.util.List;
|
||||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
+import org.bukkit.craftbukkit.inventory.CraftShapelessRecipe;
|
+import org.bukkit.craftbukkit.inventory.CraftShapelessRecipe;
|
||||||
|
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||||
+// CraftBukkit end
|
+// CraftBukkit end
|
||||||
|
|
||||||
public class ShapelessRecipes implements IRecipe {
|
public class ShapelessRecipes implements IRecipe {
|
||||||
|
|
||||||
@@ -20,6 +24,22 @@
|
@@ -20,6 +27,26 @@
|
||||||
this.ingredients = nonnulllist;
|
this.ingredients = nonnulllist;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,8 +27,12 @@
|
|||||||
+
|
+
|
||||||
+ for (RecipeItemStack list : this.ingredients) {
|
+ for (RecipeItemStack list : this.ingredients) {
|
||||||
+ list.buildChoices();
|
+ 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;
|
+ return recipe;
|
||||||
+ }
|
+ }
|
||||||
@ -34,7 +41,7 @@
|
|||||||
public MinecraftKey getKey() {
|
public MinecraftKey getKey() {
|
||||||
return this.key;
|
return this.key;
|
||||||
}
|
}
|
||||||
@@ -127,11 +147,11 @@
|
@@ -127,11 +154,11 @@
|
||||||
packetdataserializer.a(shapelessrecipes.result);
|
packetdataserializer.a(shapelessrecipes.result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,18 @@
|
|||||||
package org.bukkit.craftbukkit.inventory;
|
package org.bukkit.craftbukkit.inventory;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.Recipe;
|
import org.bukkit.inventory.Recipe;
|
||||||
|
import org.bukkit.inventory.RecipeChoice;
|
||||||
|
|
||||||
public interface CraftRecipe extends Recipe {
|
public interface CraftRecipe extends Recipe {
|
||||||
|
|
||||||
void addToCraftingManager();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package org.bukkit.craftbukkit.inventory;
|
package org.bukkit.craftbukkit.inventory;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.NonNullList;
|
import net.minecraft.server.NonNullList;
|
||||||
@ -11,6 +10,7 @@ import net.minecraft.server.ShapedRecipes;
|
|||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.RecipeChoice;
|
||||||
import org.bukkit.inventory.ShapedRecipe;
|
import org.bukkit.inventory.ShapedRecipe;
|
||||||
|
|
||||||
public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe {
|
public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe {
|
||||||
@ -34,11 +34,11 @@ public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe {
|
|||||||
ret.setGroup(recipe.getGroup());
|
ret.setGroup(recipe.getGroup());
|
||||||
String[] shape = recipe.getShape();
|
String[] shape = recipe.getShape();
|
||||||
ret.shape(shape);
|
ret.shape(shape);
|
||||||
Map<Character, ItemStack> ingredientMap = recipe.getIngredientMap();
|
Map<Character, RecipeChoice> ingredientMap = recipe.getChoiceMap();
|
||||||
for (char c : ingredientMap.keySet()) {
|
for (char c : ingredientMap.keySet()) {
|
||||||
ItemStack stack = ingredientMap.get(c);
|
RecipeChoice stack = ingredientMap.get(c);
|
||||||
if (stack != null) {
|
if (stack != null) {
|
||||||
ret.setIngredient(c, stack.getType(), stack.getDurability());
|
ret.setIngredient(c, stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@ -46,14 +46,14 @@ public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe {
|
|||||||
|
|
||||||
public void addToCraftingManager() {
|
public void addToCraftingManager() {
|
||||||
String[] shape = this.getShape();
|
String[] shape = this.getShape();
|
||||||
Map<Character, ItemStack> ingred = this.getIngredientMap();
|
Map<Character, org.bukkit.inventory.RecipeChoice> ingred = this.getChoiceMap();
|
||||||
int width = shape[0].length();
|
int width = shape[0].length();
|
||||||
NonNullList<RecipeItemStack> data = NonNullList.a(shape.length * width, RecipeItemStack.a);
|
NonNullList<RecipeItemStack> data = NonNullList.a(shape.length * width, RecipeItemStack.a);
|
||||||
|
|
||||||
for (int i = 0; i < shape.length; i++) {
|
for (int i = 0; i < shape.length; i++) {
|
||||||
String row = shape[i];
|
String row = shape[i];
|
||||||
for (int j = 0; j < row.length(); j++) {
|
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))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package org.bukkit.craftbukkit.inventory;
|
package org.bukkit.craftbukkit.inventory;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.NonNullList;
|
import net.minecraft.server.NonNullList;
|
||||||
@ -11,6 +10,7 @@ import net.minecraft.server.ShapelessRecipes;
|
|||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.RecipeChoice;
|
||||||
import org.bukkit.inventory.ShapelessRecipe;
|
import org.bukkit.inventory.ShapelessRecipe;
|
||||||
|
|
||||||
public class CraftShapelessRecipe extends ShapelessRecipe implements CraftRecipe {
|
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());
|
CraftShapelessRecipe ret = new CraftShapelessRecipe(recipe.getKey(), recipe.getResult());
|
||||||
ret.setGroup(recipe.getGroup());
|
ret.setGroup(recipe.getGroup());
|
||||||
for (ItemStack ingred : recipe.getIngredientList()) {
|
for (RecipeChoice ingred : recipe.getChoiceList()) {
|
||||||
ret.addIngredient(ingred.getType(), ingred.getDurability());
|
ret.addIngredient(ingred);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addToCraftingManager() {
|
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);
|
NonNullList<RecipeItemStack> data = NonNullList.a(ingred.size(), RecipeItemStack.a);
|
||||||
for (int i = 0; i < ingred.size(); i++) {
|
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));
|
MinecraftServer.getServer().getCraftingManager().a(new ShapelessRecipes(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), CraftItemStack.asNMSCopy(this.getResult()), data));
|
||||||
|
Loading…
Reference in New Issue
Block a user