aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-07-05 13:24:32 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-07-05 13:24:32 +0200
commitc2148dc9c57f4be833dfd8071290471a69da205f (patch)
treec59631313d5c493c3c045777e183e5f628a2c593 /src/main/java/at/hannibal2/skyhanni/utils
parent3490b6b7e01213d92474aa3f8f3fbd8a6f158140 (diff)
downloadskyhanni-c2148dc9c57f4be833dfd8071290471a69da205f.tar.gz
skyhanni-c2148dc9c57f4be833dfd8071290471a69da205f.tar.bz2
skyhanni-c2148dc9c57f4be833dfd8071290471a69da205f.zip
Added ParkourHelper
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt b/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt
new file mode 100644
index 000000000..dc9f808d7
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt
@@ -0,0 +1,106 @@
+package at.hannibal2.skyhanni.utils
+
+import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
+import at.hannibal2.skyhanni.utils.RenderUtils.draw3DLine
+import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
+import at.hannibal2.skyhanni.utils.RenderUtils.drawFilledBoundingBox
+import at.hannibal2.skyhanni.utils.RenderUtils.expandBlock
+import at.hannibal2.skyhanni.utils.jsonobjects.ParkourJson
+import net.minecraft.client.Minecraft
+import net.minecraftforge.client.event.RenderWorldLastEvent
+import java.awt.Color
+import kotlin.time.Duration.Companion.seconds
+
+class ParkourHelper(val locations: List<LorenzVec>, val shortCuts: List<ParkourJson.ShortCut>) {
+ private var current = -1
+ private var visible = false
+
+ var rainbowColor = true
+ var monochromeColor: Color = Color.WHITE
+ var lookAhead = 2
+
+
+ fun inParkour() = current != -1
+
+ fun reset() {
+ current = -1
+ visible = false
+ }
+
+ fun render(event: RenderWorldLastEvent) {
+ if (current == locations.size - 1) visible = false
+
+ val distanceToPlayer = locations.first().distanceToPlayer()
+ if (distanceToPlayer < 2) {
+ visible = true
+ } else if (distanceToPlayer > 15) {
+ if (current < 1) {
+ visible = false
+ }
+ }
+
+ if (!visible) return
+
+ for ((index, location) in locations.withIndex()) {
+ if (location.distanceToPlayer() < 2) {
+ if (Minecraft.getMinecraft().thePlayer.onGround) {
+ current = index
+ }
+ }
+ }
+ if (current < 0) return
+
+ val inProgressVec = getInProgressPair().toSingletonListOrEmpty()
+ for ((prev, next) in locations.asSequence().withIndex().zipWithNext().drop(current)
+ .take(lookAhead - 1) + inProgressVec) {
+ event.draw3DLine(prev.value, next.value, colorForIndex(prev.index), 5, false, colorForIndex(next.index))
+ }
+ val nextShortcuts = current until current + lookAhead
+ for (shortCut in shortCuts) {
+ if (shortCut.from in nextShortcuts && shortCut.to in locations.indices) {
+ event.draw3DLine(locations[shortCut.from], locations[shortCut.to], Color.RED, 3, false)
+ event.drawFilledBoundingBox(axisAlignedBB(locations[shortCut.to]), Color.RED, 1f)
+ event.drawDynamicText(locations[shortCut.to].add(-0.5, 1.0, -0.5), "§cShortcut", 2.5)
+ }
+
+ }
+
+ for ((index, location) in locations.asSequence().withIndex().drop(current)
+ .take(lookAhead) + inProgressVec.map { it.second }) {
+ var aabb = axisAlignedBB(location)
+ if (location !in locations) {
+ aabb = aabb.expandBlock()
+ }
+
+ event.drawFilledBoundingBox(aabb, colorForIndex(index), 1f)
+ }
+ }
+
+ private fun getInProgressPair(): Pair<IndexedValue<LorenzVec>, IndexedValue<LorenzVec>>? {
+ if (current < 0 || current + lookAhead >= locations.size) return null
+ val currentPosition = locations[current]
+ val nextPosition = locations[current + 1]
+ val lookAheadStart = locations[current + lookAhead - 1]
+ val lookAheadEnd = locations[current + lookAhead]
+
+ if (LocationUtils.playerLocation().distance(nextPosition) > currentPosition.distance(nextPosition)) return null
+
+ val factor = LocationUtils.playerLocation().distance(currentPosition) / currentPosition.distance(nextPosition)
+ val solpeLocation = lookAheadStart.add(lookAheadEnd.subtract(lookAheadStart).scale(factor))
+ return Pair(
+ IndexedValue(current + lookAhead - 1, lookAheadStart),
+ IndexedValue(current + lookAhead, solpeLocation)
+ )
+ }
+
+ private fun axisAlignedBB(loc: LorenzVec) = loc.add(-1.0, 0.0, -1.0).boundingToOffset(2, -1, 2).expandBlock()
+
+ private fun colorForIndex(index: Int) = if (rainbowColor) {
+ RenderUtils.chromaColor(4.seconds, offset = -index / 12f, brightness = 0.7f)
+ } else monochromeColor
+}
+
+private fun <T : Any> T?.toSingletonListOrEmpty(): List<T> {
+ if (this == null) return emptyList()
+ return listOf(this)
+} \ No newline at end of file