mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
fix: Support hex RGB colors (#RRGGBB) in chat messages (fixes #2054)
Minecraft 1.16+ servers can send custom hex colors in JSON text
components ("color": "#RRGGBB"). MCC's ChatParser.Color2tag() only
recognized the 16 named colors, silently dropping hex values and
leaving gradient/custom-colored chat as uncolored plain text.
- ChatParser: recognize hex color values and emit internal §#rrggbb
encoding; extend ColorCodeRegex to match the new format
- ClassicConsoleBackend: resolve §#rrggbb to ANSI escape codes via
ColorHelper before passing to ConsoleInteractive (adapts to the
configured ConsoleColorMode: 24-bit, 8-bit, 4-bit, or disable)
- McColorParser (TUI): parse §#rrggbb into exact SolidColorBrush
for full RGB fidelity in Avalonia
- ChatBot.GetVerbatim(): skip the full 8-char §#rrggbb sequence
instead of only 2 chars, preventing hex digits from leaking into
stripped text
Made-with: Cursor
This commit is contained in:
parent
914c56fc6e
commit
7fd70ccf38
4 changed files with 80 additions and 6 deletions
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
|
@ -612,7 +612,7 @@ namespace MinecraftClient.Scripting
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove color codes ("§c") from a text message received from the server
|
||||
/// Remove color codes ("§c" and "§#rrggbb") from a text message received from the server
|
||||
/// </summary>
|
||||
public static string GetVerbatim(string? text)
|
||||
{
|
||||
|
|
@ -623,10 +623,20 @@ namespace MinecraftClient.Scripting
|
|||
var data = new char[text.Length];
|
||||
|
||||
for (int i = 0; i < text.Length; i++)
|
||||
{
|
||||
if (text[i] != '§')
|
||||
{
|
||||
data[idx++] = text[i];
|
||||
}
|
||||
else if (i + 1 < text.Length && text[i + 1] == '#' && i + 7 < text.Length)
|
||||
{
|
||||
i += 7; // skip §#rrggbb (8 chars total, loop increments once)
|
||||
}
|
||||
else
|
||||
i++;
|
||||
{
|
||||
i++; // skip §x (2 chars total)
|
||||
}
|
||||
}
|
||||
|
||||
return new string(data, 0, idx);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue