From 7eb5d745e346f116b27ddf0125ed846a72f2ee1a Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Tue, 28 Nov 2023 00:30:40 +0100 Subject: Press key to warp to the nearest plot with pests on it. --- .../features/garden/pests/PestFinderConfig.java | 7 ++++ .../features/garden/pests/PestSpawnConfig.java | 7 ---- .../skyhanni/features/garden/GardenPlotAPI.kt | 2 ++ .../skyhanni/features/garden/pests/PestFinder.kt | 38 +++++++++++++++++++--- .../skyhanni/features/garden/pests/PestSpawn.kt | 22 ------------- 5 files changed, 43 insertions(+), 33 deletions(-) (limited to 'src/main/java/at/hannibal2') diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestFinderConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestFinderConfig.java index e527a5933..e92df8750 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestFinderConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestFinderConfig.java @@ -4,7 +4,9 @@ import at.hannibal2.skyhanni.config.FeatureToggle; import at.hannibal2.skyhanni.config.core.config.Position; import com.google.gson.annotations.Expose; import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; +import io.github.moulberry.moulconfig.annotations.ConfigEditorKeybind; import io.github.moulberry.moulconfig.annotations.ConfigOption; +import org.lwjgl.input.Keyboard; public class PestFinderConfig { @@ -36,4 +38,9 @@ public class PestFinderConfig { @Expose public Position position = new Position(-350, 200, 1.3f); + + @Expose + @ConfigOption(name = "Teleport Hotkey", desc = "Press this key to warp to the nearest plot with pests on it.") + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE) + public int teleportHotkey = Keyboard.KEY_NONE; } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestSpawnConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestSpawnConfig.java index ac91fbe5b..ba723acfa 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestSpawnConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestSpawnConfig.java @@ -4,9 +4,7 @@ import at.hannibal2.skyhanni.config.FeatureToggle; import com.google.gson.annotations.Expose; import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; import io.github.moulberry.moulconfig.annotations.ConfigEditorDropdown; -import io.github.moulberry.moulconfig.annotations.ConfigEditorKeybind; import io.github.moulberry.moulconfig.annotations.ConfigOption; -import org.lwjgl.input.Keyboard; public class PestSpawnConfig { @@ -25,9 +23,4 @@ public class PestSpawnConfig { @ConfigEditorBoolean @FeatureToggle public boolean showTitle = true; - - @Expose - @ConfigOption(name = "Teleport Hotkey", desc = "Press this key to warp to the plot where the last pest has spawned.") - @ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE) - public int teleportHotkey = Keyboard.KEY_NONE; } 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 ef3cc86e7..dc60cd61a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent +import at.hannibal2.skyhanni.features.misc.LockMouseLook import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LocationUtils.isPlayerInside import at.hannibal2.skyhanni.utils.LorenzUtils @@ -53,6 +54,7 @@ object GardenPlotAPI { fun Plot.sendTeleportTo() { LorenzUtils.sendCommandToServer("tptoplot $name") + LockMouseLook.autoDisable() } init { 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 3627e8db6..7f38d6017 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 @@ -4,6 +4,7 @@ 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.LorenzKeyPressEvent import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent import at.hannibal2.skyhanni.events.ScoreboardChangeEvent import at.hannibal2.skyhanni.events.garden.pests.PestSpawnEvent @@ -15,9 +16,10 @@ 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 +import at.hannibal2.skyhanni.utils.LocationUtils.distanceSqToPlayer import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText import at.hannibal2.skyhanni.utils.RenderUtils.exactPlayerEyeLocation @@ -26,7 +28,9 @@ import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.StringUtils import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.renderables.Renderable +import net.minecraft.client.Minecraft import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds class PestFinder { @@ -145,10 +149,11 @@ class PestFinder { } } + private fun getNearestInfectedPest() = getPlotsWithPests().minByOrNull { it.middle.distanceSqToPlayer() } + 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.") + val plot = getNearestInfectedPest() ?: run { + LorenzUtils.error("Can not remove nearest pest: No infected plots detected.") return } plot.pests-- @@ -185,5 +190,30 @@ class PestFinder { } } + private var lastKeyPress = SimpleTimeMark.farPast() + + @SubscribeEvent + fun onKeyClick(event: LorenzKeyPressEvent) { + if (!GardenAPI.inGarden()) return + if (Minecraft.getMinecraft().currentScreen != null) return + if (NEUItems.neuHasFocus()) return + + if (event.keyCode != config.teleportHotkey) return + if (lastKeyPress.passedSince() < 2.seconds) return + lastKeyPress = SimpleTimeMark.now() + + val plot = getNearestInfectedPest() ?: run { + LorenzUtils.userError("No infected plots detected to warp to!") + return + } + + if (plot.isPlayerInside()) { + LorenzUtils.userError("You stand already on the infected plot!") + return + } + + plot.sendTeleportTo() + } + fun isEnabled() = GardenAPI.inGarden() && (config.showDisplay || config.waypointInWorld) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestSpawn.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestSpawn.kt index ae90e4439..934a73ef2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestSpawn.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestSpawn.kt @@ -1,14 +1,10 @@ package at.hannibal2.skyhanni.features.garden.pests import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.events.LorenzKeyPressEvent import at.hannibal2.skyhanni.events.garden.pests.PestSpawnEvent import at.hannibal2.skyhanni.features.garden.GardenAPI -import at.hannibal2.skyhanni.features.misc.LockMouseLook import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import net.minecraft.client.Minecraft import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.seconds @@ -19,8 +15,6 @@ class PestSpawn { private val patternMultiplePests = "§6§l.*! §6(?\\d) Pests §7have spawned in §aPlot §7- §b(?.*)§7!".toPattern() - private var lastPlotTp: String? = null - @SubscribeEvent fun onChat(event: LorenzChatEvent) { if (!GardenAPI.inGarden()) return @@ -48,7 +42,6 @@ class PestSpawn { private fun pestSpawn(amount: Int, plotName: String) { PestSpawnEvent(amount, plotName).postAndCatch() - lastPlotTp = plotName if (config.showTitle) { LorenzUtils.sendTitle("§aPest Spawn! §e$amount §ain §b$plotName§a!", 7.seconds) @@ -61,19 +54,4 @@ class PestSpawn { ) } } - - @SubscribeEvent - fun onKeyClick(event: LorenzKeyPressEvent) { - if (!GardenAPI.inGarden()) return - if (Minecraft.getMinecraft().currentScreen != null) return - if (NEUItems.neuHasFocus()) return - - if (event.keyCode != config.teleportHotkey) return - - lastPlotTp?.let { - lastPlotTp = null - LorenzUtils.sendCommandToServer("tptoplot $it") - LockMouseLook.autoDisable() - } - } } -- cgit