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 a52852a8193f..9f2e3cc3fd71 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -72,6 +72,7 @@ import at.hannibal2.skyhanni.features.misc.TpsCounter import at.hannibal2.skyhanni.features.misc.discordrpc.DiscordRPCManager import at.hannibal2.skyhanni.features.misc.limbo.LimboTimeTracker import at.hannibal2.skyhanni.features.misc.massconfiguration.DefaultConfigFeatures +import at.hannibal2.skyhanni.features.misc.pathfind.NavigationHelper import at.hannibal2.skyhanni.features.misc.reminders.ReminderManager import at.hannibal2.skyhanni.features.misc.update.UpdateManager import at.hannibal2.skyhanni.features.misc.visualwords.VisualWordGui @@ -182,6 +183,7 @@ object Commands { ) registerCommand("shremind", "Set a reminder for yourself") { ReminderManager.command(it) } registerCommand("shwords", "Opens the config list for modifying visual words") { openVisualWords() } + registerCommand("shnavigate", "Using path finder to go to locatons") { NavigationHelper.onCommand(it) } } private fun usersNormal() { diff --git a/src/main/java/at/hannibal2/skyhanni/data/model/GraphNodeTag.kt b/src/main/java/at/hannibal2/skyhanni/data/model/GraphNodeTag.kt index 2cdc9e7e0d1d..6bf00edafcf6 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/model/GraphNodeTag.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/model/GraphNodeTag.kt @@ -6,7 +6,7 @@ import at.hannibal2.skyhanni.utils.LorenzColor enum class GraphNodeTag( val internalName: String, val color: LorenzColor, - cleanName: String, + val cleanName: String, val description: String, val onlyIsland: IslandType? = null, ) { @@ -17,7 +17,7 @@ enum class GraphNodeTag( AREA("area", LorenzColor.DARK_GREEN, "Area", "A big SkyBlock area."), SMALL_AREA("small_area", LorenzColor.GREEN, "Small Area", "A small SkyBlock area, e.g. a house."), POI("poi", LorenzColor.WHITE, "Point of Interest", "A relevant spot or a landmark on the map."), -// LAUNCH_PAD("launch", LorenzColor.WHITE, "Launch Pad", "Slime blocks sending you to another server."), + // LAUNCH_PAD("launch", LorenzColor.WHITE, "Launch Pad", "Slime blocks sending you to another server."), TELEPORT("teleport", LorenzColor.BLUE, "Teleport", "A spot from/to teleport."), // on multiple islands @@ -43,18 +43,36 @@ enum class GraphNodeTag( // Rift RIFT_ENIGMA("rift_enigma", LorenzColor.DARK_PURPLE, "Enigma Soul", "Enigma Souls in the Rift.", onlyIsland = IslandType.THE_RIFT), RIFT_EYE("rift_eye", LorenzColor.DARK_RED, "Rift Eye", "An Eye in the Rift to teleport to.", onlyIsland = IslandType.THE_RIFT), - RIFT_MONTEZUMA("rift_montezuma", LorenzColor.GRAY, "Montezuma Soul Piece", "A piece of the Montezuma Soul.", onlyIsland = IslandType.THE_RIFT), + RIFT_MONTEZUMA( + "rift_montezuma", + LorenzColor.GRAY, + "Montezuma Soul Piece", + "A piece of the Montezuma Soul.", + onlyIsland = IslandType.THE_RIFT, + ), RIFT_EFFIGY("rift_effigy", LorenzColor.RED, "Blood Effigies", "Locations of the Blood Effigies.", onlyIsland = IslandType.THE_RIFT), // Spider's Den - SPIDER_RELIC("SPIDER_RELIC", LorenzColor.DARK_PURPLE, "Spider's Relic", "An relic in the Spider's Den.", onlyIsland = IslandType.SPIDER_DEN), + SPIDER_RELIC( + "SPIDER_RELIC", + LorenzColor.DARK_PURPLE, + "Spider's Relic", + "An relic in the Spider's Den.", + onlyIsland = IslandType.SPIDER_DEN, + ), // Dwarven Mines MINES_EMISSARY("mines_emissary", LorenzColor.GOLD, "Mines Emissary", "An Emissary to the king.", onlyIsland = IslandType.DWARVEN_MINES), // commission areas // Crimson Isles - CRIMSON_MINIBOSS("crimson_miniboss", LorenzColor.RED, "Crimson Miniboss", "A Miniboss in the Crimson Isle.", onlyIsland = IslandType.CRIMSON_ISLE), + CRIMSON_MINIBOSS( + "crimson_miniboss", + LorenzColor.RED, + "Crimson Miniboss", + "A Miniboss in the Crimson Isle.", + onlyIsland = IslandType.CRIMSON_ISLE, + ), // The End END_GOLEM("end_golem", LorenzColor.RED, "Golem Spawn", "A spot where the golem can spawn in the End.", onlyIsland = IslandType.THE_END), diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/HelpCommand.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/HelpCommand.kt index 1890c62930d1..0f07c47f8d14 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/HelpCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/HelpCommand.kt @@ -5,13 +5,10 @@ import at.hannibal2.skyhanni.utils.StringUtils.splitLines import at.hannibal2.skyhanni.utils.chat.Text import at.hannibal2.skyhanni.utils.chat.Text.asComponent import at.hannibal2.skyhanni.utils.chat.Text.center -import at.hannibal2.skyhanni.utils.chat.Text.fitToChat import at.hannibal2.skyhanni.utils.chat.Text.hover import at.hannibal2.skyhanni.utils.chat.Text.onClick import at.hannibal2.skyhanni.utils.chat.Text.send -import at.hannibal2.skyhanni.utils.chat.Text.style import at.hannibal2.skyhanni.utils.chat.Text.suggest -import net.minecraft.util.EnumChatFormatting import net.minecraft.util.IChatComponent import kotlin.math.ceil @@ -20,11 +17,6 @@ object HelpCommand { private const val COMMANDS_PER_PAGE = 15 private const val HELP_ID = -6457563 - private fun createDivider() = Text.HYPHEN.fitToChat().style { - strikethrough = true - color = EnumChatFormatting.BLUE - } - private fun createCommandEntry(command: Commands.CommandInfo): IChatComponent { val category = command.category val color = category.color @@ -60,7 +52,7 @@ object HelpCommand { val text = mutableListOf() - text.add(createDivider()) + text.add(Text.createDivider()) text.add(title.asComponent().center()) text.add( Text.join( @@ -77,7 +69,7 @@ object HelpCommand { } else null, ).center(), ) - text.add(createDivider()) + text.add(Text.createDivider()) if (filtered.isEmpty()) { text.add(Text.EMPTY) @@ -91,7 +83,7 @@ object HelpCommand { } } - text.add(createDivider()) + text.add(Text.createDivider()) Text.multiline(text).send(HELP_ID) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/pathfind/NavigationHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/pathfind/NavigationHelper.kt new file mode 100644 index 000000000000..b27292559d34 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/pathfind/NavigationHelper.kt @@ -0,0 +1,110 @@ +package at.hannibal2.skyhanni.features.misc.pathfind + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.IslandGraphs +import at.hannibal2.skyhanni.data.model.GraphNode +import at.hannibal2.skyhanni.data.model.GraphNodeTag +import at.hannibal2.skyhanni.data.model.findShortestDistance +import at.hannibal2.skyhanni.utils.CollectionUtils.sorted +import at.hannibal2.skyhanni.utils.LorenzUtils.round +import at.hannibal2.skyhanni.utils.chat.Text +import at.hannibal2.skyhanni.utils.chat.Text.asComponent +import at.hannibal2.skyhanni.utils.chat.Text.center +import at.hannibal2.skyhanni.utils.chat.Text.hover +import at.hannibal2.skyhanni.utils.chat.Text.onClick +import at.hannibal2.skyhanni.utils.chat.Text.send +import kotlinx.coroutines.launch +import net.minecraft.util.IChatComponent + +object NavigationHelper { + private val NAVIGATION_CHAT_ID = -6457562 + + val allowedTags = listOf( + GraphNodeTag.NPC, + GraphNodeTag.AREA, + GraphNodeTag.SMALL_AREA, + GraphNodeTag.POI, + GraphNodeTag.SLAYER, + GraphNodeTag.GRIND_MOBS, + GraphNodeTag.GRIND_ORES, + GraphNodeTag.GRIND_CROPS, + GraphNodeTag.MINES_EMISSARY, + GraphNodeTag.CRIMSON_MINIBOSS, + ) + + fun onCommand(args: Array) { + SkyHanniMod.coroutineScope.launch { + doCommandAsync(args) + } + } + + private fun doCommandAsync(args: Array) { + val searchTerm = args.joinToString(" ").lowercase() + val distances = calculateDistances(searchTerm) + val names = calculateNames(distances) + + val text = mutableListOf() + text.add(Text.createDivider()) + text.add("§7Found ${names.size} locations ($searchTerm)".asComponent().center()) + val goBack = { + onCommand(searchTerm.split(" ").toTypedArray()) + IslandGraphs.stop() + } + // TODO dont show a too long list, add pages + for ((name, node) in names) { + val distance = distances[node]!!.round(1) + val component = "$name §e$distance".asComponent() + component.onClick { + IslandGraphs.pathFind(node.position) + sendNavigateMessage(name, goBack) + } + val tag = node.tags.first { it in allowedTags } + // TODO include most closest area, if this is no area (type in area = forger in forge) + component.hover = + ("§eClick to start navigating to\n" + "§7Type: §r${tag.displayName}\n" + "§7Distance: §e$distance blocks").asComponent() + text.add(component) + } + text.add(Text.createDivider()) + Text.multiline(text).send(NAVIGATION_CHAT_ID) + } + + private fun sendNavigateMessage(name: String, goBack: () -> Unit) { + val componentText = "§7Navigating to §r$name".asComponent() + componentText.onClick(onClick = goBack) + componentText.send(NAVIGATION_CHAT_ID) + } + + private fun calculateNames(distances: Map): MutableMap { + val names = mutableMapOf() + for (node in distances.sorted().keys) { + val tag = node.tags.first { it in allowedTags } + val name = "${node.name} §7(${tag.displayName}§7)" + if (name in names) continue + names[name] = node + } + return names + } + + private fun calculateDistances( + searchTerm: String, + ): Map { + val grapth = IslandGraphs.currentIslandGraph ?: return emptyMap() + val closedNote = IslandGraphs.closedNote ?: return emptyMap() + + val nodes = grapth.nodes + val distances = mutableMapOf() + for (node in nodes) { + val name = node.name ?: continue + val remainingTags = node.tags.filter { it in allowedTags } + if (remainingTags.isEmpty()) continue + if (name.lowercase().contains(searchTerm)) { + distances[node] = grapth.findShortestDistance(closedNote, node) + } + if (remainingTags.size != 1) { + println("found node with invalid amount of tags: ${node.name} (${remainingTags.map { it.cleanName }}") + } + } + return distances + } + +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/reminders/ReminderManager.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/reminders/ReminderManager.kt index 472aac2de6be..1df878ac9a2f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/reminders/ReminderManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/reminders/ReminderManager.kt @@ -13,13 +13,10 @@ import at.hannibal2.skyhanni.utils.chat.Text import at.hannibal2.skyhanni.utils.chat.Text.asComponent import at.hannibal2.skyhanni.utils.chat.Text.center import at.hannibal2.skyhanni.utils.chat.Text.command -import at.hannibal2.skyhanni.utils.chat.Text.fitToChat import at.hannibal2.skyhanni.utils.chat.Text.hover import at.hannibal2.skyhanni.utils.chat.Text.send -import at.hannibal2.skyhanni.utils.chat.Text.style import at.hannibal2.skyhanni.utils.chat.Text.suggest import at.hannibal2.skyhanni.utils.chat.Text.wrap -import net.minecraft.util.EnumChatFormatting import net.minecraft.util.IChatComponent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration @@ -44,11 +41,6 @@ object ReminderManager { private fun sendMessage(message: String) = Text.join("§e[Reminder]", " ", message).send(REMINDERS_ACTION_ID) - private fun createDivider() = Text.HYPHEN.fitToChat().style { - strikethrough = true - color = EnumChatFormatting.BLUE - } - private fun parseDuration(text: String): Duration? = try { val duration = TimeUtils.getDuration(text) if (duration <= 1.seconds) null else duration @@ -64,7 +56,7 @@ object ReminderManager { val text: MutableList = mutableListOf() - text.add(createDivider()) + text.add(Text.createDivider()) text.add( Text.join( @@ -113,7 +105,7 @@ object ReminderManager { text.add(Text.EMPTY) } - text.add(createDivider()) + text.add(Text.createDivider()) Text.join(*text.toTypedArray(), separator = Text.NEWLINE).send(REMINDERS_LIST_ID) } @@ -183,7 +175,7 @@ object ReminderManager { } private fun help() { - createDivider().send() + Text.createDivider().send() "§6SkyHanni Reminder Commands:".asComponent().send() "§e/shremind