From a7a95d991c9298d116383c9334475cc03e0d1501 Mon Sep 17 00:00:00 2001 From: BruceChen Date: Thu, 19 Mar 2026 00:12:06 +0800 Subject: [PATCH] Fix EntityProperties attribute ID mapping for 1.20.6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- MinecraftClient/Protocol/Handlers/Protocol18.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index f552b2f9..a274b6e4 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -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 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 op0 = new();