Fixed translations crash

This commit is contained in:
Anon 2024-02-28 11:48:23 +01:00
parent 620e8bf274
commit bc0781cee9
2 changed files with 5706 additions and 4990 deletions

View file

@ -450,13 +450,19 @@ namespace MinecraftClient.Protocol.Message
case "extra": case "extra":
{ {
object[] extras = (object[])value; object[] extras = (object[])value;
for (int i = 0; i < extras.Length; i++) for (var i = 0; i < extras.Length; i++)
{ {
try try
{ {
var extraDict = extras[i] is string var extraDict = extras[i] switch
? new Dictionary<string, object>() { { "text", (string)extras[i] } } {
: (Dictionary<string, object>)extras[i]; int => new Dictionary<string, object> { { "text", $"{extras[i]}" } },
string => new Dictionary<string, object>
{
{ "text", (string)extras[i] }
},
_ => (Dictionary<string, object>)extras[i]
};
extraBuilder.Append(NbtToString(extraDict) + "§r"); extraBuilder.Append(NbtToString(extraDict) + "§r");
} }
@ -480,13 +486,19 @@ namespace MinecraftClient.Protocol.Message
if (nbt.TryGetValue("with", out object withComponent)) if (nbt.TryGetValue("with", out object withComponent))
{ {
var withs = (object[])withComponent; var withs = (object[])withComponent;
for (int i = 0; i < withs.Length; i++) for (var i = 0; i < withs.Length; i++)
{ {
try try
{ {
var withDict = withs[i] is string var withDict = withs[i] switch
? new Dictionary<string, object>() { { "text", (string)withs[i] } } {
: (Dictionary<string, object>)withs[i]; int => new Dictionary<string, object> { { "text", $"{withs[i]}" } },
string => new Dictionary<string, object>
{
{ "text", (string)withs[i] }
},
_ => (Dictionary<string, object>)withs[i]
};
translateString.Add(NbtToString(withDict)); translateString.Add(NbtToString(withDict));
} }

File diff suppressed because it is too large Load diff