From c67f2b9206c647a1f01e91216160e3751b411c6b Mon Sep 17 00:00:00 2001 From: MuffinTime <50742161+RealMuffinTime@users.noreply.github.com> Date: Thu, 29 Aug 2024 19:44:38 +0200 Subject: [PATCH] Improvements to Nametags module (#4869) - add TNT minecarts - ignore empty items - support non-living entities --- .../systems/modules/render/Nametags.java | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Nametags.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Nametags.java index 2057f9009a..584f7800b3 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Nametags.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/Nametags.java @@ -35,6 +35,7 @@ import net.minecraft.entity.*; import net.minecraft.entity.decoration.ItemFrameEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.vehicle.TntMinecartEntity; import net.minecraft.item.ItemStack; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.entry.RegistryEntry; @@ -297,7 +298,7 @@ public class Nametags extends Module { private final List entityList = new ArrayList<>(); public Nametags() { - super(Categories.Render, "nametags", "Displays customizable nametags above players."); + super(Categories.Render, "nametags", "Displays customizable nametags above players, items and other entities."); } private static String ticksToTime(int ticks) { @@ -358,8 +359,11 @@ private void onRender2D(Render2DEvent event) { else if (type == EntityType.ITEM) renderNametagItem(((ItemEntity) entity).getStack(), shadow); else if (type == EntityType.ITEM_FRAME) renderNametagItem(((ItemFrameEntity) entity).getHeldItemStack(), shadow); - else if (type == EntityType.TNT) renderTntNametag((TntEntity) entity, shadow); - else if (entity instanceof LivingEntity) renderGenericNametag((LivingEntity) entity, shadow); + else if (type == EntityType.TNT) renderTntNametag(ticksToTime(((TntEntity) entity).getFuse()), shadow); + else if (type == EntityType.TNT_MINECART && ((TntMinecartEntity) entity).isPrimed()) + renderTntNametag(ticksToTime(((TntMinecartEntity) entity).getFuseTicks()), shadow); + else if (entity instanceof LivingEntity) renderGenericLivingNametag((LivingEntity) entity, shadow); + else renderGenericNametag(entity, shadow); } } } @@ -577,6 +581,8 @@ private void renderNametagPlayer(Render2DEvent event, PlayerEntity player, boole } private void renderNametagItem(ItemStack stack, boolean shadow) { + if (stack.isEmpty()) return; + TextRenderer text = TextRenderer.get(); NametagUtils.begin(pos); @@ -604,7 +610,7 @@ private void renderNametagItem(ItemStack stack, boolean shadow) { NametagUtils.end(); } - private void renderGenericNametag(LivingEntity entity, boolean shadow) { + private void renderGenericLivingNametag(LivingEntity entity, boolean shadow) { TextRenderer text = TextRenderer.get(); NametagUtils.begin(pos); @@ -644,11 +650,32 @@ private void renderGenericNametag(LivingEntity entity, boolean shadow) { NametagUtils.end(); } - private void renderTntNametag(TntEntity entity, boolean shadow) { + private void renderGenericNametag(Entity entity, boolean shadow) { TextRenderer text = TextRenderer.get(); NametagUtils.begin(pos); - String fuseText = ticksToTime(entity.getFuse()); + //Name + String nameText = entity.getType().getName().getString(); + + double nameWidth = text.getWidth(nameText, shadow); + double heightDown = text.getHeight(shadow); + double widthHalf = nameWidth / 2; + + drawBg(-widthHalf, -heightDown, nameWidth, heightDown); + + text.beginBig(); + double hX = -widthHalf; + double hY = -heightDown; + + text.render(nameText, hX, hY, nameColor.get(), shadow); + text.end(); + + NametagUtils.end(); + } + + private void renderTntNametag(String fuseText, boolean shadow) { + TextRenderer text = TextRenderer.get(); + NametagUtils.begin(pos); double width = text.getWidth(fuseText, shadow); double heightDown = text.getHeight(shadow);