aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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"