Minecraft-Console-Client/MinecraftClient
BruceChen 56f2426c1f Fix StructuredComponent serialization correctness for 1.20.6
Audited all 58 StructuredComponent subclasses against the official Minecraft
1.20.6 decompiled source to verify Parse()/Serialize() symmetry. Found and
fixed four bugs across four components:

1. ContainerComponent: Parse() skipped null item slots (empty slots in a
   container) but Serialize() looped NumberOfItems times using Items[i],
   causing IndexOutOfRangeException when any slot was empty. The official
   ItemContainerContents uses OPTIONAL_STREAM_CODEC which serializes empty
   slots as VarInt(0). Fixed: Parse now stores all slots including nulls,
   Serialize uses Items.Count and iterates all entries. GetItemSlot(null)
   correctly writes VarInt(0) for empty slots.

2. ChargedProjectilesComponent: Used Items.OfType<Item>() in Serialize()
   which silently dropped null entries, causing the serialized count to
   differ from the written VarInt header. The official ChargedProjectiles
   uses STREAM_CODEC (non-optional, no empty slots allowed). Fixed: Items
   list is now List<Item> (non-nullable), Parse defensively skips nulls,
   Serialize writes Items.Count matching the actual list.

3. BundleContentsComponent: Same issue as ChargedProjectilesComponent.
   Applied the same fix pattern.

4. FoodComponentComponent: Two type mismatches vs the official
   FoodProperties.DIRECT_STREAM_CODEC:
   - Saturation was declared as bool and read with ReadNextBool (1 byte),
     but the protocol sends it as float (4 bytes). This caused all
     subsequent fields in the component to be read at wrong offsets,
     corrupting CanAlwaysEat, SecondsToEat, and the effects list.
   - NumberOfEffects was serialized with GetFloat() instead of GetVarInt(),
     writing 4 bytes of IEEE 754 float instead of a variable-length integer.
   Fixed both Parse and Serialize to use correct types.

Also removed redundant NumberOfItems/NumberOfEffects fields from components
where the count is derivable from the list length, and replaced
ArgumentNullException with cleaner patterns.

Tested end-to-end on vanilla 1.20.6 server: item receiving (diamond_sword,
golden_apple, diamond_pickaxe), inventory slot movement (click to pick up
and place), and inventory listing all work correctly with no server-side
protocol errors.

Made-with: Cursor
2026-03-19 01:37:56 +08:00
..
ChatBots Add FileInputBot for non-interactive debugging and fix NbtToString crash 2026-03-19 00:45:51 +08:00
CommandHandler [skip ci] Miscellaneous scripting QoL improvements and fixes (#2740) 2024-06-22 06:40:23 +08:00
Commands Handle non-interactive terminal environments gracefully 2026-03-19 00:11:13 +08:00
config Merge into master 2022-12-06 20:32:46 +08:00
Crypto Trim 2023-01-14 21:07:09 +08:00
Inventory Wire up 1.20.6 structured components to Item and fix GetItemSlot serialization 2026-03-19 00:34:10 +08:00
Logger Implement command completion suggestions. 2022-12-06 15:50:17 +08:00
Mapping Fix EntityProperties crash and add default attribute registry fallback 2026-03-19 01:26:20 +08:00
Properties Fix all warnings & Trim (#2226) 2022-10-02 18:31:08 +08:00
Protocol Fix StructuredComponent serialization correctness for 1.20.6 2026-03-19 01:37:56 +08:00
Proxy Tooltip support & Bug fix 2022-12-11 13:00:19 +08:00
Resources Add Sentry Error Tracking (#2670) 2024-06-22 06:41:13 +08:00
Scripting Merge branch 'master' into 1.20.6 2025-12-02 00:06:16 +08:00
WinAPI Bug fix 2022-10-10 10:56:12 +08:00
AutoTimeout.cs Fix all warnings & Trim (#2226) 2022-10-02 18:31:08 +08:00
ColorHelper.cs legacy color support 2022-12-14 14:45:51 +08:00
Command.cs Bug fix 2022-12-11 16:30:45 +08:00
ConsoleIO.cs fixed typo in word heAlper lol 2024-04-16 21:21:08 +03:00
ExtensionMethods.cs Better translation 2022-10-17 20:00:33 +08:00
FileMonitor.cs Remove color code from text 2022-11-30 16:08:55 +08:00
INIFile.cs [skip ci] Normalize all line endings 2023-09-15 14:44:11 +08:00
Json.cs Re-added WebSocketChat bot and improved it, no longer using WebsocketSharp library 2023-05-27 19:46:28 +02:00
McClient.cs Add FileInputBot for non-interactive debugging and fix NbtToString crash 2026-03-19 00:45:51 +08:00
MinecraftClient.csproj Ported to .NET 8 2024-12-22 13:20:04 +01:00
Program.cs Handle non-interactive terminal environments gracefully 2026-03-19 00:11:13 +08:00
Settings.cs Temporarily removed WebSocket bot because of a false positive virus detection. I will make it in to a standalone bot later. 2025-05-22 13:56:27 +02:00
TaskWithDelay.cs Fix all warnings & Trim (#2226) 2022-10-02 18:31:08 +08:00
TaskWithResult.cs Fix all warnings & Trim (#2226) 2022-10-02 18:31:08 +08:00
UpgradeHelper.cs Make UpgradeHelper compliant with .NET RID catalog 2023-03-29 20:15:22 +08:00