Fix EntityProperties attribute ID mapping for 1.20.6

The 1.20.6 EntityProperties packet sends attribute IDs as VarInts
instead of strings. The existing mapping dictionary had three issues:

1. IDs 5/6/7 used the wrong prefix "generic." but the official
   1.20.6 registry uses "player." for these attributes:
   - 5: player.block_break_speed (was generic.block_break_speed)
   - 6: player.block_interaction_range (was generic.block_interaction_range)
   - 7: player.entity_interaction_range (was generic.entity_interaction_range)

2. IDs 22-24 (submerged_mining_speed, sweeping_damage_ratio,
   water_movement_efficiency) do not exist in the 1.20.6 attribute
   registry — they were introduced in 1.21. Their presence could
   cause incorrect attribute resolution.

3. Direct dictionary indexing (attributeDictionary[id]) throws
   KeyNotFoundException if the server sends an unknown attribute ID,
   crashing the packet handler. Replaced with TryGetValue and a
   safe fallback to "unknown".

Made-with: Cursor
This commit is contained in:
BruceChen 2026-03-19 00:12:06 +08:00
parent ff1c570a78
commit a7a95d991c

View file

@ -2521,9 +2521,9 @@ namespace MinecraftClient.Protocol.Handlers
{ 2, "generic.attack_damage" },
{ 3, "generic.attack_knockback" },
{ 4, "generic.attack_speed" },
{ 5, "generic.block_break_speed" },
{ 6, "generic.block_interaction_range" },
{ 7, "generic.entity_interaction_range" },
{ 5, "player.block_break_speed" },
{ 6, "player.block_interaction_range" },
{ 7, "player.entity_interaction_range" },
{ 8, "generic.fall_damage_multiplier" },
{ 9, "generic.flying_speed" },
{ 10, "generic.follow_range" },
@ -2537,17 +2537,16 @@ namespace MinecraftClient.Protocol.Handlers
{ 18, "generic.safe_fall_distance" },
{ 19, "generic.scale" },
{ 20, "zombie.spawn_reinforcements" },
{ 21, "generic.step_height" },
{ 22, "generic.submerged_mining_speed" },
{ 23, "generic.sweeping_damage_ratio" },
{ 24, "generic.water_movement_efficiency" }
{ 21, "generic.step_height" }
};
Dictionary<string, double> keys = new();
for (var i = 0; i < numberOfProperties; i++)
{
var propertyKey = protocolVersion < MC_1_20_6_Version ? dataTypes.ReadNextString(packetData)
: attributeDictionary[dataTypes.ReadNextVarInt(packetData)];
var propertyKey = protocolVersion < MC_1_20_6_Version
? dataTypes.ReadNextString(packetData)
: (attributeDictionary.TryGetValue(dataTypes.ReadNextVarInt(packetData), out var attrName)
? attrName : "unknown");
var propertyValue2 = dataTypes.ReadNextDouble(packetData);
List<double> op0 = new();