aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/RiftUpsideDownParkour.kt23
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/ParkourWaypointSaver.kt (renamed from src/main/java/at/hannibal2/skyhanni/test/WaypointSaver.kt)28
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt127
6 files changed, 130 insertions, 63 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index 2513c1860..4dac5f6c7 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -329,7 +329,7 @@ class SkyHanniMod {
loadModule(TestBingo)
loadModule(TestCopyRngMeterValues)
loadModule(HighlightMissingRepoItems())
- loadModule(WaypointSaver())
+ loadModule(ParkourWaypointSaver())
}
@Mod.EventHandler
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/RiftUpsideDownParkour.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/RiftUpsideDownParkour.kt
index b81018bb5..ba1a16146 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/rift/RiftUpsideDownParkour.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/RiftUpsideDownParkour.kt
@@ -14,13 +14,18 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class RiftUpsideDownParkour {
private val config get() = SkyHanniMod.feature.rift.mirrorVerse.upsideDownParkour
-
private var parkourHelper: ParkourHelper? = null
@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
val data = event.getConstant<ParkourJson>("RiftUpsideDownParkour") ?: return
- parkourHelper = ParkourHelper(data.locations, data.shortCuts)
+ parkourHelper = ParkourHelper(
+ data.locations.map { it.add(-1.0, -1.0, -1.0) },// TODO remove offset. change repo instead
+ data.shortCuts,
+ platformSize = 2.0,
+ detectionRange = 2.0
+ )
+ updateConfig()
}
@SubscribeEvent
@@ -47,11 +52,15 @@ class RiftUpsideDownParkour {
@SubscribeEvent
fun onConfigLoad(event: ConfigLoadEvent) {
LorenzUtils.onToggle(config.rainbowColor, config.monochromeColor, config.lookAhead) {
- parkourHelper?.run {
- rainbowColor = config.rainbowColor.get()
- monochromeColor = config.monochromeColor.get().toChromaColor()
- lookAhead = config.lookAhead.get() + 1
- }
+ updateConfig()
+ }
+ }
+
+ private fun updateConfig() {
+ parkourHelper?.run {
+ rainbowColor = config.rainbowColor.get()
+ monochromeColor = config.monochromeColor.get().toChromaColor()
+ lookAhead = config.lookAhead.get() + 1
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/test/WaypointSaver.kt b/src/main/java/at/hannibal2/skyhanni/test/ParkourWaypointSaver.kt
index cc3ae7e9f..1020a5a9c 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/WaypointSaver.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/ParkourWaypointSaver.kt
@@ -1,8 +1,9 @@
package at.hannibal2.skyhanni.test
import at.hannibal2.skyhanni.SkyHanniMod
-import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled
import at.hannibal2.skyhanni.utils.*
+import at.hannibal2.skyhanni.utils.RenderUtils.drawFilledBoundingBox
+import at.hannibal2.skyhanni.utils.RenderUtils.expandBlock
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.client.gui.inventory.GuiEditSign
@@ -12,10 +13,11 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
import org.lwjgl.input.Keyboard
-class WaypointSaver {
+class ParkourWaypointSaver {
private val config get() = SkyHanniMod.feature.dev.waypoint
private var timeLastSaved: Long = 0
private var locations = mutableListOf<LorenzVec>()
+ private var parkourHelper: ParkourHelper? = null
@SubscribeEvent
fun onTick(event: TickEvent.ClientTickEvent) {
@@ -31,7 +33,7 @@ class WaypointSaver {
val key = if (Keyboard.getEventKey() == 0) Keyboard.getEventCharacter().code + 256 else Keyboard.getEventKey()
if (config.deleteKey == key) {
locations = locations.dropLast(1).toMutableList()
- locations.copyLocations()
+ update()
}
if (config.saveKey == key) {
val newLocation = LocationUtils.playerLocation().roundLocation()
@@ -39,7 +41,15 @@ class WaypointSaver {
if (newLocation == locations.last()) return
}
locations.add(newLocation)
- locations.copyLocations()
+ update()
+ }
+ }
+
+ private fun update() {
+ locations.copyLocations()
+ parkourHelper = ParkourHelper(locations, emptyList()).also {
+ it.showEverything = true
+ it.rainbowColor = true
}
}
@@ -58,8 +68,14 @@ class WaypointSaver {
@SubscribeEvent
fun onRenderWorld(event: RenderWorldLastEvent) {
if (!LorenzUtils.inSkyBlock) return
- for (location in locations) {
- event.drawWaypointFilled(location, LorenzColor.GREEN.toColor())
+
+ if (locations.size > 2) {
+ parkourHelper?.render(event)
+ } else {
+ for (location in locations) {
+ val aabb = location.boundingToOffset(1.0, 1.0, 1.0).expandBlock()
+ event.drawFilledBoundingBox(aabb, LorenzColor.GREEN.toColor(), 1f)
+ }
}
}
} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index 129cec02e..d0b970187 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -384,4 +384,9 @@ object LorenzUtils {
get(index)
} else null
}
+
+ fun <T : Any> T?.toSingletonListOrEmpty(): List<T> {
+ if (this == null) return emptyList()
+ return listOf(this)
+ }
} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt
index 1d1909875..7380c4c37 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt
@@ -7,11 +7,7 @@ import net.minecraft.util.AxisAlignedBB
import net.minecraft.util.BlockPos
import net.minecraft.util.Rotations
import net.minecraft.util.Vec3
-import kotlin.math.cos
-import kotlin.math.pow
-import kotlin.math.round
-import kotlin.math.sin
-import kotlin.math.sqrt
+import kotlin.math.*
data class LorenzVec(
val x: Double,
@@ -107,7 +103,7 @@ data class LorenzVec(
return LorenzVec(x, y, z)
}
- fun boundingToOffset(offX: Int, offY: Int, offZ: Int) = AxisAlignedBB(x, y, z, x + offX, y + offY, z + offZ)
+ fun boundingToOffset(offX: Double, offY: Double, offZ: Double) = AxisAlignedBB(x, y, z, x + offX, y + offY, z + offZ)
fun scale(scalar: Double): LorenzVec {
return LorenzVec(scalar * x, scalar * y, scalar * z)
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt b/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt
index b33f6bc99..081641c9a 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt
@@ -1,9 +1,12 @@
package at.hannibal2.skyhanni.utils
+import at.hannibal2.skyhanni.test.command.CopyErrorCommand
import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
+import at.hannibal2.skyhanni.utils.LorenzUtils.toSingletonListOrEmpty
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.drawString
import at.hannibal2.skyhanni.utils.RenderUtils.expandBlock
import at.hannibal2.skyhanni.utils.jsonobjects.ParkourJson
import net.minecraft.client.Minecraft
@@ -11,13 +14,19 @@ import net.minecraftforge.client.event.RenderWorldLastEvent
import java.awt.Color
import kotlin.time.Duration.Companion.seconds
-class ParkourHelper(val locations: List<LorenzVec>, private val shortCuts: List<ParkourJson.ShortCut>) {
+class ParkourHelper(
+ val locations: List<LorenzVec>,
+ private val shortCuts: List<ParkourJson.ShortCut>,
+ val platformSize: Double = 1.0,
+ val detectionRange: Double = 1.0
+) {
private var current = -1
private var visible = false
- var rainbowColor = true
+ var rainbowColor = false
var monochromeColor: Color = Color.WHITE
var lookAhead = 2
+ var showEverything = false
fun inParkour() = current != -1
@@ -27,54 +36,91 @@ class ParkourHelper(val locations: List<LorenzVec>, private val shortCuts: List<
}
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 (locations.isEmpty()) {
+ CopyErrorCommand.logError(
+ IllegalArgumentException("locations is empty"),
+ "Trying to render an empty parkour"
+ )
+ return
}
- if (!visible) return
+ try {
+ if (!showEverything) {
+ if (current == locations.size - 1) visible = false
+
+ val distanceToPlayer = locations.first().offsetCenter().distanceToPlayer()
+ if (distanceToPlayer < detectionRange) {
+ 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
+ for ((index, location) in locations.withIndex()) {
+ if (location.offsetCenter().distanceToPlayer() < detectionRange) {
+ 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)
+ if (current < 0) return
+ } else {
+ current = 0
+ lookAhead = locations.size
}
- }
+ val inProgressVec = getInProgressPair().toSingletonListOrEmpty()
+ for ((prev, next) in locations.asSequence().withIndex().zipWithNext().drop(current)
+ .take(lookAhead - 1) + inProgressVec) {
+ event.draw3DLine(
+ prev.value.offsetCenter(),
+ next.value.offsetCenter(),
+ 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].offsetCenter(),
+ locations[shortCut.to].offsetCenter(),
+ 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)
+ for ((index, location) in locations.asSequence().withIndex().drop(current)
+ .take(lookAhead) + inProgressVec.map { it.second }) {
+ var aabb = axisAlignedBB(location)
+ val isMovingPlattform = location !in locations
+ if (isMovingPlattform) {
+ aabb = aabb.expandBlock()
+ }
+
+ event.drawFilledBoundingBox(aabb, colorForIndex(index), 1f)
+ if (!isMovingPlattform) {
+ event.drawString(location.offsetCenter().add(0, 1, 0), "§a§l$index", seeThroughBlocks = true)
+ }
+ }
+ } catch (e: Throwable) {
+ CopyErrorCommand.logError(e, "Error while rendering a parkour")
}
}
+ private fun LorenzVec.offsetCenter() = add(platformSize / 2, 1.0, platformSize / 2)
+
private fun getInProgressPair(): Pair<IndexedValue<LorenzVec>, IndexedValue<LorenzVec>>? {
if (current < 0 || current + lookAhead >= locations.size) return null
val currentPosition = locations[current]
@@ -92,14 +138,9 @@ class ParkourHelper(val locations: List<LorenzVec>, private val shortCuts: List<
)
}
- private fun axisAlignedBB(loc: LorenzVec) = loc.add(-1.0, 0.0, -1.0).boundingToOffset(2, -1, 2).expandBlock()
+ private fun axisAlignedBB(loc: LorenzVec) = loc.boundingToOffset(platformSize, 1.0, platformSize).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