diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-03-27 21:22:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-27 21:22:50 +0100 |
commit | 07eca4f6a1637eb261450481a2ecdf455ea43f07 (patch) | |
tree | 835ead89bb1fbc74a6d09b9f632a7c99441abdfc /src/main/java/at/hannibal2/skyhanni/features/garden | |
parent | 86bad256905c05b07ad48fe5d29a9110eab60d03 (diff) | |
download | skyhanni-07eca4f6a1637eb261450481a2ecdf455ea43f07.tar.gz skyhanni-07eca4f6a1637eb261450481a2ecdf455ea43f07.tar.bz2 skyhanni-07eca4f6a1637eb261450481a2ecdf455ea43f07.zip |
Fix: Visitor Tooltip and Tab List (#1251)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden')
3 files changed, 16 insertions, 14 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index f29fd4faf..cfa4fdfb3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -18,7 +18,6 @@ import at.hannibal2.skyhanni.events.garden.visitor.VisitorArrivalEvent import at.hannibal2.skyhanni.events.garden.visitor.VisitorOpenEvent import at.hannibal2.skyhanni.events.garden.visitor.VisitorRefusedEvent import at.hannibal2.skyhanni.events.garden.visitor.VisitorRenderEvent -import at.hannibal2.skyhanni.events.garden.visitor.VisitorToolTipEvent import at.hannibal2.skyhanni.features.garden.CropType.Companion.getByNameOrNull import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed.getSpeed @@ -63,14 +62,13 @@ import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.item.EntityArmorStand import net.minecraft.item.ItemStack import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent -import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.math.round import kotlin.time.Duration.Companion.seconds private val config get() = VisitorAPI.config -class GardenVisitorFeatures { +object GardenVisitorFeatures { private var display = emptyList<List<Any>>() @@ -297,16 +295,13 @@ class GardenVisitorFeatures { } } - @SubscribeEvent(priority = EventPriority.HIGH) - fun onVisitorTooltip(event: VisitorToolTipEvent) { - if (event.itemStack.name != "§aAccept Offer") return + fun onTooltip(visitor: VisitorAPI.Visitor, itemStack: ItemStack, toolTip: MutableList<String>) { + if (itemStack.name != "§aAccept Offer") return - val visitor = event.visitor - val toolTip = event.toolTip toolTip.clear() if (visitor.lastLore.isEmpty()) { - readToolTip(visitor, event.itemStack) + readToolTip(visitor, itemStack) } toolTip.addAll(visitor.lastLore) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt index 18bdcb49e..dab1d40e7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt @@ -26,7 +26,7 @@ object VisitorAPI { private val logger = LorenzLogger("garden/visitors/api") val patternGroup = RepoPattern.group("garden.visitor.api") - private val visitorCountPattern by patternGroup.pattern( + val visitorCountPattern by patternGroup.pattern( "visitor.count", "§b§lVisitors: §r§f\\((?<info>.*)\\)" ) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt index 653290395..8693053ab 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt @@ -12,11 +12,11 @@ import at.hannibal2.skyhanni.events.ProfileJoinEvent import at.hannibal2.skyhanni.events.TabListUpdateEvent import at.hannibal2.skyhanni.events.garden.visitor.VisitorOpenEvent import at.hannibal2.skyhanni.events.garden.visitor.VisitorRenderEvent -import at.hannibal2.skyhanni.events.garden.visitor.VisitorToolTipEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI.VisitorStatus import at.hannibal2.skyhanni.mixins.transformers.gui.AccessorGuiContainer import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.DelayedRun import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld @@ -24,6 +24,7 @@ import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.exactLocation +import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiContainer @@ -43,7 +44,6 @@ class VisitorListener { private val logger = LorenzLogger("garden/visitors/listener") companion object { - private val VISITOR_INFO_ITEM_SLOT = 13 private val VISITOR_ACCEPT_ITEM_SLOT = 29 private val VISITOR_REFUSE_ITEM_SLOT = 33 @@ -70,8 +70,11 @@ class VisitorListener { @SubscribeEvent fun onTabListUpdate(event: TabListUpdateEvent) { if (!GardenAPI.inGarden()) return - val visitorsInTab = VisitorAPI.visitorsInTabList(event.tabList) + val hasVisitorInfo = event.tabList.any { VisitorAPI.visitorCountPattern.matches(it) } + if (!hasVisitorInfo) return + + val visitorsInTab = VisitorAPI.visitorsInTabList(event.tabList) if (LorenzUtils.lastWorldSwitch.passedSince() > 2.seconds) { VisitorAPI.getVisitors().forEach { val name = it.visitorName @@ -160,6 +163,10 @@ class VisitorListener { } VisitorAPI.changeStatus(visitor, VisitorStatus.REFUSED, "refused") + // fallback if tab list is disabled + DelayedRun.runDelayed(10.seconds) { + VisitorAPI.removeVisitor(visitor.visitorName) + } return } if (event.slotId == VISITOR_ACCEPT_ITEM_SLOT && event.slot?.stack?.getLore() @@ -175,7 +182,7 @@ class VisitorListener { if (!GardenAPI.onBarnPlot) return if (!VisitorAPI.inInventory) return val visitor = VisitorAPI.getVisitor(lastClickedNpc) ?: return - VisitorToolTipEvent(visitor, event.itemStack, event.toolTip).postAndCatch() + GardenVisitorFeatures.onTooltip(visitor, event.itemStack, event.toolTip) } @SubscribeEvent |