blob: b1692a119b6243da9a97296bb38bc2dc41bd8abf (
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
|
package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.SKYBLOCK_COIN
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble
import io.github.moulberry.notenoughupdates.recipes.Ingredient
class PrimitiveIngredient(val internalName: NEUInternalName, val count: Double = 1.0) {
constructor(internalName: NEUInternalName, count: Int) : this(internalName, count.toDouble())
constructor(ingredientIdentifier: String) : this(
ingredientIdentifier.substringBefore(':').asInternalName(),
// if second part is blank, the count is assumed to be 1
ingredientIdentifier.substringAfter(':', "").let { if (it.isBlank()) 1.0 else it.formatDouble() },
)
companion object {
fun coinIngredient(count: Double = 1.0) = PrimitiveIngredient(SKYBLOCK_COIN, count)
fun fromNeuIngredient(neuIngredient: Ingredient) =
PrimitiveIngredient(neuIngredient.internalItemId.asInternalName(), neuIngredient.count)
fun Set<PrimitiveIngredient>.toPrimitiveItemStacks(): List<PrimitiveItemStack> =
map { it.toPrimitiveItemStack() }
}
fun isCoin() = internalName == SKYBLOCK_COIN
override fun toString() = "$internalName x$count"
fun toPair() = Pair(internalName, count)
// TODO should maybe throw an error when trying to use with internalName == SKYBLOCK_COIN
fun toPrimitiveItemStack() = PrimitiveItemStack(internalName, count.toInt())
}
|