diff --git a/gradle.properties b/gradle.properties index 01598a3..39084f8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/java/dev/microcontrollers/nametagtweaks/config/NametagTweaksConfig.java b/src/main/java/dev/microcontrollers/nametagtweaks/config/NametagTweaksConfig.java index 4de1914..1339fd7 100644 --- a/src/main/java/dev/microcontrollers/nametagtweaks/config/NametagTweaksConfig.java +++ b/src/main/java/dev/microcontrollers/nametagtweaks/config/NametagTweaksConfig.java @@ -4,15 +4,17 @@ 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 INSTANCE = GsonConfigInstance.createBuilder(NametagTweaksConfig.class) .setPath(FabricLoader.getInstance().getConfigDir().resolve("nametagtweaks.json")) @@ -20,11 +22,11 @@ public class NametagTweaksConfig { @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 @@ -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) @@ -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.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")) diff --git a/src/main/java/dev/microcontrollers/nametagtweaks/mixin/EntityRendererMixin.java b/src/main/java/dev/microcontrollers/nametagtweaks/mixin/EntityRendererMixin.java index d3a13a4..627d29b 100644 --- a/src/main/java/dev/microcontrollers/nametagtweaks/mixin/EntityRendererMixin.java +++ b/src/main/java/dev/microcontrollers/nametagtweaks/mixin/EntityRendererMixin.java @@ -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; @@ -13,7 +12,6 @@ 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) @@ -21,7 +19,7 @@ public class EntityRendererMixin { @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(); } @@ -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(); } } diff --git a/src/main/java/dev/microcontrollers/nametagtweaks/mixin/LivingEntityRendererMixin.java b/src/main/java/dev/microcontrollers/nametagtweaks/mixin/LivingEntityRendererMixin.java index 963630b..f0e4068 100644 --- a/src/main/java/dev/microcontrollers/nametagtweaks/mixin/LivingEntityRendererMixin.java +++ b/src/main/java/dev/microcontrollers/nametagtweaks/mixin/LivingEntityRendererMixin.java @@ -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 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)