Minecraft-Console-Client/MinecraftClient/Protocol/Handlers/StructuredComponents/Components/1_20_6/InstrumentComponent.cs

69 lines
2.4 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
public class InstrumentComponent(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry)
: StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
{
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
// holder ID: 0 = inline instrument data, N>0 = registry reference (id = N-1)
public int InstrumentHolderId { get; set; }
// Inline instrument fields (only when InstrumentHolderId == 0):
// holder ID for SoundEvent: 0 = inline sound, N>0 = registry reference (id = N-1)
public int SoundEventHolderId { get; set; }
// Inline SoundEvent fields (only when SoundEventHolderId == 0):
public string? SoundLocation { get; set; }
public bool HasFixedRange { get; set; }
public float FixedRange { get; set; }
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
public int UseDuration { get; set; }
public float Range { get; set; }
public override void Parse(Queue<byte> data)
{
InstrumentHolderId = DataTypes.ReadNextVarInt(data);
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
if (InstrumentHolderId == 0)
{
SoundEventHolderId = DataTypes.ReadNextVarInt(data);
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
if (SoundEventHolderId == 0)
{
SoundLocation = DataTypes.ReadNextString(data);
HasFixedRange = DataTypes.ReadNextBool(data);
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
if (HasFixedRange)
FixedRange = DataTypes.ReadNextFloat(data);
}
UseDuration = DataTypes.ReadNextVarInt(data);
Range = DataTypes.ReadNextFloat(data);
}
}
public override Queue<byte> Serialize()
{
var data = new List<byte>();
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
data.AddRange(DataTypes.GetVarInt(InstrumentHolderId));
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
if (InstrumentHolderId == 0)
{
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
data.AddRange(DataTypes.GetVarInt(SoundEventHolderId));
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
if (SoundEventHolderId == 0)
{
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
data.AddRange(DataTypes.GetString(SoundLocation ?? ""));
data.AddRange(DataTypes.GetBool(HasFixedRange));
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
if (HasFixedRange)
data.AddRange(DataTypes.GetFloat(FixedRange));
}
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
data.AddRange(DataTypes.GetVarInt(UseDuration));
data.AddRange(DataTypes.GetFloat(Range));
}
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
return new Queue<byte>(data);
}
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
}