Skip to content

fix(protocol): fix multi-version client protocol compatibility - #3072

Draft
Q2297045667 wants to merge 6 commits into
Pumpkin-MC:masterfrom
Q2297045667:fix-multi-version-support
Draft

fix(protocol): fix multi-version client protocol compatibility#3072
Q2297045667 wants to merge 6 commits into
Pumpkin-MC:masterfrom
Q2297045667:fix-multi-version-support

Conversation

@Q2297045667

@Q2297045667 Q2297045667 commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Multi-version protocol compatibility fixes

Improved multi-version protocol compatibility and stability for legacy (1.7–1.12) Java clients.

Root Cause

1. Container Content Packet (CSetContainerContent)

  • Offhand slot: The player inventory screen (window ID 0) always contains 46 slots, where index 45 is the offhand slot. The offhand slot was introduced in 1.9, so 1.7/1.8 clients only expect 45 slots. Receiving 46 slots made those clients crash with IndexOutOfBoundsException: Index: 45, Size: 45 while running Container.getSlot(45).
  • Fix: When version < 1.9 && window_id == 0 && slot_data.len() == 46, skip index 45 (the offhand slot) and write a slot count of 45. Behavior for 1.9+ is unchanged. Serialization is read-only, so the server-side offhand stack is never mutated across client-version switches.

2. Multi Block Update Packet (CMultiBlockUpdate)

  • Multi-version chunk handling: Previously the server always wrote the 1.13+ format (i64 chunk position + VarLong records) for every version. 1.9–1.12 clients expect two separate chunk X/Z ints and, per record, a u16 position followed by a VarInt block state; 1.7/1.8 use different formats again. The mismatch caused 1.9–1.12 clients to crash mid-decode with readerIndex ... exceeds writerIndex.
  • Fix: Write the correct format per target version:
    • >= 1.13: i64 chunk section + VarInt count + VarLong records (unchanged).
    • 1.9 – 1.12: chunkX (i32) + chunkZ (i32) + VarInt count + (u16 position + VarInt block state).
    • 1.8: chunkX/chunkZ + VarInt count + (u8 horizontal position + u8 y + VarInt block state).
    • 1.7.x: chunkX/chunkZ + short count + i32 data length + (u16 position + u16 block state), where block state is (block id << 4) | metadata.

Testing

  • Added unit tests covering offhand-slot stripping, cross-version offhand persistence, and every MultiBlockChange version boundary (1.7 / 1.8 / 1.9 / 1.13+).
  • cargo test -p pumpkin-protocol --lib → 105 passed, 0 failed.
  • cargo check --all-targets --all-features, cargo clippy --all-targets --all-features, and cargo fmt --all -- --check all pass.
  • cargo-machete reports no unused dependencies.

Known remaining issues

  • 1.13 entity spawn: SPacketSpawnMob / SPacketSpawnObject still send legacy 1.12 numeric entity IDs instead of 1.13 registry IDs (the ViaBackwards mappings-1.13to1.12.nbt has no entities section), causing EntitySmallFireball cannot be cast to EntityLivingBase on 1.13 clients.
  • 1.16+ / 1.19+ join: not yet diagnosed; client logs show no Java exception.

Related PRs

With multi-version support, the encoding for Multi Block Update and Set Container Content packets is now differentiated by protocol version:
- 1.13+: Chunk coordinates use i64, and records use VarLong.
- 1.9-1.12: Use the short record format.
- 1.8/1.7: Use legacy coordinate and block ID encoding.
- Pre-1.9: Omit the offhand slot in the player inventory (window ID 0) to prevent out-of-bounds errors on older clients.

Added corresponding unit tests to ensure data integrity during alternating encoding/decoding between legacy and modern versions.
@Q2297045667
Q2297045667 requested a review from Snowiiii as a code owner August 26, 2026 09:47
@Q2297045667
Q2297045667 marked this pull request as draft August 26, 2026 09:47
@RoosterBooster007 RoosterBooster007 added protocol About Packets or the Protocol bug Something isn't working labels Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working protocol About Packets or the Protocol

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants