diff options
author | Empa <42304516+ItsEmpa@users.noreply.github.com> | 2024-04-05 18:41:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-05 18:41:51 +0200 |
commit | 31fa031485a3cb59d8a57081cad25c7650df9f14 (patch) | |
tree | 6b16f90d9abad6d4e81a612a616c59c82bfcb9da /src/main/java/at/hannibal2/skyhanni/features/garden | |
parent | 6f76c464825de167b2c475c6a635c29db694924e (diff) | |
download | skyhanni-31fa031485a3cb59d8a57081cad25c7650df9f14.tar.gz skyhanni-31fa031485a3cb59d8a57081cad25c7650df9f14.tar.bz2 skyhanni-31fa031485a3cb59d8a57081cad25c7650df9f14.zip |
Fix: Impossible Pest Counts (#1362)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt index f4df7f94e..1af4e43b8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.features.garden.pests +import at.hannibal2.skyhanni.events.DebugDataCollectEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent @@ -12,8 +13,10 @@ import at.hannibal2.skyhanni.features.garden.GardenPlotAPI import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.isBarn import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.isPestCountInaccurate import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.locked +import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.name import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.pests import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.uncleared +import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore @@ -27,6 +30,7 @@ import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.input.Keyboard object PestAPI { @@ -104,7 +108,7 @@ object PestAPI { "§cThere are not any Pests on your Garden right now! Keep farming!" ) - private fun fixPests() { + private fun fixPests(loop: Int = 2) { val accurateAmount = getPlotsWithAccuratePests().sumOf { it.pests } val inaccurateAmount = getPlotsWithInaccuratePests().size if (scoreboardPests == accurateAmount + inaccurateAmount) { // if we can assume all inaccurate plots have 1 pest each @@ -116,6 +120,14 @@ object PestAPI { val plot = getPlotsWithInaccuratePests().firstOrNull() plot?.pests = scoreboardPests - accurateAmount plot?.isPestCountInaccurate = false + } else if (accurateAmount + inaccurateAmount > scoreboardPests) { + sendPestError(true) + getInfestedPlots().forEach { + it.pests = 0 + it.isPestCountInaccurate = true + } + if (loop > 0) fixPests(loop - 1) + else sendPestError(false) } } @@ -276,6 +288,7 @@ object PestAPI { return } if (!plot.isPestCountInaccurate) plot.pests-- + scoreboardPests-- updatePests() } @@ -287,4 +300,42 @@ object PestAPI { } updatePests() } + + private fun sendPestError(betaOnly: Boolean) { + ErrorManager.logErrorStateWithData( + "Error getting pest count", + "Impossible pest count", + "scoreboardPests" to scoreboardPests, + "plots" to getInfestedPlots().map { "id: ${it.id} pests: ${it.pests} isInaccurate: ${it.isPestCountInaccurate}" }, + noStackTrace = true, betaOnly = betaOnly + ) + } + + @SubscribeEvent + fun onDebugDataCollect(event: DebugDataCollectEvent) { + event.title("Garden Pests") + + if (!GardenAPI.inGarden()) { + event.addIrrelevant("not in garden") + return + } + if (!config.pestFinder.showDisplay && !config.pestFinder.showPlotInWorld && + config.pestFinder.teleportHotkey == Keyboard.KEY_NONE + ) { + event.addIrrelevant("disabled in config") + return + } + + event.addIrrelevant { + add("scoreboardPests is $scoreboardPests") + add("") + getInfestedPlots().forEach { + add("id: ${it.id}") + add("name: ${it.name}") + add("isPestCountInaccurate: ${it.isPestCountInaccurate}") + add("pests: ${it.pests}") + add("") + } + } + } } |