diff options
author | bowser0000 <bowser0000@gmail.com> | 2021-08-26 22:41:16 -0400 |
---|---|---|
committer | bowser0000 <bowser0000@gmail.com> | 2021-08-26 22:41:16 -0400 |
commit | e1cd7b73d0e96b1be4892d75f46cc92ad7bf979e (patch) | |
tree | 07cb2978382a856c7178e3f0415a8a6079ceb805 /src/main/java/me/Danker/features/ColouredNames.java | |
parent | 5a045d7805b0708e2baa9db648130137be986e9a (diff) | |
download | SkyblockMod-e1cd7b73d0e96b1be4892d75f46cc92ad7bf979e.tar.gz SkyblockMod-e1cd7b73d0e96b1be4892d75f46cc92ad7bf979e.tar.bz2 SkyblockMod-e1cd7b73d0e96b1be4892d75f46cc92ad7bf979e.zip |
Reduce lag with custom colours
Diffstat (limited to 'src/main/java/me/Danker/features/ColouredNames.java')
-rw-r--r-- | src/main/java/me/Danker/features/ColouredNames.java | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/main/java/me/Danker/features/ColouredNames.java b/src/main/java/me/Danker/features/ColouredNames.java index d0daf2a..dfd6d84 100644 --- a/src/main/java/me/Danker/features/ColouredNames.java +++ b/src/main/java/me/Danker/features/ColouredNames.java @@ -13,16 +13,21 @@ import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.client.event.RenderLivingEvent; import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.event.entity.player.PlayerEvent; +import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; public class ColouredNames { public static List<String> users = new ArrayList<>(); + public static Map<String, String> nametags = new HashMap<>(); public static final EnumChatFormatting[] RAINBOW_COLOURS = new EnumChatFormatting[]{EnumChatFormatting.RED, EnumChatFormatting.GOLD, EnumChatFormatting.YELLOW, EnumChatFormatting.GREEN, EnumChatFormatting.AQUA, EnumChatFormatting.BLUE, EnumChatFormatting.DARK_PURPLE}; @SubscribeEvent @@ -58,20 +63,38 @@ public class ColouredNames { } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.LOW) public void onRenderLiving(RenderLivingEvent.Specials.Pre<EntityLivingBase> event) { if (!ToggleCommand.customColouredNames || !Utils.inSkyblock) return; Entity entity = event.entity; - if (entity instanceof EntityArmorStand && entity.hasCustomName()) { - for (String user : users) { - if (entity.getCustomNameTag().contains(user)) { - entity.setCustomNameTag(replaceName(entity.getCustomNameTag(), user, getColourFromName(user))); + if (entity instanceof EntityArmorStand && !entity.isDead && entity.hasCustomName()) { + String name = entity.getCustomNameTag(); + if (name.charAt(name.length() - 1) == '❤') return; + + String id = entity.getUniqueID().toString(); + String nametag = nametags.get(id); + + if (name.equals(nametag)) { + entity.setCustomNameTag(nametag); + } else { + for (String user : users) { + if (name.contains(user)) { + name = replaceName(name, user, getColourFromName(user)); + } } + + nametags.put(id, name); + entity.setCustomNameTag(name); } } } + @SubscribeEvent + public void onWorldChange(WorldEvent.Load event) { + nametags.clear(); + } + // https://github.com/SteveKunG/SkyBlockcatia/blob/1.8.9/src/main/java/com/stevekung/skyblockcatia/utils/SupporterUtils.java#L53 public static String replaceName(String text, String name, String colour) { String namePattern = "(?:(?:\\u00a7[0-9a-fbr])\\B(?:" + name + ")\\b)|(?:\\u00a7[rb]" + name + "\\u00a7r)|\\b" + name + "\\b"; |