From 73e62b8fde3869b43ea75e99f849c1ef885d515e Mon Sep 17 00:00:00 2001 From: Uraneptus Date: Tue, 10 Sep 2024 00:23:25 +0200 Subject: [PATCH] config to disable vanilla name tag --- .../java/vazkii/neat/NeatFiberConfig.java | 10 ++++++++ .../java/vazkii/neat/NeatForgeConfig.java | 7 ++++++ .../src/main/java/vazkii/neat/NeatConfig.java | 1 + .../neat/mixin/EntityRendererMixin.java | 23 +++++++++++++++++++ Xplat/src/main/resources/neat.mixins.json | 1 + 5 files changed, 42 insertions(+) create mode 100644 Xplat/src/main/java/vazkii/neat/mixin/EntityRendererMixin.java diff --git a/Fabric/src/main/java/vazkii/neat/NeatFiberConfig.java b/Fabric/src/main/java/vazkii/neat/NeatFiberConfig.java index ffdbfd3..d0149d4 100644 --- a/Fabric/src/main/java/vazkii/neat/NeatFiberConfig.java +++ b/Fabric/src/main/java/vazkii/neat/NeatFiberConfig.java @@ -78,6 +78,7 @@ private static class Client implements NeatConfig.ConfigAccess { private final PropertyMirror showFullHealth = PropertyMirror.create(BOOLEAN); private final PropertyMirror enableDebugInfo = PropertyMirror.create(BOOLEAN); private final PropertyMirror showEntityName = PropertyMirror.create(BOOLEAN); + private final PropertyMirror disableNameTag = PropertyMirror.create(BOOLEAN); private final PropertyMirror> blacklist = PropertyMirror.create(ConfigTypes.makeList(STRING)); public ConfigTree configure(ConfigTreeBuilder builder) { @@ -181,6 +182,10 @@ public ConfigTree configure(ConfigTreeBuilder builder) { .withComment("Show entity name") .finishValue(showEntityName::mirror) + .beginValue("disableNameTag", BOOLEAN, false) + .withComment("Disables the rendering of the vanilla name tag") + .finishValue(disableNameTag::mirror) + .beginValue("blacklist", ConfigTypes.makeList(STRING), NeatConfig.DEFAULT_DISABLED) .withComment("Entity ID's that should not have bars rendered") .finishValue(blacklist::mirror); @@ -313,6 +318,11 @@ public boolean showEntityName() { return showEntityName.getValue(); } + @Override + public boolean disableNameTag() { + return disableNameTag.getValue(); + } + @Override public List blacklist() { return blacklist.getValue(); diff --git a/Forge/src/main/java/vazkii/neat/NeatForgeConfig.java b/Forge/src/main/java/vazkii/neat/NeatForgeConfig.java index cd984f7..e6252cf 100644 --- a/Forge/src/main/java/vazkii/neat/NeatForgeConfig.java +++ b/Forge/src/main/java/vazkii/neat/NeatForgeConfig.java @@ -42,6 +42,7 @@ private static class ForgeNeatConfig implements NeatConfig.ConfigAccess { private final ConfigValue showFullHealth; private final ConfigValue enableDebugInfo; private final ConfigValue showEntityName; + private final ConfigValue disableNameTag; private final ConfigValue> blacklist; public ForgeNeatConfig(ForgeConfigSpec.Builder builder) { @@ -72,6 +73,7 @@ public ForgeNeatConfig(ForgeConfigSpec.Builder builder) { showFullHealth = builder.define("Show entities with full health", true); enableDebugInfo = builder.define("Show Debug Info with F3", true); showEntityName = builder.define("show_entity_name", true); + disableNameTag = builder.comment("Disables the rendering of the vanilla name tag").define("disable_name_tag", false); blacklist = builder.comment("Blacklist uses entity IDs, not their display names. Use F3 to see them in the Neat bar.") .defineList("Blacklist", NeatConfig.DEFAULT_DISABLED, a -> true); @@ -203,6 +205,11 @@ public boolean showEntityName() { return showEntityName.get(); } + @Override + public boolean disableNameTag() { + return disableNameTag.get(); + } + @SuppressWarnings("unchecked") @Override public List blacklist() { diff --git a/Xplat/src/main/java/vazkii/neat/NeatConfig.java b/Xplat/src/main/java/vazkii/neat/NeatConfig.java index 4aa1b4c..c642668 100644 --- a/Xplat/src/main/java/vazkii/neat/NeatConfig.java +++ b/Xplat/src/main/java/vazkii/neat/NeatConfig.java @@ -33,6 +33,7 @@ public interface ConfigAccess { boolean showFullHealth(); boolean enableDebugInfo(); boolean showEntityName(); + boolean disableNameTag(); List blacklist(); } diff --git a/Xplat/src/main/java/vazkii/neat/mixin/EntityRendererMixin.java b/Xplat/src/main/java/vazkii/neat/mixin/EntityRendererMixin.java new file mode 100644 index 0000000..b7275ea --- /dev/null +++ b/Xplat/src/main/java/vazkii/neat/mixin/EntityRendererMixin.java @@ -0,0 +1,23 @@ +package vazkii.neat.mixin; + +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.world.entity.Entity; +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.CallbackInfo; +import vazkii.neat.HealthBarRenderer; +import vazkii.neat.NeatConfig; + +@Mixin(EntityRenderer.class) +public class EntityRendererMixin { + + @Inject(method = "render(Lnet/minecraft/world/entity/Entity;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/EntityRenderer;renderNameTag(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/network/chat/Component;Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V"), cancellable = true) + private void neat_disableNameTag(Entity $$0, float $$1, float $$2, PoseStack $$3, MultiBufferSource $$4, int $$5, CallbackInfo ci) { + if (NeatConfig.instance.disableNameTag()) { + ci.cancel(); + } + } +} diff --git a/Xplat/src/main/resources/neat.mixins.json b/Xplat/src/main/resources/neat.mixins.json index 432d937..6e4a0c9 100644 --- a/Xplat/src/main/resources/neat.mixins.json +++ b/Xplat/src/main/resources/neat.mixins.json @@ -4,6 +4,7 @@ "compatibilityLevel": "JAVA_17", "package": "vazkii.neat.mixin", "mixins": [ + "EntityRendererMixin" ], "client": [ "AccessorRenderType",