Fix enchant_item button id: varint, not i8 (1.21 container rework)#1201
Open
atiweb wants to merge 1 commit into
Open
Fix enchant_item button id: varint, not i8 (1.21 container rework)#1201atiweb wants to merge 1 commit into
atiweb wants to merge 1 commit into
Conversation
ServerboundContainerButtonClickPacket (minecraft-data packet_enchant_item) was reworked in 1.21 to encode the button id as a VarInt. The vanilla codec is StreamCodec.composite(CONTAINER_ID/VAR_INT, ::containerId, VAR_INT, ::buttonId). mcdata updated windowId to ContainerID (varint) for 1.21+ but left enchantment (the button id) as i8. Before 1.21 both fields were a single byte (readByte/writeByte), so i8 is correct there; this only affects 1.21.1-1.21.11. A VarInt and a byte encode identically for button ids below 128, so it seldom breaks, but a button id >= 128 (e.g. a stonecutter/loom recipe index on a server with many recipes) needs a 2-byte VarInt that an i8 writer cannot represent. Serverbound. Verified against the Mojang server jars: byte/byte in 1.19.4, VAR_INT button id in 1.21.1 and 1.21.3-1.21.9. proto.yml edited, protocol.json regenerated with npm run build.
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.
Problem
packet_enchant_item(vanillaServerboundContainerButtonClickPacket) defines itsenchantmentfield — the container button id — asi8. Since the 1.21 container rework the vanilla codec encodes it as a VarInt:minecraft-data already updated
windowIdtoContainerID(varint) for 1.21+, but leftenchantmentasi8— an incomplete update of the same packet.i8i8✓ContainerIDi8✗Before 1.21 both fields were a single byte (
readByte/writeByte), soi8is correct there — this only affects 1.21.1 – 1.21.11.Impact
A VarInt and a byte encode identically for button ids below 128, so it seldom surfaces. But a button id ≥ 128 — e.g. a stonecutter or loom recipe index on a server with a large recipe set — needs a 2-byte VarInt that an
i8writer cannot represent. The packet is serverbound, so this affects any client encoding it.Verification
Decompiled the official Mojang server jars:
readByte/writeBytefor both fields in 1.19.4 (pre-rework), and aVAR_INTbutton id in 1.21.1 (where the rework lands) and 1.21.3 / 1.21.5 / 1.21.6 / 1.21.8 / 1.21.9.Change
enchantment: i8→enchantment: varintinpacket_enchant_item, for 1.21.1 → 1.21.11.proto.ymledited andprotocol.jsonregenerated withnpm run build(16 files, +16/−16; nothing else touched).node compileProtocol.jsvalidate passes for all versions.