Merge pull request #948 from rdbtCVS/t3/fix-issue-945

🤖 Agent: merged, thanks rdbt! Spectator scroll-wheel flight speed now follows vanilla (6,791 oracle cases); verified on the combined commit with local_input and the client tests. Fixes #945.
This commit is contained in:
Ludovic Marie
2026-10-19 04:20:53 +02:00
committed by GitHub
7 changed files with 111 additions and 22 deletions
+16 -6
View File
@@ -9933,15 +9933,25 @@ impl ApplicationHandler for Game<'_> {
&& self.sleeping.is_none()
&& self.player.is_some()
&& !self.extras_scroll(d)
&& let Some((wheel, _)) =
&& let Some((wheel, (_, vertical_steps))) =
self.mouse
.on_scroll(raw_x, raw_y, discrete, wheel_sensitivity)
{
self.selected = horizon_client::mouse::ScrollWheelHandler::next_selection(
f64::from(wheel),
self.selected as i32,
9,
) as usize;
if self.spectator() {
if let Some(player) = &mut self.player {
player.flying_speed = horizon_client::mouse::spectator_flying_speed(
player.flying_speed,
vertical_steps,
);
}
} else {
self.selected =
horizon_client::mouse::ScrollWheelHandler::next_selection(
f64::from(wheel),
self.selected as i32,
9,
) as usize;
}
}
if self.screen == Screen::Chat && d != 0.0 {
self.chat_scroll(d);
+6 -1
View File
@@ -1805,7 +1805,12 @@ impl Game<'_> {
}
_ => {}
},
C::PlayerAbilities(p) => self.creative = p.flags & 8 != 0,
C::PlayerAbilities(p) => {
self.creative = p.flags & 8 != 0;
if let Some(player) = &mut self.player {
player.flying_speed = p.flying_speed;
}
}
C::SetHeldSlot(p) => {
self.selected = p.slot.clamp(0, 8) as usize;
if let Some(r) = self.remote.as_mut() {
+47 -3
View File
@@ -224,6 +224,8 @@ pub struct PlayerMotion {
/// Spectator mode: no physics, always flying (`Player.tick`).
pub spectator: bool,
pub flying: bool,
/// Client-side `Abilities.flyingSpeed`, adjusted by the spectator scroll wheel.
pub flying_speed: f32,
/// The jump key last tick (LocalPlayer.aiStep's wasJumping).
pub was_jumping: bool,
/// `LocalPlayer.autoJumpEnabled` (the Auto-Jump option) and
@@ -387,6 +389,7 @@ impl PlayerMotion {
invulnerable: false,
spectator: false,
flying: false,
flying_speed: 0.05,
was_jumping: false,
auto_jump_enabled: false,
auto_jump_time: 0,
@@ -789,7 +792,7 @@ impl MotionWorld<'_, '_, '_> {
// Vertical flight: jump up, shift down, three times the flying speed.
let ya = i32::from(jumping) - i32::from(self.player.shift_key_down);
if ya != 0 {
self.player.velocity.y += f64::from(ya as f32 * 0.05 * 3.0);
self.player.velocity.y += f64::from(ya as f32 * self.player.flying_speed * 3.0);
}
}
self.dry_tick(TickInput::PreparedLocal {
@@ -1863,8 +1866,8 @@ impl LivingAirWorld for MotionWorld<'_, '_, '_> {
}
fn flying_speed(&mut self) -> Result<f32> {
if self.player.flying {
// Abilities.flyingSpeed 0.05, doubled when sprinting.
return Ok(if self.player.sprinting { 0.1 } else { 0.05 });
// Player.getFlyingSpeed: abilities speed, doubled when sprinting.
return Ok(self.player.flying_speed * if self.player.sprinting { 2.0 } else { 1.0 });
}
Ok(if self.player.sprinting {
0.025999999
@@ -2123,6 +2126,47 @@ mod tests {
assert!(player.position.y < 84.0);
}
#[test]
fn spectator_scroll_speed_controls_horizontal_and_vertical_flight() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3");
if !root.join("movement-properties.nbt").exists() {
return;
}
let assets = Assets::load(&root).unwrap();
let render = assets.reload(&root).unwrap();
let binding = crate::collisions::load(&root, assets.registry).unwrap();
let resources = MotionResources::load(&root, &assets).unwrap();
let run = |steps| {
let mut scene = World::test_scene(&assets, &render, 2).unwrap();
let start = Vec3::new(20.5, 12.0, 20.5);
let mut player = PlayerMotion::new(&resources, start).unwrap();
player.spectator = true;
player.flying_speed = crate::mouse::spectator_flying_speed(player.flying_speed, steps);
MotionWorld {
entities: &[],
player: &mut player,
scene: &mut scene,
assets: &assets,
collision_binding: &binding,
resources: &resources,
}
.controlled_simulation_tick(crate::sprint::Keys {
forward: true,
jump: true,
..Default::default()
})
.unwrap();
player.position.subtract(start)
};
let stopped = run(-100);
assert_eq!(stopped, Vec3::ZERO);
let normal = run(0);
let fast = run(10);
assert!(normal.y > 0.0 && normal.z > 0.0);
assert!((fast.y - normal.y * 2.0).abs() < 1e-6);
assert!((fast.z - normal.z * 2.0).abs() < 1e-6);
}
#[test]
fn resident_spectator_flight_ignores_solid_and_climbable_blocks() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3");
+6
View File
@@ -80,6 +80,12 @@ impl ScrollWheelHandler {
}
}
/// `MouseHandler.onScroll` with the spectator menu closed. Only vertical whole
/// wheel steps adjust `Abilities.flyingSpeed`; horizontal scrolling does not.
pub fn spectator_flying_speed(speed: f32, vertical_steps: i32) -> f32 {
(speed + vertical_steps as f32 * 0.005).clamp(0.0, 0.2)
}
/// Entity rotation as `Entity.turn` keeps it.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Rotation {