summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorHiZe_ <superhize@hotmail.com>2023-07-04 14:25:48 +0200
committerGitHub <noreply@github.com>2023-07-04 14:25:48 +0200
commita58f5cea0a3378b0f32a57750ad5c750aeec92d3 (patch)
treeb2028f6b3fe710b61637b5fa7b43e8b5011245e9 /src/main/java/at/hannibal2/skyhanni/features
parentdd1dc872a97dcc14fe7842fc69c1bd34b44223fe (diff)
downloadskyhanni-a58f5cea0a3378b0f32a57750ad5c750aeec92d3.tar.gz
skyhanni-a58f5cea0a3378b0f32a57750ad5c750aeec92d3.tar.bz2
skyhanni-a58f5cea0a3378b0f32a57750ad5c750aeec92d3.zip
Merge pull request #278
* start * i sleep * hide others players * change * thing * useless import * config option to change space between lines of text * removed useless val * Code cleanup * Merge branch 'beta' into danceroom_helper * use repo for instructions * merged beta * display a message when instructions list is empty * more beautiful colors and moved category into mirror verse
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/DanceRoomHelper.kt129
1 files changed, 129 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/DanceRoomHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/DanceRoomHelper.kt
new file mode 100644
index 000000000..300dd2b23
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/DanceRoomHelper.kt
@@ -0,0 +1,129 @@
+package at.hannibal2.skyhanni.features.rift
+
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.CheckRenderEntityEvent
+import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.LorenzTickEvent
+import at.hannibal2.skyhanni.events.RepositoryReloadEvent
+import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
+import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase
+import at.hannibal2.skyhanni.utils.getLorenzVec
+import at.hannibal2.skyhanni.utils.jsonobjects.DanceRoomInstructionsJson
+import kotlinx.coroutines.*
+import net.minecraft.client.Minecraft
+import net.minecraft.client.entity.EntityOtherPlayerMP
+import net.minecraft.util.AxisAlignedBB
+import net.minecraftforge.event.world.WorldEvent
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+object DanceRoomHelper {
+
+ private var display = emptyList<String>()
+ private val config get() = SkyHanniMod.feature.rift.mirrorVerse.danceRoomHelper
+ private var index = 0
+ private var found = false
+ private val danceRoom = AxisAlignedBB(-260.0, 32.0, -110.0, -267.0, 40.0, -102.0)
+ private var inRoom = false
+ private var instructions = emptyList<String>()
+
+ fun update() {
+ display = buildList {
+ if (instructions.isEmpty()) {
+ add("§cError fetching Dance Room Instructions!")
+ add("§cTry §e/shreloadlocalrepo §cor §e/shupdaterepo")
+ }
+ for (line in instructions.withIndex()) {
+ if (index == line.index) {
+ add("§7Now: ${line.value.format()}")
+ } else if (index + 1 == line.index) {
+ add("§7Next: ${line.value.format()}")
+ } else if ((index + 2..index + config.lineToShow).contains(line.index)) {
+ add("§7Later: ${line.value.format()}")
+ }
+ }
+ }
+ }
+
+ private fun String.format() = split(" ").joinToString(" ") { it.firstLetterUppercase().addColor() }
+
+ private fun String.addColor() = when (this) {
+ "Move" -> "§e"
+ "Stand" -> "§e"
+ "Sneak" -> "§5"
+ "Jump" -> "§b"
+ "Punch" -> "§d"
+ else -> "§f"
+ } + this
+
+ @SubscribeEvent
+ fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) {
+ if (!isEnabled()) return
+ config.position.renderStrings(
+ display,
+ config.extraSpace,
+ posLabel = "Dance Room Helper"
+ )
+ }
+
+ @SubscribeEvent
+ fun onWorldChange(event: WorldEvent.Load) {
+ inRoom = false
+ }
+
+ @SubscribeEvent
+ fun onTick(event: LorenzTickEvent) {
+ if (!isEnabled()) return
+ if (event.isMod(10)) {
+ inRoom = danceRoom.isVecInside(Minecraft.getMinecraft().thePlayer.positionVector)
+ }
+ if (inRoom) {
+ update()
+ }
+ }
+
+ @SubscribeEvent
+ fun onSound(event: at.hannibal2.skyhanni.events.PlaySoundEvent) {
+ if (!isEnabled() && !inRoom) return
+ if (event.soundName == "random.burp" && event.volume == 0.8f) {
+ index = 0
+ found = false
+ update()
+ }
+ if (event.soundName == "note.bassattack" && event.pitch == 0.6984127f && event.volume == 1.0f && !found) {
+ found = true
+ start(2000)
+ update()
+ }
+ }
+
+ @SubscribeEvent
+ fun onCheckRender(event: CheckRenderEntityEvent<*>) {
+ if (RiftAPI.inRift() && config.hidePlayers) {
+ val entity = event.entity
+ if (entity is EntityOtherPlayerMP) {
+ if (danceRoom.isVecInside(entity.getLorenzVec().toVec3())) {
+ event.isCanceled = true
+ }
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onRepoReload(event: RepositoryReloadEvent) {
+ event.getConstant<DanceRoomInstructionsJson>("DanceRoomInstructions")?.let {
+ instructions = it.instructions
+ }
+ }
+
+ fun start(interval: Long): Job {
+ return CoroutineScope(Dispatchers.Default).launch {
+ while (NonCancellable.isActive && found) {
+ index++
+ delay(interval)
+ }
+ }
+ }
+
+ fun isEnabled() = RiftAPI.inRift() && config.enabled
+} \ No newline at end of file