Skip to content

Commit

Permalink
add TNT Minecarts, ignore empty ItemStacks, more default values, bett…
Browse files Browse the repository at this point in the history
…er description
  • Loading branch information
RealMuffinTime committed Aug 25, 2024
1 parent 902308f commit 42b9d64
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -57,7 +58,7 @@ public class Nametags extends Module {
private final Setting<Set<EntityType<?>>> entities = sgGeneral.add(new EntityTypeListSetting.Builder()
.name("entities")
.description("Select entities to draw nametags on.")
.defaultValue(EntityType.PLAYER, EntityType.ITEM)
.defaultValue(EntityType.PLAYER, EntityType.ITEM, EntityType.ITEM_FRAME, EntityType.TNT, EntityType.TNT_MINECART)
.build()
);

Expand Down Expand Up @@ -297,7 +298,7 @@ public class Nametags extends Module {
private final List<Entity> 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) {
Expand Down Expand Up @@ -358,7 +359,8 @@ 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 (type == EntityType.TNT) renderTntNametag(ticksToTime(((TntEntity) entity).getFuse()), shadow);
else if (type == EntityType.TNT_MINECART) renderTntNametag(ticksToTime(((TntMinecartEntity) entity).getFuseTicks()), shadow);
else if (entity instanceof LivingEntity) renderGenericNametag((LivingEntity) entity, shadow);
}
}
Expand Down Expand Up @@ -577,6 +579,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);

Expand Down Expand Up @@ -644,12 +648,10 @@ private void renderGenericNametag(LivingEntity entity, boolean shadow) {
NametagUtils.end();
}

private void renderTntNametag(TntEntity entity, boolean shadow) {
private void renderTntNametag(String fuseText, boolean shadow) {
TextRenderer text = TextRenderer.get();
NametagUtils.begin(pos);

String fuseText = ticksToTime(entity.getFuse());

double width = text.getWidth(fuseText, shadow);
double heightDown = text.getHeight(shadow);

Expand Down

0 comments on commit 42b9d64

Please sign in to comment.