From 1e851e0ff4293633d2977e1a3d125fdc01193ab5 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Mon, 29 May 2023 13:41:07 +0200 Subject: Fixed FPS drops with Pet Candy Used feature --- .../skyhanni/features/misc/PetCandyUsedDisplay.kt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/main/java/at/hannibal2/skyhanni') 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() + + 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" -- cgit