[PR #6871] [MERGED] A facing target wraps the yaw to -180..180 #7163

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

📋 Pull Request Information

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

Base: main ← Head: fix/look-at-wrap


📝 Commits (2)

  • a2ed6c2 A facing target wraps the yaw to -180..180
  • 4cbcd2e Use lookAt's float degree constant, and wrap the pitch as vanilla does

📊 Changes

2 files changed (+34 additions, -12 deletions)

View changed files

📝 crates/horizon-client/src/game/commands.rs (+1 -6)
📝 crates/horizon-client/src/game/commands/world_cmds.rs (+33 -6)

📄 Description

Vanilla behaviour

Entity.lookAt(EntityAnchorArgument.Anchor, Vec3) sets the pitch to
Mth.wrapDegrees(-atan2(dy, horizontal) * 180/PI) and the yaw to
Mth.wrapDegrees(atan2(dz, dx) * 180/PI - 90). Mth.wrapDegrees folds an angle into -180..180:
f = value % 360; if (f >= 180) f -= 360; if (f < -180) f += 360.

/tp <targets> <pos> facing <pos|entity> calls it through LookAt.perform after the teleport,
and so does /rotate <target> facing ... - RotateCommand builds a LookAt and calls
LookAt.perform (javap of RotateCommand).

What Horizon got wrong

The same direction was stored as a different number, which /data get entity ... Rotation, an
entity_properties/data predicate and the rotation in the teleport packet a guest receives all
read:

  • /tp <targets> <pos> facing ... (game/commands.rs) computed atan2(dz, dx) - 90 and kept it
    raw: facing a target at -1 64 -1 from 0 64 0 gives -225 where vanilla keeps 135.
  • /rotate <target> facing ... (game/commands/world_cmds.rs) used rem_euclid(360), so the
    same target gives 225, and facing a target due east gives 270 where vanilla keeps -90.

Both now go through one helper, world_cmds::look_at, which wraps the yaw with the
Mth.wrapDegrees copy that already lived next to rotation_in in game/commands.rs.

Proven: cargo test -q -p horizon-client --lib game::commands::world_cmds - 1 passed
(a_facing_target_wraps_the_yaw_to_180: north-west 135, due north -180, east -90, south 0, west 90,
pitch unchanged). cargo clippy -q -p horizon-client --lib clean, rustfmt --edition 2024 --check
clean on the build VM. Vanilla: javap of Entity.lookAt and RotateCommand.

Not proven: not run in game. In-game check: /tp @s 0 64 0 facing -1 64 -1 then
/data get entity @s Rotation[0] reads 135.0 (before: -225.0), and
/rotate @s facing 1 64 0 then the same read gives -90.0 (before: 270.0).


🔄 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/6871 **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/look-at-wrap` --- ### 📝 Commits (2) - [`a2ed6c2`](https://github.com/horizon-rust/horizon/commit/a2ed6c28823e5fa684b090def79c7cb397ffb660) A facing target wraps the yaw to -180..180 - [`4cbcd2e`](https://github.com/horizon-rust/horizon/commit/4cbcd2e4fcc8b6bacb6689f885a81a4461251d40) Use lookAt's float degree constant, and wrap the pitch as vanilla does ### 📊 Changes **2 files changed** (+34 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/commands.rs` (+1 -6) 📝 `crates/horizon-client/src/game/commands/world_cmds.rs` (+33 -6) </details> ### 📄 Description ## Vanilla behaviour `Entity.lookAt(EntityAnchorArgument.Anchor, Vec3)` sets the pitch to `Mth.wrapDegrees(-atan2(dy, horizontal) * 180/PI)` and the yaw to `Mth.wrapDegrees(atan2(dz, dx) * 180/PI - 90)`. `Mth.wrapDegrees` folds an angle into -180..180: `f = value % 360; if (f >= 180) f -= 360; if (f < -180) f += 360`. `/tp <targets> <pos> facing <pos|entity>` calls it through `LookAt.perform` after the teleport, and so does `/rotate <target> facing ...` - `RotateCommand` builds a `LookAt` and calls `LookAt.perform` (javap of `RotateCommand`). ## What Horizon got wrong The same direction was stored as a different number, which `/data get entity ... Rotation`, an `entity_properties`/`data` predicate and the rotation in the teleport packet a guest receives all read: - `/tp <targets> <pos> facing ...` (`game/commands.rs`) computed `atan2(dz, dx) - 90` and kept it raw: facing a target at `-1 64 -1` from `0 64 0` gives -225 where vanilla keeps 135. - `/rotate <target> facing ...` (`game/commands/world_cmds.rs`) used `rem_euclid(360)`, so the same target gives 225, and facing a target due east gives 270 where vanilla keeps -90. Both now go through one helper, `world_cmds::look_at`, which wraps the yaw with the `Mth.wrapDegrees` copy that already lived next to `rotation_in` in `game/commands.rs`. **Proven:** `cargo test -q -p horizon-client --lib game::commands::world_cmds` - 1 passed (`a_facing_target_wraps_the_yaw_to_180`: north-west 135, due north -180, east -90, south 0, west 90, pitch unchanged). `cargo clippy -q -p horizon-client --lib` clean, `rustfmt --edition 2024 --check` clean on the build VM. Vanilla: `javap` of `Entity.lookAt` and `RotateCommand`. **Not proven:** not run in game. In-game check: `/tp @s 0 64 0 facing -1 64 -1` then `/data get entity @s Rotation[0]` reads 135.0 (before: -225.0), and `/rotate @s facing 1 64 0` then the same read gives -90.0 (before: 270.0). --- <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:06 +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#7163
No description provided.