aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-29 13:41:07 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-29 13:41:07 +0200
commit1e851e0ff4293633d2977e1a3d125fdc01193ab5 (patch)
tree92783f6fbe0607090bb0aca8624273578af5216e /src
parent75d27ce5ce44c5f677036d73f40549ae251bbcd8 (diff)
downloadskyhanni-1e851e0ff4293633d2977e1a3d125fdc01193ab5.tar.gz
skyhanni-1e851e0ff4293633d2977e1a3d125fdc01193ab5.tar.bz2
skyhanni-1e851e0ff4293633d2977e1a3d125fdc01193ab5.zip
Fixed FPS drops with Pet Candy Used feature
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/PetCandyUsedDisplay.kt19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/PetCandyUsedDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/PetCandyUsedDisplay.kt
index b09ec0896..ec98aa655 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/PetCandyUsedDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/PetCandyUsedDisplay.kt
@@ -4,10 +4,25 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiRenderItemEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getPetCandyUsed
+import com.google.common.cache.CacheBuilder
import net.minecraft.client.renderer.GlStateManager
+import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.util.concurrent.TimeUnit
class PetCandyUsedDisplay {
+ private var cache =
+ CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.SECONDS).build<ItemStack, Int>()
+
+ private fun getCachedPetCandyUsed(stack: ItemStack): Int? {
+ cache.getIfPresent(stack)?.let {
+ if (it == -1) return null
+ return it
+ }
+ val candyUsed = stack.getPetCandyUsed()
+ cache.put(stack, candyUsed ?: -1)
+ return candyUsed
+ }
@SubscribeEvent
fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.GuiRenderItemPost) {
@@ -15,7 +30,9 @@ class PetCandyUsedDisplay {
if (!LorenzUtils.inSkyBlock || stack.stackSize != 1) return
if (!SkyHanniMod.feature.misc.petCandyUsed) return
- val petCandyUsed = stack.getPetCandyUsed() ?: return
+
+ val petCandyUsed = getCachedPetCandyUsed(stack) ?: return
+// val petCandyUsed = stack.getPetCandyUsed() ?: return
if (petCandyUsed == 0) return
val stackTip = "§c$petCandyUsed"