SPIGOT-4587: Enforce at least one valid choice for FurnaceRecipe

Dieser Commit ist enthalten in:
md_5 2019-01-21 10:39:24 +11:00
Ursprung 7fc66b28db
Commit 1a64d4ae2b
4 geänderte Dateien mit 19 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -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()));
}
}

Datei anzeigen

@ -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) {

Datei anzeigen

@ -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));
}
}

Datei anzeigen

@ -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));