aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/PrimitiveRecipe.kt
blob: f064183ba372dc4bdd5d322aa704d3909f841bac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package at.hannibal2.skyhanni.utils

import at.hannibal2.skyhanni.utils.RecipeType.CRAFTING
import io.github.moulberry.notenoughupdates.recipes.EssenceUpgrades
import io.github.moulberry.notenoughupdates.recipes.ForgeRecipe
import io.github.moulberry.notenoughupdates.recipes.ItemShopRecipe
import io.github.moulberry.notenoughupdates.recipes.KatRecipe
import io.github.moulberry.notenoughupdates.recipes.MobLootRecipe
import io.github.moulberry.notenoughupdates.recipes.NeuRecipe
import io.github.moulberry.notenoughupdates.recipes.VillagerTradeRecipe

data class PrimitiveRecipe(
    val ingredients: Set<PrimitiveIngredient>,
    val outputs: Set<PrimitiveIngredient>,
    val recipeType: RecipeType,
) {

    val output by lazy { outputs.firstOrNull() }

    companion object {
        fun fromNeuRecipe(neuRecipe: NeuRecipe): PrimitiveRecipe {
            val ingredients = neuRecipe.ingredients.map { PrimitiveIngredient.fromNeuIngredient(it) }.toSet()
            val outputs = neuRecipe.outputs.map { PrimitiveIngredient.fromNeuIngredient(it) }.toSet()

            val recipeType = when (neuRecipe::class.java) {
                ForgeRecipe::class.java -> RecipeType.FORGE
                VillagerTradeRecipe::class.java -> RecipeType.TRADE
                EssenceUpgrades::class.java -> RecipeType.ESSENCE
                MobLootRecipe::class.java -> RecipeType.MOB_DROP
                ItemShopRecipe::class.java -> RecipeType.NPC_SHOP
                KatRecipe::class.java -> RecipeType.KAT_UPGRADE
                else -> CRAFTING
            }

            return PrimitiveRecipe(ingredients, outputs, recipeType)
        }

        fun convertMultiple(neuRecipes: Collection<NeuRecipe>) = neuRecipes.map { fromNeuRecipe(it) }
    }

    fun isCraftingRecipe() = this.recipeType == CRAFTING
}

enum class RecipeType {
    FORGE,
    TRADE,
    MOB_DROP,
    NPC_SHOP,
    KAT_UPGRADE,
    ESSENCE,
    CRAFTING,
    ;
}