Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
1.2.0 - bg color and fix config/logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MicrocontrollersDev committed Jan 21, 2024
1 parent 6e9c28c commit becb29c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.20.1+build.10
loader_version=0.14.21

# Mod Properties
mod_version=1.1.0
mod_version=1.2.0
maven_group=dev.microcontrollers.nametagtweaks
archives_base_name=nametagtweaks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@
import dev.isxander.yacl3.api.Option;
import dev.isxander.yacl3.api.OptionDescription;
import dev.isxander.yacl3.api.YetAnotherConfigLib;
import dev.isxander.yacl3.api.controller.FloatSliderControllerBuilder;
import dev.isxander.yacl3.api.controller.TickBoxControllerBuilder;
import dev.isxander.yacl3.config.ConfigEntry;
import dev.isxander.yacl3.config.ConfigInstance;
import dev.isxander.yacl3.config.GsonConfigInstance;
import dev.isxander.yacl3.gui.controllers.ColorController;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;

import java.awt.*;

public class NametagTweaksConfig {
public static final ConfigInstance<NametagTweaksConfig> INSTANCE = GsonConfigInstance.createBuilder(NametagTweaksConfig.class)
.setPath(FabricLoader.getInstance().getConfigDir().resolve("nametagtweaks.json"))
.build();

@ConfigEntry public boolean removeNametags = false;
@ConfigEntry public boolean showOwnNametags = false;
@ConfigEntry public boolean showNametagsInHiddenHud = false;
@ConfigEntry public boolean hideNametagsInHiddenHud = false;
@ConfigEntry public boolean hideEntityNametagsInHiddenHud = true;
@ConfigEntry public boolean hidePlayerNametagsInHiddenHud = false;
@ConfigEntry public boolean hideArmorStandNametagsInHiddenHud = false;
@ConfigEntry public boolean nametagTextShadow = false;
@ConfigEntry public float nametagOpacity = 25F;
@ConfigEntry public Color nametagColor = new Color(0, 0, 0, 63);

public static Screen configScreen(Screen parent) {
return YetAnotherConfigLib.create(INSTANCE, ((defaults, config, builder) -> builder
Expand All @@ -44,15 +46,15 @@ public static Screen configScreen(Screen parent) {
.controller(TickBoxControllerBuilder::create)
.build())
.option(Option.createBuilder(boolean.class)
.name(Text.literal("Show Entity Nametags in F1 Mode"))
.description(OptionDescription.of(Text.of("Show non-player and non-armor stand nametags in F1 mode when the HUD is hidden.")))
.binding(defaults.showNametagsInHiddenHud, () -> config.showNametagsInHiddenHud, newVal -> config.showNametagsInHiddenHud = newVal)
.name(Text.literal("Hide Entity Nametags in F1 Mode"))
.description(OptionDescription.of(Text.of("Hide non-player and non-armor stand nametags in F1 mode when the HUD is hidden.")))
.binding(defaults.hideEntityNametagsInHiddenHud, () -> config.hideEntityNametagsInHiddenHud, newVal -> config.hideEntityNametagsInHiddenHud = newVal)
.controller(TickBoxControllerBuilder::create)
.build())
.option(Option.createBuilder(boolean.class)
.name(Text.literal("Hide Player Nametags in F1 Mode"))
.description(OptionDescription.of(Text.of("Hide player nametags in F1 mode when the HUD is hidden.")))
.binding(defaults.hideNametagsInHiddenHud, () -> config.hideNametagsInHiddenHud, newVal -> config.hideNametagsInHiddenHud = newVal)
.binding(defaults.hidePlayerNametagsInHiddenHud, () -> config.hidePlayerNametagsInHiddenHud, newVal -> config.hidePlayerNametagsInHiddenHud = newVal)
.controller(TickBoxControllerBuilder::create)
.build())
.option(Option.createBuilder(boolean.class)
Expand All @@ -61,14 +63,10 @@ public static Screen configScreen(Screen parent) {
.binding(defaults.hideArmorStandNametagsInHiddenHud, () -> config.hideArmorStandNametagsInHiddenHud, newVal -> config.hideArmorStandNametagsInHiddenHud = newVal)
.controller(TickBoxControllerBuilder::create)
.build())
.option(Option.createBuilder(float.class)
.name(Text.literal("Custom Nametag Background Opacity"))
.description(OptionDescription.of(Text.of("The value for custom nametag background opacity. The default vanilla value is 25%.")))
.binding(25F, () -> config.nametagOpacity, newVal -> config.nametagOpacity = newVal)
.controller(opt -> FloatSliderControllerBuilder.create(opt)
.valueFormatter(value -> Text.of(String.format("%,.0f", value) + "%"))
.range(0F, 100F)
.step(1F))
.option(Option.<Color>createBuilder()
.name(Text.literal("Color Option"))
.binding(defaults.nametagColor, () -> config.nametagColor, value -> config.nametagColor = value)
.customController(opt -> new ColorController(opt, true))
.build())
.option(Option.createBuilder(boolean.class)
.name(Text.literal("Nametag Text Shadow"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import dev.microcontrollers.nametagtweaks.config.NametagTweaksConfig;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.GameOptions;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.util.math.MatrixStack;
Expand All @@ -13,15 +12,14 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(EntityRenderer.class)
public class EntityRendererMixin<T extends Entity> {
@Inject(method = "renderLabelIfPresent", at = @At("HEAD"), cancellable = true)
public void hideNametags(T entity, Text text, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
if (NametagTweaksConfig.INSTANCE.getConfig().removeNametags ||
(NametagTweaksConfig.INSTANCE.getConfig().hideNametagsInHiddenHud && !MinecraftClient.isHudEnabled() && entity.isPlayer()) ||
(NametagTweaksConfig.INSTANCE.getConfig().hideEntityNametagsInHiddenHud && !MinecraftClient.isHudEnabled() && !entity.isPlayer()) ||
(NametagTweaksConfig.INSTANCE.getConfig().hideArmorStandNametagsInHiddenHud && !MinecraftClient.isHudEnabled() && entity instanceof ArmorStandEntity))
ci.cancel();
}
Expand All @@ -31,8 +29,8 @@ public boolean addNametagShadow(boolean shadow) {
return NametagTweaksConfig.INSTANCE.getConfig().nametagTextShadow;
}

@Redirect(method = "renderLabelIfPresent", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/GameOptions;getTextBackgroundOpacity(F)F"))
public float setNametagBackground(GameOptions instance, float fallback) {
return NametagTweaksConfig.INSTANCE.getConfig().nametagOpacity / 100F;
@ModifyArg(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", ordinal = 0), index = 8)
public int changeNametagBackground(int color) {
return NametagTweaksConfig.INSTANCE.getConfig().nametagColor.getRGB();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class LivingEntityRendererMixin {
@Inject(method = "hasLabel(Lnet/minecraft/entity/LivingEntity;)Z", at = @At(value = "TAIL", shift = At.Shift.BEFORE), cancellable = true)
public void showInThirdPerson(LivingEntity livingEntity, CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(
(MinecraftClient.isHudEnabled() || !NametagTweaksConfig.INSTANCE.getConfig().hideNametagsInHiddenHud)
(MinecraftClient.isHudEnabled() || !(NametagTweaksConfig.INSTANCE.getConfig().hidePlayerNametagsInHiddenHud && livingEntity == MinecraftClient.getInstance().player))
&& (NametagTweaksConfig.INSTANCE.getConfig().showOwnNametags
|| livingEntity != MinecraftClient.getInstance().getCameraEntity())
&& !livingEntity.isInvisibleTo(MinecraftClient.getInstance().player)
Expand Down

0 comments on commit becb29c

Please sign in to comment.