| 1 | package net.minecraft.client.gui;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.util.List;
|
| 5 | import net.minecraft.client.Minecraft;
|
| 6 | import net.minecraft.util.ChatComponentText;
|
| 7 | import net.minecraft.util.EnumChatFormatting;
|
| 8 | import net.minecraft.util.IChatComponent;
|
| 9 |
|
| 10 | public class GuiUtilRenderComponents
|
| 11 | {
|
| 12 | public static String func_178909_a(String p_178909_0_, boolean p_178909_1_)
|
| 13 | {
|
| 14 | return !p_178909_1_ && !Minecraft.getMinecraft().gameSettings.chatColours ? EnumChatFormatting.getTextWithoutFormattingCodes(p_178909_0_) : p_178909_0_;
|
| 15 | }
|
| 16 |
|
| 17 | public static List<IChatComponent> splitText(IChatComponent p_178908_0_, int p_178908_1_, FontRenderer p_178908_2_, boolean p_178908_3_, boolean p_178908_4_)
|
| 18 | {
|
| 19 | int i = 0;
|
| 20 | IChatComponent ichatcomponent = new ChatComponentText("");
|
| 21 | List<IChatComponent> list = Lists.<IChatComponent>newArrayList();
|
| 22 | List<IChatComponent> list1 = Lists.newArrayList(p_178908_0_);
|
| 23 |
|
| 24 | for (int j = 0; j < ((List)list1).size(); ++j)
|
| 25 | {
|
| 26 | IChatComponent ichatcomponent1 = (IChatComponent)list1.get(j);
|
| 27 | String s = ichatcomponent1.getUnformattedTextForChat();
|
| 28 | boolean flag = false;
|
| 29 |
|
| 30 | if (s.contains("\n"))
|
| 31 | {
|
| 32 | int k = s.indexOf(10);
|
| 33 | String s1 = s.substring(k + 1);
|
| 34 | s = s.substring(0, k + 1);
|
| 35 | ChatComponentText chatcomponenttext = new ChatComponentText(s1);
|
| 36 | chatcomponenttext.setChatStyle(ichatcomponent1.getChatStyle().createShallowCopy());
|
| 37 | list1.add(j + 1, chatcomponenttext);
|
| 38 | flag = true;
|
| 39 | }
|
| 40 |
|
| 41 | String s4 = func_178909_a(ichatcomponent1.getChatStyle().getFormattingCode() + s, p_178908_4_);
|
| 42 | String s5 = s4.endsWith("\n") ? s4.substring(0, s4.length() - 1) : s4;
|
| 43 | int i1 = p_178908_2_.getStringWidth(s5);
|
| 44 | ChatComponentText chatcomponenttext1 = new ChatComponentText(s5);
|
| 45 | chatcomponenttext1.setChatStyle(ichatcomponent1.getChatStyle().createShallowCopy());
|
| 46 |
|
| 47 | if (i + i1 > p_178908_1_)
|
| 48 | {
|
| 49 | String s2 = p_178908_2_.trimStringToWidth(s4, p_178908_1_ - i, false);
|
| 50 | String s3 = s2.length() < s4.length() ? s4.substring(s2.length()) : null;
|
| 51 |
|
| 52 | if (s3 != null && s3.length() > 0)
|
| 53 | {
|
| 54 | int l = s2.lastIndexOf(" ");
|
| 55 |
|
| 56 | if (l >= 0 && p_178908_2_.getStringWidth(s4.substring(0, l)) > 0)
|
| 57 | {
|
| 58 | s2 = s4.substring(0, l);
|
| 59 |
|
| 60 | if (p_178908_3_)
|
| 61 | {
|
| 62 | ++l;
|
| 63 | }
|
| 64 |
|
| 65 | s3 = s4.substring(l);
|
| 66 | }
|
| 67 | else if (i > 0 && !s4.contains(" "))
|
| 68 | {
|
| 69 | s2 = "";
|
| 70 | s3 = s4;
|
| 71 | }
|
| 72 |
|
| 73 | ChatComponentText chatcomponenttext2 = new ChatComponentText(s3);
|
| 74 | chatcomponenttext2.setChatStyle(ichatcomponent1.getChatStyle().createShallowCopy());
|
| 75 | list1.add(j + 1, chatcomponenttext2);
|
| 76 | }
|
| 77 |
|
| 78 | i1 = p_178908_2_.getStringWidth(s2);
|
| 79 | chatcomponenttext1 = new ChatComponentText(s2);
|
| 80 | chatcomponenttext1.setChatStyle(ichatcomponent1.getChatStyle().createShallowCopy());
|
| 81 | flag = true;
|
| 82 | }
|
| 83 |
|
| 84 | if (i + i1 <= p_178908_1_)
|
| 85 | {
|
| 86 | i += i1;
|
| 87 | ichatcomponent.appendSibling(chatcomponenttext1);
|
| 88 | }
|
| 89 | else
|
| 90 | {
|
| 91 | flag = true;
|
| 92 | }
|
| 93 |
|
| 94 | if (flag)
|
| 95 | {
|
| 96 | list.add(ichatcomponent);
|
| 97 | i = 0;
|
| 98 | ichatcomponent = new ChatComponentText("");
|
| 99 | }
|
| 100 | }
|
| 101 |
|
| 102 | list.add(ichatcomponent);
|
| 103 | return list;
|
| 104 | }
|
| 105 | }
|
| 106 |
|