diff options
author | inglettronald <inglettronald@gmail.com> | 2023-07-23 08:59:42 -0500 |
---|---|---|
committer | inglettronald <inglettronald@gmail.com> | 2023-07-23 08:59:42 -0500 |
commit | 362f71b14f864c6d86e7c805e51cd64a8194d9fb (patch) | |
tree | 6681eed0ecb0564050d74f805a10b78208aa01dc | |
parent | 6028973423c664e4a4626c577f4884cc4d92cbe0 (diff) | |
download | DulkirMod-Fabric-362f71b14f864c6d86e7c805e51cd64a8194d9fb.tar.gz DulkirMod-Fabric-362f71b14f864c6d86e7c805e51cd64a8194d9fb.tar.bz2 DulkirMod-Fabric-362f71b14f864c6d86e7c805e51cd64a8194d9fb.zip |
improved usability of Title Util
-rw-r--r-- | build.gradle | 4 | ||||
-rw-r--r-- | src/main/kotlin/com/dulkirfabric/features/RenderTest.kt | 6 | ||||
-rw-r--r-- | src/main/kotlin/com/dulkirfabric/util/HudRenderUtil.kt | 24 |
3 files changed, 27 insertions, 7 deletions
diff --git a/build.gradle b/build.gradle index 7ed61c6..b46b1dd 100644 --- a/build.gradle +++ b/build.gradle @@ -23,6 +23,7 @@ repositories { // for more information about repositories. maven { url = "https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1" } maven { url "https://repo.nea.moe/mirror" } + maven { url "https://repo.nea.moe/releases/" } maven { url "https://maven.shedaniel.me/" } maven { url "https://maven.terraformersmc.com/releases/" } maven { url = "https://jitpack.io/" } @@ -42,6 +43,9 @@ dependencies { include "com.github.llamalad7.mixinextras:mixinextras-fabric:0.2.0-beta.9" implementation "com.github.llamalad7.mixinextras:mixinextras-fabric:0.2.0-beta.9" annotationProcessor "com.github.llamalad7.mixinextras:mixinextras-fabric:0.2.0-beta.9" + modImplementation("moe.nea.jarvis:jarvis-api:1.0.0") + include("moe.nea.jarvis:jarvis-fabric:1.0.0") + modLocalRuntime("moe.nea.jarvis:jarvis-fabric:1.0.0") } loom { 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 |