Match vanilla animal breeding rules: rabbits breed, damage ends love, horse and wolf checks, breeding XP rule

Rabbits get BreedGoal and TemptGoal with rabbit food. Damage to an animal
resets love. Horses, donkeys and llamas need canParent (not ridden, tame,
adult, full health) for both parents, a sitting wolf is no partner, and the
breeding experience orb needs the mob_drops game rule.
This commit is contained in:
Kacpherek
2026-10-26 13:25:30 +01:00
parent 23c748b2f3
commit 23d089aa7c
4 changed files with 46 additions and 12 deletions
+12 -5
View File
@@ -1117,7 +1117,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
@@ -1261,6 +1261,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,
@@ -1354,7 +1361,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 {
@@ -1375,7 +1382,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 {
@@ -1397,7 +1404,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.
@@ -1413,7 +1420,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
+10
View File
@@ -1243,6 +1243,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 {
@@ -1315,6 +1319,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.
@@ -1752,6 +1758,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);
+14 -6
View File
@@ -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)
+10 -1
View File
@@ -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;