3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 12:30:06 +01:00

Consistent multiple choice APIs for RecipeChoice.

Dieser Commit ist enthalten in:
md_5 2019-01-25 13:59:11 +11:00
Ursprung 13f71402e8
Commit 1748af891b

Datei anzeigen

@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.inventory;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import net.minecraft.server.RecipeItemStack; import net.minecraft.server.RecipeItemStack;
import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -18,11 +17,11 @@ public interface CraftRecipe extends Recipe {
RecipeItemStack stack; RecipeItemStack stack;
if (bukkit == null) { if (bukkit == null) {
stack= RecipeItemStack.a; stack = RecipeItemStack.a;
} else if (bukkit instanceof RecipeChoice.MaterialChoice) { } 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))))); 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) { } else if (bukkit instanceof RecipeChoice.ExactChoice) {
stack = new RecipeItemStack(Stream.of(new net.minecraft.server.RecipeItemStack.StackProvider(CraftItemStack.asNMSCopy(((RecipeChoice.ExactChoice) bukkit).getItemStack())))); stack = new RecipeItemStack(((RecipeChoice.ExactChoice) bukkit).getChoices().stream().map((mat) -> new net.minecraft.server.RecipeItemStack.StackProvider(CraftItemStack.asNMSCopy(mat))));
stack.exact = true; stack.exact = true;
} else { } else {
throw new IllegalArgumentException("Unknown recipe stack instance " + bukkit); throw new IllegalArgumentException("Unknown recipe stack instance " + bukkit);
@ -44,10 +43,14 @@ public interface CraftRecipe extends Recipe {
} }
if (list.exact) { if (list.exact) {
Preconditions.checkState(list.choices.length == 1, "Exact recipe must have 1 choice"); List<org.bukkit.inventory.ItemStack> choices = new ArrayList<>(list.choices.length);
return new RecipeChoice.ExactChoice(CraftItemStack.asBukkitCopy(list.choices[0])); for (net.minecraft.server.ItemStack i : list.choices) {
choices.add(CraftItemStack.asBukkitCopy(i));
} }
return new RecipeChoice.ExactChoice(choices);
} else {
List<org.bukkit.Material> choices = new ArrayList<>(list.choices.length); List<org.bukkit.Material> choices = new ArrayList<>(list.choices.length);
for (net.minecraft.server.ItemStack i : list.choices) { for (net.minecraft.server.ItemStack i : list.choices) {
choices.add(CraftMagicNumbers.getMaterial(i.getItem())); choices.add(CraftMagicNumbers.getMaterial(i.getItem()));
@ -55,4 +58,5 @@ public interface CraftRecipe extends Recipe {
return new RecipeChoice.MaterialChoice(choices); return new RecipeChoice.MaterialChoice(choices);
} }
}
} }