Skip to content

Fix lpVec3 packet endianness#1506

Open
GenerelSchwerz wants to merge 2 commits into
PrismarineJS:masterfrom
GenerelSchwerz:fix/lpvec3-endianness
Open

Fix lpVec3 packet endianness#1506
GenerelSchwerz wants to merge 2 commits into
PrismarineJS:masterfrom
GenerelSchwerz:fix/lpvec3-endianness

Conversation

@GenerelSchwerz

Copy link
Copy Markdown

Problem

lpVec3 reads and writes its 32-bit word as little-endian, while Minecraft uses FriendlyByteBuf.readUnsignedInt / writeInt (big-endian). This silently corrupts nonzero entity velocity vectors on 1.21.9+.

Fix

  • Read and write the packed 32-bit word as big-endian.
  • Preserve the datatype’s native blocks-per-tick values; version-aware consumers can distinguish it from legacy vec3i16 using Add feature flag for lpVec3 entity velocity minecraft-data#1206.
  • Add decode and byte-exact round-trip coverage using payloads captured from vanilla 1.21.11.

This is an alternative to #1494: it keeps protocol datatype units native instead of converting lpVec3 into legacy 1/8000 units.

Validation

  • npx standard src/datatypes/lpVec3.js test/lpVec3Test.js
  • npx mocha test/lpVec3Test.js

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes lpVec3 encoding/decoding to match Minecraft’s on-wire big-endian 32-bit word layout (preventing silent corruption of nonzero velocity vectors on 1.21.9+), and adds regression coverage using real 1.21.11 payloads.

Changes:

  • Switch lpVec3 read/write of the 32-bit portion to big-endian and align byte layout with packed = c << 16 | b << 8 | a.
  • Refactor packing/unpacking bit extraction to avoid 32-bit bitwise truncation.
  • Add mocha tests covering zero-vector decoding and byte-exact round-trips of captured vanilla payloads.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/datatypes/lpVec3.js Updates lpVec3 serialization/deserialization to big-endian and adjusts packing/unpacking implementation.
test/lpVec3Test.js Adds targeted decode + exact round-trip tests using real 1.21.11 payloads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/datatypes/lpVec3.js
@GenerelSchwerz

Copy link
Copy Markdown
Author

Failing tests are redundant there, its the fault of the test, not me.

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.

2 participants