diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-27 23:37:42 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-27 23:37:42 +0100 |
commit | c24d972d76156c93b5b373a062d12b06faa8ab15 (patch) | |
tree | 36715f3d53e24c81e6aba6b561f70e2fa5cb5ba0 /src/main/java/at/hannibal2 | |
parent | 0bc653bf143ba9e0f8e645d8a23a4801d814fc55 (diff) | |
download | skyhanni-c24d972d76156c93b5b373a062d12b06faa8ab15.tar.gz skyhanni-c24d972d76156c93b5b373a062d12b06faa8ab15.tar.bz2 skyhanni-c24d972d76156c93b5b373a062d12b06faa8ab15.zip |
Fixed pest kill detection. Show configure plot hint only if data is incorrect.
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt | 8 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt | 66 |
2 files changed, 46 insertions, 28 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt index e66a468ae..ef3cc86e7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt @@ -2,8 +2,7 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.LocationUtils -import at.hannibal2.skyhanni.utils.LocationUtils.isInside +import at.hannibal2.skyhanni.utils.LocationUtils.isPlayerInside import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher @@ -18,8 +17,7 @@ object GardenPlotAPI { var plots = listOf<Plot>() fun getCurrentPlot(): Plot? { - val location = LocationUtils.playerLocation() - return plots.firstOrNull { it.box.isInside(location) } + return plots.firstOrNull { it.isPlayerInside() } } class Plot(val id: Int, var inventorySlot: Int, val box: AxisAlignedBB, val middle: LorenzVec) @@ -51,6 +49,8 @@ object GardenPlotAPI { fun Plot.isBarn() = id == -1 + fun Plot.isPlayerInside() = box.isPlayerInside() + fun Plot.sendTeleportTo() { LorenzUtils.sendCommandToServer("tptoplot $name") } 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 21bf9bcdd..3627e8db6 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 @@ -1,20 +1,21 @@ package at.hannibal2.skyhanni.features.garden.pests -import at.hannibal2.skyhanni.events.DamageIndicatorDeathEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.IslandChangeEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent +import at.hannibal2.skyhanni.events.ScoreboardChangeEvent import at.hannibal2.skyhanni.events.garden.pests.PestSpawnEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.features.garden.GardenPlotAPI +import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.isPlayerInside import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.name import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.pests import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.sendTeleportTo import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer +import at.hannibal2.skyhanni.utils.LocationUtils import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber @@ -31,7 +32,10 @@ class PestFinder { private val config get() = PestAPI.config.pestFinder + private val pestsInScoreboardPattern = " §7⏣ §aThe Garden §4§lൠ§7 x(?<pests>.*)".toPattern() + private var display = emptyList<Renderable>() + private var scoreboardPests = 0 @SubscribeEvent fun onPestSpawn(event: PestSpawnEvent) { @@ -71,20 +75,17 @@ class PestFinder { } private fun drawDisplay() = buildList { - val totalAmount = totalAmount() - if (totalAmount == 0) { - add(Renderable.string("§cNo pests detected.")) - add(Renderable.string("§7Open §eConfigure Plots Menu")) - add(Renderable.string("§7when incorrect to reload.")) + val totalAmount = getPlotsWithPests().sumOf { it.pests } + if (totalAmount != scoreboardPests) { + add(Renderable.string("§cIncorrect pest amount!")) + add(Renderable.string("§eOpen Configure Plots Menu!")) return@buildList } - add(Renderable.string("§eTotal pests in garden: §c${totalAmount()}§7/§c8")) + add(Renderable.string("§eTotal pests in garden: §c${totalAmount}§7/§c8")) - for (plot in GardenPlotAPI.plots) { + for (plot in getPlotsWithPests()) { val pests = plot.pests - if (pests == 0) continue - val plotName = plot.name val pestsName = StringUtils.optionalPlural(pests, "pest", "pests") val renderable = Renderable.clickAndHover( @@ -120,23 +121,38 @@ class PestFinder { } @SubscribeEvent - fun onDamageIndicatorDeath(event: DamageIndicatorDeathEvent) { + fun onScoreboardChange(event: ScoreboardChangeEvent) { if (!isEnabled()) return - // Check if an unknown damage indiactor mob dies in the garden - val type = event.data.bossType - if (!PestType.entries.any { it.damageIndicatorBoss == type }) return - - val plot = GardenPlotAPI.getCurrentPlot()?.takeIf { it.pests > 0 } ?: run { - LorenzUtils.userError("Could not detect the plot of the killed pest. Please Open the Configure Plots menu again.") - return + var newPests = 0 + for (line in event.newList) { + pestsInScoreboardPattern.matchMatcher(line) { + newPests = group("pests").formatNumber().toInt() + } } - plot.pests-- + if (newPests == scoreboardPests) return + + removePests(scoreboardPests - newPests) + scoreboardPests = newPests update() } - private fun totalAmount() = GardenPlotAPI.plots.sumOf { it.pests } + private fun removePests(removedPests: Int) { + if (removedPests < 1) return + repeat(removedPests) { + removeNearestPest() + } + } + + private fun removeNearestPest() { + val location = LocationUtils.playerLocation() + val plot = getPlotsWithPests().minByOrNull { it.middle.distanceSq(location) } ?: run { + LorenzUtils.error("Can not remove nearest pest: No plots with pests detected.") + return + } + plot.pests-- + } @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent) { @@ -149,6 +165,8 @@ class PestFinder { } } + private fun getPlotsWithPests() = GardenPlotAPI.plots.filter { it.pests > 0 } + @SubscribeEvent fun onRenderWorld(event: LorenzRenderWorldEvent) { if (!isEnabled()) return @@ -156,13 +174,13 @@ class PestFinder { if (config.onlyWithVacuum && !PestAPI.hasVacuumInHand()) return val playerLocation = event.exactPlayerEyeLocation() - GardenPlotAPI.plots.filter { it.pests > 0 }.forEach { plot -> + for (plot in getPlotsWithPests()) { + if (plot.isPlayerInside()) continue val pestsName = StringUtils.optionalPlural(plot.pests, "pest", "pests") val plotName = plot.name val middle = plot.middle val location = playerLocation.copy(x = middle.x, z = middle.z) - if (location.distanceToPlayer() < 15) return@forEach - event.drawWaypointFilled(location, LorenzColor.WHITE.toColor()) + event.drawWaypointFilled(location, LorenzColor.RED.toColor()) event.drawDynamicText(location, "§c$pestsName §7in §b$plotName", 1.5) } } |