From ff29d43793b8ebee6c88f46c182e5a5ea6c51049 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 24 Feb 2023 20:52:54 +0100 Subject: Fixed errors and flickering with the garden visitor item need list rendering. --- .../features/garden/GardenVisitorFeatures.kt | 22 ++++++++++++++-------- .../at/hannibal2/skyhanni/utils/RenderUtils.kt | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt index 7cae1bf81..d43bac5b6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt @@ -24,6 +24,7 @@ class GardenVisitorFeatures { private val display = mutableListOf>() private var lastClickedNpc = 0 private var nearby = false + private var tick = 0 @SubscribeEvent fun onChatPacket(event: InventoryOpenEvent) { @@ -63,9 +64,14 @@ class GardenVisitorFeatures { } private fun update() { + val list = drawDisplay() display.clear() + display.addAll(list) + } - if (!SkyHanniMod.feature.garden.visitorNeedsDisplay) return + private fun drawDisplay(): List> { + val newDisplay = mutableListOf>() + if (!SkyHanniMod.feature.garden.visitorNeedsDisplay) return newDisplay val requiredItems = mutableMapOf() val newVisitors = mutableListOf() @@ -80,27 +86,27 @@ class GardenVisitorFeatures { } } if (requiredItems.isNotEmpty()) { - display.add(Collections.singletonList("§7Visitor items needed:")) + newDisplay.add(Collections.singletonList("§7Visitor items needed:")) for ((name, amount) in requiredItems) { val internalName = NEUItems.getInternalName(name) val itemStack = NEUItems.getItemStack(internalName) - display.add(listOf(" §7- ", itemStack, "$name §8x$amount")) + newDisplay.add(listOf(" §7- ", itemStack, "$name §8x$amount")) } } if (newVisitors.isNotEmpty()) { if (requiredItems.isNotEmpty()) { - display.add(Collections.singletonList("")) + newDisplay.add(Collections.singletonList("")) } val amount = newVisitors.size val visitorLabel = if (amount == 1) "visitor" else "visitors" - display.add(Collections.singletonList("§e$amount §7new $visitorLabel:")) + newDisplay.add(Collections.singletonList("§e$amount §7new $visitorLabel:")) for (visitor in newVisitors) { - display.add(Collections.singletonList(" §7- $visitor")) + newDisplay.add(Collections.singletonList(" §7- $visitor")) } } - } - var tick = 0 + return newDisplay + } @SubscribeEvent fun onTooltip(event: ItemTooltipEvent) { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index a72483cb1..cec4cfb3c 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -475,7 +475,7 @@ object RenderUtils { if (list.isEmpty()) return var offsetY = 0 - for (line in list) { + for (line in list.toMutableList()) { renderLine(line, offsetY) offsetY += 10 + extraSpace + 2 } -- cgit