Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameTags fixes #798

Merged
merged 8 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/main/java/net/wurstclient/hacks/NameTagsHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,29 @@ 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()
{
super("NameTags");
setCategory(Category.RENDER);
addSetting(unlimitedRange);
addSetting(seeThrough);
addSetting(forceNametags);
addSetting(forceMobNametags);
addSetting(forcePlayerNametags);
}

public boolean isUnlimitedRange()
Expand All @@ -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
}
14 changes: 7 additions & 7 deletions src/main/java/net/wurstclient/mixin/EntityRendererMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ private void shouldForceLabel(LivingEntity entity,
CallbackInfoReturnable<Boolean> cir)
{
// return true immediately after the distance check
if(WurstClient.INSTANCE.getHax().nameTagsHack.shouldForceNametags())
if(WurstClient.INSTANCE.getHax().nameTagsHack
.shouldForcePlayerNametags())
cir.setReturnValue(true);
}
}
38 changes: 38 additions & 0 deletions src/main/java/net/wurstclient/mixin/MobEntityRendererMixin.java
Original file line number Diff line number Diff line change
@@ -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<Boolean> cir)
{
// skip the mobEntity == dispatcher.targetedEntity check and return true
if(WurstClient.INSTANCE.getHax().nameTagsHack.shouldForceMobNametags())
cir.setReturnValue(true);
}
}
1 change: 1 addition & 0 deletions src/main/resources/wurst.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"LanguageManagerMixin",
"LivingEntityRendererMixin",
"MinecraftClientMixin",
"MobEntityRendererMixin",
"MouseMixin",
"MultiplayerScreenMixin",
"PackScreenMixin",
Expand Down