From 5ed8181adca456aae7ca081bc8b0acd6e1d5b47b Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Fri, 23 Oct 2026 19:12:44 +0200 Subject: [PATCH] Elytra glides on a server's players: the client sends START_FALL_FLYING and the server checks it A server's client never took the chest slot's Elytra into its own movement (player.glider) and never told the server it started gliding, so on the server thread and as a LAN guest the player just fell. The client now sets the glider as the window's own tick does and sends ServerboundPlayerCommandPacket START_FALL_FLYING when a glide starts. The hub used to accept that command blindly and never clear it. The game now answers it as handlePlayerCommand does (Player.tryToStartFallFlying, else stopFallFlying), and each tick runs LivingEntity.updateFallFlying for a gliding guest: the glide ends once canGlide fails (landed, riding, flying, levitation, a glider about to break), every 20th tick wears the Elytra, every 10th is an elytra_glide game event, and a glide that isn't diving keeps the fall distance at 1 (checkFallDistanceAccumulation). lan_e2e gets an elytra check, for the host and the guest, both modes. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game.rs | 27 +++--- crates/horizon-client/src/game/agent.rs | 1 + crates/horizon-client/src/game/lan.rs | 2 + crates/horizon-client/src/game/lan_actions.rs | 89 +++++++++++++++++++ crates/horizon-client/src/game/remote.rs | 17 ++++ crates/horizon-client/src/lan/hub.rs | 7 +- tools/lan_e2e.py | 55 ++++++++++++ 7 files changed, 181 insertions(+), 17 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 486f042a9..c62994dec 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -1812,6 +1812,16 @@ impl Game<'_> { self.stack_in_mut(self.held_slot()) } /// The slot of the hand that acts: the selected one, or `OFFHAND_SLOT`. + /// `LivingEntity.canGlideUsing`: a glider in the chest slot that will + /// not break with its next point of wear. + fn glider_worn(&self) -> bool { + self.armor[1].as_ref().is_some_and(|s| { + self.res + .items() + .get(&s.item) + .is_some_and(|i| i.glider && (i.max_damage == 0 || s.damage + 1 < i.max_damage)) + }) + } fn held_slot(&self) -> usize { match self.hand { Hand::Main => self.selected, @@ -3931,13 +3941,7 @@ impl Game<'_> { .as_ref() .map_or(0, |s| s.enchantment_level("minecraft:respiration") as i32); player.pitch = self.pitch; - // LivingEntity.canGlideUsing: a glider in its slot that will not break next. - player.glider = self.armor[1].as_ref().is_some_and(|s| { - self.res - .items() - .get(&s.item) - .is_some_and(|i| i.glider && (i.max_damage == 0 || s.damage + 1 < i.max_damage)) - }); + player.glider = self.glider_worn(); // A saved death already dropped inventory/XP and counted the death. if player.health.dead_or_dying() { self.screen = Screen::Dead; @@ -4015,6 +4019,7 @@ impl Game<'_> { let riding = self.riding.is_some(); let ghast_collisions = self.happy_ghast_player_collisions(); let spin_targets = self.spin_targets(); + let glider = self.glider_worn(); let Some(player) = self.player.as_mut() else { // A dedicated server has no local player: the world still runs. if self.options.dedicated.is_some() { @@ -4057,13 +4062,7 @@ impl Game<'_> { .as_ref() .map_or(0, |s| s.enchantment_level("minecraft:respiration") as i32); player.pitch = self.pitch; - // LivingEntity.canGlideUsing: a glider in its slot that will not break next. - player.glider = self.armor[1].as_ref().is_some_and(|s| { - self.res - .items() - .get(&s.item) - .is_some_and(|i| i.glider && (i.max_damage == 0 || s.damage + 1 < i.max_damage)) - }); + player.glider = glider; // LocalPlayer.modifyInput: walking while using an item. player.item_use_speed = self .using diff --git a/crates/horizon-client/src/game/agent.rs b/crates/horizon-client/src/game/agent.rs index 0c1954891..89fec4254 100644 --- a/crates/horizon-client/src/game/agent.rs +++ b/crates/horizon-client/src/game/agent.rs @@ -463,6 +463,7 @@ impl Game<'_> { "velocity": [p.velocity.x, p.velocity.y, p.velocity.z], "on_ground": p.ground.on_ground, "flying": p.flying, + "fall_flying": p.fall_flying, "sneaking": self.keys.contains(&KeyCode::ShiftLeft), "sprinting": self.keys.contains(&KeyCode::ControlLeft), "health": p.health.health(), diff --git a/crates/horizon-client/src/game/lan.rs b/crates/horizon-client/src/game/lan.rs index 8467b6d3a..9db544421 100644 --- a/crates/horizon-client/src/game/lan.rs +++ b/crates/horizon-client/src/game/lan.rs @@ -410,6 +410,8 @@ impl Game<'_> { // ItemCooldowns: the ticks the shield an axe disabled stays down. "shield_cooldown": h.play.get(&g.conn).map_or(0, |p| p.shield_cooldown), "sneaking": g.sneaking, + // The server's Elytra glide (shared flag 7). + "fall_flying": g.fall_flying, "sleeping": g.bed, "health": g.health, // The server's body: its air supply and golden hearts. diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index 73fa67ba9..81ee2860b 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -1027,6 +1027,7 @@ impl Game<'_> { g.open_ridden_mount_menu(); }); } + S::PlayerCommand(p) if p.action == 6 => self.lan_start_gliding(host, conn), S::ContainerButtonClick(p) => { self.lan_station_button(host, conn, p.container, p.button); } @@ -1850,6 +1851,13 @@ impl Game<'_> { /// sounds are heard at the guest. fn guest_server_tick(&mut self, host: &mut LanHost, conn: u32) { self.guest_vehicle_tick(host, conn); + // The last move's fall stands in for the server's delta movement. + let fell = host + .hub + .guest_mut(conn) + .and_then(|g| g.moves.last().map(|m| m.0[1])) + .unwrap_or(0.0); + self.guest_glide_tick(host, conn, fell); let Some(g) = host.hub.guest_mut(conn) else { return; }; @@ -1966,6 +1974,87 @@ impl Game<'_> { } } + /// ServerGamePacketListenerImpl.handlePlayerCommand START_FALL_FLYING: + /// `Player.tryToStartFallFlying`, or else `stopFallFlying` (a second + /// start while gliding ends the glide, as in vanilla). + fn lan_start_gliding(&mut self, host: &mut LanHost, conn: u32) { + let Some(g) = host.hub.guest_mut(conn) else { + return; + }; + let start = !g.fall_flying && self.guest_can_glide(host, conn) == Some(true); + let in_liquid = self + .as_guest(host, conn, |game| { + game.player + .as_ref() + .is_some_and(|p| p.fluids.was_touching_water || p.is_in_lava()) + }) + .unwrap_or(true); + if let Some(g) = host.hub.guest_mut(conn) { + g.fall_flying = start && !in_liquid; + } + } + + /// `Player.canGlide`: not flying, airborne, not riding, no levitation, and + /// a glider that its next point of wear won't break. + fn guest_can_glide(&mut self, host: &mut LanHost, conn: u32) -> Option { + let g = host.hub.guest_mut(conn)?; + if g.flying || g.on_ground || g.vehicle.is_some() { + return Some(false); + } + self.as_guest(host, conn, |game| { + game.glider_worn() && game.potions.effects.get("levitation").is_none() + }) + } + + /// `LivingEntity.updateFallFlying` on the server, once a tick for a + /// gliding guest: the glide ends once `canGlide` fails; otherwise every + /// 20th tick wears the glider by one, and every 10th is an + /// `elytra_glide` game event. Entity.checkFallDistanceAccumulation runs + /// first: a glide that isn't diving keeps the fall distance at 1. + fn guest_glide_tick(&mut self, host: &mut LanHost, conn: u32, fell: f64) { + let Some(g) = host.hub.guest_mut(conn) else { + return; + }; + if !g.fall_flying { + if let Some(m) = g.motion.as_mut() { + m.fall_fly_ticks = 0; + } + return; + } + let creative = g.creative(); + if let Some(m) = g.motion.as_mut() + && fell > -0.5 + && m.fall_distance > 1.0 + { + m.fall_distance = 1.0; + } + if self.guest_can_glide(host, conn) != Some(true) { + if let Some(g) = host.hub.guest_mut(conn) { + g.fall_flying = false; + } + return; + } + self.as_guest(host, conn, |game| { + let Some(p) = game.player.as_mut() else { + return; + }; + p.fall_fly_ticks += 1; + let next = p.fall_fly_ticks + 1; + let at = [p.position.x, p.position.y, p.position.z]; + if next % 10 != 0 { + return; + } + if (next / 10) % 2 == 0 + && !creative + && let Some(elytra) = game.armor[1].as_mut() + { + elytra.damage += 1; + } + let ctx = game.player_context(None); + game.post_game_event("minecraft:elytra_glide", at, ctx); + }); + } + /// `Player.isInWall`: a suffocating block in the 0.48-wide box at the /// eyes. Suffocating is a full collision box that is also a full render /// cube (`BlockBehaviour.isSuffocating`'s default; glass and the like diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index bb4a3d9c1..362dc3cf2 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -3139,6 +3139,12 @@ impl Game<'_> { .as_ref() .map_or(0, |s| s.enchantment_level("minecraft:respiration") as i32); player.fluids.fast_lava = self.dim == Dim::Nether; + let glider = self.glider_worn(); + let Some(player) = self.player.as_mut() else { + return Ok(()); + }; + player.glider = glider; + let was_gliding = player.fall_flying; let dead = self.screen == Screen::Dead; // LivingEntity.isImmobile: a sleeper lies still in the bed. if let Some(head) = self.sleeping { @@ -3163,6 +3169,9 @@ impl Game<'_> { // LocalPlayer.onUpdateAbilities: flight turned on or off (a double // jump, a spectator, landing) is sent to the server. let flying = player.flying; + // LocalPlayer.aiStep: a glide this client started is sent to the + // server (ServerboundPlayerCommandPacket START_FALL_FLYING). + let started_gliding = player.fall_flying && !was_gliding; let events = std::mem::take(&mut player.events); self.previous_eye = self.eye; self.eye += (player.dimensions.eye_height - self.eye) * 0.5; @@ -3202,6 +3211,14 @@ impl Game<'_> { flags: if flying { 2 } else { 0 }, })); } + if started_gliding { + let id = self.remote.as_ref().map_or(0, |r| r.entity_id); + self.send(S::PlayerCommand(play::PlayerCommand { + id, + action: 6, + data: 0, + })); + } self.remote_send_state(input); Ok(()) } diff --git a/crates/horizon-client/src/lan/hub.rs b/crates/horizon-client/src/lan/hub.rs index c8f2e980d..0b2ce442a 100644 --- a/crates/horizon-client/src/lan/hub.rs +++ b/crates/horizon-client/src/lan/hub.rs @@ -2011,14 +2011,15 @@ impl Hub { self.guests[i].sneaking = p.flags & 32 != 0; self.guests[i].sprinting = p.flags & 64 != 0 && p.flags & 1 != 0; } - // OPEN_INVENTORY is the game's: the ridden mount's inventory. - S::PlayerCommand(p) if p.action == 5 => { + // OPEN_INVENTORY (the ridden mount's inventory) and + // START_FALL_FLYING (checked against the guest's chest slot + // and effects) are the game's. + S::PlayerCommand(p) if matches!(p.action, 5 | 6) => { events.push(HostEvent::Packet(conn, Box::new(S::PlayerCommand(p)))); } S::PlayerCommand(p) => match p.action { 1 => self.guests[i].sprinting = true, 2 => self.guests[i].sprinting = false, - 6 => self.guests[i].fall_flying = true, // STOP_SLEEPING. 0 => self.wake(i), _ => {} diff --git a/tools/lan_e2e.py b/tools/lan_e2e.py index 3b369564f..d93a142f1 100755 --- a/tools/lan_e2e.py +++ b/tools/lan_e2e.py @@ -186,6 +186,10 @@ address. The script then checks, from both sides, what a guest's game used to ge (ServerboundEditBookPacket), read the written book the server gave them (ClientboundOpenBookPacket), then drop it: the other side sees its title, author and page (#1366). +- elytra: the host and the guest, high up with an Elytra on, jump in the air and glide + (ServerboundPlayerCommandPacket START_FALL_FLYING): both their client and the server + have them gliding, they go forward far more than down, and the glide ends on both once + they land (#1288). Each check is reported on its own (a failing one doesn't stop the others) and the screenshots of both sides go to --out (host-*.png, guest-*.png). @@ -4219,5 +4223,56 @@ CHECKS += ['totem', 'keepinv', 'signs', 'books'] CHECK_FNS.update(totem=check_totem, keepinv=check_keep_inventory, signs=check_signs, books=check_books) +def check_elytra(host, guest, out): + """LivingEntity.updateFallFlying for each player: a jump while falling with an Elytra on starts a + glide that the server takes too (Player.tryToStartFallFlying), the glide carries the player + forward rather than down, and landing ends it on both sides (canGlide fails on the ground).""" + hx, hy, hz = (int(v // 1) for v in pos_of(host)) + seen = {} + try: + for game, dx in ((host, -2), (guest, 2)): + x, z = hx + dx, hz + host('command', command=f'fill {x - 1} {hy - 1} {z - 1} {x + 1} {hy - 1} {z + 1} minecraft:stone') + host('command', command=f'fill {x - 1} {hy} {z - 1} {x + 1} {hy + 3} {z + 1} minecraft:air') + game('command', command='gamemode survival') + game('command', command='clear @s') + game('command', command='effect give @s minecraft:resistance 60 4 true') + game('command', command='item replace entity @s armor.chest with minecraft:elytra') + game('command', command=f'tp @s {x + 0.5} {hy + 60} {z + 0.5} 0 0') + game.wait(6) + start = pos_of(game) + game.raw('key', 'space', 'down') + game.wait(1) + game.raw('key', 'space', 'up') + game.wait(30) + end = pos_of(game) + glide = {'client': own(game).get('fall_flying'), + 'server': server_player(host, game).get('fall_flying'), + 'forward': round(math.hypot(end[0] - start[0], end[2] - start[2]), 1), + 'down': round(start[1] - end[1], 1)} + game.shot(out, 'elytra') + game('command', command=f'tp @s {x + 0.5} {hy + 1} {z + 0.5}') + game.wait(30) + landed = {'on_ground': own(game).get('on_ground'), + 'client': own(game).get('fall_flying'), + 'server': server_player(host, game).get('fall_flying')} + seen[game.name] = {'glide': glide, 'landed': landed} + finally: + for game in (host, guest): + game('command', command='clear @s') + game('command', command='effect clear @s') + face_each_other(host, guest) + for name, s in seen.items(): + g, l = s['glide'], s['landed'] + # Falling alone covers about 25 blocks in those 30 ticks and goes nowhere. + assert g['client'] and g['server'] and g['forward'] > 8 and g['down'] < 20, f'{name} glide: {seen}' + assert l['on_ground'] and not l['client'] and not l['server'], f'{name} landed: {seen}' + return seen + + +CHECKS += ['elytra'] +CHECK_FNS.update(elytra=check_elytra) + + if __name__ == '__main__': main()