aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-04-24 09:31:24 +0200
committerGitHub <noreply@github.com>2024-04-24 09:31:24 +0200
commitf9b776fc3c3d09e0992816932118569ac5399431 (patch)
tree299c41483997927a8a2127c6b22af8674fee4945 /src/main/java/at/hannibal2/skyhanni
parent6e87fd8b1d5ed751aa26124eb7b0fec888b4dddd (diff)
downloadskyhanni-f9b776fc3c3d09e0992816932118569ac5399431.tar.gz
skyhanni-f9b776fc3c3d09e0992816932118569ac5399431.tar.bz2
skyhanni-f9b776fc3c3d09e0992816932118569ac5399431.zip
Backend: Create NEUItems.getPrimitiveMultiplier (#1165)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: Cal <cwolfson58@gmail.com>
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) }
}
}