aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/DanceRoomHelper.kt72
1 files changed, 52 insertions, 20 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
index 6931cbd3b..9cc152e7f 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/rift/DanceRoomHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/DanceRoomHelper.kt
@@ -2,16 +2,14 @@ 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.events.*
import at.hannibal2.skyhanni.utils.LocationUtils.isPlayerInside
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase
import at.hannibal2.skyhanni.utils.jsonobjects.DanceRoomInstructionsJson
import kotlinx.coroutines.*
import net.minecraft.client.entity.EntityOtherPlayerMP
+import net.minecraft.network.play.server.S45PacketTitle
import net.minecraft.util.AxisAlignedBB
import net.minecraftforge.event.world.WorldEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -25,6 +23,7 @@ object DanceRoomHelper {
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>()
+ private var countdown: String? = null
fun update() {
display = buildList {
@@ -32,27 +31,29 @@ object DanceRoomHelper {
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()}")
+ for ((lineIndex, line) in instructions.withIndex()) {
+ if (line != null) {
+ if (index < instructions.size && index == lineIndex) {
+ add("${config.danceRoomFormatting.now.replace("&", "§")} ${line.format()} ${if (countdown != null) "${config.danceRoomFormatting.color.countdown.replace("&", "§")}$countdown" else ""}")
+ } else if (index + 1 < instructions.size && index + 1 == lineIndex) {
+ add("${config.danceRoomFormatting.next.replace("&", "§")} ${line.format()}")
+ } else if (index + 2 < instructions.size && (index + 2..index + config.lineToShow).contains(lineIndex)) {
+ add("${config.danceRoomFormatting.later.replace("&", "§")} ${line.format()}")
+ }
}
}
}
}
- private fun String.format() = split(" ").joinToString(" ") { it.firstLetterUppercase().addColor() }
+ private fun String.format() = split(" ").joinToString(" ") { it.firstLetterUppercase().addColor().replace("&", "§") }
private fun String.addColor() = when (this) {
- "Move" -> "§e"
- "Stand" -> "§e"
- "Sneak" -> "§5"
- "Jump" -> "§b"
- "Punch" -> "§d"
- else -> "§f"
+ "Move" -> config.danceRoomFormatting.color.move
+ "Stand" -> config.danceRoomFormatting.color.stand
+ "Sneak" -> config.danceRoomFormatting.color.sneak
+ "Jump" -> config.danceRoomFormatting.color.jump
+ "Punch" -> config.danceRoomFormatting.color.punch
+ else -> config.danceRoomFormatting.color.fallback
} + this
@SubscribeEvent
@@ -83,11 +84,12 @@ object DanceRoomHelper {
}
@SubscribeEvent
- fun onSound(event: at.hannibal2.skyhanni.events.PlaySoundEvent) {
+ fun onSound(event: PlaySoundEvent) {
if (!isEnabled() || !inRoom) return
- if (event.soundName == "random.burp" && event.volume == 0.8f) {
+ if ((event.soundName == "random.burp" && event.volume == 0.8f) || (event.soundName == "random.levelup" && event.pitch == 1.8412699f && event.volume == 1.0f)) {
index = 0
found = false
+ countdown = null
update()
}
if (event.soundName == "note.bassattack" && event.pitch == 0.6984127f && event.volume == 1.0f && !found) {
@@ -98,6 +100,35 @@ object DanceRoomHelper {
}
@SubscribeEvent
+ fun onPacket(event: PacketEvent.ReceiveEvent) {
+ if (!isEnabled()) return
+ val packet = event.packet
+ if (packet !is S45PacketTitle) return
+ if (config.hideOriginalTitle && inRoom) event.isCanceled = true
+ }
+
+ private fun startCountdown(seconds: Int, milliseconds: Int) {
+ if (seconds <= 0 && milliseconds <= 0) {
+ countdown = null
+ return
+ }
+
+ val countdownString = "%01d:%03d".format(seconds, milliseconds)
+ countdown = countdownString
+
+ CoroutineScope(Dispatchers.Default).launch {
+ delay(1)
+ var updatedSeconds = seconds
+ var updatedMilliseconds = milliseconds - 1
+ if (updatedMilliseconds < 0) {
+ updatedSeconds -= 1
+ updatedMilliseconds += 1000
+ }
+ startCountdown(updatedSeconds, updatedMilliseconds)
+ }
+ }
+
+ @SubscribeEvent
fun onCheckRender(event: CheckRenderEntityEvent<*>) {
if (RiftAPI.inRift() && config.hidePlayers) {
val entity = event.entity
@@ -120,6 +151,7 @@ object DanceRoomHelper {
return CoroutineScope(Dispatchers.Default).launch {
while (NonCancellable.isActive && found) {
index++
+ startCountdown(0, 500)
delay(interval)
}
}