Minecraft-Console-Client/MinecraftClient/Inventory
BruceChen 8eac21b4a4 Wire up 1.20.6 structured components to Item and fix GetItemSlot serialization
In 1.20.6+, items use structured components instead of NBT for metadata.
Previously, ReadNextItemSlot parsed the components but never stored them
on the Item instance, leaving DisplayName/Lores/Damage/Enchantments all
empty. GetItemSlot also still used the pre-1.20.6 format (bool + VarInt +
byte + NBT), causing the server to reject any item operation packets.

Changes:

Item.cs:
- Add List<StructuredComponent>? Components field to hold the raw
  component list for round-trip serialization
- DisplayName property: read from CustomNameComponent (with
  ItemNameComponent as fallback) when Components is present
- Lores property: read from LoreNameComponent1206 when Components is
  present
- Damage property: read from DamageComponent when Components is present
- Add EnchantmentList property: read from EnchantmentsComponent (covers
  both normal and StoredEnchantmentsComponent for enchanted books)
- ToFullString(): use EnchantmentList with EnchantmentMapping for display
  when available, fall back to NBT path for older versions
- Add CloneWithCount() method that preserves both NBT and Components

DataTypes.cs - ReadNextItemSlot:
- Assign parsed strcturedComponentsToAdd to item.Components

DataTypes.cs - GetItemSlot:
- Add 1.20.6+ branch: write VarInt(count) + VarInt(itemId) + component
  counts + serialized components (using each component's TypeId and
  Serialize() method)
- Empty slot sends VarInt(0) per the 1.20.6 protocol spec

StructuredComponent.cs:
- Add int TypeId property (default -1) to store the registry type ID
  assigned during parsing, enabling round-trip serialization

StructuredComponentRegistry.cs:
- Set component.TypeId = id after instantiation in ParseComponent()

McClient.cs:
- Replace manual Item constructor calls (new Item(type, count, nbt))
  with Item.CloneWithCount() to preserve Components during inventory
  operations like slot moves, stack splits, and right-click placement

Made-with: Cursor
2026-03-19 00:34:10 +08:00
..
ItemPalettes Inventory, Terrain and Entity handling 2024-07-02 11:08:46 +02:00
BookPage.cs Added more structured components 2024-09-11 20:58:24 +02:00
Container.cs Added enchanting 2022-10-12 19:51:01 +02:00
ContainerExtensions.cs Added slab handling for 1.20/.1 2023-06-23 16:25:18 +02:00
ContainerType.cs Fix all warnings & Trim (#2226) 2022-10-02 18:31:08 +08:00
ContainerTypeExtensions.cs Crowdin localization support (#2310) 2022-10-28 11:13:20 +08:00
Effects.cs [SKIP_BUILD] Change file encoding to UTF-8 with BOM 2022-11-28 13:55:05 +08:00
Enchantment.cs WIP: Added some strctured components 2024-09-11 19:12:31 +02:00
EnchantmentData.cs WIP: Added some strctured components 2024-09-11 19:12:31 +02:00
EnchantmentMapping.cs Preliminary 1.21 Support 2024-12-06 16:45:48 +01:00
EnchantmentPropertyInfo.cs Added enchanting 2022-10-12 19:51:01 +02:00
Enchantments.cs WIP: Added some strctured components 2024-09-11 19:12:31 +02:00
Hand.cs [SKIP_BUILD] Change file encoding to UTF-8 with BOM 2022-11-28 13:55:05 +08:00
Item.cs Wire up 1.20.6 structured components to Item and fix GetItemSlot serialization 2026-03-19 00:34:10 +08:00
ItemMovingHelper.cs Implement command completion suggestions. 2022-12-06 15:50:17 +08:00
ItemRarity.cs WIP: Added some strctured components 2024-09-11 19:12:31 +02:00
ItemType.cs Inventory, Terrain and Entity handling 2024-07-02 11:08:46 +02:00
ItemTypeExtensions.cs Fix all warnings & Trim (#2226) 2022-10-02 18:31:08 +08:00
SuspiciousStewEffect.cs Added more structured components 2024-09-11 20:58:24 +02:00
TrimAssetOverride.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
VillagerInfo.cs Implement command completion suggestions. 2022-12-06 15:50:17 +08:00
VillagerTrade.cs Fix all warnings & Trim (#2226) 2022-10-02 18:31:08 +08:00
WindowActionType.cs Added ShiftRightClick (#2582) 2023-09-16 19:39:55 +08:00