From 2c81a84841e88e89cac35c86222023c4f24453a4 Mon Sep 17 00:00:00 2001 From: appable Date: Wed, 26 Apr 2023 13:56:43 -0700 Subject: add sixth visitor to display (#60) --- .../garden/visitor/GardenVisitorFeatures.kt | 5 ++++- .../features/garden/visitor/GardenVisitorTimer.kt | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features') 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 4025fa9a0..26799eedf 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 @@ -416,7 +416,10 @@ class GardenVisitorFeatures { } private fun addVisitor(name: String) { - visitors[name] = Visitor(name, status = VisitorStatus.NEW) + val visitor = Visitor(name, status = VisitorStatus.NEW) + visitors[name] = visitor + VisitorArrivalEvent(visitor).postAndCatch() + logger.log("New visitor detected: '$name'") if (config.visitorNotificationTitle) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt index 8e2ba8f9f..3e5ffa6bb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt @@ -4,12 +4,12 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.BlockClickEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.TabListUpdateEvent +import at.hannibal2.skyhanni.events.VisitorArrivalEvent import at.hannibal2.skyhanni.features.garden.CropType.Companion.getCropType import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.RenderUtils.renderString import at.hannibal2.skyhanni.utils.TimeUtils import net.minecraftforge.event.world.WorldEvent -import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.math.roundToLong @@ -20,11 +20,17 @@ class GardenVisitorTimer { private var lastMillis = 0L private var lastVisitors: Int = -1 private var sixthVisitorArrivalTime: Long = 0 + private var visitorJustArrived: Boolean = false private var visitorInterval get() = SkyHanniMod.feature.hidden.visitorInterval set(value) { SkyHanniMod.feature.hidden.visitorInterval = value } - @SubscribeEvent(priority = EventPriority.LOW) + @SubscribeEvent + fun onVisitorArrival(event: VisitorArrivalEvent) { + visitorJustArrived = true + } + + @SubscribeEvent fun onTabListUpdate(event: TabListUpdateEvent) { if (!isEnabled()) return @@ -53,12 +59,19 @@ class GardenVisitorTimer { if (!queueFull) { visitorInterval = ((millis - 1) / 60_000L + 1) * 60_000L } else { - sixthVisitorArrivalTime = System.currentTimeMillis() + visitorInterval + updateSixthVisitorArrivalTime() } } if (queueFull) { + if (sixthVisitorArrivalTime != 0L && visitorJustArrived) { + updateSixthVisitorArrivalTime() + visitorJustArrived = false + } millis = sixthVisitorArrivalTime - System.currentTimeMillis() + if (isSixthVisitorEnabled() && sixthVisitorArrivalTime != 0L && millis < 0) { + visitorsAmount++ + } } val diff = lastMillis - millis @@ -100,6 +113,9 @@ class GardenVisitorTimer { sixthVisitorArrivalTime -= 100 } + private fun updateSixthVisitorArrivalTime() { + sixthVisitorArrivalTime = System.currentTimeMillis() + visitorInterval + } private fun isSixthVisitorEnabled() = SkyHanniMod.feature.garden.visitorTimerSixthVisitorEnabled private fun isEnabled() = GardenAPI.inGarden() && SkyHanniMod.feature.garden.visitorTimerEnabled } \ No newline at end of file -- cgit