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 fe3f43401..5eadb0626 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" @@ -3510,7 +3510,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 bc2daf6ea..f760bd82f 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, @@ -695,10 +695,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/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 df0da4bac..812d6fc15 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 { @@ -4318,8 +4318,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/bee.rs b/crates/horizon-client/src/mobs/bee.rs index 53eacba1c..27d8e7c84 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 bc1d6ed10..9456c00a1 100644 --- a/crates/horizon-client/src/mobs/monster_brain.rs +++ b/crates/horizon-client/src/mobs/monster_brain.rs @@ -677,7 +677,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 74d34e2fd..7b311a9e0 100644 --- a/crates/horizon-client/src/mobs/villager_brain.rs +++ b/crates/horizon-client/src/mobs/villager_brain.rs @@ -2777,8 +2777,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; @@ -3171,7 +3171,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 c4df7d147..0d4f4d623 100644 --- a/crates/horizon-client/src/particles.rs +++ b/crates/horizon-client/src/particles.rs @@ -3233,7 +3233,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 {