From 9e4bfa95924cbb9765ee0a8e5337c17ec287f0c8 Mon Sep 17 00:00:00 2001 From: Njol Date: Wed, 28 Jul 2021 14:23:04 +0200 Subject: [PATCH 1/3] Removed health bars from armor stands and invisible entities that aren't glowing --- .../torocraft/torohealth/bars/HealthBarRenderer.java | 2 +- .../net/torocraft/torohealth/util/EntityUtil.java | 11 +++++++++++ .../java/net/torocraft/torohealth/util/RayTrace.java | 5 +++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java b/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java index 801f494..8794128 100644 --- a/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java +++ b/src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java @@ -44,7 +44,7 @@ public static void renderInWorld(MatrixStack matrix, LivingEntity entity, Camera MinecraftClient client = MinecraftClient.getInstance(); - if (client.player == entity) { + if (!EntityUtil.showHealthBar(entity, client)) { return; } diff --git a/src/main/java/net/torocraft/torohealth/util/EntityUtil.java b/src/main/java/net/torocraft/torohealth/util/EntityUtil.java index ddd6990..11d9b55 100644 --- a/src/main/java/net/torocraft/torohealth/util/EntityUtil.java +++ b/src/main/java/net/torocraft/torohealth/util/EntityUtil.java @@ -1,6 +1,9 @@ package net.torocraft.torohealth.util; +import net.minecraft.client.MinecraftClient; import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.decoration.ArmorStandEntity; import net.minecraft.entity.mob.AmbientEntity; import net.minecraft.entity.mob.GhastEntity; import net.minecraft.entity.mob.HostileEntity; @@ -37,4 +40,12 @@ public static Relation determineRelation(Entity entity) { return Relation.UNKNOWN; } } + + public static boolean showHealthBar(Entity entity, MinecraftClient client) { + return entity instanceof LivingEntity + && !(entity instanceof ArmorStandEntity) + && (!entity.isInvisibleTo(client.player) || entity.isGlowing()) + && entity != client.player + && !entity.isSpectator(); + } } diff --git a/src/main/java/net/torocraft/torohealth/util/RayTrace.java b/src/main/java/net/torocraft/torohealth/util/RayTrace.java index 140117c..c9524aa 100644 --- a/src/main/java/net/torocraft/torohealth/util/RayTrace.java +++ b/src/main/java/net/torocraft/torohealth/util/RayTrace.java @@ -1,6 +1,5 @@ package net.torocraft.torohealth.util; -import java.util.function.Predicate; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; import net.minecraft.client.MinecraftClient; @@ -23,8 +22,9 @@ import net.minecraft.world.RaycastContext; import net.minecraft.world.RaycastContext.FluidHandling; +import java.util.function.Predicate; + public class RayTrace implements BlockView { - private static Predicate isVisible = entity -> !entity.isSpectator() && entity.collides(); private static MinecraftClient minecraft = MinecraftClient.getInstance(); @Override @@ -55,6 +55,7 @@ public LivingEntity getEntityInCrosshair (float partialTicks, double reachDistan Vec3d max = position.add(look.x * reachDistance, look.y * reachDistance, look.z * reachDistance); Box searchBox = viewer.getBoundingBox().stretch(look.multiply(reachDistance)).expand(1.0D, 1.0D, 1.0D); + Predicate isVisible = entity -> entity.collides() && EntityUtil.showHealthBar(entity, client); EntityHitResult result = ProjectileUtil.raycast(viewer, position, max, searchBox, isVisible, reachDistance * reachDistance); if (result == null || result.getEntity() == null) { From 35e26f02e25dcef4db8f7a590c1886d21feef57f Mon Sep 17 00:00:00 2001 From: Njol Date: Wed, 28 Jul 2021 17:51:27 +0200 Subject: [PATCH 2/3] Show health bars for invisible entities that have equipment, since the equipment is visible --- .../java/net/torocraft/torohealth/util/EntityUtil.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/torocraft/torohealth/util/EntityUtil.java b/src/main/java/net/torocraft/torohealth/util/EntityUtil.java index 11d9b55..1ccd6cd 100644 --- a/src/main/java/net/torocraft/torohealth/util/EntityUtil.java +++ b/src/main/java/net/torocraft/torohealth/util/EntityUtil.java @@ -13,6 +13,8 @@ import net.minecraft.entity.passive.PassiveEntity; import net.minecraft.entity.passive.SquidEntity; +import java.util.stream.StreamSupport; + public class EntityUtil { public enum Relation { @@ -44,7 +46,10 @@ public static Relation determineRelation(Entity entity) { public static boolean showHealthBar(Entity entity, MinecraftClient client) { return entity instanceof LivingEntity && !(entity instanceof ArmorStandEntity) - && (!entity.isInvisibleTo(client.player) || entity.isGlowing()) + && (!entity.isInvisibleTo(client.player) + || entity.isGlowing() + || entity.isOnFire() + || StreamSupport.stream(entity.getItemsEquipped().spliterator(), false).anyMatch(is -> !is.isEmpty())) && entity != client.player && !entity.isSpectator(); } From b9254d843a8c9aca9bd96f574b5cef931fefca04 Mon Sep 17 00:00:00 2001 From: Njol Date: Thu, 29 Jul 2021 21:06:06 +0200 Subject: [PATCH 3/3] Show health bar of invisible charged creepers since their lightning effect is visible --- src/main/java/net/torocraft/torohealth/util/EntityUtil.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/net/torocraft/torohealth/util/EntityUtil.java b/src/main/java/net/torocraft/torohealth/util/EntityUtil.java index 1ccd6cd..8d0d6de 100644 --- a/src/main/java/net/torocraft/torohealth/util/EntityUtil.java +++ b/src/main/java/net/torocraft/torohealth/util/EntityUtil.java @@ -5,6 +5,7 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.decoration.ArmorStandEntity; import net.minecraft.entity.mob.AmbientEntity; +import net.minecraft.entity.mob.CreeperEntity; import net.minecraft.entity.mob.GhastEntity; import net.minecraft.entity.mob.HostileEntity; import net.minecraft.entity.mob.SlimeEntity; @@ -49,6 +50,7 @@ public static boolean showHealthBar(Entity entity, MinecraftClient client) { && (!entity.isInvisibleTo(client.player) || entity.isGlowing() || entity.isOnFire() + || entity instanceof CreeperEntity && ((CreeperEntity) entity).shouldRenderOverlay() // charged creeper || StreamSupport.stream(entity.getItemsEquipped().spliterator(), false).anyMatch(is -> !is.isEmpty())) && entity != client.player && !entity.isSpectator();