diff --git a/crates/horizon-client/examples/mob_ai_probe.rs b/crates/horizon-client/examples/mob_ai_probe.rs index 7058d448f..9f083e2d5 100644 --- a/crates/horizon-client/examples/mob_ai_probe.rs +++ b/crates/horizon-client/examples/mob_ai_probe.rs @@ -173,6 +173,11 @@ fn goal_name(m: &Mob, name: &str) -> String { "TryFindWater" => "TryFindWaterGoal", "RangedAttack" => "RangedAttackGoal", "MoveTowardsTarget" => "MoveTowardsTargetGoal", + "TakeBlock" => "EndermanTakeBlockGoal", + "LeaveBlock" => "EndermanLeaveBlockGoal", + "FreezeWhenLookedAt" => "EndermanFreezeWhenLookedAt", + "LookForPlayer" => "EndermanLookForPlayerGoal", + "HealRaiders" => "NearestHealableRaiderTargetGoal", other => return other.to_owned(), }; vanilla.to_owned() diff --git a/crates/horizon-client/src/mobs/breeze.rs b/crates/horizon-client/src/mobs/breeze.rs index 9667a827a..d01bd34cc 100644 --- a/crates/horizon-client/src/mobs/breeze.rs +++ b/crates/horizon-client/src/mobs/breeze.rs @@ -330,7 +330,12 @@ fn tick_shoot(m: &mut Mob, cx: &mut Cx) { Some(Who::Mob(m.id)), ); // 5 - 4 * difficulty at normal. - p.shoot(&mut m.random, [xd, yd, zd], 0.7, -3.0); + p.shoot( + &mut crate::projectiles::own_random(m), + [xd, yd, zd], + 0.7, + -3.0, + ); cx.events.push(MobEvent::Projectile(p)); cx.events .push(MobEvent::Sound("entity.breeze.shoot", m.center(), 1.5, 1.0)); diff --git a/crates/horizon-client/src/mobs/goals.rs b/crates/horizon-client/src/mobs/goals.rs index 5869d4478..673eb560b 100644 --- a/crates/horizon-client/src/mobs/goals.rs +++ b/crates/horizon-client/src/mobs/goals.rs @@ -1015,6 +1015,8 @@ pub struct NearestTarget { /// A condition checked before anything else, by subclasses overriding /// `canUse` (SpiderTargetGoal: only in the dark). pub gate: Option bool>, + /// The vanilla class name of a subclass (`Goal::name`). + pub label: Option<&'static str>, found: Option, target_goal: TargetState, } @@ -1043,6 +1045,7 @@ impl NearestTarget { interval: reduced(10), when: None, gate: None, + label: None, found: None, target_goal: TargetState { unseen_memory: 60, @@ -1077,6 +1080,11 @@ impl NearestTarget { self.gate = Some(f); self } + /// A subclass's name, e.g. `NearestAttackableWitchTargetGoal`. + pub fn named(mut self, label: &'static str) -> Self { + self.label = Some(label); + self + } } /// TargetGoal.canContinueToUse pub fn target_continue(st: &mut TargetState, must_see: bool, m: &mut Mob, cx: &mut Cx) -> bool { @@ -1105,6 +1113,9 @@ pub fn target_continue(st: &mut TargetState, must_see: bool, m: &mut Mob, cx: &m } impl Goal for NearestTarget { goal_clone!(); + fn name(&self) -> &'static str { + self.label.unwrap_or("NearestTarget") + } fn flags(&self) -> u8 { TARGET } diff --git a/crates/horizon-client/src/mobs/golem.rs b/crates/horizon-client/src/mobs/golem.rs index d12f26788..089f5f7fd 100644 --- a/crates/horizon-client/src/mobs/golem.rs +++ b/crates/horizon-client/src/mobs/golem.rs @@ -284,7 +284,12 @@ fn snowball_attack(m: &mut Mob, who: Who, _power: f32, cx: &mut Cx) { let yo = (xd * xd + zd * zd).sqrt() * 0.2; let mut p = Projectile::new(ProjectileKind::Snowball, start, Some(Who::Mob(m.id))); // rangedAttackUncertainty: 14 - 4 * difficulty (normal: 6). - p.shoot(&mut m.random, [xd, yd + yo - start.y, zd], 1.6, 6.0); + p.shoot( + &mut crate::projectiles::own_random(m), + [xd, yd + yo - start.y, zd], + 1.6, + 6.0, + ); cx.events.push(MobEvent::Projectile(p)); let pitch = 0.4 / (m.random.next_float() * 0.4 + 0.8); cx.events.push(MobEvent::Sound( diff --git a/crates/horizon-client/src/mobs/illager.rs b/crates/horizon-client/src/mobs/illager.rs index 46d3ff9d2..15be02a1d 100644 --- a/crates/horizon-client/src/mobs/illager.rs +++ b/crates/horizon-client/src/mobs/illager.rs @@ -543,7 +543,12 @@ fn shoot_crossbow(m: &mut Mob, who: Who, cx: &mut Cx) { ); p.bonus = super::gear::arrow_bonus(m); // rangedAttackUncertainty at normal difficulty: 14 - 2 * 4. - p.shoot(&mut m.random, [dx, dy, dz], 1.6, 6.0); + p.shoot( + &mut crate::projectiles::own_random(m), + [dx, dy, dz], + 1.6, + 6.0, + ); cx.events.push(MobEvent::Projectile(p)); let pitch = 1.0 / (m.random.next_float() * 0.5 + 1.8) + 0.53; cx.events.push(MobEvent::Sound( diff --git a/crates/horizon-client/src/mobs/llama.rs b/crates/horizon-client/src/mobs/llama.rs index fbae29b02..82aeebe17 100644 --- a/crates/horizon-client/src/mobs/llama.rs +++ b/crates/horizon-client/src/mobs/llama.rs @@ -174,7 +174,12 @@ fn spit(m: &mut Mob, who: Who, _power: f32, cx: &mut Cx) { let zd = t.position.z - m.position.z; let yo = (xd * xd + zd * zd).sqrt() * f64::from(0.2_f32); let mut p = Projectile::new(ProjectileKind::LlamaSpit, start, Some(Who::Mob(m.id))); - p.shoot(&mut m.random, [xd, yd + yo, zd], 1.5, 10.0); + p.shoot( + &mut crate::projectiles::own_random(m), + [xd, yd + yo, zd], + 1.5, + 10.0, + ); cx.events.push(MobEvent::Projectile(p)); let pitch = 1.0 + (m.random.next_float() - m.random.next_float()) * 0.2; cx.events.push(MobEvent::Sound( diff --git a/crates/horizon-client/src/mobs/undead.rs b/crates/horizon-client/src/mobs/undead.rs index 4d6c76d73..50ac9934f 100644 --- a/crates/horizon-client/src/mobs/undead.rs +++ b/crates/horizon-client/src/mobs/undead.rs @@ -236,10 +236,8 @@ fn drowned_throw(m: &mut Mob, who: Who, _power: f32, cx: &mut Cx) { start, Some(Who::Mob(m.id)), ); - // The spread draws from the new projectile's own random. - let mut spread = horizon_core::random::LegacyRandom::new(i64::from(m.id) ^ m.age as i64); p.shoot( - &mut spread, + &mut crate::projectiles::own_random(m), [xd, yd + dist * f64::from(0.2_f32), zd], 1.6, (14 - 2 * 4) as f32, @@ -739,7 +737,8 @@ pub fn perform_ranged_attack(m: &mut Mob, who: Who, cx: &mut Cx, power: f32) { let zd = t.position.z - m.position.z; let dist = (xd * xd + zd * zd).sqrt(); // AbstractArrow.setBaseDamageFromMob: power * 2 + triangle(difficulty * 0.11, 0.57425). - let base = f64::from(power) * 2.0 + m.random.triangle(2.0 * 0.11, 0.574_25); + let mut arrow_random = crate::projectiles::own_random(m); + let base = f64::from(power) * 2.0 + arrow_random.triangle(2.0 * 0.11, 0.574_25); let effect = match m.species() { Species::Stray => Some(("minecraft:slowness", 600)), Species::Bogged => Some(("minecraft:poison", 100)), @@ -757,7 +756,7 @@ pub fn perform_ranged_attack(m: &mut Mob, who: Who, cx: &mut Cx, power: f32) { ); p.bonus = super::gear::arrow_bonus(m); p.shoot( - &mut m.random, + &mut arrow_random, [xd, yd + dist * 0.2, zd], 1.6, (14 - 2 * 4) as f32, diff --git a/crates/horizon-client/src/mobs/witch.rs b/crates/horizon-client/src/mobs/witch.rs index 0995d64e6..0990ae01d 100644 --- a/crates/horizon-client/src/mobs/witch.rs +++ b/crates/horizon-client/src/mobs/witch.rs @@ -26,7 +26,8 @@ pub fn register(m: &mut Mob) { 3, NearestTarget::player(true) .interval(10) - .gate(|m, _| m.extra.counter2 <= 0), + .gate(|m, _| m.extra.counter2 <= 0) + .named("NearestAttackableWitchTargetGoal"), ); } /// `NearestHealableRaiderTargetGoal`: in a raid, target another raider to @@ -221,7 +222,7 @@ fn witch_attack(m: &mut Mob, who: Who, _power: f32, cx: &mut Cx) { ); // Splash potions throw with gravity 0.05. p.shoot( - &mut m.random, + &mut crate::projectiles::own_random(m), [xd, yd + dist * 0.2, zd], if dist <= 2.0 { 0.45 } else { 0.75 }, 8.0, diff --git a/crates/horizon-client/src/projectiles.rs b/crates/horizon-client/src/projectiles.rs index d855fdaea..59d419a46 100644 --- a/crates/horizon-client/src/projectiles.rs +++ b/crates/horizon-client/src/projectiles.rs @@ -9,6 +9,17 @@ use horizon_core::{ random::RandomSource, }; +/// A new projectile entity's own random: vanilla seeds every entity's random +/// unpredictably, and a projectile's spread (and an arrow's base damage) come +/// from it, never from the shooter's random. +pub fn own_random(shooter: &crate::mobs::Mob) -> horizon_core::random::LegacyRandom { + horizon_core::random::LegacyRandom::new( + i64::from(shooter.id).wrapping_mul(0x9E37_79B9) + ^ i64::from(shooter.age) + ^ shooter.position.x.to_bits() as i64, + ) +} + #[derive(Clone, Debug, PartialEq)] pub enum ProjectileKind { /// Arrow with its base damage, critical flag and tipped/stray/bogged effect.