aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/dulkirfabric
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/com/dulkirfabric')
-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