aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoringlettronald <inglettronald@gmail.com>2023-07-23 08:59:42 -0500
committeringlettronald <inglettronald@gmail.com>2023-07-23 08:59:42 -0500
commit362f71b14f864c6d86e7c805e51cd64a8194d9fb (patch)
tree6681eed0ecb0564050d74f805a10b78208aa01dc /src
parent6028973423c664e4a4626c577f4884cc4d92cbe0 (diff)
downloadDulkirMod-Fabric-362f71b14f864c6d86e7c805e51cd64a8194d9fb.tar.gz
DulkirMod-Fabric-362f71b14f864c6d86e7c805e51cd64a8194d9fb.tar.bz2
DulkirMod-Fabric-362f71b14f864c6d86e7c805e51cd64a8194d9fb.zip
improved usability of Title Util
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/RenderTest.kt6
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/HudRenderUtil.kt24
2 files changed, 23 insertions, 7 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt b/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt
index d747b93..ac34ede 100644
--- a/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt
+++ b/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt
@@ -1,7 +1,6 @@
package com.dulkirfabric.features
import com.dulkirfabric.events.EntityLoadEvent
-import com.dulkirfabric.events.HudRenderEvent
import com.dulkirfabric.events.WorldRenderLastEvent
import com.dulkirfabric.util.WorldRenderUtils
import meteordevelopment.orbit.EventHandler
@@ -31,9 +30,4 @@ object RenderTest {
//if (event.entity !is GlowingEntityInterface) return
//event.entity.setDulkirEntityGlow(true, Color(0, 0, 255, 255),false)
}
-
- @EventHandler
- fun onHudRender(event: HudRenderEvent) {
- // HudRenderUtil.drawTitle(event.context, Text.literal("Hello World!"))
- }
} \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/util/HudRenderUtil.kt b/src/main/kotlin/com/dulkirfabric/util/HudRenderUtil.kt
index 02b79f7..327afdd 100644
--- a/src/main/kotlin/com/dulkirfabric/util/HudRenderUtil.kt
+++ b/src/main/kotlin/com/dulkirfabric/util/HudRenderUtil.kt
@@ -1,11 +1,18 @@
package com.dulkirfabric.util
import com.dulkirfabric.DulkirModFabric.mc
+import com.dulkirfabric.events.HudRenderEvent
+import meteordevelopment.orbit.EventHandler
import net.minecraft.client.gui.DrawContext
import net.minecraft.text.Text
+import java.time.Duration
object HudRenderUtil {
- fun drawTitle(context: DrawContext, content: Text) {
+
+ private var curTitle: Text? = null
+ private var clearTime: Long = -1
+
+ private fun drawTitle(context: DrawContext, content: Text) {
val matrices = context.matrices
val tr = mc.textRenderer
val w = tr.getWidth(content)
@@ -16,4 +23,19 @@ object HudRenderUtil {
context.drawText(tr, content, 0, -tr.fontHeight / 2, -1, true)
matrices.pop()
}
+
+ fun drawTitle(content: Text, duration: Duration) {
+ curTitle = content
+ clearTime = System.currentTimeMillis() + duration.toMillis()
+ }
+
+ @EventHandler
+ fun onHudRender(event: HudRenderEvent) {
+ val content = curTitle ?: return
+ if (System.currentTimeMillis() >= clearTime) {
+ curTitle = null
+ return
+ }
+ drawTitle(event.context, content)
+ }
} \ No newline at end of file