[PR #2550] [MERGED] Add the missing sprint-state regression tests for #1593, #1598 and #1680 #4418

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2550
Author: @levzzz5154
Created: 10/26/2026
Status: ✅ Merged
Merged: 10/27/2026
Merged by: @ludovic111

Base: main ← Head: fix/sprint-state-persistence


📝 Commits (3)

  • ef0714a Lock in the sprint state that outlives the sprint key
  • 0fe747a Merge remote-tracking branch 'upstream/main' into fix/sprint-state-persistence
  • 5815560 Merge remote-tracking branch 'upstream/main' into fix/sprint-state-persistence

📊 Changes

1 file changed (+186 additions, -0 deletions)

View changed files

📝 crates/horizon-client/src/motion.rs (+186 -0)

📄 Description

🤖 Opened by levzzz5154's AI agent (Claude Code), not by levzzz5154 himself.

What and why

Sprint is a state, not a held key. In vanilla LocalPlayer.aiStep starts the sprint with the sprint key and stops it only on a vanilla stop condition (forward released, hard collision, not enough food, sneaking, shallow water), so releasing the sprint key keeps the sprint while forward is held.

That behaviour already holds on main. The server no longer rewrites the player's sprint flag from the held keys on every input packet: the S::PlayerInput arm in lan/hub.rs only records the keys and the crouching, and the flag changes only through PlayerCommand (START_SPRINTING / STOP_SPRINTING), which the client already sends when its own sprint state changes. The local sprint machine in sprint.rs mirrors LocalPlayer.aiStep.

What was missing was a test that drives the whole path, so the three reported symptoms could be shown to hold rather than argued:

  • #1593 (a) sprint swimming — the swim speed is unchanged when the sprint key comes up while forward is held;
  • #1593 (b) and #1598, the sprint jump — the jump keeps LivingEntity.jumpFromGround's 0.2 forward impulse when the sprint key comes up in the air;
  • #1680, the flight speed — it follows the sprint state, not the sprint key, so holding Ctrl while flying no longer changes the speed.

This pull request changes no behaviour: it adds those three regression tests to crates/horizon-client/src/motion.rs. Fixes #1593, #1598, #1680.

Vanilla reference

Read from the pinned 26.3 sources (.local/minecraft/26.3/sources).

  • net.minecraft.client.player.LocalPlayer#aiStep — the sprint phase. canStartSprinting() (forward impulse, isSprintingPossible(getAbilities().flying), not slow due to using an item, not fall flying or moving slowly unless under water) starts the sprint, this.input.keyPresses.sprint() calls setSprinting(true), and the stop rules are shouldStopRunSprinting() (not sprinting possible, no forward impulse, hard horizontal collision) and shouldStopSwimSprinting() (not sprinting possible, not in water, or no forward impulse while not on the ground and not sneaking). The sprint key only ever starts the sprint; it never ends it.
  • net.minecraft.client.player.LocalPlayer#isSprintingPossible and #canStartSprinting — the food condition (hasEnoughFoodToDoExhaustiveManoeuvres) and the shallow-water condition.
  • net.minecraft.world.entity.LivingEntity#setSprinting — the minecraft:sprinting movement-speed modifier (0.3, AddMultipliedTotal).
  • net.minecraft.world.entity.LivingEntity#jumpFromGround — while isSprinting(), addDeltaMovement((-sin(yaw) * 0.2, 0, cos(yaw) * 0.2)).
  • net.minecraft.world.entity.LivingEntity#travelInWater — a sprinting swimmer keeps slowDown = 0.9 instead of getWaterSlowDown() (0.8), so the swim speed follows the sprint state.
  • net.minecraft.world.entity.player.Player#getFlyingSpeed — a flying player moves at abilities.getFlyingSpeed() (0.05), doubled while isSprinting(); the flight speed follows the sprint state, and the sprint key only starts that state. LivingEntity#getFrictionInfluencedSpeed uses it for the airborne speed.
  • net.minecraft.server.network.ServerGamePacketListenerImpl#handlePlayerCommand — START_SPRINTING and STOP_SPRINTING are the only things that change the server's sprint state; ServerboundPlayerInputPacket only carries which keys are down.

Self-check

cargo test -p horizon-client --lib -- sprint (the three new tests plus the state-machine test added in #2022):

running 4 tests
test sprint::tests::sprint_survives_releasing_the_key_through_a_jump ... ok
test motion::tests::a_sprint_jump_keeps_its_impulse_when_the_sprint_key_comes_up ... ok
test motion::tests::the_flight_speed_follows_the_sprint_state_not_the_sprint_key ... ok
test motion::tests::a_sprint_survives_the_sprint_key_coming_up_while_swimming ... ok

test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 1213 filtered out; finished in 5.97s

cargo test -p horizon-client --test lan_bot -- sprint_commands_survive_keyboard_input_changes (the server side, added in #1779):

running 1 test
test sprint_commands_survive_keyboard_input_changes ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 2 filtered out; finished in 0.31s

python3 tools/parity.py sprint_input player_travel (the sprint machine and the flight speed against the pinned 26.3 client and server jars):

Running 2 harnesses, 4 at a time here...
PASS sprint_input 2s
PASS player_travel 7s

2 passed, 0 failed in 0.1 min.

The three new tests fail if the sprint state is dropped when the key comes up: with the pre-fix rule restored in sprint.rs ("the sprint key owns the state") all three fail ("the sprint state survives the sprint key in water", "the sprint state survives the sprint key in the air"), and with the pre-#1779 line restored in lan/hub.rs the hub test fails ("keyboard input 1 cleared the sprint flag"). Measured values: the sprint jump raises the forward speed from 0.153 to 0.262 (the 0.2 impulse through the ground friction), and a flying player is at 0.05, at 0.1 while the sprint state holds, and still at 0.1 after the sprint key comes up.

🤖 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/2550 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/27/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/sprint-state-persistence` --- ### 📝 Commits (3) - [`ef0714a`](https://github.com/horizon-rust/horizon/commit/ef0714a99a7926bb218c4901c107c07701420e6e) Lock in the sprint state that outlives the sprint key - [`0fe747a`](https://github.com/horizon-rust/horizon/commit/0fe747ad51ba82ace098bc27b03ec6391ca511c2) Merge remote-tracking branch 'upstream/main' into fix/sprint-state-persistence - [`5815560`](https://github.com/horizon-rust/horizon/commit/5815560b0b518b9558bc952bde4478955a9fe0da) Merge remote-tracking branch 'upstream/main' into fix/sprint-state-persistence ### 📊 Changes **1 file changed** (+186 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/motion.rs` (+186 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code), not by levzzz5154 himself. ## What and why Sprint is a state, not a held key. In vanilla `LocalPlayer.aiStep` starts the sprint with the sprint key and stops it only on a vanilla stop condition (forward released, hard collision, not enough food, sneaking, shallow water), so releasing the sprint key keeps the sprint while forward is held. That behaviour already holds on main. The server no longer rewrites the player's sprint flag from the held keys on every input packet: the `S::PlayerInput` arm in `lan/hub.rs` only records the keys and the crouching, and the flag changes only through `PlayerCommand` (`START_SPRINTING` / `STOP_SPRINTING`), which the client already sends when its own sprint state changes. The local sprint machine in `sprint.rs` mirrors `LocalPlayer.aiStep`. What was missing was a test that drives the whole path, so the three reported symptoms could be *shown* to hold rather than argued: - #1593 (a) sprint swimming — the swim speed is unchanged when the sprint key comes up while forward is held; - #1593 (b) and #1598, the sprint jump — the jump keeps `LivingEntity.jumpFromGround`'s 0.2 forward impulse when the sprint key comes up in the air; - #1680, the flight speed — it follows the sprint state, not the sprint key, so holding Ctrl while flying no longer changes the speed. This pull request changes no behaviour: it adds those three regression tests to `crates/horizon-client/src/motion.rs`. Fixes #1593, #1598, #1680. ## Vanilla reference Read from the pinned 26.3 sources (`.local/minecraft/26.3/sources`). - `net.minecraft.client.player.LocalPlayer#aiStep` — the sprint phase. `canStartSprinting()` (forward impulse, `isSprintingPossible(getAbilities().flying)`, not slow due to using an item, not fall flying or moving slowly unless under water) starts the sprint, `this.input.keyPresses.sprint()` calls `setSprinting(true)`, and the stop rules are `shouldStopRunSprinting()` (not sprinting possible, no forward impulse, hard horizontal collision) and `shouldStopSwimSprinting()` (not sprinting possible, not in water, or no forward impulse while not on the ground and not sneaking). The sprint key only ever *starts* the sprint; it never ends it. - `net.minecraft.client.player.LocalPlayer#isSprintingPossible` and `#canStartSprinting` — the food condition (`hasEnoughFoodToDoExhaustiveManoeuvres`) and the shallow-water condition. - `net.minecraft.world.entity.LivingEntity#setSprinting` — the `minecraft:sprinting` movement-speed modifier (0.3, `AddMultipliedTotal`). - `net.minecraft.world.entity.LivingEntity#jumpFromGround` — while `isSprinting()`, `addDeltaMovement((-sin(yaw) * 0.2, 0, cos(yaw) * 0.2))`. - `net.minecraft.world.entity.LivingEntity#travelInWater` — a sprinting swimmer keeps `slowDown = 0.9` instead of `getWaterSlowDown()` (0.8), so the swim speed follows the sprint state. - `net.minecraft.world.entity.player.Player#getFlyingSpeed` — a flying player moves at `abilities.getFlyingSpeed()` (0.05), doubled while `isSprinting()`; the flight speed follows the sprint *state*, and the sprint key only starts that state. `LivingEntity#getFrictionInfluencedSpeed` uses it for the airborne speed. - `net.minecraft.server.network.ServerGamePacketListenerImpl#handlePlayerCommand` — `START_SPRINTING` and `STOP_SPRINTING` are the only things that change the server's sprint state; `ServerboundPlayerInputPacket` only carries which keys are down. ## Self-check `cargo test -p horizon-client --lib -- sprint` (the three new tests plus the state-machine test added in #2022): ``` running 4 tests test sprint::tests::sprint_survives_releasing_the_key_through_a_jump ... ok test motion::tests::a_sprint_jump_keeps_its_impulse_when_the_sprint_key_comes_up ... ok test motion::tests::the_flight_speed_follows_the_sprint_state_not_the_sprint_key ... ok test motion::tests::a_sprint_survives_the_sprint_key_coming_up_while_swimming ... ok test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 1213 filtered out; finished in 5.97s ``` `cargo test -p horizon-client --test lan_bot -- sprint_commands_survive_keyboard_input_changes` (the server side, added in #1779): ``` running 1 test test sprint_commands_survive_keyboard_input_changes ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 2 filtered out; finished in 0.31s ``` `python3 tools/parity.py sprint_input player_travel` (the sprint machine and the flight speed against the pinned 26.3 client and server jars): ``` Running 2 harnesses, 4 at a time here... PASS sprint_input 2s PASS player_travel 7s 2 passed, 0 failed in 0.1 min. ``` The three new tests fail if the sprint state is dropped when the key comes up: with the pre-fix rule restored in `sprint.rs` ("the sprint key owns the state") all three fail ("the sprint state survives the sprint key in water", "the sprint state survives the sprint key in the air"), and with the pre-#1779 line restored in `lan/hub.rs` the hub test fails ("keyboard input 1 cleared the sprint flag"). Measured values: the sprint jump raises the forward speed from 0.153 to 0.262 (the 0.2 impulse through the ground friction), and a flying player is at 0.05, at 0.1 while the sprint state holds, and still at 0.1 after the sprint key comes up. 🤖 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 04:17:00 +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#4418
No description provided.