diff options
author | Appability <appable@icloud.com> | 2022-10-13 18:58:00 -0700 |
---|---|---|
committer | Appability <appable@icloud.com> | 2022-10-13 18:58:00 -0700 |
commit | d0cbc11018c8126575117aaeb2b861957386fa9a (patch) | |
tree | c5419fb1f00b147604bded231c1388d6b391d27e /src/main/kotlin/com/ambientaddons/features/display/WitherShieldOverlay.kt | |
parent | c599ee0d78ed8bc17488636f2d9b9b1d5b6dd4a8 (diff) | |
download | AmbientAddons-d0cbc11018c8126575117aaeb2b861957386fa9a.tar.gz AmbientAddons-d0cbc11018c8126575117aaeb2b861957386fa9a.tar.bz2 AmbientAddons-d0cbc11018c8126575117aaeb2b861957386fa9a.zip |
steal a bunch of code from sbc! +melodyhelper, kuudra ready, wither shield overlay
Diffstat (limited to 'src/main/kotlin/com/ambientaddons/features/display/WitherShieldOverlay.kt')
-rw-r--r-- | src/main/kotlin/com/ambientaddons/features/display/WitherShieldOverlay.kt | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/main/kotlin/com/ambientaddons/features/display/WitherShieldOverlay.kt b/src/main/kotlin/com/ambientaddons/features/display/WitherShieldOverlay.kt new file mode 100644 index 0000000..fa210aa --- /dev/null +++ b/src/main/kotlin/com/ambientaddons/features/display/WitherShieldOverlay.kt @@ -0,0 +1,41 @@ +package com.ambientaddons.features.display + +import AmbientAddons.Companion.config +import AmbientAddons.Companion.mc +import com.ambientaddons.utils.Alignment +import com.ambientaddons.utils.render.OverlayUtils +import com.ambientaddons.utils.SkyBlock +import com.ambientaddons.utils.dungeon.TextStyle +import net.minecraft.client.gui.ScaledResolution +import net.minecraftforge.client.event.ClientChatReceivedEvent +import net.minecraftforge.client.event.RenderGameOverlayEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.math.ceil +import kotlin.math.roundToInt + +object WitherShieldOverlay { + private var witherImpactEndTime = 0L + + @SubscribeEvent + fun onRenderOverlay(event: RenderGameOverlayEvent) { + if (event.type != RenderGameOverlayEvent.ElementType.TEXT) return + if (!SkyBlock.inSkyblock || config.witherShieldDisplay == 0) return + val diff = ((witherImpactEndTime - System.currentTimeMillis()) / 1000.0).takeIf { it >= 0 } ?: return + val display = ceil(diff).roundToInt().toString() + val resolution = ScaledResolution(mc) + val x = resolution.scaledWidth / 2 + 1 + val y = resolution.scaledHeight / 2 + 10 + val style = TextStyle.fromInt(config.witherShieldDisplay - 1) ?: return + OverlayUtils.drawString(x, y, display, style, Alignment.Center) + } + + @SubscribeEvent + fun onChat(event: ClientChatReceivedEvent) { + if (!SkyBlock.inSkyblock || config.witherShieldDisplay == 0) return + if (event.type == 2.toByte() && event.message.unformattedText.contains("Wither Impact")) { + if (((witherImpactEndTime - System.currentTimeMillis()) / 1000.0) < 0) { + witherImpactEndTime = System.currentTimeMillis() + 5000 + } + } + } +}
\ No newline at end of file |