aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-30 23:43:37 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-30 23:43:37 +0200
commit57d3a145417242d1c733219013490543baca26c5 (patch)
treecd2e9a2ae4fbdcfda900102201d28e55ea683852 /src/main
parent546d6d9874fc90130c5b29bc049e88cae61c5f52 (diff)
downloadskyhanni-57d3a145417242d1c733219013490543baca26c5.tar.gz
skyhanni-57d3a145417242d1c733219013490543baca26c5.tar.bz2
skyhanni-57d3a145417242d1c733219013490543baca26c5.zip
Removed neu item caches that caused memory leaks
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt37
1 files changed, 9 insertions, 28 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
index f24ea4949..2437174c3 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
@@ -18,8 +18,6 @@ import net.minecraft.nbt.NBTTagCompound
object NEUItems {
val manager: NEUManager get() = NotEnoughUpdates.INSTANCE.manager
- private val itemIdCache = mutableMapOf<ItemStack, String>() // stack -> internal name
- private val idItemCache = mutableMapOf<String, ItemStack>() // internal name -> stack
private val itemNameCache = mutableMapOf<String, String>() // item name -> internal name
private val multiplierCache = mutableMapOf<String, Pair<String, Int>>()
private val recipesCache = mutableMapOf<String, Set<NeuRecipe>>()
@@ -57,22 +55,13 @@ object NEUItems {
return text
}
- fun getInternalName(itemStack: ItemStack): String {
- if (itemIdCache.containsKey(itemStack)) {
- return itemIdCache[itemStack]!!
- }
-
- val internalId = ItemResolutionQuery(manager)
- .withCurrentGuiContext()
- .withItemStack(itemStack)
- .resolveInternalName() ?: ""
- itemIdCache[itemStack] = internalId
- return internalId
- }
+ fun getInternalName(itemStack: ItemStack) = ItemResolutionQuery(manager)
+ .withCurrentGuiContext()
+ .withItemStack(itemStack)
+ .resolveInternalName() ?: ""
- fun getInternalNameOrNull(nbt: NBTTagCompound): String? {
- return ItemResolutionQuery(manager).withItemNBT(nbt).resolveInternalName()
- }
+ fun getInternalNameOrNull(nbt: NBTTagCompound) =
+ ItemResolutionQuery(manager).withItemNBT(nbt).resolveInternalName()
fun getPriceOrNull(internalName: String, useSellingPrice: Boolean = false): Double? {
val price = getPrice(internalName, useSellingPrice)
@@ -103,17 +92,9 @@ object NEUItems {
return result
}
- fun getItemStackOrNull(internalName: String): ItemStack? {
- if (idItemCache.contains(internalName)) {
- return idItemCache[internalName]!!.copy()
- }
-
- val itemStack = ItemResolutionQuery(manager)
- .withKnownInternalName(internalName)
- .resolveToItemStack() ?: return null
- idItemCache[internalName] = itemStack
- return itemStack.copy()
- }
+ fun getItemStackOrNull(internalName: String) = ItemResolutionQuery(manager)
+ .withKnownInternalName(internalName)
+ .resolveToItemStack()?.copy()
fun getItemStack(internalName: String): ItemStack {
val stack = getItemStackOrNull(internalName)