[PR #4631] [MERGED] Decompose matrix display transformations like MatrixUtil #5739

Closed
opened 2026-11-03 05:14:39 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4631
Author: @AurelienBelloir
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @rdbtCVS

Base: main ← Head: parity/display-entity-transforms


📝 Commits (3)

  • e040b00 Decompose matrix display transformations like MatrixUtil
  • 3033b81 Name the extended transformation codec in display_data
  • e41d766 Merge remote-tracking branch 'origin/main' into pr-4631

📊 Changes

3 files changed (+307 additions, -13 deletions)

View changed files

📝 crates/horizon-assets/src/math.rs (+216 -0)
📝 crates/horizon-client/src/text_display.rs (+61 -13)
📝 crates/horizon-protocol/src/entity_data.rs (+30 -0)

📄 Description

🤖 Opened by AurelienBelloir's AI agent (Claude Code, Claude Opus 5.5), not by AurelienBelloir personally.

What and why

Item, block and text displays whose saved transformation is in matrix form (16 floats) stayed at the identity: Horizon read only the four-part form. Vanilla's Display.readAdditionalSaveData reads Transformation.EXTENDED_CODEC, which falls back to ExtraCodecs.MATRIX4F, and new Transformation(matrix) splits the matrix into translation, left rotation, scale and right rotation with MatrixUtil.svdDecompose. Those four parts are what the host sends as DATA_TRANSLATION_ID to DATA_RIGHT_ROTATION_ID.

The VECTOR3/QUATERNION serializers, the host's display entity data and the client's transform rendering were already on main, so that part of #3520 was stale.

Changes:

  • horizon-assets/src/math.rs: new svd_decompose, following MatrixUtil.svdDecompose (eigenvalueJacobi/stepJacobi on a^T*a for the right rotation, then QR Givens rotations about z, y and x for the left rotation and scale). The arithmetic matches GivensParameters and JOML 1.10.9's Matrix3f.mul, Matrix3f.rotate and Quaternionf.mul. A test checks the exact bits vanilla's own decomposition returns for three matrices.
  • horizon-client/src/text_display.rs: a transformation given as a 16-float list is now decomposed. Axis-angle rotations follow new Quaternionf(AxisAngle4f): the angle is wrapped to [0, 2pi) and the axis is not normalized. Four-component rotations follow Quaternionf.normalize. Both reuse the existing horizon-assets helpers.
  • horizon-protocol/src/entity_data.rs: a test fixes VECTOR3 (id 39) and QUATERNION (id 40) to the byte layout of FriendlyByteBuf.writeVector3f/writeQuaternion: big-endian floats.

Fixes #4629

Not covered: - I did not check that every path that changes a display (summon, /data merge, live edits) refreshes the NBT kept in persist.raw that lan_display_data reads; this commit only fixes the decoding of that NBT.

  • When a matrix decomposes to a right rotation of (-0,-0,-0,1), vanilla treats it as non-default and sends it, because JOML equality compares float bits. Horizon's Value::Floats compares with f32 ==, so it skips the entry. The client ends up with the same transform either way.
  • Rendering was already wired (TLS*R, billboard, interpolation). Nothing in this commit compares it to vanilla.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Read from the 26.3 bytecode with javap -c:

  • net.minecraft.world.entity.Display.readAdditionalSaveData
  • net.minecraft.world.entity.Display.setTransformation
  • com.mojang.math.Transformation.<clinit> (EXTENDED_CODEC = withAlternative(CODEC, MATRIX4F.xmap))
  • com.mojang.math.Transformation.<init>(Matrix4fc)
  • com.mojang.math.Transformation.ensureDecomposed
  • com.mojang.math.MatrixUtil.svdDecompose(Matrix4fc,Vector3f,Quaternionf,Vector3f,Quaternionf)
  • com.mojang.math.MatrixUtil.svdDecompose(Matrix3f,Quaternionf,Vector3f,Quaternionf)
  • com.mojang.math.MatrixUtil.eigenvalueJacobi
  • com.mojang.math.MatrixUtil.stepJacobi
  • com.mojang.math.MatrixUtil.similarityTransform
  • com.mojang.math.MatrixUtil.approxGivensQuat
  • com.mojang.math.MatrixUtil.qrGivensQuat
  • com.mojang.math.MatrixUtil.<clinit> (G, PI_4)
  • com.mojang.math.GivensParameters.fromUnnormalized/fromPositiveAngle/inverse/cos/sin/aroundX/aroundY/aroundZ
  • net.minecraft.util.ExtraCodecs.<clinit> (MATRIX4F, QUATERNIONF, AXISANGLE4F)
  • net.minecraft.util.ExtraCodecs.lambda$static$19 (MATRIX4F setRowColumn)
  • net.minecraft.network.FriendlyByteBuf.writeQuaternion
  • net.minecraft.network.syncher.EntityDataSerializers.<clinit>
  • org.joml.Matrix3f.mul(Matrix3fc,Matrix3f)
  • org.joml.Matrix3f.rotate(Quaternionfc,Matrix3f)
  • org.joml.Matrix3f.transpose
  • org.joml.Matrix3f.scale
  • org.joml.Quaternionf.mul(Quaternionfc,Quaternionf)
  • org.joml.Quaternionf.normalize(Quaternionf)
  • org.joml.Quaternionf.conjugate
  • org.joml.Quaternionf.<init>(AxisAngle4f)
  • org.joml.AxisAngle4f.<init>(float,float,float,float)
  • org.joml.Math.invsqrt/sin/cosFromSinInternal

Tests added or extended:

  • horizon-assets math::tests::svd_decomposes_like_matrix_util
  • horizon-client text_display::tests::a_matrix_transformation_is_decomposed
  • horizon-client text_display::tests::axis_angle_rotations_keep_the_axis_and_wrap_the_angle
  • horizon-protocol entity_data::tests::vectors_and_quaternions_are_big_endian_floats

No new parity harness.

Self-check

The full tools/pr_ready.py needs more disk than this machine has (see #4543). Checked by hand on Windows, with prepared 26.3 resources in HORIZON_RESOURCES (CARGO_INCREMENTAL=0):

  • rustfmt: ✅
  • cargo clippy -p horizon-assets -p horizon-protocol -p horizon-client --all-targets -- -D warnings: ✅
  • cargo test --no-fail-fast -p horizon-assets -p horizon-protocol -p horizon-client --lib --bins --tests: horizon-assets lib 10 passed; horizon-protocol lib 120 passed; horizon-client lib 782 passed, 1 failed: title::tests::each_world_preset_writes_its_own_generator, which fails on Windows only and already fails on main; #4544 fixes it; horizon-client bin 240 passed; horizon-ctl 18 passed; all 8 integration suites pass
  • Public tree hook: ✅
  • An independent review against the 26.3 bytecode before opening; its findings are fixed in this branch.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/4631 **Author:** [@AurelienBelloir](https://github.com/AurelienBelloir) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `parity/display-entity-transforms` --- ### 📝 Commits (3) - [`e040b00`](https://github.com/horizon-rust/horizon/commit/e040b000b08103557f9e4401ada07408ea49a521) Decompose matrix display transformations like MatrixUtil - [`3033b81`](https://github.com/horizon-rust/horizon/commit/3033b8133fa73150e73d79a200405b2ac2ab869a) Name the extended transformation codec in display_data - [`e41d766`](https://github.com/horizon-rust/horizon/commit/e41d76620ebff074e768f0dee67b3ac1a96c6698) Merge remote-tracking branch 'origin/main' into pr-4631 ### 📊 Changes **3 files changed** (+307 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-assets/src/math.rs` (+216 -0) 📝 `crates/horizon-client/src/text_display.rs` (+61 -13) 📝 `crates/horizon-protocol/src/entity_data.rs` (+30 -0) </details> ### 📄 Description > 🤖 Opened by AurelienBelloir's AI agent (Claude Code, Claude Opus 5.5), not by AurelienBelloir personally. ## What and why Item, block and text displays whose saved `transformation` is in matrix form (16 floats) stayed at the identity: Horizon read only the four-part form. Vanilla's `Display.readAdditionalSaveData` reads `Transformation.EXTENDED_CODEC`, which falls back to `ExtraCodecs.MATRIX4F`, and `new Transformation(matrix)` splits the matrix into translation, left rotation, scale and right rotation with `MatrixUtil.svdDecompose`. Those four parts are what the host sends as DATA_TRANSLATION_ID to DATA_RIGHT_ROTATION_ID. The VECTOR3/QUATERNION serializers, the host's display entity data and the client's transform rendering were already on main, so that part of #3520 was stale. Changes: - `horizon-assets/src/math.rs`: new `svd_decompose`, following `MatrixUtil.svdDecompose` (`eigenvalueJacobi`/`stepJacobi` on a^T*a for the right rotation, then QR Givens rotations about z, y and x for the left rotation and scale). The arithmetic matches `GivensParameters` and JOML 1.10.9's `Matrix3f.mul`, `Matrix3f.rotate` and `Quaternionf.mul`. A test checks the exact bits vanilla's own decomposition returns for three matrices. - `horizon-client/src/text_display.rs`: a `transformation` given as a 16-float list is now decomposed. Axis-angle rotations follow `new Quaternionf(AxisAngle4f)`: the angle is wrapped to [0, 2pi) and the axis is not normalized. Four-component rotations follow `Quaternionf.normalize`. Both reuse the existing horizon-assets helpers. - `horizon-protocol/src/entity_data.rs`: a test fixes VECTOR3 (id 39) and QUATERNION (id 40) to the byte layout of `FriendlyByteBuf.writeVector3f`/`writeQuaternion`: big-endian floats. Fixes #4629 Not covered: - I did not check that every path that changes a display (summon, /data merge, live edits) refreshes the NBT kept in persist.raw that lan_display_data reads; this commit only fixes the decoding of that NBT. - When a matrix decomposes to a right rotation of (-0,-0,-0,1), vanilla treats it as non-default and sends it, because JOML equality compares float bits. Horizon's Value::Floats compares with f32 ==, so it skips the entry. The client ends up with the same transform either way. - Rendering was already wired (T*L*S*R, billboard, interpolation). Nothing in this commit compares it to vanilla. ## Kind - [x] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference Read from the 26.3 bytecode with `javap -c`: - `net.minecraft.world.entity.Display.readAdditionalSaveData` - `net.minecraft.world.entity.Display.setTransformation` - `com.mojang.math.Transformation.<clinit> (EXTENDED_CODEC = withAlternative(CODEC, MATRIX4F.xmap))` - `com.mojang.math.Transformation.<init>(Matrix4fc)` - `com.mojang.math.Transformation.ensureDecomposed` - `com.mojang.math.MatrixUtil.svdDecompose(Matrix4fc,Vector3f,Quaternionf,Vector3f,Quaternionf)` - `com.mojang.math.MatrixUtil.svdDecompose(Matrix3f,Quaternionf,Vector3f,Quaternionf)` - `com.mojang.math.MatrixUtil.eigenvalueJacobi` - `com.mojang.math.MatrixUtil.stepJacobi` - `com.mojang.math.MatrixUtil.similarityTransform` - `com.mojang.math.MatrixUtil.approxGivensQuat` - `com.mojang.math.MatrixUtil.qrGivensQuat` - `com.mojang.math.MatrixUtil.<clinit> (G, PI_4)` - `com.mojang.math.GivensParameters.fromUnnormalized/fromPositiveAngle/inverse/cos/sin/aroundX/aroundY/aroundZ` - `net.minecraft.util.ExtraCodecs.<clinit> (MATRIX4F, QUATERNIONF, AXISANGLE4F)` - `net.minecraft.util.ExtraCodecs.lambda$static$19 (MATRIX4F setRowColumn)` - `net.minecraft.network.FriendlyByteBuf.writeQuaternion` - `net.minecraft.network.syncher.EntityDataSerializers.<clinit>` - `org.joml.Matrix3f.mul(Matrix3fc,Matrix3f)` - `org.joml.Matrix3f.rotate(Quaternionfc,Matrix3f)` - `org.joml.Matrix3f.transpose` - `org.joml.Matrix3f.scale` - `org.joml.Quaternionf.mul(Quaternionfc,Quaternionf)` - `org.joml.Quaternionf.normalize(Quaternionf)` - `org.joml.Quaternionf.conjugate` - `org.joml.Quaternionf.<init>(AxisAngle4f)` - `org.joml.AxisAngle4f.<init>(float,float,float,float)` - `org.joml.Math.invsqrt/sin/cosFromSinInternal` Tests added or extended: - `horizon-assets math::tests::svd_decomposes_like_matrix_util` - `horizon-client text_display::tests::a_matrix_transformation_is_decomposed` - `horizon-client text_display::tests::axis_angle_rotations_keep_the_axis_and_wrap_the_angle` - `horizon-protocol entity_data::tests::vectors_and_quaternions_are_big_endian_floats` No new parity harness. ## Self-check The full `tools/pr_ready.py` needs more disk than this machine has (see #4543). Checked by hand on Windows, with prepared 26.3 resources in `HORIZON_RESOURCES` (`CARGO_INCREMENTAL=0`): - rustfmt: ✅ - `cargo clippy -p horizon-assets -p horizon-protocol -p horizon-client --all-targets -- -D warnings`: ✅ - `cargo test --no-fail-fast -p horizon-assets -p horizon-protocol -p horizon-client --lib --bins --tests`: horizon-assets lib 10 passed; horizon-protocol lib 120 passed; horizon-client lib 782 passed, 1 failed: `title::tests::each_world_preset_writes_its_own_generator`, which fails on Windows only and already fails on main; #4544 fixes it; horizon-client bin 240 passed; horizon-ctl 18 passed; all 8 integration suites pass - Public tree hook: ✅ - An independent review against the 26.3 bytecode before opening; its findings are fixed in this branch. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:14:39 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#5739
No description provided.