Merge pull request #2138 from kacpherek/fix/animal-breeding-rules
🤖 Agent: Gate check by Ludovic's AI agent (Claude). Checked against 26.3: rabbits breed (`Rabbit.isFood`), damage ends love (`Animal.hurtServer` resets `inLove`), the horse and wolf `canMate` checks, and the breeding orb only with `mob_drops` (`Animal.finalizeSpawnChildFromBreeding`). Gate: this wave's 55 PRs merged on main in one tree: clippy `-D warnings` clean, 1186 horizon-client and 163 horizon-world tests pass, and of the 101 harnesses `parity.py --changed-files` picked, 100 pass (`block_removal` failed on one spawner case from #2199's orb merging, fixed there). `lan_e2e.py` passes 24 checks with the host on its server thread and in-frame (chest, xp, pvp, doors, villagers, beds, frames, projectiles, arrows, fishing, damage, mobs, blast, drops, elytra, breath, predict, cracks, barter, kills, hurt, contacts, underwater, plates), plus forced-levels on the server thread. Thanks @kacpherek!
This commit is contained in:
@@ -1128,7 +1128,7 @@ impl Game<'_> {
|
||||
self.particles.add(&options, at, velocity);
|
||||
}
|
||||
}
|
||||
MobEvent::Experience { at, amount } => self.spawn_orbs(at, amount),
|
||||
MobEvent::Experience { at, amount } => self.spawn_breeding_orb(at, amount),
|
||||
MobEvent::AxolotlSupportPlayer => {
|
||||
let previous = self
|
||||
.potions
|
||||
@@ -1272,6 +1272,13 @@ impl Game<'_> {
|
||||
m.extra.egg_time = life;
|
||||
}
|
||||
}
|
||||
/// `Animal.finalizeSpawnChildFromBreeding`'s experience orb: only when the
|
||||
/// `mob_drops` game rule is on.
|
||||
fn spawn_breeding_orb(&mut self, at: [f64; 3], amount: u32) {
|
||||
if self.ui.rules.bool("mob_drops") {
|
||||
self.spawn_orbs(at, amount);
|
||||
}
|
||||
}
|
||||
/// Animal.spawnChildFromBreeding
|
||||
fn breed(
|
||||
&mut self,
|
||||
@@ -1365,7 +1372,7 @@ impl Game<'_> {
|
||||
}
|
||||
self.world.random = r;
|
||||
let xp = 1 + self.world.random.next_int_bound(7).unwrap_or(0) as u32;
|
||||
self.spawn_orbs([p.position.x, p.position.y, p.position.z], xp);
|
||||
self.spawn_breeding_orb([p.position.x, p.position.y, p.position.z], xp);
|
||||
return;
|
||||
}
|
||||
if p.species() == Species::Cat {
|
||||
@@ -1386,7 +1393,7 @@ impl Game<'_> {
|
||||
};
|
||||
}
|
||||
let xp = 1 + self.world.random.next_int_bound(7).unwrap_or(0) as u32;
|
||||
self.spawn_orbs([p.position.x, p.position.y, p.position.z], xp);
|
||||
self.spawn_breeding_orb([p.position.x, p.position.y, p.position.z], xp);
|
||||
return;
|
||||
}
|
||||
if p.species() == Species::Wolf {
|
||||
@@ -1408,7 +1415,7 @@ impl Game<'_> {
|
||||
};
|
||||
}
|
||||
let xp = 1 + self.world.random.next_int_bound(7).unwrap_or(0) as u32;
|
||||
self.spawn_orbs([p.position.x, p.position.y, p.position.z], xp);
|
||||
self.spawn_breeding_orb([p.position.x, p.position.y, p.position.z], xp);
|
||||
return;
|
||||
}
|
||||
// Nautilus.getBreedOffspring: a tame parent's baby is tame too.
|
||||
@@ -1424,7 +1431,7 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
let xp = 1 + self.world.random.next_int_bound(7).unwrap_or(0) as u32;
|
||||
self.spawn_orbs([p.position.x, p.position.y, p.position.z], xp);
|
||||
self.spawn_breeding_orb([p.position.x, p.position.y, p.position.z], xp);
|
||||
}
|
||||
/// `MobEffectUtil.addEffectToPlayersAround` for an elder guardian:
|
||||
/// mining fatigue III for five minutes unless a stronger or longer one
|
||||
|
||||
@@ -1251,6 +1251,10 @@ pub struct Seen {
|
||||
/// `MAX_HEALTH`, `JUMP_STRENGTH` and `MOVEMENT_SPEED` base values (a
|
||||
/// horse's breeding stock).
|
||||
pub stats: [f64; 3],
|
||||
/// `Wolf.isInSittingPose`.
|
||||
pub sitting: bool,
|
||||
/// `Entity.isVehicle` or `isPassenger`.
|
||||
pub ridden: bool,
|
||||
}
|
||||
impl Mob {
|
||||
pub fn burning_time(&self) -> f64 {
|
||||
@@ -1323,6 +1327,8 @@ impl Mob {
|
||||
m.extra.vector[0],
|
||||
m.attrs.speed,
|
||||
],
|
||||
sitting: m.extra.sitting,
|
||||
ridden: m.rider.is_some() || m.extra.rider.is_some() || m.extra.mount.is_some(),
|
||||
}
|
||||
}
|
||||
/// `EntityType.getCategory`'s name.
|
||||
@@ -1760,6 +1766,10 @@ impl Mob {
|
||||
self.health -= amount;
|
||||
self.hurt_time = 10;
|
||||
}
|
||||
// Animal.actuallyHurt: damage taken ends love mode (`resetLove`).
|
||||
if drops::is_animal(self.species()) {
|
||||
self.extra.in_love = 0;
|
||||
}
|
||||
self.last_damage = Some((source, i64::from(self.age)));
|
||||
if let Some(who) = source.attacker {
|
||||
self.ai.last_hurt_by = Some(who);
|
||||
|
||||
@@ -1771,11 +1771,16 @@ impl Goal for Breed {
|
||||
}
|
||||
let llama = super::llama::is_llama(species);
|
||||
let equine = matches!(species, Species::Horse | Species::Donkey) || llama;
|
||||
if equine && !m.extra.tame {
|
||||
return false;
|
||||
}
|
||||
// Llama.canParent: not ridden, and at full health.
|
||||
if llama && (m.rider.is_some() || m.health < m.attrs.max_health) {
|
||||
// AbstractHorse.canParent: tame, an adult, not a vehicle or passenger
|
||||
// and at full health.
|
||||
if equine
|
||||
&& (!m.extra.tame
|
||||
|| m.is_baby()
|
||||
|| m.rider.is_some()
|
||||
|| m.extra.rider.is_some()
|
||||
|| m.extra.mount.is_some()
|
||||
|| m.health < m.attrs.max_health)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
self.partner =
|
||||
@@ -1788,7 +1793,10 @@ impl Goal for Breed {
|
||||
&& s.in_love
|
||||
&& !s.baby
|
||||
&& (!tamable || s.tame)
|
||||
&& (!equine || s.tame)
|
||||
// Wolf.canMate: a sitting wolf is no partner.
|
||||
&& !(species == Species::Wolf && s.sitting)
|
||||
// AbstractHorse.canParent of the partner.
|
||||
&& (!equine || s.tame && !s.ridden && s.health >= s.stats[0] as f32)
|
||||
&& (!sniffer || super::sniffer::can_mate_state(s.variant))
|
||||
})
|
||||
.map(|s| s.id)
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
//! Rabbit hopping controls and the clocks consumed by `RabbitModel`.
|
||||
use super::{Mob, MobEvent, MobWorld, control::Operation};
|
||||
use super::{
|
||||
Mob, MobEvent, MobWorld,
|
||||
control::Operation,
|
||||
goals::{Breed, Tempt},
|
||||
};
|
||||
use horizon_core::{
|
||||
geometry::{Vec3, trig},
|
||||
random::RandomSource,
|
||||
@@ -14,7 +18,12 @@ const IDLE_TIMEOUT: usize = 3;
|
||||
const CLIENT_JUMP_TICKS: usize = 4;
|
||||
const CLIENT_JUMP_DURATION: usize = 5;
|
||||
|
||||
/// Rabbit.registerGoals after the generic panic and stroll: BreedGoal and
|
||||
/// TemptGoal with rabbit food.
|
||||
pub fn register(m: &mut Mob) {
|
||||
let food = m.kind.food.clone();
|
||||
m.ai.goals.add(2, Breed::new(0.8));
|
||||
m.ai.goals.add(3, Tempt::new(1.0, food, false));
|
||||
m.ai.mov.kind = super::control::MoveKind::Custom;
|
||||
m.ai.nav.can_float = true;
|
||||
m.extra.ints[IDLE_TIMEOUT] = m.random.next_int_bound(40).unwrap_or(0) + 180;
|
||||
|
||||
Reference in New Issue
Block a user