From 9436ec1c284fce2d928b718965be9f19b0eea3fa Mon Sep 17 00:00:00 2001 From: yurisuika Date: Thu, 11 Jan 2024 10:01:06 -0800 Subject: [PATCH] chat rendering broke in two, overlay message is taking in everything now isn't it huh --- .../raised/client/gui/RaisedGui.java | 15 +++++++++ .../mixin/client/gui/hud/InGameHudMixin.java | 32 +++++++++++++------ .../client/gui/screen/ChatScreenMixin.java | 27 ++++++++++++++++ src/main/resources/raised.mixins.json | 3 +- 4 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 src/main/java/dev/yurisuika/raised/client/gui/RaisedGui.java create mode 100644 src/main/java/dev/yurisuika/raised/mixin/client/gui/screen/ChatScreenMixin.java diff --git a/src/main/java/dev/yurisuika/raised/client/gui/RaisedGui.java b/src/main/java/dev/yurisuika/raised/client/gui/RaisedGui.java new file mode 100644 index 00000000..09b7da40 --- /dev/null +++ b/src/main/java/dev/yurisuika/raised/client/gui/RaisedGui.java @@ -0,0 +1,15 @@ +package dev.yurisuika.raised.client.gui; + +import net.minecraft.client.gui.DrawContext; + +public class RaisedGui { + + public static void start(DrawContext context, int x, int y, int z) { + context.getMatrices().translate(x, -y, +z); + } + + public static void end(DrawContext context, int x, int y, int z) { + context.getMatrices().translate(x, +y, -z); + } + +} \ No newline at end of file diff --git a/src/main/java/dev/yurisuika/raised/mixin/client/gui/hud/InGameHudMixin.java b/src/main/java/dev/yurisuika/raised/mixin/client/gui/hud/InGameHudMixin.java index 42d3c7e2..9fbbe1fd 100644 --- a/src/main/java/dev/yurisuika/raised/mixin/client/gui/hud/InGameHudMixin.java +++ b/src/main/java/dev/yurisuika/raised/mixin/client/gui/hud/InGameHudMixin.java @@ -10,6 +10,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.invoke.arg.Args; +import static dev.yurisuika.raised.client.gui.RaisedGui.*; import static dev.yurisuika.raised.client.option.RaisedConfig.*; public abstract class InGameHudMixin { @@ -21,48 +22,59 @@ public abstract static class Pre { @Inject(method = "render", at = @At("HEAD")) private void startHeadTranslate(DrawContext context, float tickDelta, CallbackInfo ci) { if (getSupport()) { - context.getMatrices().translate(0, -getHud(), 0); + start(context, 0, getHud(), 0); } } // MAIN HUD @Inject(method = "renderMainHud", at = @At(value = "HEAD")) private void startSpectatorMenuTranslate(DrawContext context, float tickDelta, CallbackInfo ci) { - context.getMatrices().translate(0, -getHud(), 0); + start(context, 0, getHud(), 0); } @Inject(method = "renderMainHud", at = @At(value = "TAIL")) private void endSpectatorMenuTranslate(DrawContext context, float tickDelta, CallbackInfo ci) { - context.getMatrices().translate(0, +getHud(), 0); + end(context, 0, getHud(), 0); } // OVERLAY MESSAGE @Inject(method = "renderOverlayMessage", at = @At(value = "HEAD")) private void startOverlayMessageTranslate(DrawContext context, float tickDelta, CallbackInfo ci) { - context.getMatrices().translate(0, -getHud(), 0); + start(context, 0, getHud(), 0); } @Inject(method = "renderOverlayMessage", at = @At(value = "TAIL")) private void endOverlayMessageTranslate(DrawContext context, float tickDelta, CallbackInfo ci) { - context.getMatrices().translate(0, +getHud(), 0); + end(context, 0, getHud(), 0); + } + + // TITLE AND SUBTITLES + @Inject(method = "renderOverlayMessage", at = @At(value = "HEAD")) + private void startTitleAndSubtitlesTranslate(DrawContext context, float tickDelta, CallbackInfo ci) { + end(context, 0, getHud(), 0); + } + + @Inject(method = "renderOverlayMessage", at = @At(value = "TAIL")) + private void endTitleAndSubtitlesTranslate(DrawContext context, float tickDelta, CallbackInfo ci) { + start(context, 0, getHud(), 0); } // CHAT @Inject(method = "renderChat", at = @At(value = "HEAD")) private void startChatTranslate(DrawContext context, float tickDelta, CallbackInfo ci) { - context.getMatrices().translate(0, -(getSync() ? getHud() : getChat()), +300); + start(context, 0, getSync() ? getHud() : getChat(), 0); } @Inject(method = "renderChat", at = @At(value = "TAIL")) private void endChatTranslate(DrawContext context, float tickDelta, CallbackInfo ci) { - context.getMatrices().translate(0, +(getSync() ? getHud() : getChat()), -300); + end(context, 0, getSync() ? getHud() : getChat(), 0); } // TAIL @Inject(method = "render", at = @At("TAIL")) private void startTailTranslate(DrawContext context, float tickDelta, CallbackInfo ci) { if (getSupport()) { - context.getMatrices().translate(0, -getHud(), 0); + start(context, 0, getHud(), 0); } } @@ -82,7 +94,7 @@ public abstract static class Post { @Inject(method = "render", at = @At("HEAD")) private void endHeadTranslate(DrawContext context, float tickDelta, CallbackInfo ci) { if (getSupport()) { - context.getMatrices().translate(0, +getHud(), 0); + end(context, 0, getHud(), 0); } } @@ -90,7 +102,7 @@ private void endHeadTranslate(DrawContext context, float tickDelta, CallbackInfo @Inject(method = "render", at = @At("TAIL")) private void endTailTranslate(DrawContext context, float tickDelta, CallbackInfo ci) { if (getSupport()) { - context.getMatrices().translate(0, +getHud(), 0); + end(context, 0, getHud(), 0); } } diff --git a/src/main/java/dev/yurisuika/raised/mixin/client/gui/screen/ChatScreenMixin.java b/src/main/java/dev/yurisuika/raised/mixin/client/gui/screen/ChatScreenMixin.java new file mode 100644 index 00000000..6a935a2f --- /dev/null +++ b/src/main/java/dev/yurisuika/raised/mixin/client/gui/screen/ChatScreenMixin.java @@ -0,0 +1,27 @@ +package dev.yurisuika.raised.mixin.client.gui.screen; + +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.ChatScreen; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import static dev.yurisuika.raised.client.gui.RaisedGui.*; +import static dev.yurisuika.raised.client.option.RaisedConfig.*; + +@Mixin(ChatScreen.class) +public class ChatScreenMixin { + + // CHAT + @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/ChatHud;render(Lnet/minecraft/client/gui/DrawContext;IIIZ)V")) + private void startChatTranslate(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) { + start(context, 0, getSync() ? getHud() : getChat(), 0); + } + + @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/ChatHud;render(Lnet/minecraft/client/gui/DrawContext;IIIZ)V", shift = At.Shift.AFTER)) + private void endChatTranslate(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) { + end(context, 0, getSync() ? getHud() : getChat(), 0); + } + +} \ No newline at end of file diff --git a/src/main/resources/raised.mixins.json b/src/main/resources/raised.mixins.json index 478ab2a0..42127225 100644 --- a/src/main/resources/raised.mixins.json +++ b/src/main/resources/raised.mixins.json @@ -9,7 +9,8 @@ "client": [ "client.gui.hud.ChatHudMixin", "client.gui.hud.InGameHudMixin$Post", - "client.gui.hud.InGameHudMixin$Pre" + "client.gui.hud.InGameHudMixin$Pre", + "client.gui.screen.ChatScreenMixin" ], "injectors": { "defaultRequire": 1