diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-12-09 21:36:42 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-12-09 21:36:42 +0100 |
commit | 5dd949398d70bc38fc90829ced65bd538cffddf2 (patch) | |
tree | 66ab6f47eaf6aa8c81a7c70a4b034cfbf6be2623 /src/main/java/at/hannibal2/skyhanni | |
parent | 1055c493987469ca143cb6890c6455f45cdf9ac0 (diff) | |
download | skyhanni-5dd949398d70bc38fc90829ced65bd538cffddf2.tar.gz skyhanni-5dd949398d70bc38fc90829ced65bd538cffddf2.tar.bz2 skyhanni-5dd949398d70bc38fc90829ced65bd538cffddf2.zip |
Using scoreboardPests value in API class.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
3 files changed, 27 insertions, 32 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt index edd91e8c8..d40d02718 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt @@ -6,7 +6,6 @@ import at.hannibal2.skyhanni.data.CropAccessoryData import at.hannibal2.skyhanni.data.GardenCropMilestones import at.hannibal2.skyhanni.data.GardenCropMilestones.getCounter import at.hannibal2.skyhanni.data.GardenCropUpgrades.Companion.getUpgradeLevel -import at.hannibal2.skyhanni.data.ScoreboardData import at.hannibal2.skyhanni.events.GardenToolChangeEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzTickEvent @@ -14,7 +13,7 @@ import at.hannibal2.skyhanni.events.PreProfileSwitchEvent import at.hannibal2.skyhanni.events.TabListUpdateEvent import at.hannibal2.skyhanni.features.garden.CropType.Companion.getTurboCrop import at.hannibal2.skyhanni.features.garden.GardenAPI.addCropIcon -import at.hannibal2.skyhanni.features.garden.pests.PestFinder +import at.hannibal2.skyhanni.features.garden.pests.PestAPI import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils @@ -38,7 +37,8 @@ import kotlin.time.Duration.Companion.seconds class FarmingFortuneDisplay { private val tabFortuneUniversalPattern = " Farming Fortune: §r§6☘(?<fortune>\\d+)".toPattern() - private val tabFortuneCropPattern = " (?<crop>Wheat|Carrot|Potato|Pumpkin|Sugar Cane|Melon|Cactus|Cocoa Beans|Mushroom|Nether Wart) Fortune: §r§6☘(?<fortune>\\d+)".toPattern() + private val tabFortuneCropPattern = + " (?<crop>Wheat|Carrot|Potato|Pumpkin|Sugar Cane|Melon|Cactus|Cocoa Beans|Mushroom|Nether Wart) Fortune: §r§6☘(?<fortune>\\d+)".toPattern() private var display = emptyList<List<Any>>() private var accessoryProgressDisplay = "" @@ -124,15 +124,9 @@ class FarmingFortuneDisplay { } }) - for (line in ScoreboardData.sidebarLinesFormatted) { - PestFinder.pestsInScoreboardPattern.matchMatcher(line) { - val pests = group("pests").toInt() - val ffReduction = getPestFFReduction(pests) - if (ffReduction > 0) { - updatedDisplay.addAsSingletonList("§cPests are reducing your fortune by §e$ffReduction%§c!") - } - break - } + val ffReduction = getPestFFReduction() + if (ffReduction > 0) { + updatedDisplay.addAsSingletonList("§cPests are reducing your fortune by §e$ffReduction%§c!") } if (wrongTabCrop) { @@ -160,15 +154,13 @@ class FarmingFortuneDisplay { private fun isEnabled(): Boolean = GardenAPI.inGarden() && config.display - private fun getPestFFReduction(pests: Int): Int { - return when (pests) { - in 0..3 -> 0 - 4 -> 5 - 5 -> 15 - 6 -> 30 - 7 -> 50 - else -> 75 - } + private fun getPestFFReduction(): Int = when (PestAPI.scoreboardPests) { + in 0..3 -> 0 + 4 -> 5 + 5 -> 15 + 6 -> 30 + 7 -> 50 + else -> 75 } companion object { 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 5609b61b8..f886648d0 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 @@ -7,6 +7,8 @@ import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName object PestAPI { val config get() = GardenAPI.config.pests + var scoreboardPests = 0 + val vacuumVariants = listOf( "SKYMART_VACUUM".asInternalName(), "SKYMART_TURBO_VACUUM".asInternalName(), diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt index e1b0e2055..1206a70a2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt @@ -38,8 +38,10 @@ class PestFinder { private val config get() = PestAPI.config.pestFinder + // TODO repo pattern + private val pestsInScoreboardPattern = " §7⏣ §[ac]The Garden §4§lൠ§7 x(?<pests>.*)".toPattern() + private var display = emptyList<Renderable>() - private var scoreboardPests = 0 private var lastTimeVacuumHold = SimpleTimeMark.farPast() @SubscribeEvent @@ -76,12 +78,14 @@ class PestFinder { } private fun update() { - display = drawDisplay() + if (isEnabled()) { + display = drawDisplay() + } } private fun drawDisplay() = buildList { val totalAmount = getPlotsWithPests().sumOf { it.pests } - if (totalAmount != scoreboardPests) { + if (totalAmount != PestAPI.scoreboardPests) { add(Renderable.string("§cIncorrect pest amount!")) add(Renderable.string("§eOpen Configure Plots Menu!")) return@buildList @@ -127,7 +131,7 @@ class PestFinder { @SubscribeEvent fun onScoreboardChange(event: ScoreboardChangeEvent) { - if (!isEnabled()) return + if (!GardenAPI.inGarden()) return var newPests = 0 for (line in event.newList) { @@ -136,14 +140,15 @@ class PestFinder { } } - if (newPests == scoreboardPests) return + if (newPests == PestAPI.scoreboardPests) return - removePests(scoreboardPests - newPests) - scoreboardPests = newPests + removePests(PestAPI.scoreboardPests - newPests) + PestAPI.scoreboardPests = newPests update() } private fun removePests(removedPests: Int) { + if (!isEnabled()) return if (removedPests < 1) return repeat(removedPests) { removeNearestPest() @@ -231,8 +236,4 @@ class PestFinder { } fun isEnabled() = GardenAPI.inGarden() && (config.showDisplay || config.showPlotInWorld) - - companion object { - val pestsInScoreboardPattern = " §7⏣ §[ac]The Garden §4§lൠ§7 x(?<pests>.*)".toPattern() - } } |