From 40ce5c3324181b945a2412846f1622a7c82a4d96 Mon Sep 17 00:00:00 2001 From: 0xTas Date: Sat, 28 Dec 2024 23:34:08 -0800 Subject: [PATCH] Added override option to Meteor's Nametags module to force rendering nametags with the default font (cherry picked from commit 3242f4b86b6f7b59c238bf6d8ee3d401c083092f) --- .../dev/stardust/mixin/NametagsMixin.java | 77 +++++++++++++++++++ src/main/resources/stardust.mixins.json | 1 + 2 files changed, 78 insertions(+) create mode 100644 src/main/java/dev/stardust/mixin/NametagsMixin.java diff --git a/src/main/java/dev/stardust/mixin/NametagsMixin.java b/src/main/java/dev/stardust/mixin/NametagsMixin.java new file mode 100644 index 0000000..a40e906 --- /dev/null +++ b/src/main/java/dev/stardust/mixin/NametagsMixin.java @@ -0,0 +1,77 @@ +package dev.stardust.mixin; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.jetbrains.annotations.Nullable; +import com.llamalad7.mixinextras.sugar.Local; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; +import meteordevelopment.meteorclient.settings.Setting; +import meteordevelopment.meteorclient.settings.BoolSetting; +import meteordevelopment.meteorclient.settings.SettingGroup; +import meteordevelopment.meteorclient.systems.modules.Module; +import meteordevelopment.meteorclient.systems.modules.Category; +import meteordevelopment.meteorclient.renderer.text.TextRenderer; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import meteordevelopment.meteorclient.systems.modules.render.Nametags; +import meteordevelopment.meteorclient.renderer.text.VanillaTextRenderer; + +/** + * @author Tas [@0xTas] + * Allows use of default font for Nametags even when custom font is chosen in the global config. + **/ +@Mixin(value = Nametags.class, remap = false) +public abstract class NametagsMixin extends Module { + @Shadow + @Final + private SettingGroup sgGeneral; + + public NametagsMixin(Category category, String name, String description) { + super(category, name, description); + } + + @Unique + private @Nullable Setting forceDefaultFont = null; + + @Inject(method = "", at = @At(value = "FIELD", target = "Lmeteordevelopment/meteorclient/systems/modules/render/Nametags;scale:Lmeteordevelopment/meteorclient/settings/Setting;", shift = At.Shift.AFTER)) + private void addDefaultFontSettings(CallbackInfo ci) { + forceDefaultFont = sgGeneral.add( + new BoolSetting.Builder() + .name("force-default-font") + .description("Force nametags to render using the default font, even if a custom GUI font is selected in your Meteor config.") + .defaultValue(false) + .build() + ); + } + + @Inject(method = "renderNametagPlayer", at = @At(value = "INVOKE", target = "Lmeteordevelopment/meteorclient/systems/modules/render/Nametags;drawBg(DDDD)V")) + private void injectDefaultFontForPlayerNametags(CallbackInfo ci, @Local LocalRef text) { + if (forceDefaultFont != null && forceDefaultFont.get()) { + text.set(VanillaTextRenderer.INSTANCE); + } + } + + @Inject(method = "renderNametagItem", at = @At(value = "INVOKE", target = "Lmeteordevelopment/meteorclient/systems/modules/render/Nametags;drawBg(DDDD)V")) + private void injectDefaultFontForItemNametags(CallbackInfo ci, @Local LocalRef text) { + if (forceDefaultFont != null && forceDefaultFont.get()) { + text.set(VanillaTextRenderer.INSTANCE); + } + } + + @Inject(method = "renderGenericNametag", at = @At(value = "INVOKE", target = "Lmeteordevelopment/meteorclient/systems/modules/render/Nametags;drawBg(DDDD)V")) + private void injectDefaultFontForGenericNametags(CallbackInfo ci, @Local LocalRef text) { + if (forceDefaultFont != null && forceDefaultFont.get()) { + text.set(VanillaTextRenderer.INSTANCE); + } + } + + @Inject(method = "renderTntNametag", at = @At(value = "INVOKE", target = "Lmeteordevelopment/meteorclient/systems/modules/render/Nametags;drawBg(DDDD)V")) + private void injectDefaultFontForTNTNametags(CallbackInfo ci, @Local LocalRef text) { + if (forceDefaultFont != null && forceDefaultFont.get()) { + text.set(VanillaTextRenderer.INSTANCE); + } + } +} diff --git a/src/main/resources/stardust.mixins.json b/src/main/resources/stardust.mixins.json index ad1a980..1666677 100644 --- a/src/main/resources/stardust.mixins.json +++ b/src/main/resources/stardust.mixins.json @@ -40,6 +40,7 @@ "WorldMixin", "EntityMixin", "FreecamMixin", + "NametagsMixin", "AutoMendMixin", "NoRenderMixin", "ItemStackMixin",