From a5b8d17fefc3ec5b74343e72a1aedf5a13ecc511 Mon Sep 17 00:00:00 2001 From: Danielle Voznyy Date: Mon, 19 Aug 2024 16:41:49 -0400 Subject: [PATCH] fix: toRecipe not correctly setting ingredients for Shaped/Shapeless recipes --- .../recipes/ShapedRecipeIngredients.kt | 20 +++++++++---------- .../recipes/ShapelessRecipeIngredients.kt | 16 +++++++-------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/recipes/ShapedRecipeIngredients.kt b/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/recipes/ShapedRecipeIngredients.kt index c9a8618..154937a 100644 --- a/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/recipes/ShapedRecipeIngredients.kt +++ b/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/recipes/ShapedRecipeIngredients.kt @@ -7,6 +7,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import org.bukkit.NamespacedKey import org.bukkit.inventory.ItemStack +import org.bukkit.inventory.Recipe import org.bukkit.inventory.RecipeChoice import org.bukkit.inventory.ShapedRecipe import org.bukkit.inventory.recipe.CraftingBookCategory @@ -17,15 +18,8 @@ class ShapedRecipeIngredients( val items: Map, val configuration: String = "", ) : SerializableRecipeIngredients() { - override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String, category: String): ShapedRecipe { - val recipe = ShapedRecipe(key, result) - - recipe.shape(*configuration.replace("|", "").split("\n").toTypedArray()) - - recipe.group = group - recipe.category = CraftingBookCategory.entries.find { it.name == category } ?: CraftingBookCategory.MISC - - return recipe + override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String, category: String): Recipe { + return toRecipeWithOptions(key, result, group, category).recipe } override fun toRecipeWithOptions( @@ -34,7 +28,13 @@ class ShapedRecipeIngredients( group: String, category: String, ): RecipeWithOptions { - val recipe = toRecipe(key, result, group, category) + val recipe = ShapedRecipe(key, result) + + recipe.shape(*configuration.replace("|", "").split("\n").toTypedArray()) + + recipe.group = group + recipe.category = CraftingBookCategory.entries.find { it.name == category } ?: CraftingBookCategory.MISC + val options = items.mapNotNull { (key, ingredient) -> val choice = if (ingredient.tag?.isNotEmpty() == true) { val namespacedKey = NamespacedKey.fromString(ingredient.tag, null)!! diff --git a/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/recipes/ShapelessRecipeIngredients.kt b/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/recipes/ShapelessRecipeIngredients.kt index 97bc201..454724a 100644 --- a/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/recipes/ShapelessRecipeIngredients.kt +++ b/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/recipes/ShapelessRecipeIngredients.kt @@ -8,6 +8,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import org.bukkit.NamespacedKey import org.bukkit.inventory.ItemStack +import org.bukkit.inventory.Recipe import org.bukkit.inventory.RecipeChoice import org.bukkit.inventory.ShapelessRecipe import org.bukkit.inventory.recipe.CraftingBookCategory @@ -17,13 +18,8 @@ import org.bukkit.inventory.recipe.CraftingBookCategory class ShapelessRecipeIngredients( val items: List, ) : SerializableRecipeIngredients() { - override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String, category: String): ShapelessRecipe { - val recipe = ShapelessRecipe(key, result) - - recipe.group = group - recipe.category = CraftingBookCategory.entries.find { it.name == category } ?: CraftingBookCategory.MISC - - return recipe + override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String, category: String): Recipe { + return toRecipeWithOptions(key, result, group, category).recipe } override fun toRecipeWithOptions( @@ -32,7 +28,11 @@ class ShapelessRecipeIngredients( group: String, category: String, ): RecipeWithOptions { - val recipe = toRecipe(key, result, group, category) + val recipe = ShapelessRecipe(key, result) + + recipe.group = group + recipe.category = CraftingBookCategory.entries.find { it.name == category } ?: CraftingBookCategory.MISC + val options = items.mapNotNull { ingredient -> val choice = if (ingredient.tag?.isNotEmpty() == true) { val namespacedKey = NamespacedKey.fromString(ingredient.tag, null)!!