Fix issues with Recipe API
This commit is contained in:
@@ -19,7 +19,7 @@ public interface CraftRecipe extends Recipe {
|
||||
void addToCraftingManager();
|
||||
|
||||
default Optional<Ingredient> toNMSOptional(RecipeChoice bukkit, boolean requireNotEmpty) {
|
||||
return (bukkit == null) ? Optional.empty() : Optional.of(this.toNMS(bukkit, requireNotEmpty));
|
||||
return (bukkit == null || bukkit == RecipeChoice.empty()) ? Optional.empty() : Optional.of(this.toNMS(bukkit, requireNotEmpty)); // Paper - support "empty" choices
|
||||
}
|
||||
|
||||
default Ingredient toNMS(RecipeChoice bukkit, boolean requireNotEmpty) {
|
||||
@@ -36,6 +36,13 @@ public interface CraftRecipe extends Recipe {
|
||||
stack = Ingredient.of(((RecipeChoice.MaterialChoice) bukkit).getChoices().stream().map((mat) -> CraftItemType.bukkitToMinecraft(mat)));
|
||||
} else if (bukkit instanceof RecipeChoice.ExactChoice) {
|
||||
stack = Ingredient.ofStacks(((RecipeChoice.ExactChoice) bukkit).getChoices().stream().map((mat) -> CraftItemStack.asNMSCopy(mat)).toList());
|
||||
// Paper start - support "empty" choices - legacy method that spigot might incorrectly call
|
||||
// Their impl of Ingredient.of() will error, ingredients need at least one entry.
|
||||
// Callers running into this exception may have passed an incorrect empty() recipe choice to a non-empty slot or
|
||||
// spigot calls this method in a wrong place.
|
||||
} else if (bukkit == RecipeChoice.empty()) {
|
||||
throw new IllegalArgumentException("This ingredient cannot be empty");
|
||||
// Paper end - support "empty" choices
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown recipe stack instance " + bukkit);
|
||||
}
|
||||
@@ -48,12 +55,12 @@ public interface CraftRecipe extends Recipe {
|
||||
}
|
||||
|
||||
public static RecipeChoice toBukkit(Optional<Ingredient> list) {
|
||||
return list.map(CraftRecipe::toBukkit).orElse(null);
|
||||
return list.map(CraftRecipe::toBukkit).orElse(RecipeChoice.empty()); // Paper - fix issue with recipe API
|
||||
}
|
||||
|
||||
public static RecipeChoice toBukkit(Ingredient list) {
|
||||
if (list.isEmpty()) {
|
||||
return null;
|
||||
return RecipeChoice.empty(); // Paper - null breaks API contracts
|
||||
}
|
||||
|
||||
if (list.isExact()) {
|
||||
|
||||
Reference in New Issue
Block a user