Minecraft-Console-Client/MinecraftClient/Mapping
BruceChen b692b13bbc Fix EntityProperties crash and add default attribute registry fallback
After the previous commit (99ac3d0) moved attribute lookup from a hardcoded
dictionary to the dynamic RegistryData, MCC would crash immediately upon
joining a vanilla 1.20.6 server with:

  System.ArgumentException: An item with the same key has already been added.
  Key: unknown

Root cause: When KnownDataPacks negotiation tells the server that MCC already
has the "minecraft" data pack, the server skips sending RegistryData for
registries it considers "known" — including minecraft:attribute. This left
the dynamic attribute map empty, so every VarInt attribute ID resolved to
"unknown". The EntityProperties packet often contains multiple attributes
(e.g. armor, max_health, movement_speed), and `keys.Add("unknown", ...)` on
the second "unknown" attribute threw ArgumentException.

Two fixes applied:

1. World.GetAttributeNameById(): When the dynamic attribute map is empty
   (server didn't send the registry), automatically load the vanilla 1.20.6
   default attribute order (22 entries matching Attributes.java registration
   order). This mirrors the pattern used for dimensions where defaults are
   loaded when RegistryData is not sent. If a modded server sends a custom
   attribute registry, the dynamic map takes precedence.

2. Protocol18.cs EntityProperties handler: Change `keys.Add(propertyKey,
   propertyValue2)` to `keys[propertyKey] = propertyValue2` to tolerate
   duplicate keys defensively, in case an unknown attribute ID still appears.

Tested: MCC now connects to a vanilla 1.20.6 offline-mode server, stays
online for 6+ minutes with no crashes or disconnections. Verified: chat
messages received, inventory listing (item names/counts correct), entity
detection, TPS query, and health query all work correctly.

Made-with: Cursor
2026-03-19 01:26:20 +08:00
..
BlockPalettes Inventory, Terrain and Entity handling 2024-07-02 11:08:46 +02:00
EntityMetadataPalettes Implement 1.8 Entity MetaData 2023-03-27 18:22:50 +08:00
EntityPalettes Inventory, Terrain and Entity handling 2024-07-02 11:08:46 +02:00
Block.cs Implement command completion suggestions. 2022-12-06 15:50:17 +08:00
BlockExtension.cs Added slab handling for 1.20/.1 2023-06-23 16:25:18 +02:00
Chunk.cs Fix all warnings & Trim (#2226) 2022-10-02 18:31:08 +08:00
ChunkColumn.cs Fix all warnings & Trim (#2226) 2022-10-02 18:31:08 +08:00
CombatEventType.cs Added Player Killed event (Combat and CombatDeath packets). 2022-10-26 20:53:09 +02:00
CommandBlockFlags.cs [skip ci] Update Minecraft wiki links to new domain (#2593) 2023-10-07 17:59:08 +08:00
CommandBlockMode.cs [skip ci] Update Minecraft wiki links to new domain (#2593) 2023-10-07 17:59:08 +08:00
Dimension.cs Implement command completion suggestions. 2022-12-06 15:50:17 +08:00
Direction.cs [skip ci] Update Minecraft wiki links to new domain (#2593) 2023-10-07 17:59:08 +08:00
DirectionExtensions.cs Done auxiliary methods for Direction 2024-03-05 21:49:29 +05:00
Entity.cs merge brigadier-dev into milutinke:1.19.3 2023-01-14 20:42:15 +08:00
EntityMetadataPalette.cs Preliminary 1.21 Support 2024-12-06 16:45:48 +01:00
EntityMetaDataType.cs Implement 1.8 Entity MetaData 2023-03-27 18:22:50 +08:00
EntityPose.cs [SKIP_BUILD] Change file encoding to UTF-8 with BOM 2022-11-28 13:55:05 +08:00
EntityType.cs Inventory, Terrain and Entity handling 2024-07-02 11:08:46 +02:00
EntityTypeExtensions.cs Fix all warnings & Trim (#2226) 2022-10-02 18:31:08 +08:00
InteractType.cs Fix all warnings & Trim (#2226) 2022-10-02 18:31:08 +08:00
Location.cs Implement command completion suggestions. 2022-12-06 15:50:17 +08:00
MapIcon.cs Fix all warnings & Trim (#2226) 2022-10-02 18:31:08 +08:00
MapIconType.cs Fix all warnings & Trim (#2226) 2022-10-02 18:31:08 +08:00
Material.cs Inventory, Terrain and Entity handling 2024-07-02 11:08:46 +02:00
Material2Tool.cs Inventory, Terrain and Entity handling 2024-07-02 11:08:46 +02:00
MaterialExtensions.cs Added slab handling 1.13-1.19.4 2023-05-16 23:19:31 +02:00
MessageFilterType.cs Trim 2023-01-14 21:07:09 +08:00
Movement.cs Added slab handling 1.13-1.19.4 2023-05-16 23:19:31 +02:00
RaycastHelper.cs Implement command completion suggestions. 2022-12-06 15:50:17 +08:00
VillagerInfo.cs Adds support for villager trading (#1316) 2020-11-08 23:39:07 +01:00
World.cs Fix EntityProperties crash and add default attribute registry fallback 2026-03-19 01:26:20 +08:00