Add nbtOptionalLengthPrefixed datatype (length-prefixed optional NBT)#1495
Open
atiweb wants to merge 1 commit into
Open
Add nbtOptionalLengthPrefixed datatype (length-prefixed optional NBT)#1495atiweb wants to merge 1 commit into
atiweb wants to merge 1 commit into
Conversation
A network (anonymous) optional NBT tag preceded by its byte length as a VarInt -- Mojang's ByteBufCodecs.optionalTagCodec(...).apply(ByteBufCodecs.lengthPrefixed(N)), used by ServerboundCustomClickActionPacket and the dialog system added in 1.21.6. An empty tag is a single TAG_END byte, so an absent value encodes as `01 00`. This is the datatype minecraft-data needs to define custom_click_action's payload correctly; it is currently typed as option<anonymousNbt>, which emits a spurious presence boolean and omits the length prefix. See PrismarineJS#1484. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
nbtOptionalLengthPrefixeddatatype: a network (anonymous) optional NBT tag preceded by its byte length as a VarInt.This is Mojang's
ByteBufCodecs.optionalTagCodec(...).apply(ByteBufCodecs.lengthPrefixed(N)), used byServerboundCustomClickActionPacketand the dialog system introduced in 1.21.6. The empty tag is a singleTAG_END(0x00) byte, so an absent value encodes as01 00(length 1, thenTAG_END).Why
It's the datatype
minecraft-dataneeds to describecustom_click_action's payload correctly. Today that payload is typed asoption<anonymousNbt>, which emits a spurious presence boolean and omits the length prefix, so the bytes sent to the server are wrong. See #1484.Validation
test/nbtOptionalLengthPrefixedTest.jschecks, against bytes captured from a real 1.21.11 dialog submit, that a present compound{ password: "hello world" }encodes as1a(VarInt 26) + the 26-byte anonymous NBT, round-trips, and that an absent tag is01 00.The matching
minecraft-datachange (typingcustom_click_action.payloadasnbtOptionalLengthPrefixed) is a separate PR.