aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt24
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/PrimitiveItemStack.kt6
2 files changed, 18 insertions, 12 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
index 3d6f0e74e..7c11f03db 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
@@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.utils.ItemBlink.checkBlinkItem
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NumberUtil.isInt
+import at.hannibal2.skyhanni.utils.PrimitiveItemStack.Companion.makePrimitiveStack
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import com.google.gson.JsonObject
import com.google.gson.JsonPrimitive
@@ -45,7 +46,7 @@ import org.lwjgl.opengl.GL11
object NEUItems {
val manager: NEUManager get() = NotEnoughUpdates.INSTANCE.manager
- private val multiplierCache = mutableMapOf<NEUInternalName, Pair<NEUInternalName, Int>>()
+ private val multiplierCache = mutableMapOf<NEUInternalName, PrimitiveItemStack>()
private val recipesCache = mutableMapOf<NEUInternalName, Set<NeuRecipe>>()
private val ingredientsCache = mutableMapOf<NeuRecipe, Set<Ingredient>>()
@@ -250,18 +251,21 @@ object NEUItems {
fun allNeuRepoItems(): Map<String, JsonObject> = NotEnoughUpdates.INSTANCE.manager.itemInformation
- // TODO create extended function
+ @Deprecated("outdated", ReplaceWith("NEUItems.getPrimitiveMultiplier(internalName, tryCount)"))
fun getMultiplier(internalName: NEUInternalName, tryCount: Int = 0): Pair<NEUInternalName, Int> {
- if (multiplierCache.contains(internalName)) {
- return multiplierCache[internalName]!!
- }
+ val (name, amount) = getPrimitiveMultiplier(internalName, tryCount)
+ return Pair(name, amount)
+ }
+
+ fun getPrimitiveMultiplier(internalName: NEUInternalName, tryCount: Int = 0): PrimitiveItemStack {
+ multiplierCache[internalName]?.let { return it }
if (tryCount == 10) {
ErrorManager.logErrorStateWithData(
"Could not load recipe data.",
"Failed to find item multiplier",
"internalName" to internalName
)
- return Pair(internalName, 1)
+ return internalName.makePrimitiveStack()
}
for (recipe in getRecipes(internalName)) {
if (recipe !is CraftingRecipe) continue
@@ -297,16 +301,16 @@ object NEUItems {
val current = map.iterator().next().toPair()
val id = current.first
return if (current.second > 1) {
- val child = getMultiplier(id, tryCount + 1)
- val result = Pair(child.first, child.second * current.second)
+ val child = getPrimitiveMultiplier(id, tryCount + 1)
+ val result = child.multiply(current.second)
multiplierCache[internalName] = result
result
} else {
- Pair(internalName, 1)
+ internalName.makePrimitiveStack()
}
}
- val result = Pair(internalName, 1)
+ val result = internalName.makePrimitiveStack()
multiplierCache[internalName] = result
return result
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/PrimitiveItemStack.kt b/src/main/java/at/hannibal2/skyhanni/utils/PrimitiveItemStack.kt
index 26338c839..2173fcc8f 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/PrimitiveItemStack.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/PrimitiveItemStack.kt
@@ -7,13 +7,15 @@ import net.minecraft.item.ItemStack
data class PrimitiveItemStack(val internalName: NEUInternalName, val amount: Int) {
- fun createItem() = internalName.getItemStack().apply { stackSize = amount }
+ fun createItem(): ItemStack = internalName.getItemStack().apply { stackSize = amount }
+
+ fun multiply(multiplier: Int): PrimitiveItemStack = PrimitiveItemStack(internalName, amount * multiplier)
val itemName by lazy { internalName.itemName }
companion object {
- fun NEUInternalName.makePrimitiveStack(amount: Int) = PrimitiveItemStack(this, amount)
+ fun NEUInternalName.makePrimitiveStack(amount: Int = 1) = PrimitiveItemStack(this, amount)
fun ItemStack.toPrimitiveStackOrNull() = getInternalNameOrNull()?.let { PrimitiveItemStack(it, stackSize) }
}
}