1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
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!"
private val timeUntilBreak: Double
get() = 20.0 - ((System.currentTimeMillis() - lastPickedUpBow) / 1000.0)
@SubscribeEvent
fun onChat(event: ClientChatReceivedEvent) {
if (SBLocation.dungeonFloor?.floor != 4) return
if (event.message.unformattedText.stripControlCodes() == bowPickedUpString && timeUntilBreak < 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
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()
}
}
}
|