From b80bc19b57c519e3708947c64a7e060daccbe314 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Fri, 9 Oct 2026 02:22:40 +0200 Subject: [PATCH] Add creative flight Double-tapping jump within seven ticks toggles flight (jumping off the ground when it starts), jump and sneak move up and down at three times the 0.05 flying speed, horizontal acceleration uses the flying speed (doubled while sprinting), Player.travel keeps 0.6 of the vertical speed, flight ends on landing, and flying players neither crouch nor take fall damage. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game.rs | 2 ++ crates/horizon-client/src/motion.rs | 54 +++++++++++++++++++++++++++-- crates/horizon-client/src/pose.rs | 5 +-- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 444ca05a7..03820ef67 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -1934,6 +1934,7 @@ impl Game<'_> { }; let mut player = PlayerMotion::new(self.motion, feet)?; player.yaw = self.yaw; + player.may_fly = self.creative; if self.level.health > 0.0 && self.ticks < 2 { player.set_health(self.level.health, false)?; player.health.food.food = self.level.food; @@ -2007,6 +2008,7 @@ impl Game<'_> { self.previous_position = player.position; } player.yaw = self.yaw; + player.may_fly = self.creative; // LocalPlayer.modifyInput: walking while using an item. player.item_use_speed = self .using diff --git a/crates/horizon-client/src/motion.rs b/crates/horizon-client/src/motion.rs index ce2840473..08097dea2 100644 --- a/crates/horizon-client/src/motion.rs +++ b/crates/horizon-client/src/motion.rs @@ -138,6 +138,11 @@ pub struct PlayerMotion { pub jumping: bool, pub no_jump_delay: i32, pub jump_trigger_time: i32, + /// Abilities.mayfly / flying (creative flight). + pub may_fly: bool, + pub flying: bool, + /// The jump key last tick (LocalPlayer.aiStep's wasJumping). + pub was_jumping: bool, pub sprinting: bool, pub sprint_input: crate::sprint::SprintState, pub shift_key_down: bool, @@ -207,6 +212,9 @@ impl PlayerMotion { jumping: false, no_jump_delay: 0, jump_trigger_time: 0, + may_fly: false, + flying: false, + was_jumping: false, sprinting: false, sprint_input: crate::sprint::SprintState::default(), shift_key_down: false, @@ -437,7 +445,38 @@ impl MotionWorld<'_, '_, '_> { self.player.jump_trigger_time -= 1; } self.player.peaceful_regeneration(self.scene.health_rules)?; - self.dry_tick(TickInput::PreparedLocal { direction, jumping })?; + // LocalPlayer.aiStep: double-tap jump toggles creative flight. + let was_jumping = std::mem::replace(&mut self.player.was_jumping, jumping); + if !self.player.may_fly { + self.player.flying = false; + } else if !was_jumping && jumping { + if self.player.jump_trigger_time == 0 { + self.player.jump_trigger_time = 7; + } else { + self.player.flying = !self.player.flying; + if self.player.flying && self.player.ground.on_ground { + self.jump_from_ground()?; + } + self.player.jump_trigger_time = 0; + } + } + if self.player.flying { + // 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.dry_tick(TickInput::PreparedLocal { + direction, + jumping: jumping && !self.player.flying, + })?; + if self.player.flying { + self.player.fall_distance = 0.0; + if self.player.ground.on_ground { + self.player.flying = false; + } + } self.player.head_yaw = self.player.yaw; // Player.aiStep refreshes speed after movement, not before travel. self.player.speed = self.player.attribute("minecraft:movement_speed")? as f32; @@ -514,7 +553,14 @@ impl MotionWorld<'_, '_, '_> { } else { self.player.no_jump_delay = 0; } - self.travel_in_air(input)?; + if self.player.flying { + // Player.travel while flying: keep 0.6 of the vertical speed. + let y = self.player.velocity.y; + self.travel_in_air(input)?; + self.player.velocity.y = y * 0.6; + } else { + self.travel_in_air(input)?; + } self.player.remove_frost() } pub fn jump_from_ground(&mut self) -> Result<()> { @@ -883,6 +929,10 @@ impl LivingAirWorld for MotionWorld<'_, '_, '_> { Ok(self.player.attribute("minecraft:movement_speed")? as f32) } fn flying_speed(&mut self) -> Result { + if self.player.flying { + // Abilities.flyingSpeed 0.05, doubled when sprinting. + return Ok(if self.player.sprinting { 0.1 } else { 0.05 }); + } Ok(if self.player.sprinting { 0.025999999 } else { diff --git a/crates/horizon-client/src/pose.rs b/crates/horizon-client/src/pose.rs index 2eb1975df..1f3f20a1a 100644 --- a/crates/horizon-client/src/pose.rs +++ b/crates/horizon-client/src/pose.rs @@ -84,7 +84,8 @@ impl MotionWorld<'_, '_, '_> { /// LocalPlayer.aiStep computes crouching BEFORE KeyboardInput.tick, using /// the old shift input. This is distinct from Entity's current pose. pub fn update_local_crouching(&mut self) -> Result<()> { - self.player.local_crouching = self.can_fit_pose(Pose::Crouching)? + self.player.local_crouching = !self.player.flying + && self.can_fit_pose(Pose::Crouching)? && (self.player.shift_key_down || !self.can_fit_pose(Pose::Standing)?); Ok(()) } @@ -94,7 +95,7 @@ impl MotionWorld<'_, '_, '_> { if !self.can_fit_pose(Pose::Swimming)? { return Ok(()); } - let desired = if self.player.shift_key_down { + let desired = if self.player.shift_key_down && !self.player.flying { Pose::Crouching } else { Pose::Standing