diff --git a/src/main/java/net/wurstclient/hacks/NameTagsHack.java b/src/main/java/net/wurstclient/hacks/NameTagsHack.java index 6e787e8016..f64b8a3569 100644 --- a/src/main/java/net/wurstclient/hacks/NameTagsHack.java +++ b/src/main/java/net/wurstclient/hacks/NameTagsHack.java @@ -22,13 +22,20 @@ public final class NameTagsHack extends Hack private final CheckboxSetting seeThrough = new CheckboxSetting( "See-through mode", "Renders nametags on the see-through text layer. This makes them" - + " easier to read behind walls, but harder to read behind water" - + " and other transparent things.", + + " easier to read behind walls, but causes some graphical glitches" + + " with water and other transparent things.", false); - private final CheckboxSetting forceNametags = new CheckboxSetting( - "Force nametags", - "Forces nametags of all players to be visible, even your own.", false); + private final CheckboxSetting forceMobNametags = new CheckboxSetting( + "Always show named mobs", "Displays the nametags of named mobs even" + + " when you are not looking directly at them.", + true); + + private final CheckboxSetting forcePlayerNametags = + new CheckboxSetting("Always show player names", + "Displays your own nametag as well as any player names that would" + + " normally be disabled by scoreboard team settings.", + false); public NameTagsHack() { @@ -36,7 +43,8 @@ public NameTagsHack() setCategory(Category.RENDER); addSetting(unlimitedRange); addSetting(seeThrough); - addSetting(forceNametags); + addSetting(forceMobNametags); + addSetting(forcePlayerNametags); } public boolean isUnlimitedRange() @@ -49,11 +57,16 @@ public boolean isSeeThrough() return isEnabled() && seeThrough.isChecked(); } - public boolean shouldForceNametags() + public boolean shouldForceMobNametags() + { + return isEnabled() && forceMobNametags.isChecked(); + } + + public boolean shouldForcePlayerNametags() { - return isEnabled() && forceNametags.isChecked(); + return isEnabled() && forcePlayerNametags.isChecked(); } - // See LivingEntityRendererMixin and - // EntityRendererMixin.wurstRenderLabelIfPresent() + // See EntityRendererMixin.wurstRenderLabelIfPresent(), + // LivingEntityRendererMixin, MobEntityRendererMixin } diff --git a/src/main/java/net/wurstclient/mixin/EntityRendererMixin.java b/src/main/java/net/wurstclient/mixin/EntityRendererMixin.java index c8acb3fd70..f047a1f042 100644 --- a/src/main/java/net/wurstclient/mixin/EntityRendererMixin.java +++ b/src/main/java/net/wurstclient/mixin/EntityRendererMixin.java @@ -93,16 +93,16 @@ protected void wurstRenderLabelIfPresent(T entity, Text text, TextRenderer tr = getTextRenderer(); float labelX = -tr.getWidth(text) / 2; - // draw background - tr.draw(text, labelX, labelY, 0x20FFFFFF, false, matrix, - vertexConsumers, - notSneaky ? TextLayerType.SEE_THROUGH : TextLayerType.NORMAL, - bgColor, light); - - // use the see-through layer for text if configured in NameTags + // adjust layers if using NameTags in see-through mode + TextLayerType bgLayer = notSneaky && !nameTags.isSeeThrough() + ? TextLayerType.SEE_THROUGH : TextLayerType.NORMAL; TextLayerType textLayer = nameTags.isSeeThrough() ? TextLayerType.SEE_THROUGH : TextLayerType.NORMAL; + // draw background + tr.draw(text, labelX, labelY, 0x20FFFFFF, false, matrix, + vertexConsumers, bgLayer, bgColor, light); + // draw text if(notSneaky) tr.draw(text, labelX, labelY, 0xFFFFFFFF, false, matrix, diff --git a/src/main/java/net/wurstclient/mixin/LivingEntityRendererMixin.java b/src/main/java/net/wurstclient/mixin/LivingEntityRendererMixin.java index 1a48b2d383..a937263c9e 100644 --- a/src/main/java/net/wurstclient/mixin/LivingEntityRendererMixin.java +++ b/src/main/java/net/wurstclient/mixin/LivingEntityRendererMixin.java @@ -49,7 +49,8 @@ private void shouldForceLabel(LivingEntity entity, CallbackInfoReturnable cir) { // return true immediately after the distance check - if(WurstClient.INSTANCE.getHax().nameTagsHack.shouldForceNametags()) + if(WurstClient.INSTANCE.getHax().nameTagsHack + .shouldForcePlayerNametags()) cir.setReturnValue(true); } } diff --git a/src/main/java/net/wurstclient/mixin/MobEntityRendererMixin.java b/src/main/java/net/wurstclient/mixin/MobEntityRendererMixin.java new file mode 100644 index 0000000000..0dcc619a1e --- /dev/null +++ b/src/main/java/net/wurstclient/mixin/MobEntityRendererMixin.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2014-2023 Wurst-Imperium and contributors. + * + * This source code is subject to the terms of the GNU General Public + * License, version 3. If a copy of the GPL was not distributed with this + * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt + */ +package net.wurstclient.mixin; + +import org.objectweb.asm.Opcodes; +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.CallbackInfoReturnable; + +import net.minecraft.client.render.entity.MobEntityRenderer; +import net.wurstclient.WurstClient; + +@Mixin(MobEntityRenderer.class) +public abstract class MobEntityRendererMixin +{ + /** + * Makes name-tagged mobs always show their name tags if configured in + * NameTags. + */ + @Inject(at = @At(value = "FIELD", + target = "Lnet/minecraft/client/render/entity/EntityRenderDispatcher;targetedEntity:Lnet/minecraft/entity/Entity;", + opcode = Opcodes.GETFIELD, + ordinal = 0), + method = "hasLabel(Lnet/minecraft/entity/mob/MobEntity;)Z", + cancellable = true) + private void onHasLabel(CallbackInfoReturnable cir) + { + // skip the mobEntity == dispatcher.targetedEntity check and return true + if(WurstClient.INSTANCE.getHax().nameTagsHack.shouldForceMobNametags()) + cir.setReturnValue(true); + } +} diff --git a/src/main/resources/wurst.mixins.json b/src/main/resources/wurst.mixins.json index 4ffd232f11..1b46047239 100644 --- a/src/main/resources/wurst.mixins.json +++ b/src/main/resources/wurst.mixins.json @@ -44,6 +44,7 @@ "LanguageManagerMixin", "LivingEntityRendererMixin", "MinecraftClientMixin", + "MobEntityRendererMixin", "MouseMixin", "MultiplayerScreenMixin", "PackScreenMixin",