diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-05-25 13:42:03 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-05-25 13:42:03 +0200 |
commit | da07d19354c53a0145bc3495b041419d8c2ab3fd (patch) | |
tree | ee8d4fef514d1bb1542da98b774bd7735c3bca4c /src/main/java/at/hannibal2 | |
parent | c03cdfcbd136e3eceb2128c5c4d8293e39476ed4 (diff) | |
download | skyhanni-da07d19354c53a0145bc3495b041419d8c2ab3fd.tar.gz skyhanni-da07d19354c53a0145bc3495b041419d8c2ab3fd.tar.bz2 skyhanni-da07d19354c53a0145bc3495b041419d8c2ab3fd.zip |
Added Contest Summary
Diffstat (limited to 'src/main/java/at/hannibal2')
7 files changed, 140 insertions, 5 deletions
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 @@ -1184,6 +1184,14 @@ public class Garden { 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 public boolean forcefullyEnabledAlwaysFinnegan = false; 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,15 +14,69 @@ 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(?<month>.*) (?<day>.*)(?:rd|st|nd|th), Year (?<year>.*)".toPattern() private val contests = mutableMapOf<Long, FarmingContest>() private val cropPattern = "§8(?<crop>.*) Contest".toPattern() + private var tick = 0 + var inContest = false + var contestCrop: CropType? = null + private val sidebarCropPattern = "§e○ §f(?<crop>.*) §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") { inInventory = true 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 |