From da07d19354c53a0145bc3495b041419d8c2ab3fd Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 25 May 2023 13:42:03 +0200 Subject: Added Contest Summary --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 6 +-- .../hannibal2/skyhanni/config/features/Garden.java | 8 +++ .../skyhanni/events/FarmingContestEvent.kt | 6 +++ .../features/garden/contest/FarmingContestAPI.kt | 57 ++++++++++++++++++++ .../features/garden/contest/FarmingContestPhase.kt | 7 +++ .../garden/contest/JacobContestStatsSummary.kt | 60 ++++++++++++++++++++++ .../features/garden/farming/GardenCropSpeed.kt | 1 - 7 files changed, 140 insertions(+), 5 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/events/FarmingContestEvent.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestPhase.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestStatsSummary.kt (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 9c3ccb021..d2fb44a30 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -26,10 +26,7 @@ import at.hannibal2.skyhanni.features.garden.composter.ComposterDisplay import at.hannibal2.skyhanni.features.garden.composter.ComposterInventoryNumbers import at.hannibal2.skyhanni.features.garden.composter.ComposterOverlay import at.hannibal2.skyhanni.features.garden.composter.GardenComposterInventoryFeatures -import at.hannibal2.skyhanni.features.garden.contest.FarmingContestAPI -import at.hannibal2.skyhanni.features.garden.contest.JacobContestFFNeededDisplay -import at.hannibal2.skyhanni.features.garden.contest.JacobContestTimeNeeded -import at.hannibal2.skyhanni.features.garden.contest.JacobFarmingContestsInventory +import at.hannibal2.skyhanni.features.garden.contest.* import at.hannibal2.skyhanni.features.garden.farming.* import at.hannibal2.skyhanni.features.garden.inventory.* import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorColorNames @@ -269,6 +266,7 @@ class SkyHanniMod { loadModule(WildStrawberryDyeNotification()) loadModule(JacobContestFFNeededDisplay()) loadModule(JacobContestTimeNeeded()) + loadModule(JacobContestStatsSummary()) loadModule(GardenYawAndPitch()) loadModule(MovementSpeedDisplay()) loadModule(ChumBucketHider()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java index b20b04e96..d4c3a5859 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java @@ -1183,6 +1183,14 @@ public class Garden { @Expose public Position jacobContextTimesPos = new Position(-359, 149, false, true); + @Expose + @ConfigOption( + name = "Contest Summary", + desc = "Show the average Blocks Per Second and blocks clicked at the end of a Jacob Farming Contest in chat." + ) + @ConfigEditorBoolean + public boolean jacobContestSummary = true; + @Expose @ConfigOption(name = "Always Finnegan", desc = "Forcefully set the Finnegan Farming Simulator perk to be active. This is useful if the auto mayor detection fails.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/events/FarmingContestEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/FarmingContestEvent.kt new file mode 100644 index 000000000..194bcc5bf --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/FarmingContestEvent.kt @@ -0,0 +1,6 @@ +package at.hannibal2.skyhanni.events + +import at.hannibal2.skyhanni.features.garden.CropType +import at.hannibal2.skyhanni.features.garden.contest.FarmingContestPhase + +class FarmingContestEvent(val crop: CropType, val phase: FarmingContestPhase): LorenzEvent() \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt index a9f05f615..6e279e7d2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt @@ -1,9 +1,12 @@ package at.hannibal2.skyhanni.features.garden.contest +import at.hannibal2.skyhanni.data.ScoreboardData +import at.hannibal2.skyhanni.events.FarmingContestEvent import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryOpenEvent import at.hannibal2.skyhanni.features.garden.CropType +import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc @@ -11,14 +14,68 @@ import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import io.github.moulberry.notenoughupdates.util.SkyBlockTime import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent object FarmingContestAPI { private val timePattern = "§a(?.*) (?.*)(?:rd|st|nd|th), Year (?.*)".toPattern() private val contests = mutableMapOf() private val cropPattern = "§8(?.*) Contest".toPattern() + private var tick = 0 + var inContest = false + var contestCrop: CropType? = null + private val sidebarCropPattern = "§e○ §f(?.*) §a.*".toPattern() var inInventory = false + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (event.phase != TickEvent.Phase.START) return + tick++ + + if (tick % 20 == 0) { + if (!LorenzUtils.inSkyBlock) return + if (!GardenAPI.inGarden()) return + + checkActiveContest() + } + } + + private fun checkActiveContest() { + val currentCrop = readCurrentCrop() + val currentContest = currentCrop != null + + if (inContest != currentContest) { + if (currentContest) { + FarmingContestEvent(currentCrop!!, FarmingContestPhase.START).postAndCatch() + } else { + FarmingContestEvent(contestCrop!!, FarmingContestPhase.STOP).postAndCatch() + } + inContest = currentContest + } else { + if (currentCrop != contestCrop) { + FarmingContestEvent(currentCrop!!, FarmingContestPhase.CHANGE).postAndCatch() + } + } + contestCrop = currentCrop + } + + private fun readCurrentCrop(): CropType? { + var next = false + for (line in ScoreboardData.sidebarLinesFormatted) { + if (line == "§eJacob's Contest") { + next = true + continue + } + if (next) { + sidebarCropPattern.matchMatcher(line) { + return CropType.getByName(group("crop")) + } + } + } + + return null + } + @SubscribeEvent fun onInventoryOpen(event: InventoryOpenEvent) { if (event.inventoryName == "Your Contests") { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestPhase.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestPhase.kt new file mode 100644 index 000000000..5d280a960 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestPhase.kt @@ -0,0 +1,7 @@ +package at.hannibal2.skyhanni.features.garden.contest + +enum class FarmingContestPhase { + START, + STOP, + CHANGE +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestStatsSummary.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestStatsSummary.kt new file mode 100644 index 000000000..ecd8f5f72 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestStatsSummary.kt @@ -0,0 +1,60 @@ +package at.hannibal2.skyhanni.features.garden.contest + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.ClickType +import at.hannibal2.skyhanni.events.CropClickEvent +import at.hannibal2.skyhanni.events.FarmingContestEvent +import at.hannibal2.skyhanni.features.garden.GardenAPI +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.round +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.TimeUtils +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class JacobContestStatsSummary { + private val config get() = SkyHanniMod.feature.garden + private var blocksBroken = 0 + private var startTime = 0L + + @SubscribeEvent + fun onBlockClick(event: CropClickEvent) { + if (!isEnabled()) return + if (event.clickType != ClickType.LEFT_CLICK) return + + if (FarmingContestAPI.inContest) { + if (event.crop == FarmingContestAPI.contestCrop) { + blocksBroken++ + } + } + } + + @SubscribeEvent + fun onFarmingContestEvent(event: FarmingContestEvent) { + if (!isEnabled()) return + + when (event.phase) { + FarmingContestPhase.START -> { + LorenzUtils.chat("§e[SkyHanni] Started tracking your Jacob Contest Blocks Per Second!") + startTime = System.currentTimeMillis() + } + FarmingContestPhase.STOP -> { + val duration = System.currentTimeMillis() - startTime + val durationInSeconds = duration / 1000 + val blocksPerSecond = (blocksBroken.toDouble() / durationInSeconds).round(2) + val cropName = event.crop.cropName + LorenzUtils.chat("§e[SkyHanni] Stats for $cropName Contest:") + val time = TimeUtils.formatDuration(duration) + LorenzUtils.chat("§e[SkyHanni] §7Blocks Broken in total: §e${blocksBroken.addSeparators()}") + LorenzUtils.chat("§e[SkyHanni] §7Average Blocks Per Second: §c$blocksPerSecond") + LorenzUtils.chat("§e[SkyHanni] §7Participated for §b$time") + } + FarmingContestPhase.CHANGE -> { + LorenzUtils.chat("§e[SkyHanni] You changed the crop during the contest, resetting the Blocks Per Second calculation..") + startTime = System.currentTimeMillis() + } + } + blocksBroken = 0 + } + + fun isEnabled() = GardenAPI.inGarden() && config.jacobContestSummary +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt index 7903c2199..f33a03504 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt @@ -59,7 +59,6 @@ object GardenCropSpeed { @SubscribeEvent fun onBlockClick(event: CropClickEvent) { - if (!GardenAPI.inGarden()) return if (event.clickType != ClickType.LEFT_CLICK) return lastBrokenCrop = event.crop -- cgit