diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java | 69 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/rift/DanceRoomHelper.kt | 72 |
2 files changed, 121 insertions, 20 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 d9d90cd35..c88a89b3c 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java @@ -267,6 +267,75 @@ public class RiftConfig { public boolean hidePlayers = false; @Expose + @ConfigOption(name = "Hide Title", desc = "Hide Instructions, \"§aIt's happening!\" §7and \"§aKeep it up!\" §7titles.") + @ConfigEditorBoolean + public boolean hideOriginalTitle = false; + + @Expose + @ConfigOption(name = "Formatting", desc = "") + @Accordion + public DanceRoomFormatting danceRoomFormatting = new DanceRoomFormatting(); + + public static class DanceRoomFormatting { + + @Expose + @ConfigOption(name = "Now", desc = "Formatting for \"Now:\"") + @ConfigEditorText + public String now = "&7Now:"; + + @Expose + @ConfigOption(name = "Next", desc = "Formatting for \"Next:\"") + @ConfigEditorText + public String next = "&7Next:"; + + @Expose + @ConfigOption(name = "Later", desc = "Formatting for \"Later:\"") + @ConfigEditorText + public String later = "&7Later:"; + + @Expose + @ConfigOption(name = "Color Option", desc = "") + @Accordion + public Color color = new Color(); + public static class Color { + @Expose + @ConfigOption(name = "Move", desc = "Color for the Move instruction") + @ConfigEditorText + public String move = "&e"; + + @Expose + @ConfigOption(name = "Stand", desc = "Color for the Stand instruction") + @ConfigEditorText + public String stand = "&e"; + + @Expose + @ConfigOption(name = "Sneak", desc = "Color for the Sneak instruction") + @ConfigEditorText + public String sneak = "&5"; + + @Expose + @ConfigOption(name = "Jump", desc = "Color for the Jump instruction") + @ConfigEditorText + public String jump = "&b"; + + @Expose + @ConfigOption(name = "Punch", desc = "Color for the Punch instruction") + @ConfigEditorText + public String punch = "&d"; + + @Expose + @ConfigOption(name = "Countdown", desc = "Color for the Countdown") + @ConfigEditorText + public String countdown = "&f"; + + @Expose + @ConfigOption(name = "Default", desc = "Fallback color") + @ConfigEditorText + public String fallback = "&f"; + } + } + + @Expose public Position position = new Position(442, 239, false, true); } 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) } } |