Minecraft-Console-Client/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6
BruceChen 1e2b853b14 Fix PotionContentsComponent and InstrumentComponent serialization for 1.20.6
Both components had incorrect Parse/Serialize implementations that would
cause packet deserialization misalignment when encountered in-game.

PotionContentsComponent (3 bugs):
- Serialize unconditionally wrote VarInt(PotionId) and Int(CustomColor)
  even when HasPotionId/HasCustomColor was false. The official format
  (PotionContents.STREAM_CODEC) uses Optional encoding: Bool(hasValue)
  followed by the value only when true. The extra bytes caused all
  subsequent fields in the packet to be read at wrong offsets.
- Serialize omitted the VarInt(count) prefix for the custom effects list.
  The official codec uses ByteBufCodecs.list() which always writes a
  VarInt count header before the list elements.
- Also fixed typo: PotiononId -> PotionId.

InstrumentComponent (3 bugs):
- The official Instrument.STREAM_CODEC uses ByteBufCodecs.holder() which
  encodes as VarInt(holderId): 0 = inline data, N>0 = registry ref (N-1).
  The SoundEvent field inside uses the same holder pattern. The old code
  unconditionally read SoundName (ResourceLocation) and HasFixedRange/
  FixedRange even when SoundEventHolderId != 0 (registry reference case
  has no inline data).
- UseDuration was read/written as Float, but the official codec uses
  ByteBufCodecs.VAR_INT. This caused a 4-byte vs variable-length
  mismatch that would shift all subsequent data.
- HasFixedRange was read unconditionally when SoundEventHolderId == 0,
  but FixedRange was also read unconditionally. The official SoundEvent
  DIRECT_STREAM_CODEC uses Optional<Float> encoding: Bool(hasValue)
  followed by Float only when true.

These components are used for potion items and goat horns respectively.
Verified against official 1.20.6 decompiled source:
- net.minecraft.world.item.alchemy.PotionContents (STREAM_CODEC)
- net.minecraft.world.item.Instrument (STREAM_CODEC/DIRECT_STREAM_CODEC)
- net.minecraft.sounds.SoundEvent (STREAM_CODEC/DIRECT_STREAM_CODEC)
- net.minecraft.network.codec.ByteBufCodecs (holder/optional/list)

Made-with: Cursor
2026-03-19 01:44:23 +08:00
..
AttributeModifiersComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
BannerPatternsComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
BaseColorComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
BeesComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
BlockStateComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
BundleContentsComponent.cs Fix StructuredComponent serialization correctness for 1.20.6 2026-03-19 01:37:56 +08:00
CanBreakComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
CanPlaceOnComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
ChargedProjectilesComponent.cs Fix StructuredComponent serialization correctness for 1.20.6 2026-03-19 01:37:56 +08:00
ContainerComponent.cs Fix StructuredComponent serialization correctness for 1.20.6 2026-03-19 01:37:56 +08:00
ContainerLootComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
CreativeSlotLockComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
CustomDataComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
CustomModelDataComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
CustomNameComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
DamageComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
DebugStickStateComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
DyeColorComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
EnchantmentGlintOverrideComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
EnchantmentsComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
EntityDataComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
FireResistantComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
FireworkExplosionComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
FireworksComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
FoodComponentComponent.cs Fix StructuredComponent serialization correctness for 1.20.6 2026-03-19 01:37:56 +08:00
HideAdditionalTooltipComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
HideTooltipComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
InstrumentComponent.cs Fix PotionContentsComponent and InstrumentComponent serialization for 1.20.6 2026-03-19 01:44:23 +08:00
IntangibleProjectileComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
ItemNameComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
LockComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
LodestoneTrackerComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
LoreComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
MapColorComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
MapDecorationsComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
MapIdComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
MapPostProcessingComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
MaxDamageComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
MaxStackSizeComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
NoteBlockSoundComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
OmniousBottleAmplifierComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
PotDecorationsComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
PotionContentsComponent.cs Fix PotionContentsComponent and InstrumentComponent serialization for 1.20.6 2026-03-19 01:44:23 +08:00
ProfileComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
RarityComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
RecipesComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
RepairCostComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
StoredEnchantmentsComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
SuspiciousStewEffectsComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
ToolComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
TrimComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
UnbreakableComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
WritableBlookContentComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
WrittenBlookContentComponent.cs Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00