From c4427d2a14b1dd029ea07c1b2437d7668759ad0e Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Tue, 27 Oct 2026 06:27:34 +0100 Subject: [PATCH] Size the mount hearts from the server's max health and fix the jump bar --- crates/horizon-client/src/game/mounts.rs | 23 +++++++++------ crates/horizon-client/src/game/remote.rs | 36 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/crates/horizon-client/src/game/mounts.rs b/crates/horizon-client/src/game/mounts.rs index fa4bbc209..c216a18ff 100644 --- a/crates/horizon-client/src/game/mounts.rs +++ b/crates/horizon-client/src/game/mounts.rs @@ -253,10 +253,7 @@ impl Game<'_> { /// `LocalPlayer.aiStep`'s riding jump: the bar charges while jump is /// held; on release, the jump's strength (0 when there is none). pub(super) fn charge_mount_jump(&mut self, i: usize, keys: Keys) -> f32 { - // PlayerRideableJumping: horses, camels and nautili (the dash). - let saddled = self.mobs[i].extra.saddled - && (equine::is_equine(self.mobs[i].species()) - || horizon_client::mobs::nautilus::is_nautilus(self.mobs[i].species())); + let saddled = self.mobs[i].extra.saddled && Self::jumps(self.mobs[i].species()); let mut jump = 0.0; if saddled { let st = &mut self.mount; @@ -463,10 +460,15 @@ impl Game<'_> { _ => {} } } - /// `Player.jumpableVehicle`: a saddled mount that jumps. + /// `PlayerRideableJumping`: horses, camels and nautili (the dash). + fn jumps(species: Species) -> bool { + equine::is_equine(species) || horizon_client::mobs::nautilus::is_nautilus(species) + } + /// `Player.jumpableVehicle`: a saddled mount that jumps (not a pig or a + /// strider, which a saddle only steers). pub(super) fn jumpable_mount(&self) -> bool { self.mount_index() - .is_some_and(|i| self.mobs[i].extra.saddled) + .is_some_and(|i| self.mobs[i].extra.saddled && Self::jumps(self.mobs[i].species())) } /// `willPrioritizeJumpInfo`: charging a jump or recharging. pub(super) fn mount_jumping(&self) -> bool { @@ -491,8 +493,13 @@ impl Game<'_> { let draws = horizon_client::hud_layout::vehicle_health(w, h, hearts, m.health); horizon_client::hud_layout::paint(batch, atlas, &draws); if jump_bar { - // JumpableVehicleBar: the cooldown shows while the jump recharges. - let cooldown = i32::from(self.mount.jump_ticks < 0); + // JumpableVehicleBar: `getJumpCooldown`, which only the camel's and + // the nautilus' dash have; a horse always shows the progress. + let cooldown = i32::from( + self.mount.jump_ticks < 0 + && (matches!(m.species(), Species::Camel | Species::CamelHusk) + || horizon_client::mobs::nautilus::is_nautilus(m.species())), + ); let draws = horizon_client::hud_overlays::jump_bar(w, h, cooldown, self.mount.jump_scale); horizon_client::hud_layout::paint(batch, atlas, &draws); diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 77e143f9a..e95a18303 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -1609,6 +1609,41 @@ impl Game<'_> { } } + /// `ClientPacketListener.handleUpdateAttributes` for a mob: its maximum + /// health (the hearts drawn over its mount) takes the server's value, from + /// `AttributeInstance.calculateValue`. + fn remote_mob_attributes(&mut self, id: i32, values: &[play::AttributeSnapshot]) { + let catalog = &self.motion.attributes; + let Some(max_health) = catalog.id("minecraft:max_health") else { + return; + }; + let Some(s) = values + .iter() + .find(|s| s.attribute == max_health.registry_id()) + else { + return; + }; + let amounts = |op: i32| { + s.modifiers + .iter() + .filter(move |m| m.operation == op) + .map(|m| m.amount) + }; + let base = s.base + amounts(0).sum::(); + let mut value = base + amounts(1).map(|a| base * a).sum::(); + for amount in amounts(2) { + value *= 1.0 + amount; + } + let value = catalog.attribute(max_health).definition.sanitize(value); + if let Some(m) = self.mobs.iter_mut().find(|m| m.id == id as u32) { + horizon_client::mobs::finalize::set_base( + m, + horizon_client::mobs::finalize::Attr::MaxHealth, + value, + ); + } + } + fn handle_packet(&mut self, packet: C) -> Result<()> { match packet { // ClientCommonPacketListenerImpl.handlePing runs on the game @@ -2199,6 +2234,7 @@ impl Game<'_> { } self.apply_remote_health(); } + C::UpdateAttributes(p) => self.remote_mob_attributes(p.id, &p.values), C::UpdateMobEffect(p) => self.remote_effect(&p), C::RemoveMobEffect(p) => { if self.remote.as_ref().is_some_and(|r| r.entity_id == p.id)