Skip to content

Commit

Permalink
feat: add RecipeBookCategory to SerializableRecipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed May 13, 2024
1 parent 115b79a commit da1921d
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ import org.bukkit.inventory.BlastingRecipe
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.Recipe
import org.bukkit.inventory.RecipeChoice
import org.bukkit.inventory.recipe.CookingBookCategory

@Serializable
@SerialName("blasting")
class BlastingRecipeIngredients(
val input: SerializableItemStack,
val experience: Float,
val cookingTime: Int
val cookingTime: Int,
) : SerializableRecipeIngredients() {
override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String): Recipe {
override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String, category: String): Recipe {
val recipe = BlastingRecipe(key, result, RecipeChoice.ExactChoice(input.toItemStack()), experience, cookingTime)

recipe.group = group
recipe.category = CookingBookCategory.entries.find { it.name == category } ?: CookingBookCategory.MISC

return recipe
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ import org.bukkit.inventory.CampfireRecipe
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.Recipe
import org.bukkit.inventory.RecipeChoice
import org.bukkit.inventory.recipe.CookingBookCategory

@Serializable
@SerialName("campfire")
class CampfireRecipeIngredients(
val input: SerializableItemStack,
val experience: Float,
val cookingTime: Int
val cookingTime: Int,
) : SerializableRecipeIngredients() {
override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String): Recipe {
override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String, category: String): Recipe {
val recipe = CampfireRecipe(key, result, RecipeChoice.ExactChoice(input.toItemStack()), experience, cookingTime)

recipe.group = group
recipe.category = CookingBookCategory.entries.find { it.name == category } ?: CookingBookCategory.MISC

return recipe
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ import org.bukkit.inventory.FurnaceRecipe
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.Recipe
import org.bukkit.inventory.RecipeChoice
import org.bukkit.inventory.recipe.CookingBookCategory

@Serializable
@SerialName("furnace")
class FurnaceRecipeIngredients(
val input: SerializableItemStack,
val experience: Float,
val cookingTime: Int
val cookingTime: Int,
) : SerializableRecipeIngredients() {
override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String): Recipe {
override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String, category: String): Recipe {
val recipe = FurnaceRecipe(key, result, RecipeChoice.ExactChoice(input.toItemStack()), experience, cookingTime)

recipe.group = group
recipe.category = CookingBookCategory.entries.find { it.name == category } ?: CookingBookCategory.MISC

return recipe
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class SerializableRecipe(
val ingredients: SerializableRecipeIngredients,
val result: SerializableItemStack,
val group: String = "",
val category: String = "MISC"
) {
fun toCraftingRecipe() =
ingredients.toRecipe(key.toMCKey(), result.toItemStack(), group)
fun toCraftingRecipe() {
ingredients.toRecipe(key.toMCKey(), result.toItemStack(), group, category)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import org.bukkit.inventory.Recipe

@Serializable
sealed class SerializableRecipeIngredients {
abstract fun toRecipe(key: NamespacedKey, result: ItemStack, group: String = ""): Recipe
abstract fun toRecipe(key: NamespacedKey, result: ItemStack, group: String = "", category: String = "MISC"): Recipe
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ 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

@Serializable
@SerialName("shaped")
class ShapedRecipeIngredients(
val items: Map<String, SerializableItemStack>,
val configuration: String = "",
) : SerializableRecipeIngredients() {
override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String): Recipe {
override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String, category: String): Recipe {
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

items.forEach { (key, ingredient) ->
if (ingredient.tag?.isNotEmpty() == true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ 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

@Serializable
@SerialName("shapeless")
class ShapelessRecipeIngredients(
val items: List<SerializableItemStack>,
) : SerializableRecipeIngredients() {
override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String): Recipe {
override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String, category: String): Recipe {
val recipe = ShapelessRecipe(key, result)

recipe.group = group
recipe.category = CraftingBookCategory.entries.find { it.name == category } ?: CraftingBookCategory.MISC

items.forEach { ingredient ->
if (ingredient.tag?.isNotEmpty() == true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SmithingTransformRecipeIngredients(
val addition: SerializableItemStack,
val copyNbt: Boolean = false
) : SerializableRecipeIngredients() {
override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String): Recipe {
override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String, category: String): Recipe {
return SmithingTransformRecipe(
key,
result,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SmithingTrimRecipeIngredients(
val addition: SerializableItemStack,
val copyNbt: Boolean = false
) : SerializableRecipeIngredients() {
override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String): Recipe {
override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String, category: String): Recipe {
return SmithingTrimRecipe(
key,
RecipeChoice.ExactChoice(template.toItemStack()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.Recipe
import org.bukkit.inventory.RecipeChoice
import org.bukkit.inventory.SmokingRecipe
import org.bukkit.inventory.recipe.CookingBookCategory

@Serializable
@SerialName("smoking")
class SmokingRecipeIngredients(
val input: SerializableItemStack,
val experience: Float,
val cookingTime: Int
val cookingTime: Int,
) : SerializableRecipeIngredients() {
override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String): Recipe {
override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String, category: String): Recipe {
val recipe = SmokingRecipe(key, result, RecipeChoice.ExactChoice(input.toItemStack()), experience, cookingTime)

recipe.group = group

recipe.category = CookingBookCategory.entries.find { it.name == category } ?: CookingBookCategory.MISC
return recipe
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.bukkit.inventory.StonecuttingRecipe
class StonecuttingRecipeIngredients(
val input: SerializableItemStack,
) : SerializableRecipeIngredients() {
override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String): Recipe {
override fun toRecipe(key: NamespacedKey, result: ItemStack, group: String, category: String): Recipe {
val recipe = StonecuttingRecipe(key, result, RecipeChoice.ExactChoice(input.toItemStack()))

recipe.group = group
Expand Down

0 comments on commit da1921d

Please sign in to comment.