Skip to content

Add nbtOptionalLengthPrefixed datatype (length-prefixed optional NBT)#1495

Open
atiweb wants to merge 1 commit into
PrismarineJS:masterfrom
atiweb:feat/nbt-optional-length-prefixed
Open

Add nbtOptionalLengthPrefixed datatype (length-prefixed optional NBT)#1495
atiweb wants to merge 1 commit into
PrismarineJS:masterfrom
atiweb:feat/nbt-optional-length-prefixed

Conversation

@atiweb

@atiweb atiweb commented Jun 15, 2026

Copy link
Copy Markdown

What

Adds a nbtOptionalLengthPrefixed datatype: 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 by ServerboundCustomClickActionPacket and the dialog system introduced in 1.21.6. The empty tag is a single TAG_END (0x00) byte, so an absent value encodes as 01 00 (length 1, then TAG_END).

Why

It's the datatype minecraft-data needs to describe custom_click_action's payload correctly. Today that payload is typed as option<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.js checks, against bytes captured from a real 1.21.11 dialog submit, that a present compound { password: "hello world" } encodes as 1a (VarInt 26) + the 26-byte anonymous NBT, round-trips, and that an absent tag is 01 00.

The matching minecraft-data change (typing custom_click_action.payload as nbtOptionalLengthPrefixed) is a separate PR.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant