Merge pull request #2985 from kacpherek/fix/hostile-mob-parity

🤖 Agent: read the diff at f69088012 ("Hostile mobs: hoglin timing, crossbow aim, witch resistance, wither sk") against the 26.3 source it cites; verify green, merges cleanly with main. Proof: cg25 union a051cc285 (local branch cg25/union in t3-ef805fdb: main 6d3489d30 + 38 contributor heads merged cleanly, no fixups): clippy -p horizon-client --all-targets -D warnings clean, horizon-client lib 1105 + bin 133 + integration tests pass, parity --changed 355/355 harnesses PASS on the Mac mini (Cargo.lock changed by #3210, so every harness ran; tab_list passed on its one retry).
This commit is contained in:
Ludovic Marie
2026-10-28 19:43:56 +01:00
committed by GitHub
10 changed files with 96 additions and 20 deletions
+5 -1
View File
@@ -10973,7 +10973,11 @@ impl Game<'_> {
// Creative players skip the monster check (`!this.isCreative()`).
let monsters = !self.creative
&& self.mobs.iter().any(|m| {
m.hostile()
// `Monster.class` entities that `isPreventingPlayerRest`: a
// zombified piglin only while it is angry.
horizon_client::mobs::ai::is_monster(m.species())
&& (m.species() != horizon_client::mobs::Species::ZombifiedPiglin
|| (m.extra.anger > 0 && m.ai.target.is_some()))
&& m.alive()
&& (m.position.x - position.x).abs() < 8.0
&& (m.position.y - position.y).abs() < 5.0
+8
View File
@@ -2230,12 +2230,20 @@ impl Game<'_> {
.filter(|p| p.alive && !p.creative && !p.spectator)
.collect();
let mut harmed: Vec<(FightWho, f32)> = Vec::new();
// DragonSittingFlamingPhase.end discards the flame cloud.
let flame_over = self
.dragon
.as_ref()
.is_some_and(|d| !matches!(d.phase, Phase::Flaming { .. }));
let mut clouds = std::mem::take(&mut self.breath_clouds);
clouds.retain_mut(|c| {
// Lingering potions' clouds tick with the potions.
if c.potion.is_some() {
return true;
}
if c.from_dragon && flame_over {
return false;
}
c.age += 1;
if c.age >= c.duration {
return false;
+4 -6
View File
@@ -960,7 +960,8 @@ impl Game<'_> {
let amount =
|base: i32| (0.5 * f64::from(base << amp) + 0.5) as i32 as f32;
if (*id == "instant_damage") != inverted {
m.hurt(amount(6), Some(at), &mut self.world.random);
let harm = m.potion_harm(amount(6));
m.hurt(harm, Some(at), &mut self.world.random);
} else {
m.health = (m.health + amount(4)).min(m.kind.max_health);
}
@@ -1228,11 +1229,8 @@ impl Game<'_> {
};
let m = &mut self.mobs[i];
if harm {
m.hurt(
(intensity * f64::from(6 << amp) + 0.5) as i32 as f32,
Some([at.x, at.y, at.z]),
&mut self.world.random,
);
let harm = m.potion_harm((intensity * f64::from(6 << amp) + 0.5) as i32 as f32);
m.hurt(harm, Some([at.x, at.y, at.z]), &mut self.world.random);
} else {
m.health = (m.health + (intensity * f64::from(4 << amp) + 0.5) as i32 as f32)
.min(m.kind.max_health);
+7
View File
@@ -121,6 +121,13 @@ impl Game<'_> {
);
}
}
// An ender dragon part takes the point of damage too; a crystal is
// not hit (`AbstractWindCharge.canHitEntity`).
Who::Mob(id) if id >= super::dragon::SPECIAL => {
if id < super::dragon::SPECIAL + 8 {
self.hit_special(id, 1.0, p.owner == Some(Who::Player), false);
}
}
Who::Mob(id) => {
let source = Damage {
kind: DamageKind::Thrown,
+13 -5
View File
@@ -120,7 +120,8 @@ impl Game<'_> {
Ok(())
}
/// `WitherSkull.onHitEntity` / `onHit`: 8 damage (healing the wither 5
/// when it kills), withering for 10 seconds, then a power 1 blast.
/// when it kills), withering on a hit (10 seconds on Normal, 40 on Hard,
/// none on Easy), then a power 1 blast.
pub(super) fn wither_skull_hit(
&mut self,
p: &Projectile,
@@ -132,17 +133,24 @@ impl Game<'_> {
_ => None,
};
let amount = if owner.is_some() { 8.0 } else { 5.0 };
let wither_ticks = match self.difficulty_id() {
2 => 200,
3 => 800,
_ => 0,
};
match who {
Some(Who::Player) => {
if !self.creative {
// WitherSkull.onHitEntity's source: the wither launched it.
self.combat.projectile_owner = owner;
self.mob_hits_player_kind(
let hit = self.mob_hits_player(
amount,
[p.previous.x, p.previous.y, p.previous.z],
"minecraft:wither_skull",
);
self.give_player_effect("minecraft:wither", 200, 1);
if hit && wither_ticks > 0 {
self.give_player_effect("minecraft:wither", wither_ticks, 1);
}
}
}
Some(Who::Mob(id)) => {
@@ -154,8 +162,8 @@ impl Game<'_> {
let killed = match self.mobs.iter_mut().find(|m| m.id == id) {
Some(m) => {
let hit = m.damage(amount, source);
if hit && m.alive() && m.species() != Species::Wither {
m.add_effect("minecraft:wither", 200, 1);
if hit && m.alive() && m.species() != Species::Wither && wither_ticks > 0 {
m.add_effect("minecraft:wither", wither_ticks, 1);
}
hit && !m.alive()
}
+21
View File
@@ -2088,6 +2088,18 @@ impl Mob {
if epf > 0.0 {
amount *= 1.0 - epf / 25.0;
}
// Witch.getDamageAfterMagicAbsorb: none from its own doing, else
// 85% less from `#witch_resistant_to`.
if self.species() == Species::Witch {
if source.attacker == Some(Who::Mob(self.id)) {
amount = 0.0;
} else if matches!(
source.kind,
DamageKind::Magic | DamageKind::SonicBoom | DamageKind::Thorns
) {
amount *= 0.15;
}
}
// Wolf.actuallyHurt: wolf armor takes the damage instead of the wolf.
let absorbed = self.wolf_armor_absorbs(&source);
let mut knock = true;
@@ -2170,6 +2182,15 @@ impl Mob {
}
true
}
/// A splash or cloud's harming effect on this mob: the potion's
/// `indirect_magic` is in `#witch_resistant_to`, so a witch takes 15%.
pub fn potion_harm(&self, amount: f32) -> f32 {
if self.species() == Species::Witch {
amount * 0.15
} else {
amount
}
}
/// `Wolf.canArmorAbsorb`: it wears wolf armor and the damage type is not
/// in `#bypasses_wolf_armor` (drowning, magic, thorns, in a wall, out of
/// the world and the untyped kills).
+18 -3
View File
@@ -533,9 +533,9 @@ pub fn tick(
true
}
/// `LivingEntity.aiStep` -> `Entity.applyEffectsFromBlocks` for the blocks
/// that hurt or hold a mob: the cactus (`CactusBlock.entityInside`, 1) and the
/// sweet berry bush (`SweetBerryBushBlock.entityInside`: stuck at 0.8, 0.75,
/// 0.8, and a grown bush pricks for 1 when the mob moved at least 0.003 on X
/// that hurt or hold a mob: the cactus (`CactusBlock.entityInside`, 1), the
/// cobweb (stuck at 0.25, 0.05, 0.25) and the sweet berry bush
/// (`SweetBerryBushBlock.entityInside`: stuck at 0.8, 0.75, 0.8, and a grown bush pricks for 1 when the mob moved at least 0.003 on X
/// or Z this tick). The blocks are those the mob's box touches anywhere along
/// its move this tick, from where it started to where it ended.
fn effects_from_blocks(m: &mut Mob, w: &MobWorld) {
@@ -562,6 +562,21 @@ fn effects_from_blocks(m: &mut Mob, w: &MobWorld) {
"minecraft:cactus" => {
m.damage(1.0, Damage::of(DamageKind::Cactus));
}
// WebBlock.entityInside -> makeStuckInBlock, which a
// spider ignores for cobwebs and a wither always.
"minecraft:cobweb"
if !matches!(
m.species(),
Species::Spider | Species::CaveSpider | Species::Wither
) =>
{
m.fall_distance = 0.0;
m.stuck_multiplier = if m.has_effect("minecraft:weaving") {
Vec3::new(0.5, 0.25, 0.5)
} else {
Vec3::new(0.25, f64::from(0.05_f32), 0.25)
};
}
"minecraft:sweet_berry_bush"
if !matches!(m.species(), Species::Fox | Species::Bee) =>
{
+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);
}
+2 -2
View File
@@ -542,12 +542,12 @@ fn shoot_crossbow(m: &mut Mob, who: Who, cx: &mut Cx) {
Some(Who::Mob(m.id)),
);
p.set_bonus(super::gear::arrow_bonus(m));
// rangedAttackUncertainty at normal difficulty: 14 - 2 * 4.
// rangedAttackUncertainty: 14 - 4 * difficulty.
p.shoot(
&mut crate::projectiles::own_random(m),
[dx, dy, dz],
1.6,
6.0,
(14 - i32::from(cx.w.difficulty.id) * 4) as f32,
);
cx.events.push(MobEvent::Projectile(p));
let pitch = 1.0 / (m.random.next_float() * 0.5 + 1.8) + 0.53;
+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());