Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
Fix color issue
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkKronicle committed Jul 25, 2022
1 parent 58f5c42 commit 4d2a5fa
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ yarn_mappings=1.19+build.4
loader_version=0.14.8
fabric_api_version=0.57.0+1.19

mod_version=1.5.3
mod_version=1.5.4
maven_group=io.github.darkkronicle
archives_base_name=AdvancedChatCore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public OrderedText asOrderedText() {
return language.reorder(this);
}

public RawText withString(String string) {
return RawText.of(string, style);
}

public static RawText of(String string) {
return RawText.of(string, Style.EMPTY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,8 @@ public static MutableText flattenText(Text text) {
*/
public static List<Text> wrapText(TextRenderer textRenderer, int scaledWidth, Text text) {
ArrayList<Text> lines = new ArrayList<>();
for (OrderedText breakRenderedChatMessageLine :
ChatMessages.breakRenderedChatMessageLines(text, scaledWidth, textRenderer)) {
StringBuilder breakRenderedChatMessageLineString = new StringBuilder();
breakRenderedChatMessageLine.accept(new CharacterVisitor() {
public boolean accept(int index, net.minecraft.text.Style style, int codePoint) {
breakRenderedChatMessageLineString.append((char) codePoint);

return true;
}
});

lines.add(Text.literal(breakRenderedChatMessageLineString.toString()));
for (OrderedText breakRenderedChatMessageLine : ChatMessages.breakRenderedChatMessageLines(text, scaledWidth, textRenderer)) {
lines.add(new TextBuilder().append(breakRenderedChatMessageLine).build());
}
return lines;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ public List<RawText> getTexts() {
return siblings;
}

public TextBuilder append(OrderedText text) {
AtomicReference<Style> last = new AtomicReference<>(null);
AtomicReference<StringBuilder> builder = new AtomicReference<>(new StringBuilder());
text.accept((index, style, codePoint) -> {
if (last.get() == null) {
last.set(style);
builder.get().append(Character.toChars(codePoint));
return true;
} else if (last.get().equals(style)) {
builder.get().append(Character.toChars(codePoint));
return true;
}
append(builder.get().toString(), last.get());
last.set(style);
builder.set(new StringBuilder().append(Character.toChars(codePoint)));
return true;
});
if (!builder.get().isEmpty()) {
append(builder.get().toString(), last.get());
}
return this;
}

public TextBuilder append(Text text) {
AtomicReference<Style> last = new AtomicReference<>(null);
AtomicReference<StringBuilder> builder = new AtomicReference<>(new StringBuilder());
Expand Down

2 comments on commit 4d2a5fa

@Kale-Ko
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course there was such a simpler way to do that xD

@DarkKronicle
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to have access to a utility class so figured this implementation would come in use later. Also helps fix some edge cases with certain text implementation.

Please sign in to comment.