3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 04:20:04 +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;
@ -15,14 +14,14 @@ public interface CraftRecipe extends Recipe {
void addToCraftingManager(); void addToCraftingManager();
default RecipeItemStack toNMS(RecipeChoice bukkit, boolean requireNotEmpty) { default RecipeItemStack toNMS(RecipeChoice bukkit, boolean requireNotEmpty) {
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,15 +43,20 @@ 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));
}
List<org.bukkit.Material> choices = new ArrayList<>(list.choices.length); return new RecipeChoice.ExactChoice(choices);
for (net.minecraft.server.ItemStack i : list.choices) { } else {
choices.add(CraftMagicNumbers.getMaterial(i.getItem()));
}
return new RecipeChoice.MaterialChoice(choices); List<org.bukkit.Material> choices = new ArrayList<>(list.choices.length);
for (net.minecraft.server.ItemStack i : list.choices) {
choices.add(CraftMagicNumbers.getMaterial(i.getItem()));
}
return new RecipeChoice.MaterialChoice(choices);
}
} }
} }