aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
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
parent3490b6b7e01213d92474aa3f8f3fbd8a6f158140 (diff)
downloadskyhanni-c2148dc9c57f4be833dfd8071290471a69da205f.tar.gz
skyhanni-c2148dc9c57f4be833dfd8071290471a69da205f.tar.bz2
skyhanni-c2148dc9c57f4be833dfd8071290471a69da205f.zip
Added ParkourHelper
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/RiftUpsideDownParkour.kt113
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt106
3 files changed, 129 insertions, 96 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java
index cbedf3dca..a728bbb2f 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java
@@ -216,17 +216,17 @@ public class RiftConfig {
@Expose
@ConfigOption(name = "Look Ahead", desc = "Change how many platforms should be shown in front of you.")
@ConfigEditorSlider(minStep = 1, maxValue = 9, minValue = 1)
- public int lookAhead = 2;
+ public Property<Integer> lookAhead = Property.of(2);
@Expose
@ConfigOption(name = "Rainbow Color", desc = "Show the rainbow color effect instead of a boring monochrome.")
@ConfigEditorBoolean
- public boolean rainbowColor = true;
+ public Property<Boolean> rainbowColor = Property.of(true);
@Expose
@ConfigOption(name = "Monochrome Color", desc = "Set a boring monochrome color for the parkour platforms.")
@ConfigEditorColour
- public String monochromeColor = "0:60:0:0:255";
+ public Property<String> monochromeColor = Property.of("0:60:0:0:255");
@Expose
@ConfigOption(name = "Hide others players", desc = "Hide other players while doing the upside down parkour.")
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 721c51654..b81018bb5 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/rift/RiftUpsideDownParkour.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/RiftUpsideDownParkour.kt
@@ -2,38 +2,25 @@ package at.hannibal2.skyhanni.features.rift
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.CheckRenderEntityEvent
+import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
-import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
-import at.hannibal2.skyhanni.utils.LocationUtils.playerLocation
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.toChromaColor
-import at.hannibal2.skyhanni.utils.LorenzVec
-import at.hannibal2.skyhanni.utils.RenderUtils
-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.ParkourHelper
import at.hannibal2.skyhanni.utils.jsonobjects.ParkourJson
-import at.hannibal2.skyhanni.utils.jsonobjects.ParkourJson.ShortCut
-import net.minecraft.client.Minecraft
import net.minecraftforge.client.event.RenderWorldLastEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import java.awt.Color
-import kotlin.time.Duration.Companion.seconds
class RiftUpsideDownParkour {
private val config get() = SkyHanniMod.feature.rift.mirrorVerse.upsideDownParkour
- private var locations = emptyList<LorenzVec>()
- private var shortCuts = emptyList<ShortCut>()
- private var current = -1
- private var visible = false
+
+ private var parkourHelper: ParkourHelper? = null
@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
val data = event.getConstant<ParkourJson>("RiftUpsideDownParkour") ?: return
- locations = data.locations
- shortCuts = data.shortCuts
+ parkourHelper = ParkourHelper(data.locations, data.shortCuts)
}
@SubscribeEvent
@@ -41,8 +28,10 @@ class RiftUpsideDownParkour {
if (!isEnabled()) return
if (!config.hidePlayers) return
- if (current != -1) {
- event.isCanceled = true
+ parkourHelper?.let {
+ if (it.inParkour()) {
+ event.isCanceled = true
+ }
}
}
@@ -51,89 +40,27 @@ class RiftUpsideDownParkour {
if (!isEnabled()) return
if (event.message == "§c§lOH NO! THE LAVA OOFED YOU BACK TO THE START!") {
- current = -1
- visible = false
+ parkourHelper?.reset()
}
}
- private val lookAhead get() = config.lookAhead + 1
-
@SubscribeEvent
- fun onRenderWorld(event: RenderWorldLastEvent) {
- if (!isEnabled()) return
-
- 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)
+ 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
}
-
- }
- for ((index, location) in locations.asSequence().withIndex().drop(current)
- .take(lookAhead) + inProgressVec.map { it.second }) {
- event.drawFilledBoundingBox(axisAlignedBB(location), 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 (playerLocation().distance(nextPosition) > currentPosition.distance(nextPosition)) return null
- return Pair(
- IndexedValue(current + lookAhead - 1, lookAheadStart),
- IndexedValue(
- current + lookAhead, lookAheadStart.add(
- lookAheadEnd.subtract(lookAheadStart)
- .scale(playerLocation().distance(currentPosition) / currentPosition.distance(nextPosition))
- )
- )
- )
- }
-
- private fun axisAlignedBB(loc: LorenzVec) = loc.add(-1.0, 0.0, -1.0).boundingToOffset(2, -1, 2).expandBlock()
+ @SubscribeEvent
+ fun onRenderWorld(event: RenderWorldLastEvent) {
+ if (!isEnabled()) return
- private fun colorForIndex(index: Int) = if (config.rainbowColor) {
- RenderUtils.chromaColor(4.seconds, offset = -index / 12f, brightness = 0.7f)
- } else {
- config.monochromeColor.toChromaColor()
+ parkourHelper?.render(event)
}
fun isEnabled() = RiftAPI.inRift() && LorenzUtils.skyBlockArea == "Mirrorverse" && config.enabled
}
-
-private fun <T : Any> T?.toSingletonListOrEmpty(): List<T> {
- if (this == null) return emptyList()
- return listOf(this)
-}
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