diff options
author | inglettronald <inglettronald@gmail.com> | 2023-07-22 22:07:46 -0500 |
---|---|---|
committer | inglettronald <inglettronald@gmail.com> | 2023-07-22 22:07:46 -0500 |
commit | 4e8e3ae91f8be1906c298bf7b0aceb1b39d083d3 (patch) | |
tree | 435f9ad0f0319a28f1e5e2a9bc3a5ec188c0cb57 | |
parent | e3f9d34e8ad5ff1effcba2cc39c7f375edaab115 (diff) | |
download | DulkirMod-Fabric-4e8e3ae91f8be1906c298bf7b0aceb1b39d083d3.tar.gz DulkirMod-Fabric-4e8e3ae91f8be1906c298bf7b0aceb1b39d083d3.tar.bz2 DulkirMod-Fabric-4e8e3ae91f8be1906c298bf7b0aceb1b39d083d3.zip |
wip
5 files changed, 47 insertions, 3 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/Registrations.kt b/src/main/kotlin/com/dulkirfabric/Registrations.kt index d4be8b0..04eb9d8 100644 --- a/src/main/kotlin/com/dulkirfabric/Registrations.kt +++ b/src/main/kotlin/com/dulkirfabric/Registrations.kt @@ -15,6 +15,7 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientEntityEvents import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents import net.fabricmc.fabric.api.client.message.v1.ClientSendMessageEvents +import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents import net.fabricmc.fabric.api.client.screen.v1.ScreenMouseEvents @@ -106,5 +107,8 @@ object Registrations { ServerWorldEvents.LOAD.register { server, world -> WorldLoadEvent(server, world).post() } + HudRenderCallback.EVENT.register { context, delta -> + HudRenderEvent(context, delta).post() + } } }
\ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt index 99eec24..8fc0285 100644 --- a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt +++ b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt @@ -169,7 +169,7 @@ class DulkirConfig { ) animations.addEntry( entryBuilder.startIntSlider(Text.literal("posY"), configOptions.animationPreset.posY, -150, 150) - .setSaveConsumer { newValue -> configOptions.animationPreset.posZ = newValue } + .setSaveConsumer { newValue -> configOptions.animationPreset.posY = newValue } .setDefaultValue(0) .build() ) diff --git a/src/main/kotlin/com/dulkirfabric/events/HudRenderEvent.kt b/src/main/kotlin/com/dulkirfabric/events/HudRenderEvent.kt new file mode 100644 index 0000000..51895ee --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/events/HudRenderEvent.kt @@ -0,0 +1,9 @@ +package com.dulkirfabric.events + +import com.dulkirfabric.events.base.Event +import net.minecraft.client.gui.DrawContext + +data class HudRenderEvent( + val context: DrawContext, + val delta: Float +): Event() diff --git a/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt b/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt index 4799e0c..6d64bac 100644 --- a/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt +++ b/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt @@ -1,10 +1,14 @@ package com.dulkirfabric.features +import com.dulkirfabric.DulkirModFabric.mc import com.dulkirfabric.events.EntityLoadEvent +import com.dulkirfabric.events.HudRenderEvent import com.dulkirfabric.events.WorldRenderLastEvent import com.dulkirfabric.util.GlowingEntityInterface +import com.dulkirfabric.util.HudRenderUtil import com.dulkirfabric.util.WorldRenderUtils import meteordevelopment.orbit.EventHandler +import net.minecraft.client.gui.DrawContext import net.minecraft.text.Style import net.minecraft.text.Text import net.minecraft.util.math.Vec3d @@ -23,11 +27,17 @@ object RenderTest { // if (it is GlowingEntityInterface) // it.setDulkirEntityGlow(true, Color(255, 255, 255, 255), Random(it.id).nextBoolean()) // } + //HudRenderUtil.drawTitle(event.context, Text.literal("Hello World!")) } @EventHandler fun onLoadEnt(event: EntityLoadEvent) { - if (event.entity !is GlowingEntityInterface) return - event.entity.setDulkirEntityGlow(true, Color(0, 0, 255, 255),false) + //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 new file mode 100644 index 0000000..40840d9 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/util/HudRenderUtil.kt @@ -0,0 +1,21 @@ +package com.dulkirfabric.util + +import com.dulkirfabric.DulkirModFabric.mc +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext +import net.minecraft.client.font.TextRenderer +import net.minecraft.client.gui.DrawContext +import net.minecraft.text.Text + +object HudRenderUtil { + fun drawTitle(context: DrawContext, content: Text) { + val matrices = context.matrices + val tr = mc.textRenderer + val w = tr.getWidth(content) + val sf: Float = mc.window.scaledWidth / w.toFloat() + matrices.push() + matrices.translate(mc.currentScreen!!.width / 3f, mc.window.scaledHeight / 2f, + 0f) + matrices.scale(sf, sf, 1f) + context.drawText(tr, content, 0, -tr.fontHeight / 2, -1, true) + } +}
\ No newline at end of file |