diff --git a/Fabric/src/main/java/vazkii/neat/NeatFiberConfig.java b/Fabric/src/main/java/vazkii/neat/NeatFiberConfig.java index d15fe2b..19943cf 100644 --- a/Fabric/src/main/java/vazkii/neat/NeatFiberConfig.java +++ b/Fabric/src/main/java/vazkii/neat/NeatFiberConfig.java @@ -54,6 +54,7 @@ public static void setup() { private static class Client implements NeatConfig.ConfigAccess { private final PropertyMirror maxDistance = PropertyMirror.create(INTEGER); + private final PropertyMirror maxDistanceWithoutLineOfSight = PropertyMirror.create(INTEGER); private final PropertyMirror renderInF1 = PropertyMirror.create(BOOLEAN); private final PropertyMirror heightAbove = PropertyMirror.create(DOUBLE); private final PropertyMirror drawBackground = PropertyMirror.create(BOOLEAN); @@ -82,6 +83,10 @@ public ConfigTree configure(ConfigTreeBuilder builder) { .withComment("Maximum distance in blocks at which health bars should render") .finishValue(maxDistance::mirror) + .beginValue("maxDistanceWithoutLineOfSight", INTEGER, 8) + .withComment("Maximum distance in blocks at which health bars should render without line of sight") + .finishValue(maxDistanceWithoutLineOfSight::mirror) + .beginValue("renderInF1", BOOLEAN, false) .withComment("Whether health bars should render when the HUD is disabled with F1") .finishValue(renderInF1::mirror) @@ -178,6 +183,11 @@ public int maxDistance() { return maxDistance.getValue(); } + @Override + public int maxDistanceWithoutLineOfSight() { + return maxDistanceWithoutLineOfSight.getValue(); + } + @Override public boolean renderInF1() { return renderInF1.getValue(); diff --git a/Forge/src/main/java/vazkii/neat/NeatForgeConfig.java b/Forge/src/main/java/vazkii/neat/NeatForgeConfig.java index 6d8dafb..4e98609 100644 --- a/Forge/src/main/java/vazkii/neat/NeatForgeConfig.java +++ b/Forge/src/main/java/vazkii/neat/NeatForgeConfig.java @@ -18,6 +18,7 @@ public static void init() { private static class ForgeNeatConfig implements NeatConfig.ConfigAccess { private final ConfigValue maxDistance; + private final ConfigValue maxDistanceWithoutLineOfSight; private final ConfigValue renderInF1; private final ConfigValue heightAbove; private final ConfigValue drawBackground; @@ -45,6 +46,7 @@ public ForgeNeatConfig(ForgeConfigSpec.Builder builder) { builder.push("general"); maxDistance = builder.define("Max Distance", 24); + maxDistanceWithoutLineOfSight = builder.define("Max Distance Without Line of Sight", 8); renderInF1 = builder.define("Render with Interface Disabled (F1)", false); heightAbove = builder.define("Height Above Mob", 0.6); drawBackground = builder.define("Draw Background", true); @@ -77,6 +79,11 @@ public int maxDistance() { return maxDistance.get(); } + @Override + public int maxDistanceWithoutLineOfSight() { + return maxDistanceWithoutLineOfSight.get(); + } + @Override public boolean renderInF1() { return renderInF1.get(); diff --git a/Xplat/src/main/java/vazkii/neat/HealthBarRenderer.java b/Xplat/src/main/java/vazkii/neat/HealthBarRenderer.java index a9a7370..46c2625 100644 --- a/Xplat/src/main/java/vazkii/neat/HealthBarRenderer.java +++ b/Xplat/src/main/java/vazkii/neat/HealthBarRenderer.java @@ -153,7 +153,8 @@ private static boolean shouldShowPlate(LivingEntity living, Entity cameraEntity) float distance = living.distanceTo(cameraEntity); if (distance > NeatConfig.instance.maxDistance() - || !living.hasLineOfSight(cameraEntity)) { + || (distance > NeatConfig.instance.maxDistanceWithoutLineOfSight() + && !living.hasLineOfSight(cameraEntity))) { return false; } if (!NeatConfig.instance.showOnBosses() && isBoss(living)) { @@ -170,8 +171,22 @@ private static boolean shouldShowPlate(LivingEntity living, Entity cameraEntity) } boolean visible = true; - if (cameraEntity instanceof Player cameraPlayer) { - visible = !living.isInvisibleTo(cameraPlayer); + if (cameraEntity instanceof Player cameraPlayer + && living.isInvisibleTo(cameraPlayer)) { + boolean wearingThings = false; + for (ItemStack armorSlot : living.getArmorSlots()) { + if (!armorSlot.isEmpty()) { + wearingThings = true; + } + } + for (ItemStack handSlot : living.getHandSlots()) { + if (!handSlot.isEmpty()) { + wearingThings = true; + } + } + if (!wearingThings) { + visible = false; + } } Team livingTeam = living.getTeam(); Team cameraTeam = cameraEntity.getTeam(); @@ -191,8 +206,7 @@ public static void hookRender(Entity entity, PoseStack poseStack, MultiBufferSou Quaternionf cameraOrientation) { final Minecraft mc = Minecraft.getInstance(); - if (!(entity instanceof LivingEntity living) || (!living.getPassengers().isEmpty() && living.getPassengers().get(0) instanceof LivingEntity)) { - // TODO handle mob stacks properly + if (!(entity instanceof LivingEntity living)) { return; } @@ -206,9 +220,7 @@ public static void hookRender(Entity entity, PoseStack poseStack, MultiBufferSou final float textScale = 0.5F; final int barHeight = NeatConfig.instance.barHeight(); final boolean boss = isBoss(living); - final String name = living.hasCustomName() - ? ChatFormatting.ITALIC + living.getCustomName().getString() - : living.getDisplayName().getString(); + final String name = living.getDisplayName().getString(); final float nameLen = mc.font.width(name) * textScale; final float halfSize = Math.max(NeatConfig.instance.plateSize(), nameLen / 2.0F + 10.0F); diff --git a/Xplat/src/main/java/vazkii/neat/NeatConfig.java b/Xplat/src/main/java/vazkii/neat/NeatConfig.java index 467b61c..aa9d005 100644 --- a/Xplat/src/main/java/vazkii/neat/NeatConfig.java +++ b/Xplat/src/main/java/vazkii/neat/NeatConfig.java @@ -9,6 +9,7 @@ public class NeatConfig { public interface ConfigAccess { int maxDistance(); + int maxDistanceWithoutLineOfSight(); boolean renderInF1(); double heightAbove(); boolean drawBackground();