forked from ChomeNS/chipmunkmod
add color code support (ohio code)
<3
This commit is contained in:
parent
60a1074759
commit
8ae88917e1
2 changed files with 16 additions and 1 deletions
|
@ -31,6 +31,8 @@ dependencies {
|
|||
|
||||
modImplementation include("net.kyori:adventure-platform-fabric:5.8.0") // for Minecraft 1.19.4
|
||||
|
||||
modImplementation include("net.kyori:adventure-text-serializer-legacy:4.13.1")
|
||||
|
||||
// Uncomment the following line to enable the deprecated Fabric API modules.
|
||||
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@ import lombok.Getter;
|
|||
import lombok.Setter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
|
||||
|
@ -40,6 +42,11 @@ public class CustomChat {
|
|||
.replace("\\", "\\\\")
|
||||
.replace("\"", "\\\"");
|
||||
|
||||
final LegacyComponentSerializer serializer = LegacyComponentSerializer.legacyAmpersand();
|
||||
|
||||
final Component deserialized = serializer.deserialize(sanitizedMessage);
|
||||
final String messageWithColor = GsonComponentSerializer.gson().serialize(deserialized);
|
||||
|
||||
try {
|
||||
// final MutablePlayerListEntry entry = Players.INSTANCE.getEntry(client.getNetworkHandler().getProfile().getId());
|
||||
|
||||
|
@ -48,11 +55,17 @@ public class CustomChat {
|
|||
// final String prefix = GsonComponentSerializer.gson().serialize(Component.join(JoinConfiguration.separator(Component.empty()), displayNameComponent.children().get(0)));
|
||||
// final String displayName = GsonComponentSerializer.gson().serialize(Component.join(JoinConfiguration.separator(Component.empty()), displayNameComponent.children().get(1)));
|
||||
|
||||
// TODO: make this code not ohio code.,.,
|
||||
final String sanitizedFormat = format
|
||||
// .replace("\"PREFIX\"", prefix)
|
||||
// .replace("\"DISPLAYNAME\"", displayName)
|
||||
.replace("USERNAME", username)
|
||||
.replace("MESSAGE", sanitizedMessage);
|
||||
|
||||
// these 2 lines are toooooo ohio code
|
||||
.replace("{\"text\":\"MESSAGE\"}", messageWithColor)
|
||||
.replace("\"extra\":[\"MESSAGE\"],\"color\":", "\"extra\":[" + messageWithColor + "],\"color\":")
|
||||
|
||||
.replace("MESSAGE", sanitizedMessage.replaceAll("&.", "")); // TODO: make this not use regex
|
||||
|
||||
CommandCore.INSTANCE.run("minecraft:tellraw @a " + sanitizedFormat);
|
||||
} catch (Exception e) {
|
||||
|
|
Loading…
Reference in a new issue