Skip to content

Commit

Permalink
better nametag
Browse files Browse the repository at this point in the history
  • Loading branch information
AutumnVN committed Jul 10, 2024
1 parent db788e1 commit 3af6adc
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/client/java/autumnvn/autumn/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Options {
public SimpleOption<Boolean> autoAttack;
public SimpleOption<Boolean> ignorePlayer;
public SimpleOption<Boolean> betterChat;
public SimpleOption<Boolean> betterNametag;
public SimpleOption<Boolean> fullBright;
public SimpleOption<Boolean> horseSwim;
public SimpleOption<Boolean> infoHud;
Expand All @@ -50,6 +51,8 @@ public Options() {
options.put("ignorePlayer", ignorePlayer);
betterChat = SimpleOption.ofBoolean("Better Chat", value -> Tooltip.of(Text.of("Lengthen chat history to 65535 lines, keep chat/command history on switching world/server & remove chat indicator")), true);
options.put("betterChat", betterChat);
betterNametag = SimpleOption.ofBoolean("Better Nametag", value -> Tooltip.of(Text.of("Add health & gamemode to nametag, make nametag always visible & show targeted entity nametag")), true);
options.put("betterNametag", betterNametag);
fullBright = SimpleOption.ofBoolean("Full Bright", value -> Tooltip.of(Text.of("No more darkness")), true);
options.put("fullBright", fullBright);
horseSwim = SimpleOption.ofBoolean("Horse Swim", value -> Tooltip.of(Text.of("Make riding horse swim in water")), true);
Expand Down
1 change: 1 addition & 0 deletions src/client/java/autumnvn/autumn/SettingsScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class SettingsScreen extends Screen {
AutumnClient.options.autoAttack,
AutumnClient.options.ignorePlayer,
AutumnClient.options.betterChat,
AutumnClient.options.betterNametag,
AutumnClient.options.fullBright,
AutumnClient.options.horseSwim,
AutumnClient.options.infoHud,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package autumnvn.autumn.mixin.client;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
import autumnvn.autumn.AutumnClient;
import autumnvn.autumn.Utils;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.Text;

@Mixin(EntityRenderer.class)
public class EntityRendererMixin<T extends Entity> {

@Shadow
private void renderLabelIfPresent(T entity, Text text, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) {}

// BetterNametag
@Inject(method = "render", at = @At("HEAD"), cancellable = true)
private void render(T entity, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
if (AutumnClient.options.betterNametag.getValue() && entity instanceof LivingEntity livingEntity && (livingEntity instanceof PlayerEntity || livingEntity == Utils.getTargetedEntity(tickDelta))) {
float health = livingEntity.getHealth() + livingEntity.getAbsorptionAmount();
renderLabelIfPresent(entity, Text.of(String.format("%s %s%.0f§c❤%s",
livingEntity.getDisplayName().getString(),
Utils.color(health, 0, livingEntity.getMaxHealth()),
health,
livingEntity instanceof PlayerEntity playerEntity ? (playerEntity.isCreative() ? " §r[C]" : playerEntity.isSpectator() ? " §r[S]" : "") : "")), matrices, vertexConsumers, light);
ci.cancel();
}
}

@ModifyVariable(method = "renderLabelIfPresent", at = @At("STORE"), ordinal = 0)
private double d(double original) {
return AutumnClient.options.betterNametag.getValue() ? 0 : original;
}

@ModifyVariable(method = "renderLabelIfPresent", at = @At("STORE"), ordinal = 0)
private boolean bl(boolean original) {
return AutumnClient.options.betterNametag.getValue() ? true : original;
}

@ModifyArgs(method = "renderLabelIfPresent", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/TextRenderer;draw(Lnet/minecraft/text/Text;FFIZLorg/joml/Matrix4f;Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/font/TextRenderer$TextLayerType;II)I"))
private void draw(Args args) {
if (AutumnClient.options.betterNametag.getValue()) {
args.set(3, 0xffffffff);
}
}
}
1 change: 1 addition & 0 deletions src/client/resources/autumn.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"ClientPlayerInteractionManagerMixin",
"ClientPlayNetworkHandlerMixin",
"EntityMixin",
"EntityRendererMixin",
"FishingBobberEntityRendererMixin",
"GameRendererMixin",
"InGameHudMixin",
Expand Down

0 comments on commit 3af6adc

Please sign in to comment.