Make armadillos shed scutes on their own

Armadillos never dropped scutes because nothing ran their shed timer.
Follow Armadillo.customServerAiStep: count down 5 to 10 minutes, then
drop a scute, play the sound and post the entity_place game event.
This commit is contained in:
Kacpherek
2026-10-26 15:13:27 +01:00
parent 8027cb4176
commit 329ce1b724
3 changed files with 49 additions and 0 deletions
@@ -1221,6 +1221,24 @@ impl Game<'_> {
m.ai.aggressive |= aggressive;
}
}
MobEvent::ShedScute { mob, at, pitch } => {
// shouldDropLoot: the `mob_drops` rule.
if self.ui.rules.bool("mob_drops") {
let table = "minecraft:gameplay/armadillo_shed";
let drops = self.sequence_loot(table, table, None);
for d in drops {
self.spawn_at_location(Vec3::new(at[0], at[1], at[2]), 0.0, d);
}
self.audio.play(
"minecraft:entity.armadillo.scute_drop",
Some(at),
1.0,
pitch,
);
let ctx = self.who_context(Some(Who::Mob(mob)), None);
self.post_game_event("minecraft:entity_place", at, ctx);
}
}
MobEvent::GiftLoot { table, at } => {
let drops =
self.res
+6
View File
@@ -1131,6 +1131,12 @@ pub enum MobEvent {
table: &'static str,
at: [f64; 3],
},
/// `Armadillo.customServerAiStep`: the armadillo sheds a scute.
ShedScute {
mob: u32,
at: [f64; 3],
pitch: f32,
},
/// A lead snaps or loses its holder: the lead item drops when asked.
LeashBreak {
mob: u32,
+25
View File
@@ -307,6 +307,10 @@ fn generic(m: &mut Mob) {
g.add(5, Stroll::avoiding_water(if rabbit { 0.6 } else { 1.0 }));
g.add(6, LookAtPlayer::new(6.0));
g.add(7, RandomLookAround::default());
if m.kind.species == Species::Armadillo {
// Armadillo's constructor: pickNextScuteDropTime.
m.extra.egg_time = next_scute_time(m);
}
}
}
/// Subclasses of `net.minecraft.world.entity.monster.Monster`.
@@ -930,9 +934,30 @@ fn server_ai_step(
}
m.jump_control_tick();
}
/// `Armadillo.pickNextScuteDropTime`: 5 to 10 minutes.
fn next_scute_time(m: &mut Mob) -> i32 {
m.random.next_int_bound(20 * 60 * 5).unwrap_or(0) + 20 * 60 * 5
}
/// `Armadillo.customServerAiStep`: the scute timer. A baby only resets it
/// (`shouldDropLoot`); the game checks the `mob_drops` rule.
fn armadillo_server_ai_step(m: &mut Mob, events: &mut Vec<MobEvent>) {
m.extra.egg_time -= 1;
if m.alive() && m.extra.egg_time <= 0 {
if !m.is_baby() {
let pitch = (m.random.next_float() - m.random.next_float()) * 0.2 + 1.0;
events.push(MobEvent::ShedScute {
mob: m.id,
at: [m.position.x, m.position.y, m.position.z],
pitch,
});
}
m.extra.egg_time = next_scute_time(m);
}
}
fn custom_server_ai_step(m: &mut Mob, cx: &mut Cx) {
match m.species() {
Species::Rabbit => super::rabbit::server_ai_step(m),
Species::Armadillo => armadillo_server_ai_step(m, cx.events),
Species::Sheep => {}
Species::Zombie
| Species::Husk