diff options
Diffstat (limited to 'src/main/java')
4 files changed, 26 insertions, 13 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 36196d912..a2e800678 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -908,7 +908,7 @@ class SkyHanniMod { loadModule(RepoPatternManager) loadModule(PestSpawn()) loadModule(PestSpawnTimer) - loadModule(PestFinder()) + loadModule(PestFinder) loadModule(PestParticleWaypoint()) loadModule(StereoHarmonyDisplay()) loadModule(PestParticleLine()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index b8fa95d85..184549a34 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -45,6 +45,7 @@ import at.hannibal2.skyhanni.features.garden.farming.GardenStartLocation import at.hannibal2.skyhanni.features.garden.farming.lane.FarmingLaneCreator import at.hannibal2.skyhanni.features.garden.fortuneguide.CaptureFarmingGear import at.hannibal2.skyhanni.features.garden.fortuneguide.FFGuideGUI +import at.hannibal2.skyhanni.features.garden.pests.PestFinder import at.hannibal2.skyhanni.features.garden.pests.PestProfitTracker import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorDropStatistics import at.hannibal2.skyhanni.features.mining.KingTalismanHelper @@ -325,6 +326,10 @@ object Commands { "shignore", "Add/Remove a user from your" ) { PartyChatCommands.blacklist(it) } + registerCommand( + "shtpinfested", + "Teleports you to the nearest infested plot" + ) { PestFinder.teleportNearestInfestedPlot() } } private fun usersBugFix() { 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 1d1c4e0b6..70ff404b5 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 @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.garden.pests import at.hannibal2.skyhanni.data.ScoreboardData import at.hannibal2.skyhanni.events.DebugDataCollectEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent +import at.hannibal2.skyhanni.events.ItemInHandChangeEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent @@ -48,6 +49,7 @@ object PestAPI { } var lastPestKillTime = SimpleTimeMark.farPast() + var lastTimeVacuumHold = SimpleTimeMark.farPast() val vacuumVariants = listOf( "SKYMART_VACUUM".asInternalName(), @@ -245,10 +247,18 @@ object PestAPI { @SubscribeEvent fun onWorldChange(event: LorenzWorldChangeEvent) { lastPestKillTime = SimpleTimeMark.farPast() + lastTimeVacuumHold = SimpleTimeMark.farPast() gardenJoinTime = SimpleTimeMark.now() firstScoreboardCheck = false } + @SubscribeEvent + fun onItemInHandChange(event: ItemInHandChangeEvent) { + if (!GardenAPI.inGarden()) return + if (event.oldItem !in vacuumVariants) return + lastTimeVacuumHold = SimpleTimeMark.now() + } + private fun getPlotsWithAccuratePests() = GardenPlotAPI.plots.filter { it.pests > 0 && !it.isPestCountInaccurate } private fun getPlotsWithInaccuratePests() = GardenPlotAPI.plots.filter { it.pests == 0 && it.isPestCountInaccurate } 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 289994862..1ac97f080 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 @@ -3,7 +3,6 @@ package at.hannibal2.skyhanni.features.garden.pests import at.hannibal2.skyhanni.config.features.garden.pests.PestFinderConfig.VisibilityType import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.IslandChangeEvent -import at.hannibal2.skyhanni.events.ItemInHandChangeEvent import at.hannibal2.skyhanni.events.LorenzKeyPressEvent import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent import at.hannibal2.skyhanni.events.garden.pests.PestUpdateEvent @@ -31,12 +30,11 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.seconds -class PestFinder { +object PestFinder { private val config get() = PestAPI.config.pestFinder private var display = emptyList<Renderable>() - private var lastTimeVacuumHold = SimpleTimeMark.farPast() @SubscribeEvent fun onPestUpdate(event: PestUpdateEvent) { @@ -111,7 +109,7 @@ class PestFinder { fun onRenderWorld(event: LorenzRenderWorldEvent) { if (!isEnabled()) return if (!config.showPlotInWorld) return - if (config.onlyWithVacuum && !PestAPI.hasVacuumInHand() && (lastTimeVacuumHold.passedSince() > config.showBorderForSeconds.seconds)) return + if (config.onlyWithVacuum && !PestAPI.hasVacuumInHand() && (PestAPI.lastTimeVacuumHold.passedSince() > config.showBorderForSeconds.seconds)) return val playerLocation = event.exactPlayerEyeLocation() val visibility = config.visibilityType @@ -165,6 +163,14 @@ class PestFinder { if (lastKeyPress.passedSince() < 2.seconds) return lastKeyPress = SimpleTimeMark.now() + teleportNearestInfestedPlot() + } + + fun teleportNearestInfestedPlot() { + // need to check again for the command + if (!GardenAPI.inGarden()) { + ChatUtils.userError("This command only works while on the Garden!") + } val plot = PestAPI.getNearestInfestedPlot() ?: run { ChatUtils.userError("No infested plots detected to warp to!") return @@ -178,13 +184,5 @@ class PestFinder { plot.sendTeleportTo() } - @SubscribeEvent - fun onItemInHandChange(event: ItemInHandChangeEvent) { - if (!isEnabled()) return - if (!config.showPlotInWorld) return - if (event.oldItem !in PestAPI.vacuumVariants) return - lastTimeVacuumHold = SimpleTimeMark.now() - } - fun isEnabled() = GardenAPI.inGarden() && (config.showDisplay || config.showPlotInWorld) } |