aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-30 10:57:48 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-30 10:57:48 +0200
commitd2e1534709e26fba3e31b98fe173b26c0c941aca (patch)
tree9843a4c39657398def929318db000b7db407f63c /src
parentd613f66318d40bc562e8557a3f6594c177b5b8ac (diff)
downloadskyhanni-d2e1534709e26fba3e31b98fe173b26c0c941aca.tar.gz
skyhanni-d2e1534709e26fba3e31b98fe173b26c0c941aca.tar.bz2
skyhanni-d2e1534709e26fba3e31b98fe173b26c0c941aca.zip
Added an item stack -> internal name cache, fixing performance problems in rng meter inventory
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
index 76da79bc5..f24ea4949 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
@@ -18,7 +18,8 @@ import net.minecraft.nbt.NBTTagCompound
object NEUItems {
val manager: NEUManager get() = NotEnoughUpdates.INSTANCE.manager
- private val itemCache = mutableMapOf<String, ItemStack>()
+ 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,10 +58,16 @@ object NEUItems {
}
fun getInternalName(itemStack: ItemStack): String {
- return ItemResolutionQuery(manager)
+ if (itemIdCache.containsKey(itemStack)) {
+ return itemIdCache[itemStack]!!
+ }
+
+ val internalId = ItemResolutionQuery(manager)
.withCurrentGuiContext()
.withItemStack(itemStack)
.resolveInternalName() ?: ""
+ itemIdCache[itemStack] = internalId
+ return internalId
}
fun getInternalNameOrNull(nbt: NBTTagCompound): String? {
@@ -97,14 +104,14 @@ object NEUItems {
}
fun getItemStackOrNull(internalName: String): ItemStack? {
- if (itemCache.contains(internalName)) {
- return itemCache[internalName]!!.copy()
+ if (idItemCache.contains(internalName)) {
+ return idItemCache[internalName]!!.copy()
}
val itemStack = ItemResolutionQuery(manager)
.withKnownInternalName(internalName)
.resolveToItemStack() ?: return null
- itemCache[internalName] = itemStack
+ idItemCache[internalName] = itemStack
return itemStack.copy()
}