use of net.minecraft.text.TextColor in project meteor-client by MeteorDevelopment.
the class TextUtils method preOrderTraverse.
/**
* Performs a pre-order text traversal of {@link Text} components and ref-returns a sequential list
* of {@link ColoredText}, such that one could know the text and its color by iterating over the list.
*
* @param text The text to flatten
* @param stack An empty stack. This is used by the recursive algorithm to keep track of the parents of the current iteration
* @param coloredTexts The list of colored text to return
*/
private static void preOrderTraverse(Text text, Stack<ColoredText> stack, List<ColoredText> coloredTexts) {
if (text == null)
return;
// Do actions here
String textString = text.asString();
TextColor mcTextColor = text.getStyle().getColor();
// If mcTextColor is null, the color should be inherited from its parent. In this case, the path of the recursion is stored on the stack,
// with the current element's parent at the top, so simply peek it if possible. If not, there is no parent element,
// and with no color, use the default of white.
Color textColor;
if (mcTextColor == null) {
if (stack.empty())
// No color defined, use default white
textColor = new Color(255, 255, 255);
else
// Use parent color
textColor = stack.peek().getColor();
} else {
// Has a color defined, so use that
// Sets alpha to max. Some damn reason Color's packed ctor is in ARGB format, not RGBA
textColor = new Color((text.getStyle().getColor().getRgb()) | 0xFF000000);
}
ColoredText coloredText = new ColoredText(textString, textColor);
coloredTexts.add(coloredText);
// For the recursion algorithm's child, the current coloredText is its parent, so add to stack
stack.push(coloredText);
// Recursively traverse
for (Text child : text.getSiblings()) preOrderTraverse(child, stack, coloredTexts);
stack.pop();
}
use of net.minecraft.text.TextColor in project EdenClient by HahaOO7.
the class StyleLoader method save.
@Override
public NbtCompound save(Object value) {
Style s = cast(value);
NbtCompound tag = new NbtCompound();
tag.putBoolean("bold", s.isBold());
tag.putBoolean("obfuscated", s.isObfuscated());
tag.putBoolean("italic", s.isItalic());
tag.putBoolean("strikethrough", s.isStrikethrough());
tag.putBoolean("underlined", s.isUnderlined());
TextColor rgb = s.getColor();
if (rgb != null)
tag.putInt("rgb", rgb.getRgb());
return tag;
}
use of net.minecraft.text.TextColor in project AdvancedChatBox by DarkKronicle.
the class ChatFormatter method format.
/**
* Format's the chat box contents
*
* @param string Contents
* @return Formatted FluidText. If nothing is changed it will be the contents with Style.EMPTY
*/
public FluidText format(String string) {
FluidText text = new FluidText(new RawText(string, Style.EMPTY));
if (string.length() == 0) {
return text;
}
if (suggestor.getAllSuggestions() != null) {
HashMap<StringMatch, FluidText.StringInsert> format = new HashMap<>();
for (AdvancedSuggestions suggestions : suggestor.getAllSuggestions()) {
if (suggestions.getSuggestions().isEmpty()) {
// Don't want to format if there's nothing there...
continue;
}
boolean atLeastOne = false;
for (AdvancedSuggestion suggestion : suggestions.getSuggestions()) {
if (suggestion.getText().length() > 0) {
atLeastOne = true;
break;
}
}
if (!atLeastOne) {
continue;
}
StringRange range = suggestions.getRange();
int start = range.getStart();
int end = range.getEnd();
if (end > string.length()) {
end = string.length();
}
if (start < 0) {
start = 0;
}
String matchString = string.subSequence(start, end).toString();
format.put(new StringMatch(matchString, start, end), (current, match) -> {
Style style = Style.EMPTY;
style = style.withFormatting(Formatting.UNDERLINE);
TextColor textColor = TextColor.fromRgb(ChatBoxConfigStorage.General.AVAILABLE_SUGGESTION_COLOR.config.get().color());
style = style.withColor(textColor);
return new FluidText(new RawText(matchString, style));
});
}
text.replaceStrings(format);
}
for (ChatFormatterRegistry.ChatFormatterOption option : ChatFormatterRegistry.getInstance().getAll()) {
if (!option.isActive()) {
continue;
}
Optional<FluidText> otext = option.getOption().format(text, suggestor.getParse());
if (otext.isPresent()) {
text = otext.get();
}
}
return text;
}
use of net.minecraft.text.TextColor in project Client by MatHax.
the class TextUtils method preOrderTraverse.
private static void preOrderTraverse(Text text, Stack<ColoredText> stack, List<ColoredText> coloredTexts) {
if (text == null)
return;
String textString = text.asString();
TextColor mcTextColor = text.getStyle().getColor();
Color textColor;
if (mcTextColor == null) {
if (stack.empty())
textColor = new Color(255, 255, 255);
else
textColor = stack.peek().getColor();
} else
textColor = new Color((text.getStyle().getColor().getRgb()) | 0xFF000000);
ColoredText coloredText = new ColoredText(textString, textColor);
coloredTexts.add(coloredText);
stack.push(coloredText);
for (Text child : text.getSiblings()) preOrderTraverse(child, stack, coloredTexts);
stack.pop();
}
use of net.minecraft.text.TextColor in project Client by MatHax.
the class ToastSystem method setText.
public void setText(@Nullable String text) {
this.text = text != null ? new LiteralText(text).setStyle(Style.EMPTY.withColor(new TextColor(textColor))) : null;
justUpdated = true;
}
Aggregations