aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-09-23 15:10:19 +0200
committerGitHub <noreply@github.com>2024-09-23 15:10:19 +0200
commit478e5c6ac5f587dbf5f6f45f6489cbe37b05fd2f (patch)
treee1018b2c3d189866f20683abb7b5392cc7b865fa /src/main/java/at/hannibal2/skyhanni/data
parent91dee900cc7bc40db5e936d2e9f2f18dcbbe870f (diff)
downloadskyhanni-478e5c6ac5f587dbf5f6f45f6489cbe37b05fd2f.tar.gz
skyhanni-478e5c6ac5f587dbf5f6f45f6489cbe37b05fd2f.tar.bz2
skyhanni-478e5c6ac5f587dbf5f6f45f6489cbe37b05fd2f.zip
Improvement: Glacite Tunnels Area Navigation (#2544)
Co-authored-by: nea <nea@nea.moe> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/IslandGraphs.kt77
1 files changed, 71 insertions, 6 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/IslandGraphs.kt b/src/main/java/at/hannibal2/skyhanni/data/IslandGraphs.kt
index ca3143b95..9e4639454 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/IslandGraphs.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/IslandGraphs.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.model.Graph
import at.hannibal2.skyhanni.data.model.GraphNode
import at.hannibal2.skyhanni.data.model.findShortestPathAsGraphWithDistance
@@ -10,23 +11,29 @@ import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
+import at.hannibal2.skyhanni.events.skyblock.ScoreboardAreaChangeEvent
import at.hannibal2.skyhanni.features.misc.IslandAreas
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.SkyHanniDebugsAndTests
+import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.LocationUtils
import at.hannibal2.skyhanni.utils.LocationUtils.canBeSeen
import at.hannibal2.skyhanni.utils.LocationUtils.distanceSqToPlayer
import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.LorenzVec
+import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.RenderUtils.draw3DLine
import at.hannibal2.skyhanni.utils.RenderUtils.draw3DPathWithWaypoint
import at.hannibal2.skyhanni.utils.RenderUtils.drawWaypointFilled
+import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.awt.Color
import java.io.File
import kotlin.math.abs
+import kotlin.time.Duration.Companion.milliseconds
/**
* TODO
@@ -101,26 +108,73 @@ object IslandGraphs {
private var fastestPath: Graph? = null
private var condition: () -> Boolean = { true }
+ private var inGlaciteTunnels: Boolean? = null
+
+ private val patternGroup = RepoPattern.group("data.island.navigation")
+
+ /**
+ * REGEX-TEST: Dwarven Base Camp
+ * REGEX-TEST: Forge
+ * REGEX-TEST: Fossil Research Center
+ */
+ private val glaciteTunnelsPattern by patternGroup.pattern(
+ "glacitetunnels",
+ "(Glacite Tunnels|Dwarven Base Camp|Great Glacite Lake|Fossil Research Center)",
+ )
@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
if (!LorenzUtils.inSkyBlock) return
- reloadFromJson(LorenzUtils.skyBlockIsland)
+ loadIsland(LorenzUtils.skyBlockIsland)
}
@SubscribeEvent
fun onIslandChange(event: IslandChangeEvent) {
- reloadFromJson(event.newIsland)
+ if (currentIslandGraph != null) return
+ if (event.newIsland == IslandType.NONE) return
+ loadIsland(event.newIsland)
}
@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
+ currentIslandGraph = null
reset()
}
- private fun reloadFromJson(newIsland: IslandType) {
- val islandName = newIsland.name
+ fun isGlaciteTunnelsArea(area: String?): Boolean = glaciteTunnelsPattern.matches(area)
+
+ @HandleEvent
+ fun onAreaChange(event: ScoreboardAreaChangeEvent) {
+ if (!IslandType.DWARVEN_MINES.isInIsland()) {
+ inGlaciteTunnels = null
+ return
+ }
+
+ val now = isGlaciteTunnelsArea(LorenzUtils.skyBlockArea)
+ if (inGlaciteTunnels != now) {
+ inGlaciteTunnels = now
+ loadDwarvenMines()
+ }
+ }
+
+ private fun loadDwarvenMines() {
+ if (isGlaciteTunnelsArea(LorenzUtils.skyBlockArea)) {
+ reloadFromJson("GLACITE_TUNNELS")
+ } else {
+ reloadFromJson("DWARVEN_MINES")
+ }
+ }
+
+ private fun loadIsland(newIsland: IslandType) {
+ if (newIsland == IslandType.DWARVEN_MINES) {
+ loadDwarvenMines()
+ } else {
+ reloadFromJson(newIsland.name)
+ }
+ }
+
+ private fun reloadFromJson(islandName: String) {
val constant = "island_graphs/$islandName"
val name = "constants/$constant.json"
val jsonFile = File(SkyHanniMod.repo.repoLocation, name)
@@ -136,6 +190,13 @@ object IslandGraphs {
fun setNewGraph(graph: Graph) {
reset()
currentIslandGraph = graph
+
+ // calling various update functions to make swtiching between deep caverns and glacite tunnels bareable
+ handleTick()
+ IslandAreas.noteMoved()
+ DelayedRun.runDelayed(150.milliseconds) {
+ IslandAreas.updatePosition()
+ }
}
private fun reset() {
@@ -143,11 +204,16 @@ object IslandGraphs {
currentTarget = null
goal = null
fastestPath = null
+ IslandAreas.display = null
}
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!LorenzUtils.inSkyBlock) return
+ handleTick()
+ }
+
+ private fun handleTick() {
val prevClosed = closedNote
val graph = currentIslandGraph ?: return
@@ -294,8 +360,7 @@ object IslandGraphs {
val nodes = graph.nodes
val potentialSkip =
- nodes.lastOrNull { it.position.canBeSeen(maxSkipDistance, -1.0) && abs(it.position.y - playerY) <= 2 }
- ?: return null
+ nodes.lastOrNull { it.position.canBeSeen(maxSkipDistance, -1.0) && abs(it.position.y - playerY) <= 2 } ?: return null
val angleSkip = if (potentialSkip == nodes.first()) {
false