From 14461c1d96443877e21fdd7fbc6be810d0c73dd6 Mon Sep 17 00:00:00 2001 From: Ganer Date: Fri, 23 Oct 2026 19:44:13 -0500 Subject: [PATCH 1/2] fix(client): preserve behavior while clearing Rust 1.90 Clippy errors --- .../examples/probe/first_person_probe.rs | 2 +- crates/horizon-client/src/containers.rs | 14 +++++----- crates/horizon-client/src/game.rs | 10 +++---- crates/horizon-client/src/game/chat.rs | 7 ++--- crates/horizon-client/src/game/debug_keys.rs | 2 +- crates/horizon-client/src/game/dragon.rs | 28 ++++++++++++++++--- crates/horizon-client/src/game/explosion.rs | 2 +- .../horizon-client/src/game/lan_vehicles.rs | 4 ++- crates/horizon-client/src/game/remote.rs | 5 ++-- crates/horizon-client/src/items.rs | 26 ++++++++--------- crates/horizon-client/src/mobs/ai.rs | 8 +++--- crates/horizon-client/src/mobs/axolotl.rs | 17 ++++++----- crates/horizon-client/src/mobs/bee.rs | 2 +- crates/horizon-client/src/mobs/living.rs | 6 ++-- .../horizon-client/src/mobs/monster_brain.rs | 2 +- crates/horizon-client/src/mobs/raider.rs | 2 +- .../horizon-client/src/mobs/villager_brain.rs | 6 ++-- crates/horizon-client/src/mobs/warden.rs | 2 +- crates/horizon-client/src/particles.rs | 2 +- crates/horizon-client/src/streaming.rs | 6 ++++ 20 files changed, 90 insertions(+), 63 deletions(-) diff --git a/crates/horizon-client/examples/probe/first_person_probe.rs b/crates/horizon-client/examples/probe/first_person_probe.rs index cb4c38e58..38829714c 100644 --- a/crates/horizon-client/examples/probe/first_person_probe.rs +++ b/crates/horizon-client/examples/probe/first_person_probe.rs @@ -203,7 +203,7 @@ impl HandWorld for Probe<'_> { let item = self.stack(Hand::Main).effective().0; // Item.canDestroyBlock: swords' tools cannot destroy in creative. let sword = item.ends_with("_sword"); - let ok = !(sword && self.creative) && !self.is_air(pos); + let ok = (!sword || !self.creative) && !self.is_air(pos); if ok { self.blocks.insert(pos, "minecraft:air".into()); } diff --git a/crates/horizon-client/src/containers.rs b/crates/horizon-client/src/containers.rs index 6ecdf0d93..de2e1b2e9 100644 --- a/crates/horizon-client/src/containers.rs +++ b/crates/horizon-client/src/containers.rs @@ -382,7 +382,7 @@ impl Providers { ); Self { ints, floats } } - fn eval(&self, v: &Value, fast: bool, table: &HashMap, depth: u32) -> f64 { + fn eval(v: &Value, fast: bool, table: &HashMap, depth: u32) -> f64 { if depth > 16 { return 0.0; } @@ -390,10 +390,10 @@ impl Providers { Value::Number(n) => n.as_f64().unwrap_or(0.0), Value::String(name) => table .get(name) - .map_or(0.0, |v| self.eval(v, fast, table, depth + 1)), + .map_or(0.0, |v| Self::eval(v, fast, table, depth + 1)), Value::Object(o) => { let f = - |k: &str| self.eval(o.get(k).unwrap_or(&Value::Null), fast, table, depth + 1); + |k: &str| Self::eval(o.get(k).unwrap_or(&Value::Null), fast, table, depth + 1); match o.get("type").and_then(Value::as_str).unwrap_or("") { "minecraft:div" => { let r = f("right"); @@ -425,14 +425,14 @@ impl Providers { } /// A plain `context_int_provider` value or reference (no context conditions). pub fn int_value(&self, v: &Value) -> i32 { - self.eval(v, false, &self.ints, 0) as i32 + Self::eval(v, false, &self.ints, 0) as i32 } /// A plain `context_float_provider` value or reference; `default` when absent. pub fn float_value(&self, v: &Value, default: f32) -> f32 { if v.is_null() { default } else { - self.eval(v, false, &self.floats, 0) as f32 + Self::eval(v, false, &self.floats, 0) as f32 } } #[cfg(test)] @@ -446,14 +446,14 @@ impl Providers { items .get(&stack.item) .and_then(|i| i.fuel.as_ref()) - .map_or(0, |(time, _)| self.eval(time, fast, &self.ints, 0) as i32) + .map_or(0, |(time, _)| Self::eval(time, fast, &self.ints, 0) as i32) } pub fn speed(&self, items: &Items, stack: &ItemStack, fast: bool) -> f32 { items .get(&stack.item) .and_then(|i| i.fuel.as_ref()) .map_or(1.0, |(_, speed)| { - self.eval(speed, fast, &self.floats, 0) as f32 + Self::eval(speed, fast, &self.floats, 0) as f32 }) } } diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 6184f1626..645e6483c 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -1741,10 +1741,10 @@ impl Game<'_> { let state = self.world.block(pos[0], pos[1], pos[2]); let f = self.res.facts().get(state); if !self.res.facts().is_air(state) - && !(f.fluid != Fluid::None - && !f.waterlogged - && &*f.name != "minecraft:kelp" - && f.render_shape != horizon_client::blocks::RenderShape::Model) + && (f.fluid == Fluid::None + || f.waterlogged + || &*f.name == "minecraft:kelp" + || f.render_shape == horizon_client::blocks::RenderShape::Model) && !matches!( &*f.name, "minecraft:water" | "minecraft:lava" | "minecraft:bubble_column" @@ -3429,7 +3429,7 @@ impl Game<'_> { return Ok(true); } // Block foods attempt placement before starting consumption. - if !on_block && !(info.block.is_some() && block_hit.is_some()) && self.start_eating(&info) { + if !on_block && (info.block.is_none() || block_hit.is_none()) && self.start_eating(&info) { return Ok(true); } // BoatItem.use also performs its own fluid/block raycast. diff --git a/crates/horizon-client/src/game/chat.rs b/crates/horizon-client/src/game/chat.rs index 0247896f5..91ddaf74a 100644 --- a/crates/horizon-client/src/game/chat.rs +++ b/crates/horizon-client/src/game/chat.rs @@ -1,6 +1,6 @@ //! Chat, the command registries and the per-world state behind commands //! (game rules, the world clock, difficulty), bound to the game. -use super::{Dim, Game, Screen}; +use super::{Game, Screen}; use horizon_client::{ chat::{Chat, ChatAction, ChatScreen, Commands, SYSTEM_INDICATOR}, command::Registries, @@ -685,10 +685,7 @@ impl Game<'_> { /// Advance the overworld clock (ServerClockManager.tick) when /// `advance_time` allows it. pub(super) fn advance_clock(&mut self) { - if !self.ui.rules.bool("advance_time") - || self.ui.clock.paused - || self.dim == Dim::Nether && false - { + if !self.ui.rules.bool("advance_time") || self.ui.clock.paused { return; } let c = &mut self.ui.clock; diff --git a/crates/horizon-client/src/game/debug_keys.rs b/crates/horizon-client/src/game/debug_keys.rs index 553cd0d96..be9f76b3f 100644 --- a/crates/horizon-client/src/game/debug_keys.rs +++ b/crates/horizon-client/src/game/debug_keys.rs @@ -38,7 +38,7 @@ impl DebugHost for Host<'_, '_> { // the menu as it always has (key_pressed). let g = &mut *self.game; if without_menu && g.screen == Screen::Playing { - g.pause_menu = !(g.has_singleplayer_server() && !g.is_published()); + g.pause_menu = !g.has_singleplayer_server() || g.is_published(); g.screen = Screen::Paused; g.capture(false); g.mining = None; diff --git a/crates/horizon-client/src/game/dragon.rs b/crates/horizon-client/src/game/dragon.rs index c6f5d419b..cd2de3736 100644 --- a/crates/horizon-client/src/game/dragon.rs +++ b/crates/horizon-client/src/game/dragon.rs @@ -27,6 +27,12 @@ const CRYSTAL_IDS: u32 = SPECIAL + 16; const FIGHT_FILE: &str = "data/minecraft/ender_dragon_fight.dat"; const MAX_HEALTH: f32 = 200.0; +/// Preserve the ordered double comparisons from vanilla: a NaN squared +/// distance fails both comparisons and must not be treated as out of range. +fn target_distance_outside_range(distance_squared: f64) -> bool { + !distance_squared.is_nan() && !(100.0..=22500.0).contains(&distance_squared) +} + #[derive(Default)] pub(super) struct Fight { loaded: bool, @@ -1286,7 +1292,7 @@ impl Game<'_> { clockwise, } => { let dt = far(*target); - if dt < 100.0 || dt > 22500.0 || collided { + if target_distance_outside_range(dt) || collided { let done = path.as_ref().is_some_and(|p| p.0.done()); let mut chosen = false; if done { @@ -1356,7 +1362,7 @@ impl Game<'_> { *target = Some(Vec3::new(pp.x, pp.y + ho, pp.z)); } let dt = far(*target); - if dt < 100.0 || dt > 22500.0 { + if target_distance_outside_range(dt) { if path.as_ref().is_none_or(|p| p.0.done()) { *path = self.ring_path(clockwise).map(PathBox); } @@ -1393,7 +1399,7 @@ impl Game<'_> { } Phase::LandingApproach { path, target } => { let dt = far(*target); - if dt < 100.0 || dt > 22500.0 || collided { + if target_distance_outside_range(dt) || collided { if path.as_ref().is_none_or(|p| p.0.done()) { let current = self.closest_node(pos.x, pos.y, pos.z); // NEAR_EGG_TARGETING: the enemy nearest the egg. @@ -1577,7 +1583,7 @@ impl Game<'_> { } } else { let dt = far(*target); - if dt < 100.0 || dt > 22500.0 { + if target_distance_outside_range(dt) { *since += 1; } } @@ -3263,4 +3269,18 @@ mod tests { let t = nearest_enemy(&players, false, Vec3::new(9.0, 64.0, 0.0), None, |_| true); assert_eq!(t.map(|p| p.who), Some(FightWho::Host)); } + #[test] + fn target_distance_respects_nan_and_exact_boundaries() { + for (distance, expected) in [ + (f64::NAN, false), + (f64::NEG_INFINITY, true), + (99.0, true), + (100.0, false), + (22500.0, false), + (22501.0, true), + (f64::INFINITY, true), + ] { + assert_eq!(super::target_distance_outside_range(distance), expected); + } + } } diff --git a/crates/horizon-client/src/game/explosion.rs b/crates/horizon-client/src/game/explosion.rs index 6ecba3a54..e3baa76fc 100644 --- a/crates/horizon-client/src/game/explosion.rs +++ b/crates/horizon-client/src/game/explosion.rs @@ -306,7 +306,7 @@ impl Game<'_> { { outcome = o; } - if !spectator && !(creative && flying) { + if !spectator && (!creative || !flying) { p.velocity = Vec3::new( p.velocity.x + dir[0] * power, p.velocity.y + dir[1] * power, diff --git a/crates/horizon-client/src/game/lan_vehicles.rs b/crates/horizon-client/src/game/lan_vehicles.rs index 8198f288e..71e9936a5 100644 --- a/crates/horizon-client/src/game/lan_vehicles.rs +++ b/crates/horizon-client/src/game/lan_vehicles.rs @@ -205,7 +205,9 @@ impl Game<'_> { return; }; let [x, y, z] = p.position; - if !(x.is_finite() && y.is_finite() && z.is_finite()) + if !x.is_finite() + || !y.is_finite() + || !z.is_finite() || !p.yaw.is_finite() || !p.pitch.is_finite() { diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 32613e42a..7859af6fc 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -544,7 +544,7 @@ impl Game<'_> { /// (`LivingEntity.forceAddEffect`): the effect replaces any of its kind. /// Other entities' effects are not shown. fn remote_effect(&mut self, p: &play::UpdateMobEffect) { - if !self.remote.as_ref().is_some_and(|r| r.entity_id == p.id) { + if self.remote.as_ref().is_none_or(|r| r.entity_id != p.id) { return; } let Some(id) = self.remote_effect_id(p.effect) else { @@ -4247,8 +4247,7 @@ impl Game<'_> { /// Keys with a multiplayer meaning; returns true when consumed. pub(super) fn remote_key(&mut self, key: KeyCode) -> Result { if self.screen != Screen::Playing { - if key == KeyCode::KeyE && self.screen == Screen::Inventory - || key == KeyCode::Escape && self.screen == Screen::Inventory + if (key == KeyCode::KeyE || key == KeyCode::Escape) && self.screen == Screen::Inventory { self.remote_close_container(); self.screen = Screen::Playing; diff --git a/crates/horizon-client/src/items.rs b/crates/horizon-client/src/items.rs index abbc1241f..95e7e2c42 100644 --- a/crates/horizon-client/src/items.rs +++ b/crates/horizon-client/src/items.rs @@ -1051,7 +1051,7 @@ impl LootContext<'_> { continue; } // LootPool: rolls.getInt (Mth.randomBetweenInclusive for uniform rolls). - let rolls = ctx.int_number(&pool["rolls"], random).max(0) as u32; + let rolls = LootContext::int_number(&pool["rolls"], random).max(0) as u32; for _ in 0..rolls { let mut produced = Vec::new(); ctx.choose( @@ -1085,7 +1085,7 @@ impl LootContext<'_> { fn enchantment_level(&self, id: &str) -> u32 { self.held.map_or(0, |h| h.enchantment_level(id)) } - fn number(&self, v: &Value, random: &mut R) -> f32 { + fn number(v: &Value, random: &mut R) -> f32 { match v { Value::Number(n) => n.as_f64().unwrap_or(0.0) as f32, Value::Object(o) => match o @@ -1097,8 +1097,8 @@ impl LootContext<'_> { o.get("value").and_then(Value::as_f64).unwrap_or(0.0) as f32 } "minecraft:uniform" => { - let min = self.number(o.get("min").unwrap_or(&Value::Null), random); - let max = self.number(o.get("max").unwrap_or(&Value::Null), random); + let min = Self::number(o.get("min").unwrap_or(&Value::Null), random); + let max = Self::number(o.get("max").unwrap_or(&Value::Null), random); // UniformGenerator.getFloat / getInt (Mth.nextInt) differ; use int for counts. if max <= min { min @@ -1107,8 +1107,8 @@ impl LootContext<'_> { } } "minecraft:binomial" => { - let n = self.number(o.get("n").unwrap_or(&Value::Null), random) as u32; - let p = self.number(o.get("p").unwrap_or(&Value::Null), random); + let n = Self::number(o.get("n").unwrap_or(&Value::Null), random) as u32; + let p = Self::number(o.get("p").unwrap_or(&Value::Null), random); (0..n).filter(|_| random.next_float() < p).count() as f32 } _ => 1.0, @@ -1116,22 +1116,22 @@ impl LootContext<'_> { _ => 1.0, } } - fn int_number(&self, v: &Value, random: &mut R) -> i32 { + fn int_number(v: &Value, random: &mut R) -> i32 { if let Value::Object(o) = v && o.get("type") .and_then(Value::as_str) .unwrap_or("minecraft:uniform") == "minecraft:uniform" { - let min = self.int_number(o.get("min").unwrap_or(&Value::Null), random); - let max = self.int_number(o.get("max").unwrap_or(&Value::Null), random); + let min = Self::int_number(o.get("min").unwrap_or(&Value::Null), random); + let max = Self::int_number(o.get("max").unwrap_or(&Value::Null), random); return if max <= min { min } else { min + random.next_int_bound(max - min + 1).unwrap_or(0) }; } - self.number(v, random).round() as i32 + Self::number(v, random).round() as i32 } fn condition(&self, c: &Value, random: &mut R) -> bool { let (kind, c) = match c { @@ -1157,7 +1157,7 @@ impl LootContext<'_> { .into_iter() .flatten() .all(|t| self.condition(t, random)), - "minecraft:random_chance" => random.next_float() < self.number(&c["chance"], random), + "minecraft:random_chance" => random.next_float() < Self::number(&c["chance"], random), "minecraft:table_bonus" => { // BonusLevelTableCondition: chances[min(level, len - 1)]. let level = @@ -1378,7 +1378,7 @@ impl LootContext<'_> { } match f["type"].as_str().or(f["function"].as_str()).unwrap_or("") { "minecraft:set_count" => { - let n = self.int_number(&f["count"], random); + let n = Self::int_number(&f["count"], random); let base = if f["add"].as_bool() == Some(true) { stack.count as i32 } else { @@ -1421,7 +1421,7 @@ impl LootContext<'_> { // Attacker's level x count, rounded (looting). let level = self.enchantment_level(f["enchantment"].as_str().unwrap_or("")); if level > 0 && self.killed_by_player && self.block.is_empty() { - let add = level as f32 * self.number(&f["count"], random); + let add = level as f32 * Self::number(&f["count"], random); stack.count = (stack.count as i32 + add.round() as i32).max(0) as u32; if let Some(limit) = f["limit"].as_i64().filter(|l| *l > 0) { stack.count = stack.count.min(limit as u32); diff --git a/crates/horizon-client/src/mobs/ai.rs b/crates/horizon-client/src/mobs/ai.rs index ae4aa91a6..97da5ea06 100644 --- a/crates/horizon-client/src/mobs/ai.rs +++ b/crates/horizon-client/src/mobs/ai.rs @@ -405,7 +405,7 @@ pub fn tick( } // Mob.tickHeadTurn -> BodyRotationControl.clientTick (a frozen // creaking's waits). - if m.alive() && !(super::creaking::is_creaking(m) && !super::creaking::can_move(m)) { + if m.alive() && (!super::creaking::is_creaking(m) || super::creaking::can_move(m)) { m.body_rotation_tick(); } events.append(&mut m.outbox); @@ -752,8 +752,8 @@ impl Mob { pub fn pushable(&self) -> bool { self.alive() && !matches!(self.species(), Species::Bat | Species::Shulker) - && !(self.kind.flags.climber && self.climbing) - && !(self.species() == Species::Creaking && !super::creaking::can_move(self)) + && (!self.kind.flags.climber || !self.climbing) + && (self.species() != Species::Creaking || super::creaking::can_move(self)) } } /// LivingEntity.onClimbable for the pusher (Spider.onClimbable: climbing a wall). @@ -780,7 +780,7 @@ fn push_entities(m: &mut Mob, w: &MobWorld, events: &mut Vec) { let self_pushable = m.alive() && m.species() != Species::Shulker && !on_climbable(m, w) - && !(m.species() == Species::Creaking && !super::creaking::can_move(m)); + && (m.species() != Species::Creaking || super::creaking::can_move(m)); let mut targets: Vec<(Who, Vec3)> = Vec::new(); if let Some(p) = &w.player // Entity.push: passengers of the same vehicle never push each other. diff --git a/crates/horizon-client/src/mobs/axolotl.rs b/crates/horizon-client/src/mobs/axolotl.rs index 55f15717c..e4a639768 100644 --- a/crates/horizon-client/src/mobs/axolotl.rs +++ b/crates/horizon-client/src/mobs/axolotl.rs @@ -166,13 +166,16 @@ mod axolotl_parity_tests { ] { let mut expected = LegacyRandom::new(seed); let mut actual = LegacyRandom::new(seed); - let result = !no_ai - && expected.next_int_bound(3).unwrap() == 0 - && ((expected.next_int_bound(3).unwrap() as f32) < 2.0 || 4.0f32 / 14.0 < 0.5) - && 2.0 < 4.0 - && water - && entity - && !already; + // The second draw is intentionally consumed even though + // the fixed 4.0 / 14.0 threshold always makes this branch + // true. Removing it changes the native RNG sequence. + let first_gate = !no_ai && expected.next_int_bound(3).unwrap() == 0; + let result = if first_gate { + let _second_draw = expected.next_int_bound(3).unwrap(); + water && entity && !already + } else { + false + }; assert_eq!( roll_play_dead(&mut actual, no_ai, 4.0, 14.0, 2.0, water, entity, already), result diff --git a/crates/horizon-client/src/mobs/bee.rs b/crates/horizon-client/src/mobs/bee.rs index cdb0318bc..018368604 100644 --- a/crates/horizon-client/src/mobs/bee.rs +++ b/crates/horizon-client/src/mobs/bee.rs @@ -1046,7 +1046,7 @@ impl Goal for GrowCrop { } fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool { // The 0.3 roll comes only after the crop count: it draws randomness. - let usable = !get(m).is_some_and(|b| b.crops_grown >= 10) + let usable = get(m).is_none_or(|b| b.crops_grown < 10) && m.random.next_float() >= 0.3 && has_nectar(m) && hive_valid(m, cx.w); diff --git a/crates/horizon-client/src/mobs/living.rs b/crates/horizon-client/src/mobs/living.rs index d5b3c7091..f16e0e18d 100644 --- a/crates/horizon-client/src/mobs/living.rs +++ b/crates/horizon-client/src/mobs/living.rs @@ -167,9 +167,9 @@ impl MobWorld<'_> { let Ok(block) = self.collision.collision_block(state) else { continue; }; - if !block.large_collision_shape - && !block.moving_piston - && !(column && meets(Axis::Y, y)) + if !(block.large_collision_shape + || block.moving_piston + || (column && meets(Axis::Y, y))) { continue; } diff --git a/crates/horizon-client/src/mobs/monster_brain.rs b/crates/horizon-client/src/mobs/monster_brain.rs index 1099e0bc3..59fe04ef6 100644 --- a/crates/horizon-client/src/mobs/monster_brain.rs +++ b/crates/horizon-client/src/mobs/monster_brain.rs @@ -712,7 +712,7 @@ impl B { .is_some_and(|l| l.contains(&Who::Player)); !reachable }; - if !(can_attack(m, cx.w, target) && !tired && alive && !stop_when) { + if !can_attack(m, cx.w, target) || tired || !alive || stop_when { set_attack_target(m, None); } *running = true; diff --git a/crates/horizon-client/src/mobs/raider.rs b/crates/horizon-client/src/mobs/raider.rs index 1c3f7ff94..6c3ab9b64 100644 --- a/crates/horizon-client/src/mobs/raider.rs +++ b/crates/horizon-client/src/mobs/raider.rs @@ -426,7 +426,7 @@ impl Goal for MoveThroughVillage { self.visited.remove(0); } let Some(s) = state(m) else { return false }; - if !(s.active_raid && !s.raid_over) || m.ai.target.is_some() { + if !s.active_raid || s.raid_over || m.ai.target.is_some() { return false; } let Some(homes) = s.homes.clone() else { diff --git a/crates/horizon-client/src/mobs/villager_brain.rs b/crates/horizon-client/src/mobs/villager_brain.rs index 194bd75ff..adedd56c0 100644 --- a/crates/horizon-client/src/mobs/villager_brain.rs +++ b/crates/horizon-client/src/mobs/villager_brain.rs @@ -2806,8 +2806,8 @@ impl B { let on_or_over = jumpable(here) || jumpable([here[0], here[1] - 1, here[2]]); let still = m.is_baby() && bed.is_some_and(jumpable) - && !(!on_or_over && *time_left <= 0) - && !(on_or_over && *jumps <= 0); + && (on_or_over || *time_left > 0) + && (!on_or_over || *jumps > 0); if !still { self.do_stop(m, cx); return; @@ -3196,7 +3196,7 @@ fn follow_trading_condition(m: &Mob, w: &MobWorld) -> bool { m.extra.flag2 && m.alive() && !m.fluids.in_water - && !(m.hurt_time > 0) + && m.hurt_time <= 0 && w.player .as_ref() .is_some_and(|p| m.distance_sqr(p.position) <= 16.0) diff --git a/crates/horizon-client/src/mobs/warden.rs b/crates/horizon-client/src/mobs/warden.rs index f78ceff25..11161ef7c 100644 --- a/crates/horizon-client/src/mobs/warden.rs +++ b/crates/horizon-client/src/mobs/warden.rs @@ -457,7 +457,7 @@ pub fn can_receive_vibration(m: &Mob, _now: i64, ctx: &Context) -> bool { && m.alive() && !st.brain.mem.vibration_cooldown.present() && !digging_or_emerging(m) - && !(ctx.living && !ctx.targetable) + && (!ctx.living || ctx.targetable) } /// `VibrationSystem.Listener.handleGameEvent` for the warden: a free /// listener within 16 blocks of its eyes schedules what it can hear. diff --git a/crates/horizon-client/src/particles.rs b/crates/horizon-client/src/particles.rs index a5df97258..31e23b87b 100644 --- a/crates/horizon-client/src/particles.rs +++ b/crates/horizon-client/src/particles.rs @@ -3223,7 +3223,7 @@ impl ParticleEngine { } => { p.base_tick(level); let (fluid, source) = level.fluid_source(ParticleLevel::block_at(p.position)); - if !p.removed && !(fluid == Fluid::Water && source) { + if !(p.removed || (fluid == Fluid::Water && source)) { p.removed = true; } if !p.removed && p.position[1] >= y_end { diff --git a/crates/horizon-client/src/streaming.rs b/crates/horizon-client/src/streaming.rs index 15ed1674e..92d37483b 100644 --- a/crates/horizon-client/src/streaming.rs +++ b/crates/horizon-client/src/streaming.rs @@ -641,6 +641,12 @@ impl Streaming { }); self.shared.ready.notify_one(); } + // Proto arrays are large; keep ownership of the incoming heap allocation + // instead of moving all nine chunks onto a transient stack frame. + #[expect( + clippy::boxed_local, + reason = "keep nine large Proto values heap resident" + )] fn receive_decorated(&mut self, x: i32, z: i32, region: Box<[Proto; 9]>) { self.generation_scan.exhausted = false; self.decorating -= 1; From b21423ae01cda2fec404604f9dbcd1526c7fea16 Mon Sep 17 00:00:00 2001 From: Ludovic Marie Date: Sat, 24 Oct 2026 11:31:10 +0200 Subject: [PATCH 2/2] Keep only the Clippy rewrites that read as well on stable CI runs stable Clippy (1.99), which is clean on main. The #[expect(clippy::boxed_local)] in streaming.rs is unfulfilled there and fails CI under -D warnings, so it goes. Also back out the rewrites that only satisfied Rust 1.90's Clippy and read worse: the dragon's range helper and its test, the axolotl test's restated formula, and two De Morgan expansions (first_person_probe, explosion). Co-Authored-By: Claude Opus 5.5 --- .../examples/probe/first_person_probe.rs | 2 +- crates/horizon-client/src/game/dragon.rs | 28 +++---------------- crates/horizon-client/src/game/explosion.rs | 2 +- crates/horizon-client/src/mobs/axolotl.rs | 17 +++++------ crates/horizon-client/src/streaming.rs | 6 ---- 5 files changed, 13 insertions(+), 42 deletions(-) diff --git a/crates/horizon-client/examples/probe/first_person_probe.rs b/crates/horizon-client/examples/probe/first_person_probe.rs index 38829714c..cb4c38e58 100644 --- a/crates/horizon-client/examples/probe/first_person_probe.rs +++ b/crates/horizon-client/examples/probe/first_person_probe.rs @@ -203,7 +203,7 @@ impl HandWorld for Probe<'_> { let item = self.stack(Hand::Main).effective().0; // Item.canDestroyBlock: swords' tools cannot destroy in creative. let sword = item.ends_with("_sword"); - let ok = (!sword || !self.creative) && !self.is_air(pos); + let ok = !(sword && self.creative) && !self.is_air(pos); if ok { self.blocks.insert(pos, "minecraft:air".into()); } diff --git a/crates/horizon-client/src/game/dragon.rs b/crates/horizon-client/src/game/dragon.rs index cd2de3736..c6f5d419b 100644 --- a/crates/horizon-client/src/game/dragon.rs +++ b/crates/horizon-client/src/game/dragon.rs @@ -27,12 +27,6 @@ const CRYSTAL_IDS: u32 = SPECIAL + 16; const FIGHT_FILE: &str = "data/minecraft/ender_dragon_fight.dat"; const MAX_HEALTH: f32 = 200.0; -/// Preserve the ordered double comparisons from vanilla: a NaN squared -/// distance fails both comparisons and must not be treated as out of range. -fn target_distance_outside_range(distance_squared: f64) -> bool { - !distance_squared.is_nan() && !(100.0..=22500.0).contains(&distance_squared) -} - #[derive(Default)] pub(super) struct Fight { loaded: bool, @@ -1292,7 +1286,7 @@ impl Game<'_> { clockwise, } => { let dt = far(*target); - if target_distance_outside_range(dt) || collided { + if dt < 100.0 || dt > 22500.0 || collided { let done = path.as_ref().is_some_and(|p| p.0.done()); let mut chosen = false; if done { @@ -1362,7 +1356,7 @@ impl Game<'_> { *target = Some(Vec3::new(pp.x, pp.y + ho, pp.z)); } let dt = far(*target); - if target_distance_outside_range(dt) { + if dt < 100.0 || dt > 22500.0 { if path.as_ref().is_none_or(|p| p.0.done()) { *path = self.ring_path(clockwise).map(PathBox); } @@ -1399,7 +1393,7 @@ impl Game<'_> { } Phase::LandingApproach { path, target } => { let dt = far(*target); - if target_distance_outside_range(dt) || collided { + if dt < 100.0 || dt > 22500.0 || collided { if path.as_ref().is_none_or(|p| p.0.done()) { let current = self.closest_node(pos.x, pos.y, pos.z); // NEAR_EGG_TARGETING: the enemy nearest the egg. @@ -1583,7 +1577,7 @@ impl Game<'_> { } } else { let dt = far(*target); - if target_distance_outside_range(dt) { + if dt < 100.0 || dt > 22500.0 { *since += 1; } } @@ -3269,18 +3263,4 @@ mod tests { let t = nearest_enemy(&players, false, Vec3::new(9.0, 64.0, 0.0), None, |_| true); assert_eq!(t.map(|p| p.who), Some(FightWho::Host)); } - #[test] - fn target_distance_respects_nan_and_exact_boundaries() { - for (distance, expected) in [ - (f64::NAN, false), - (f64::NEG_INFINITY, true), - (99.0, true), - (100.0, false), - (22500.0, false), - (22501.0, true), - (f64::INFINITY, true), - ] { - assert_eq!(super::target_distance_outside_range(distance), expected); - } - } } diff --git a/crates/horizon-client/src/game/explosion.rs b/crates/horizon-client/src/game/explosion.rs index e3baa76fc..6ecba3a54 100644 --- a/crates/horizon-client/src/game/explosion.rs +++ b/crates/horizon-client/src/game/explosion.rs @@ -306,7 +306,7 @@ impl Game<'_> { { outcome = o; } - if !spectator && (!creative || !flying) { + if !spectator && !(creative && flying) { p.velocity = Vec3::new( p.velocity.x + dir[0] * power, p.velocity.y + dir[1] * power, diff --git a/crates/horizon-client/src/mobs/axolotl.rs b/crates/horizon-client/src/mobs/axolotl.rs index e4a639768..55f15717c 100644 --- a/crates/horizon-client/src/mobs/axolotl.rs +++ b/crates/horizon-client/src/mobs/axolotl.rs @@ -166,16 +166,13 @@ mod axolotl_parity_tests { ] { let mut expected = LegacyRandom::new(seed); let mut actual = LegacyRandom::new(seed); - // The second draw is intentionally consumed even though - // the fixed 4.0 / 14.0 threshold always makes this branch - // true. Removing it changes the native RNG sequence. - let first_gate = !no_ai && expected.next_int_bound(3).unwrap() == 0; - let result = if first_gate { - let _second_draw = expected.next_int_bound(3).unwrap(); - water && entity && !already - } else { - false - }; + let result = !no_ai + && expected.next_int_bound(3).unwrap() == 0 + && ((expected.next_int_bound(3).unwrap() as f32) < 2.0 || 4.0f32 / 14.0 < 0.5) + && 2.0 < 4.0 + && water + && entity + && !already; assert_eq!( roll_play_dead(&mut actual, no_ai, 4.0, 14.0, 2.0, water, entity, already), result diff --git a/crates/horizon-client/src/streaming.rs b/crates/horizon-client/src/streaming.rs index 92d37483b..15ed1674e 100644 --- a/crates/horizon-client/src/streaming.rs +++ b/crates/horizon-client/src/streaming.rs @@ -641,12 +641,6 @@ impl Streaming { }); self.shared.ready.notify_one(); } - // Proto arrays are large; keep ownership of the incoming heap allocation - // instead of moving all nine chunks onto a transient stack frame. - #[expect( - clippy::boxed_local, - reason = "keep nine large Proto values heap resident" - )] fn receive_decorated(&mut self, x: i32, z: i32, region: Box<[Proto; 9]>) { self.generation_scan.exhausted = false; self.decorating -= 1;