Hit with a hoglin or zoglin every 40 ticks, 15 for a baby

HoglinAi and Zoglin use MeleeAttack.create(40) for adults and create(15) for babies; Horizon used the 20-tick default.
This commit is contained in:
Kacpherek
2026-10-27 22:16:09 +01:00
parent 1feb28c045
commit 6c3defa821
2 changed files with 18 additions and 3 deletions
+14 -1
View File
@@ -1065,6 +1065,8 @@ pub struct MeleeAttack {
raise_arm: i32,
/// Ticks between attacks (20 unless set).
pub interval: i32,
/// Ticks between attacks for a baby, when they differ.
pub baby_interval: Option<i32>,
}
impl MeleeAttack {
pub fn new(speed: f64, follow_unseen: bool) -> Self {
@@ -1079,6 +1081,7 @@ impl MeleeAttack {
last_check: 0,
raise_arm: 0,
interval: 20,
baby_interval: None,
}
}
pub fn zombie(mut self) -> Self {
@@ -1093,6 +1096,12 @@ impl MeleeAttack {
self.interval = ticks;
self
}
/// `MeleeAttack.create(adult)` for adults, `create(baby)` for babies.
pub fn intervals(mut self, adult: i32, baby: i32) -> Self {
self.interval = adult;
self.baby_interval = Some(baby);
self
}
}
impl Goal for MeleeAttack {
goal_clone!();
@@ -1191,7 +1200,11 @@ impl Goal for MeleeAttack {
cx,
);
} else if self.until_attack <= 0 && m.within_melee_range(&t) && m.sees(cx.w, who) {
self.until_attack = adjusted(true, self.interval);
let interval = match self.baby_interval {
Some(baby) if m.is_baby() => baby,
_ => self.interval,
};
self.until_attack = adjusted(true, interval);
m.swing();
super::ai::do_hurt_target(m, who, cx);
}
+4 -2
View File
@@ -169,7 +169,8 @@ pub fn register_hoglin(m: &mut Mob) {
let g = &mut m.ai.goals;
g.add(0, Float);
g.add(1, BabyPanic(super::goals::Panic::new(1.25)));
g.add(2, MeleeAttack::new(1.0, true));
// HoglinAi: MeleeAttack.create(40) for adults, 15 for babies.
g.add(2, MeleeAttack::new(1.0, true).intervals(40, 15));
g.add(3, super::goals::Breed::new(1.0));
g.add(3, HoglinAvoidRepellent);
g.add(4, super::goals::FollowParent::new(1.1));
@@ -185,7 +186,8 @@ pub fn register_hoglin(m: &mut Mob) {
pub fn register_zoglin(m: &mut Mob) {
let g = &mut m.ai.goals;
g.add(0, Float);
g.add(2, MeleeAttack::new(1.0, true));
// Zoglin.initMemories: MeleeAttack.create(40) for adults, 15 for babies.
g.add(2, MeleeAttack::new(1.0, true).intervals(40, 15));
g.add(5, Stroll::avoiding_water(0.4));
g.add(6, LookAtPlayer::new(8.0));
m.ai.targets.add(1, HurtByTarget::new());