Invisible players are harder for mobs to notice

Mobs now scale their detection range by 0.7 times the worn armor fraction (at least 0.1) when the player has Invisibility, like vanilla's getVisibilityPercent.
This commit is contained in:
Kacpherek
2026-10-26 15:13:15 +01:00
parent 8027cb4176
commit 2a0824cf5f
7 changed files with 21 additions and 8 deletions
@@ -1050,6 +1050,7 @@ pub fn main() -> horizon_client::Result<()> {
off_hand: None,
head: None,
armor_cover: 0.0,
invisible: false,
spectator: false,
gold_armor: false,
hurt_by: None,
@@ -186,6 +186,7 @@ impl Game<'_> {
off_hand: None,
head: self.armor[0].as_ref().map(|s| s.item.clone()),
armor_cover: self.armor.iter().filter(|a| a.is_some()).count() as f32 / 4.0,
invisible: self.potions.effects.get("invisibility").is_some(),
spectator: self.spectator(),
gold_armor: self.wearing_gold(),
hurt_by: self.player_hurt_by(),
@@ -363,6 +363,7 @@ mod tests {
off_hand: None,
head: None,
armor_cover: 0.0,
invisible: false,
spectator: false,
gold_armor: false,
hurt_by: None,
+15
View File
@@ -1448,6 +1448,8 @@ pub struct PlayerView {
pub off_hand: Option<Arc<str>>,
pub head: Option<Arc<str>>,
pub armor_cover: f32,
/// The Invisibility effect (`isInvisible`).
pub invisible: bool,
pub spectator: bool,
/// `PiglinAi.isWearingSafeArmor`: some golden armour.
pub gold_armor: bool,
@@ -1468,6 +1470,19 @@ pub struct PlayerView {
/// (`EntitySelector.pushableBy` on the client).
pub remote: bool,
}
impl PlayerView {
/// `LivingEntity.getVisibilityPercent` without the worn-skull scaling.
pub fn visibility_percent(&self) -> f64 {
let mut visibility = 1.0;
if self.sneaking {
visibility *= 0.8;
}
if self.invisible {
visibility *= 0.7 * f64::from(self.armor_cover).max(0.1);
}
visibility
}
}
#[derive(Clone)]
pub struct MobWorld<'a> {
pub world: &'a World,
@@ -625,8 +625,7 @@ fn targetable(m: &mut Mob, w: &MobWorld, who: Who) -> bool {
// TargetingConditions.forNonCombat(): in range (scaled by the
// player's visibility, at least 2) and in sight.
let Some(p) = &w.player else { return false };
let visibility = if p.sneaking { 0.8 } else { 1.0 };
let r = (range * visibility).max(2.0);
let r = (range * p.visibility_percent()).max(2.0);
p.alive && !p.spectator && m.distance_sqr(p.position) <= r * r && m.sees(w, who)
}
Who::Mob(id) => {
+1 -4
View File
@@ -601,10 +601,7 @@ impl Mob {
return false;
}
// LivingEntity.getVisibilityPercent
let mut visibility = 1.0;
if p.sneaking {
visibility *= 0.8;
}
let mut visibility = p.visibility_percent();
if let Some(head) = &p.head {
let skull = match self.species() {
Species::Zombie | Species::Husk | Species::Drowned | Species::ZombieVillager => {
@@ -364,8 +364,7 @@ impl Goal for GhastTempt {
let Some(p) = &cx.w.player else { return false };
// getNearestPlayer(TargetingConditions.forNonCombat()
// .ignoreLineOfSight().range(TEMPT_RANGE 16)): creative players too.
let visibility = if p.sneaking { 0.8 } else { 1.0 };
let range = (16.0_f64 * visibility).max(2.0);
let range = (16.0_f64 * p.visibility_percent()).max(2.0);
p.alive
&& !p.spectator
&& (Self::wants(m, &p.main_hand) || Self::wants(m, &p.off_hand))