aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/ambientaddons/features/display/ThornOverlay.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/com/ambientaddons/features/display/ThornOverlay.kt')
-rw-r--r--src/main/kotlin/com/ambientaddons/features/display/ThornOverlay.kt68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/main/kotlin/com/ambientaddons/features/display/ThornOverlay.kt b/src/main/kotlin/com/ambientaddons/features/display/ThornOverlay.kt
new file mode 100644
index 0000000..70a5d2e
--- /dev/null
+++ b/src/main/kotlin/com/ambientaddons/features/display/ThornOverlay.kt
@@ -0,0 +1,68 @@
+package com.ambientaddons.features.display
+
+import AmbientAddons.Companion.config
+import AmbientAddons.Companion.mc
+import com.ambientaddons.gui.GuiElement
+import com.ambientaddons.gui.MoveGui
+import com.ambientaddons.utils.Alignment
+import com.ambientaddons.utils.Extensions.stripControlCodes
+import com.ambientaddons.utils.SBLocation
+import com.ambientaddons.utils.dungeon.TextStyle
+import com.ambientaddons.utils.render.OverlayUtils
+import net.minecraft.client.renderer.GlStateManager
+import net.minecraftforge.client.event.ClientChatReceivedEvent
+import net.minecraftforge.client.event.RenderGameOverlayEvent
+import net.minecraftforge.event.world.WorldEvent
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.math.roundToInt
+
+object ThornOverlay {
+ val element = GuiElement("thorn", 50, 10)
+ private var lastPickedUpBow: Long = -1
+ private const val bowPickedUpString = "You picked up the Spirit Bow! Use it to attack Thorn!"
+
+ @SubscribeEvent
+ fun onChat(event: ClientChatReceivedEvent) {
+ if (SBLocation.dungeonFloor?.floor != 4) return
+ if (event.message.unformattedText.stripControlCodes() == bowPickedUpString && lastPickedUpBow < 0) {
+ lastPickedUpBow = System.currentTimeMillis()
+ }
+ }
+
+ @SubscribeEvent
+ fun onWorldUnload(event: WorldEvent.Unload) {
+ lastPickedUpBow = -1
+ }
+
+ private fun colorizeTime(time: Double) = when {
+ (time < 3) -> "§c"
+ (time < 5) -> "§e"
+ else -> "§a"
+ }
+
+ @SubscribeEvent
+ fun onRenderOverlay(event: RenderGameOverlayEvent) {
+ if (event.type != RenderGameOverlayEvent.ElementType.TEXT) return
+ val textStyle = TextStyle.fromInt(config.spiritBowTimer - 1) ?: TextStyle.Outline
+ val timeUntilBreak = 20.0 - ((System.currentTimeMillis() - lastPickedUpBow) / 1000.0)
+ if (config.spiritBowTimer != 0 && SBLocation.dungeonFloor?.floor == 4) {
+ if (timeUntilBreak > 0) {
+ val timeString = "${colorizeTime(timeUntilBreak)}%.2f".format(timeUntilBreak)
+ GlStateManager.pushMatrix()
+ GlStateManager.translate(element.position.x, element.position.y, 500.0)
+ GlStateManager.scale(element.position.scale, element.position.scale, 1.0)
+ OverlayUtils.drawString(0, 0, "§bBow:", textStyle, Alignment.Left)
+ OverlayUtils.drawString(50, 0, timeString, textStyle, Alignment.Right)
+ GlStateManager.popMatrix()
+ }
+ } else if (mc.currentScreen is MoveGui) {
+ val timeString = "§e4.98"
+ GlStateManager.pushMatrix()
+ GlStateManager.translate(element.position.x, element.position.y, 500.0)
+ GlStateManager.scale(element.position.scale, element.position.scale, 1.0)
+ OverlayUtils.drawString(0, 0, "§bBow:", textStyle, Alignment.Left)
+ OverlayUtils.drawString(50, 0, timeString, textStyle, Alignment.Right)
+ GlStateManager.popMatrix()
+ }
+ }
+} \ No newline at end of file