diff options
author | appable <enzospiacitelli@gmail.com> | 2023-04-26 13:56:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-26 22:56:43 +0200 |
commit | 2c81a84841e88e89cac35c86222023c4f24453a4 (patch) | |
tree | bb3edcfd9a2d4e233891363cbd22f638241262ef /src | |
parent | b7b1f37f93e1df412b3a4603c184a1856a72b8f9 (diff) | |
download | skyhanni-2c81a84841e88e89cac35c86222023c4f24453a4.tar.gz skyhanni-2c81a84841e88e89cac35c86222023c4f24453a4.tar.bz2 skyhanni-2c81a84841e88e89cac35c86222023c4f24453a4.zip |
add sixth visitor to display (#60)
Diffstat (limited to 'src')
3 files changed, 28 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/events/VisitorArrivalEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/VisitorArrivalEvent.kt new file mode 100644 index 000000000..6e92d85cf --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/VisitorArrivalEvent.kt @@ -0,0 +1,5 @@ +package at.hannibal2.skyhanni.events + +import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorFeatures.Visitor + +class VisitorArrivalEvent(val visitor: Visitor): LorenzEvent()
\ No newline at end of file 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 |