Skip to content

Commit

Permalink
fix: toRecipe not correctly setting ingredients for Shaped/Shapeless …
Browse files Browse the repository at this point in the history
…recipes
  • Loading branch information
0ffz committed Aug 19, 2024
1 parent 359792f commit a5b8d17
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,15 +18,8 @@ class ShapedRecipeIngredients(
val items: Map<String, SerializableItemStack>,
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(
Expand All @@ -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)!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,13 +18,8 @@ import org.bukkit.inventory.recipe.CraftingBookCategory
class ShapelessRecipeIngredients(
val items: List<SerializableItemStack>,
) : 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(
Expand All @@ -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)!!
Expand Down

0 comments on commit a5b8d17

Please sign in to comment.