feat: add version routing and metadata reading for MC 1.21.9

- Route block/entity/item/packet/metadata palettes to new 1219 variants
  for protocol >= 773, and raise upper-bound guards from MC_1_21_7 to
  MC_1_21_9 so terrain, inventory, and entity handling are enabled.
- Add DataTypes readers for three new entity metadata serializer types:
  CopperGolemState and WeatheringCopperState (both VarInt), and
  ResolvableProfile (composite: Either<GameProfile, Partial> with
  optional name/UUID/properties + PlayerSkin.Patch with 4 optional
  fields for body/cape/elytra texture ResourceLocations and model type).

Made-with: Cursor
This commit is contained in:
BruceChen 2026-03-21 14:05:06 +08:00
parent 67ad5fcf97
commit 88e9c671da
3 changed files with 65 additions and 2 deletions

View file

@ -24,7 +24,8 @@ public abstract class EntityMetadataPalette
<= Protocol18Handler.MC_1_19_3_Version => new EntityMetadataPalette1193(), // 1.19.3
< Protocol18Handler.MC_1_20_6_Version => new EntityMetadataPalette1194(), // 1.19.4 - 1.20.4
<= Protocol18Handler.MC_1_21_4_Version => new EntityMetadataPalette1206(), // 1.20.6 - 1.21.4
<= Protocol18Handler.MC_1_21_7_Version => new EntityMetadataPalette1215(), // 1.21.5 - 1.21.7
<= Protocol18Handler.MC_1_21_7_Version => new EntityMetadataPalette1215(), // 1.21.5 - 1.21.8
<= Protocol18Handler.MC_1_21_9_Version => new EntityMetadataPalette1219(), // 1.21.9 - 1.21.10
_ => throw new NotImplementedException()
};
}

View file

@ -907,6 +907,13 @@ namespace MinecraftClient.Protocol.Handlers
case EntityMetaDataType.ArmadilloState: // Armadillo state (1.20.6+)
value = ReadNextVarInt(cache);
break;
case EntityMetaDataType.CopperGolemState: // Copper Golem state (1.21.9+)
case EntityMetaDataType.WeatheringCopperState: // Weathering Copper state (1.21.9+)
value = ReadNextVarInt(cache);
break;
case EntityMetaDataType.ResolvableProfile: // ResolvableProfile (1.21.9+)
ReadNextResolvableProfile(cache);
break;
case EntityMetaDataType.Vector3: // Vector 3f
value = new List<float>
{
@ -938,6 +945,60 @@ namespace MinecraftClient.Protocol.Handlers
}
}
/// <summary>
/// Consume bytes for a ResolvableProfile (1.21.9+).
/// Wire: Either(GameProfile, Partial) + PlayerSkin.Patch
/// </summary>
private void ReadNextResolvableProfile(Queue<byte> cache)
{
bool isFullProfile = ReadNextBool(cache); // Either flag: true=GameProfile, false=Partial
if (isFullProfile)
{
ReadNextUUID(cache); // UUID
ReadNextString(cache); // player name (max 16 chars)
ReadGameProfileProperties(cache);
}
else
{
// Partial: optional name, optional UUID, properties
if (ReadNextBool(cache))
ReadNextString(cache); // optional player name
if (ReadNextBool(cache))
ReadNextUUID(cache); // optional UUID
ReadGameProfileProperties(cache);
}
// PlayerSkin.Patch: 4 optional fields
// body (optional ResourceLocation string)
if (ReadNextBool(cache))
ReadNextString(cache);
// cape
if (ReadNextBool(cache))
ReadNextString(cache);
// elytra
if (ReadNextBool(cache))
ReadNextString(cache);
// model (optional bool: true=SLIM, false=WIDE)
if (ReadNextBool(cache))
ReadNextBool(cache);
}
/// <summary>
/// Read GameProfile properties (PropertyMap): VarInt count, then per entry:
/// name string, value string, optional signature string.
/// </summary>
private void ReadGameProfileProperties(Queue<byte> cache)
{
int count = ReadNextVarInt(cache);
for (int i = 0; i < count; i++)
{
ReadNextString(cache); // property name
ReadNextString(cache); // property value
if (ReadNextBool(cache)) // has signature?
ReadNextString(cache); // signature
}
}
/// <summary>
/// Currently not handled. Reading data only
/// </summary>

View file

@ -48,8 +48,9 @@ namespace MinecraftClient.Protocol.Handlers
{
PacketTypePalette p = protocol switch
{
> Protocol18Handler.MC_1_21_7_Version => throw new NotImplementedException(Translations
> Protocol18Handler.MC_1_21_9_Version => throw new NotImplementedException(Translations
.exception_palette_packet),
<= Protocol18Handler.MC_1_21_9_Version and > Protocol18Handler.MC_1_21_7_Version => new PacketPalette1219(),
<= Protocol18Handler.MC_1_21_7_Version and > Protocol18Handler.MC_1_21_5_Version => new PacketPalette1216(),
<= Protocol18Handler.MC_1_21_5_Version and > Protocol18Handler.MC_1_21_4_Version => new PacketPalette1215(),
<= Protocol18Handler.MC_1_21_4_Version and > Protocol18Handler.MC_1_21_2_Version => new PacketPalette1214(),