[PR #6882] [MERGED] Send an item stopped by a block its exact position #7170

Closed
opened 2026-11-03 06:35:12 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6882
Author: @MSedgeMC
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: fix/item-precision-encoding


📝 Commits (3)

  • c8d2f85 Send an item stopped by a block its exact position
  • b160ede Drive the item sync test through its update interval
  • 6315a38 horizontalCollision uses Mth.equal's tolerance, as Entity.move does

📊 Changes

12 files changed (+126 additions, -1 deletions)

View changed files

📝 crates/horizon-client/src/entities.rs (+21 -0)
📝 crates/horizon-client/src/entities/fluids.rs (+2 -0)
📝 crates/horizon-client/src/entity_nbt.rs (+4 -0)
📝 crates/horizon-client/src/game.rs (+2 -0)
📝 crates/horizon-client/src/game/dragon.rs (+2 -0)
📝 crates/horizon-client/src/game/lan.rs (+2 -0)
📝 crates/horizon-client/src/game/lan_entities.rs (+2 -0)
📝 crates/horizon-client/src/game/machines.rs (+2 -0)
📝 crates/horizon-client/src/game/remote.rs (+2 -0)
📝 crates/horizon-client/src/lan/entity.rs (+83 -1)
📝 crates/horizon-client/src/lan/hub.rs (+2 -0)
📝 crates/horizon-client/tests/lan_bot.rs (+2 -0)

📄 Description

Vanilla's ServerEntity.isFullPrecisionEncodingRequired sends an item that a block stopped its exact position instead of a delta:

// javap -p -c on ServerEntity (createMovePacket's delta branch)
86-98: isFullPrecisionEncodingRequired(path.endPosition(), delta)
       -> ClientboundEntityPositionSyncPacket.of(entity, path)

// isFullPrecisionEncodingRequired
if (entity instanceof ItemEntity) {
    if (entity.verticalCollision
        && (delta.hasDeltaX() && encodingPrecisionLoss(end.x) != 0
            || delta.hasDeltaZ() && encodingPrecisionLoss(end.z) != 0)) return true;
    if (entity.horizontalCollision
        && (delta.hasDeltaX() && encodingPrecisionLoss(end.z) != 0
            || delta.hasDeltaZ() && encodingPrecisionLoss(end.x) != 0)) return true;
}
return false;

encodingPrecisionLoss(v) is decode(encode(v)) - v, the part of the coordinate a 1/4096 delta cannot express. The axis pairs are vanilla's own: a vertical stop pairs x with x and z with z, a horizontal stop pairs x with z and z with x.

Horizon's EntityState never carried Entity.verticalCollision / horizontalCollision, so ServerEntity.send_changes always encoded a moved item as a VecDelta::Linear. An item whose move a block stopped - slid to rest against a wall, landed at a fractional x/z - was decoded by guests at the nearest 1/4096 grid point (up to 1/8192 of a block away) instead of the position the collision solver gave it. ItemEntity::tick now records both flags from the movement its resolver returned, game/lan.rs copies them into the item's EntityState, and the tracker applies vanilla's check before it chooses the packet.

Proven: on the build VM, cargo test -q -p horizon-client-lib --lib stopped -> 5 passed, including an_item_stopped_by_a_block_needs_full_precision: item-only, both collisions, and both cross-over axis pairs (an x delta with z at 0.3 needs full precision, z at 0.5 does not, a y-only delta never does, and a zombie with the flags does not), and a_slow_item_stopped_by_a_wall_syncs_its_exact_position: through send_changes, an item that stopped horizontally at (0.3, 64, 0.3) sends EntityPositionSync whose path ends exactly there, while the same move with no collision sends MoveEntityPos. cargo clippy -q -p horizon-client-lib --lib and -p horizon-client --lib are silent, and both libs build.

Not proven: not watched in game; the offset is under 1/8192 of a block, so this is protocol fidelity rather than something a screenshot shows. Only items get the check, as vanilla's instanceof ItemEntity does.


🔄 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/6882 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/item-precision-encoding` --- ### 📝 Commits (3) - [`c8d2f85`](https://github.com/horizon-rust/horizon/commit/c8d2f857286023baf27772df93f6f7d7a12af138) Send an item stopped by a block its exact position - [`b160ede`](https://github.com/horizon-rust/horizon/commit/b160ede58b49bb27d3b91d6fcb6ff4a5736544a4) Drive the item sync test through its update interval - [`6315a38`](https://github.com/horizon-rust/horizon/commit/6315a3868794fda2bd2099e32de97dcdb4f5bedb) horizontalCollision uses Mth.equal's tolerance, as Entity.move does ### 📊 Changes **12 files changed** (+126 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/entities.rs` (+21 -0) 📝 `crates/horizon-client/src/entities/fluids.rs` (+2 -0) 📝 `crates/horizon-client/src/entity_nbt.rs` (+4 -0) 📝 `crates/horizon-client/src/game.rs` (+2 -0) 📝 `crates/horizon-client/src/game/dragon.rs` (+2 -0) 📝 `crates/horizon-client/src/game/lan.rs` (+2 -0) 📝 `crates/horizon-client/src/game/lan_entities.rs` (+2 -0) 📝 `crates/horizon-client/src/game/machines.rs` (+2 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+2 -0) 📝 `crates/horizon-client/src/lan/entity.rs` (+83 -1) 📝 `crates/horizon-client/src/lan/hub.rs` (+2 -0) 📝 `crates/horizon-client/tests/lan_bot.rs` (+2 -0) </details> ### 📄 Description Vanilla's `ServerEntity.isFullPrecisionEncodingRequired` sends an item that a block stopped its exact position instead of a delta: ```java // javap -p -c on ServerEntity (createMovePacket's delta branch) 86-98: isFullPrecisionEncodingRequired(path.endPosition(), delta) -> ClientboundEntityPositionSyncPacket.of(entity, path) // isFullPrecisionEncodingRequired if (entity instanceof ItemEntity) { if (entity.verticalCollision && (delta.hasDeltaX() && encodingPrecisionLoss(end.x) != 0 || delta.hasDeltaZ() && encodingPrecisionLoss(end.z) != 0)) return true; if (entity.horizontalCollision && (delta.hasDeltaX() && encodingPrecisionLoss(end.z) != 0 || delta.hasDeltaZ() && encodingPrecisionLoss(end.x) != 0)) return true; } return false; ``` `encodingPrecisionLoss(v)` is `decode(encode(v)) - v`, the part of the coordinate a 1/4096 delta cannot express. The axis pairs are vanilla's own: a vertical stop pairs x with x and z with z, a horizontal stop pairs x with z and z with x. Horizon's `EntityState` never carried `Entity.verticalCollision` / `horizontalCollision`, so `ServerEntity.send_changes` always encoded a moved item as a `VecDelta::Linear`. An item whose move a block stopped - slid to rest against a wall, landed at a fractional x/z - was decoded by guests at the nearest 1/4096 grid point (up to 1/8192 of a block away) instead of the position the collision solver gave it. `ItemEntity::tick` now records both flags from the movement its resolver returned, `game/lan.rs` copies them into the item's `EntityState`, and the tracker applies vanilla's check before it chooses the packet. **Proven:** on the build VM, `cargo test -q -p horizon-client-lib --lib stopped` -> `5 passed`, including `an_item_stopped_by_a_block_needs_full_precision`: item-only, both collisions, and both cross-over axis pairs (an x delta with z at 0.3 needs full precision, z at 0.5 does not, a y-only delta never does, and a zombie with the flags does not), and `a_slow_item_stopped_by_a_wall_syncs_its_exact_position`: through `send_changes`, an item that stopped horizontally at (0.3, 64, 0.3) sends `EntityPositionSync` whose path ends exactly there, while the same move with no collision sends `MoveEntityPos`. `cargo clippy -q -p horizon-client-lib --lib` and `-p horizon-client --lib` are silent, and both libs build. **Not proven:** not watched in game; the offset is under 1/8192 of a block, so this is protocol fidelity rather than something a screenshot shows. Only items get the check, as vanilla's `instanceof ItemEntity` does. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:35:12 +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#7170
No description provided.