aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/commands/HelpCommand.kt14
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/pathfind/NavigationHelper.kt110
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/reminders/ReminderManager.kt16
3 files changed, 117 insertions, 23 deletions
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 1890c6293..0f07c47f8 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<IChatComponent>()
- 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 000000000..b27292559
--- /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<String>) {
+ SkyHanniMod.coroutineScope.launch {
+ doCommandAsync(args)
+ }
+ }
+
+ private fun doCommandAsync(args: Array<String>) {
+ val searchTerm = args.joinToString(" ").lowercase()
+ val distances = calculateDistances(searchTerm)
+ val names = calculateNames(distances)
+
+ val text = mutableListOf<IChatComponent>()
+ 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<GraphNode, Double>): MutableMap<String, GraphNode> {
+ val names = mutableMapOf<String, GraphNode>()
+ 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<GraphNode, Double> {
+ val grapth = IslandGraphs.currentIslandGraph ?: return emptyMap()
+ val closedNote = IslandGraphs.closedNote ?: return emptyMap()
+
+ val nodes = grapth.nodes
+ val distances = mutableMapOf<GraphNode, Double>()
+ 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 472aac2de..1df878ac9 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<IChatComponent> = 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 <time> <reminder> - §bCreates a new reminder".asComponent().send()
"§e/shremind list <page> - §bLists all reminders".asComponent().send()
@@ -191,7 +183,7 @@ object ReminderManager {
"§e/shremind edit <id> <reminder> - §bEdits a reminder".asComponent().send()
"§e/shremind move <id> <time> - §bMoves a reminder".asComponent().send()
"§e/shremind help - §bShows this help message".asComponent().send()
- createDivider().send()
+ Text.createDivider().send()
}
@SubscribeEvent