Skip to content

Commit

Permalink
make a text to (& code) string function
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeRNG committed Jun 27, 2024
1 parent 2f09d9f commit 292e221
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
23 changes: 23 additions & 0 deletions src/main/java/dev/dfonline/codeclient/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import dev.dfonline.codeclient.action.impl.GetActionDump;
import dev.dfonline.codeclient.action.impl.PlaceTemplates;
import dev.dfonline.codeclient.hypercube.template.Template;
import dev.dfonline.codeclient.hypercube.template.TemplateBlock;
Expand Down Expand Up @@ -353,4 +354,26 @@ public static HashMap<Integer, String> getBlockTagLines(ItemStack item) {

return options;
}

public static void textToString(Text content, StringBuilder build, GetActionDump.ColorMode colorMode) {
TextColor lastColor = null;
for (Text text : content.getSiblings()) {
TextColor color = text.getStyle().getColor();
if (color != null && (lastColor != color) && (colorMode != GetActionDump.ColorMode.NONE)) {
lastColor = color;
if (color.getName().contains("#")) {
build.append(String.join(colorMode.text, color.getName().split("")).replace("#", colorMode.text + "x").toLowerCase());
} else {
build.append(Formatting.valueOf(String.valueOf(color).toUpperCase()).toString().replace("§", colorMode.text));
}
}
build.append(text.getString());
}
}

public static String textToString(Text content) {
var builder = new StringBuilder();
textToString(content, builder, GetActionDump.ColorMode.SECTION);
return builder.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package dev.dfonline.codeclient.action.impl;

import dev.dfonline.codeclient.Callback;
import dev.dfonline.codeclient.CodeClient;
import dev.dfonline.codeclient.FileManager;
import dev.dfonline.codeclient.OverlayManager;
import dev.dfonline.codeclient.*;
import dev.dfonline.codeclient.action.Action;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
import net.minecraft.text.Text;
import net.minecraft.text.TextColor;
import net.minecraft.util.Formatting;

import java.io.IOException;
Expand Down Expand Up @@ -49,19 +45,7 @@ public boolean onReceivePacket(Packet<?> packet) {

return true;
}
TextColor lastColor = null;
for (Text text : message.content().getSiblings()) {
TextColor color = text.getStyle().getColor();
if (color != null && (lastColor != color) && (colorMode != ColorMode.NONE)) {
lastColor = color;
if (color.getName().contains("#")) {
capturedData.append(String.join(colorMode.text, color.getName().split("")).replace("#", colorMode.text + "x").toLowerCase());
} else {
capturedData.append(Formatting.valueOf(String.valueOf(color).toUpperCase()).toString().replace("§", colorMode.text));
}
}
capturedData.append(text.getString());
}
Utility.textToString(message.content(), capturedData, colorMode);
String content = message.content().getString();
capturedData.append("\n");
lines += 1;
Expand Down

0 comments on commit 292e221

Please sign in to comment.