mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-15 07:01:36 +08:00
SPIGOT-4587: Enforce at least one valid choice for FurnaceRecipe
This commit is contained in:
parent
7fc66b28db
commit
1a64d4ae2b
@ -25,6 +25,6 @@ public class CraftFurnaceRecipe extends FurnaceRecipe implements CraftRecipe {
|
||||
public void addToCraftingManager() {
|
||||
ItemStack result = this.getResult();
|
||||
|
||||
MinecraftServer.getServer().getCraftingManager().a(new net.minecraft.server.FurnaceRecipe(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), toNMS(this.getInputChoice()), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime()));
|
||||
MinecraftServer.getServer().getCraftingManager().a(new net.minecraft.server.FurnaceRecipe(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime()));
|
||||
}
|
||||
}
|
||||
|
@ -14,19 +14,26 @@ public interface CraftRecipe extends Recipe {
|
||||
|
||||
void addToCraftingManager();
|
||||
|
||||
default net.minecraft.server.RecipeItemStack toNMS(RecipeChoice bukkit) {
|
||||
if (bukkit == null) {
|
||||
return RecipeItemStack.a;
|
||||
} else if (bukkit instanceof RecipeChoice.MaterialChoice) {
|
||||
return new RecipeItemStack(((RecipeChoice.MaterialChoice) bukkit).getChoices().stream().map((mat) -> new net.minecraft.server.RecipeItemStack.StackProvider(CraftItemStack.asNMSCopy(new ItemStack(mat)))));
|
||||
} else if (bukkit instanceof RecipeChoice.ExactChoice) {
|
||||
RecipeItemStack stack = new RecipeItemStack(Stream.of(new net.minecraft.server.RecipeItemStack.StackProvider(CraftItemStack.asNMSCopy(((RecipeChoice.ExactChoice) bukkit).getItemStack()))));
|
||||
stack.exact = true;
|
||||
default RecipeItemStack toNMS(RecipeChoice bukkit, boolean requireNotEmpty) {
|
||||
RecipeItemStack stack;
|
||||
|
||||
return stack;
|
||||
if (bukkit == null) {
|
||||
stack= RecipeItemStack.a;
|
||||
} else if (bukkit instanceof RecipeChoice.MaterialChoice) {
|
||||
stack= new RecipeItemStack(((RecipeChoice.MaterialChoice) bukkit).getChoices().stream().map((mat) -> new net.minecraft.server.RecipeItemStack.StackProvider(CraftItemStack.asNMSCopy(new ItemStack(mat)))));
|
||||
} else if (bukkit instanceof RecipeChoice.ExactChoice) {
|
||||
stack = new RecipeItemStack(Stream.of(new net.minecraft.server.RecipeItemStack.StackProvider(CraftItemStack.asNMSCopy(((RecipeChoice.ExactChoice) bukkit).getItemStack()))));
|
||||
stack.exact = true;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown recipe stack instance " + bukkit);
|
||||
}
|
||||
|
||||
stack.buildChoices();
|
||||
if (requireNotEmpty && stack.choices.length == 0) {
|
||||
throw new IllegalArgumentException("Recipe requires at least one non-air choice!");
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static RecipeChoice toBukkit(RecipeItemStack list) {
|
||||
|
@ -53,7 +53,7 @@ public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe {
|
||||
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, toNMS(ingred.get(row.charAt(j))));
|
||||
data.set(i * width + j, toNMS(ingred.get(row.charAt(j)), false));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class CraftShapelessRecipe extends ShapelessRecipe implements CraftRecipe
|
||||
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, toNMS(ingred.get(i)));
|
||||
data.set(i, toNMS(ingred.get(i), true));
|
||||
}
|
||||
|
||||
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