Add tadpoles, frog variants and saved mob ages

Frogspawn hatches into 2-5 tadpoles that swim, flop on land, wag their
tails and grow into frogs after 24000 ticks. Frogs take the warm, cold or
temperate variant from the biome. AgeableMob ages (babies, breeding
cooldowns) are now saved and loaded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-09 04:31:16 +02:00
parent 7fd50eb00b
commit f63cac5f5e
9 changed files with 106 additions and 1 deletions
+6
View File
@@ -135,6 +135,8 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag {
}
let id = m.kind.id.as_str();
if m.kind.category == "creature" {
map.insert("Age".into(), Tag::Int(m.extra.age));
map.insert("AgeLocked".into(), Tag::Byte(i8::from(m.extra.age_locked)));
for (key, value) in [
("Age", Tag::Int(0)),
("ForcedAge", Tag::Int(0)),
@@ -211,6 +213,10 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap<String, Arc<MobType>>, id: u32) -
m.death_time = number(tag.get("DeathTime")).unwrap_or(0) as i32;
m.persistent = flag(tag, "PersistenceRequired");
m.custom_name = custom_name(tag);
if m.kind.category == "creature" {
m.extra.age = number(tag.get("Age")).unwrap_or(0) as i32;
m.extra.age_locked = flag(tag, "AgeLocked");
}
m.name_visible = flag(tag, "CustomNameVisible");
if m.species() == crate::mobs::Species::Creeper {
m.extra.charged = flag(tag, "powered");
+27
View File
@@ -1280,6 +1280,33 @@ impl Game<'_> {
state,
kind: "dispense",
} => self.dispense_from(pos, state)?,
LevelEvent::BlockEvent {
pos, kind: "hatch", ..
} => {
// FrogspawnBlock.hatchFrogspawn: 2-5 tadpoles.
let at = [
f64::from(pos.x) + 0.5,
f64::from(pos.y) + 0.5,
f64::from(pos.z) + 0.5,
];
self.audio
.play("minecraft:block.frogspawn.hatch", Some(at), 1.0, 1.0);
let count = 2 + self.world.random.next_int_bound(4).unwrap_or(0);
for _ in 0..count {
// getRandomTadpolePositionOffset: 0.2..0.8 inside the block.
let r = &mut self.world.random;
let off = |r: &mut horizon_core::random::LegacyRandom| {
f64::from(r.next_float()) * 0.6 + 0.2
};
let (dx, dz) = (off(r), off(r));
let spawn = [
f64::from(pos.x) + dx,
f64::from(pos.y) - 0.5,
f64::from(pos.z) + dz,
];
let _ = self.spawn_mob("minecraft:tadpole", spawn, true);
}
}
LevelEvent::BlockEvent {
pos,
state,
@@ -156,6 +156,13 @@ impl Game<'_> {
mushroom: b.name == "minecraft:mushroom_fields",
desert: b.name == "minecraft:desert",
jungle: has("minecraft:is_jungle"),
frog: if has("minecraft:spawns_warm_variant_frogs") {
1
} else if has("minecraft:spawns_cold_variant_frogs") {
2
} else {
0
},
}
}
/// Create a mob of `kind` at a position, finalized like a natural spawn.
+3 -1
View File
@@ -389,8 +389,10 @@ pub struct Attrs {
/// Species-specific persistent state (variants, colours, taming, ageing...).
#[derive(Clone, Debug, Default)]
pub struct Extra {
/// AgeableMob.age: negative while a baby.
/// AgeableMob.age: negative while a baby (a tadpole counts up to 24000).
pub age: i32,
/// `AgeLocked` (tadpoles fed a slime ball... and ageable mobs).
pub age_locked: bool,
pub in_love: i32,
pub love_player: bool,
/// Texture/model variant index (cat type, horse colour, rabbit type...).
+1
View File
@@ -84,6 +84,7 @@ pub fn family(s: Species) -> Family {
S::Squid
| S::GlowSquid
| S::Cod
| S::Tadpole
| S::Salmon
| S::TropicalFish
| S::Pufferfish
+42
View File
@@ -34,6 +34,14 @@ pub fn register(m: &mut Mob) {
let speed = 1.0 / (m.random.next_float() + 1.0) * 0.2;
m.anim.v[TENTACLE_SPEED] = speed;
}
S::Tadpole => {
// TadpoleAi: panic, swim around and look about.
let g = &mut m.ai.goals;
g.add(0, Panic::new(2.0));
g.add(4, Stroll::swimming(1.0, 40));
m.ai.mov.kind = MoveKind::Custom;
m.ai.nav.kind = NavKind::Water { breach: false };
}
S::Cod | S::Salmon | S::TropicalFish | S::Pufferfish => {
let puffer = m.species() == S::Pufferfish;
let g = &mut m.ai.goals;
@@ -108,6 +116,35 @@ pub fn ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
use Species as S;
match m.species() {
S::Squid | S::GlowSquid => squid_ai_step(m),
S::Tadpole => {
// Tadpole.aiStep: growing up into a frog after 24000 ticks.
if m.extra.age >= 0 && !m.extra.age_locked {
m.extra.age += 1;
if m.extra.age >= 24_000 && !m.removed {
m.removed = true;
m.sound("entity.tadpole.grow_up", events);
events.push(MobEvent::SpawnKind {
kind: "minecraft:frog".into(),
at: [m.position.x, m.position.y, m.position.z],
setup: super::SpawnSetup {
yaw: m.yaw,
persistent: true,
..Default::default()
},
});
}
}
if !m.fluids.in_water && m.on_ground && m.vertical_collision_below {
let (a, b) = (m.random.next_float(), m.random.next_float());
m.velocity = Vec3::new(
m.velocity.x + f64::from((a * 2.0 - 1.0) * 0.05),
m.velocity.y + 0.4,
m.velocity.z + f64::from((b * 2.0 - 1.0) * 0.05),
);
m.on_ground = false;
m.sound("entity.tadpole.flop", events);
}
}
S::Cod | S::Salmon | S::TropicalFish | S::Pufferfish => {
// AbstractFish.aiStep flops on land (applied before travel next tick).
if !m.fluids.in_water && m.on_ground && m.vertical_collision_below {
@@ -460,6 +497,11 @@ pub fn anim(m: &Mob, s: &State, p: &mut Poses) {
}
}
S::Cod => p.yrot("tail_fin", -amp * 0.45 * (0.6 * s.age).sin()),
// TadpoleModel: a stronger tail swing out of water.
S::Tadpole => {
let a = if m.fluids.in_water { 1.0 } else { 1.5 };
p.yrot("tail", -a * 0.25 * (0.3 * s.age).sin())
}
S::TropicalFish => p.yrot("tail", -amp * 0.45 * (0.6 * s.age).sin()),
S::Salmon => {
let (a, k) = if m.fluids.in_water {
+4
View File
@@ -103,6 +103,10 @@ pub fn body(m: &Mob) -> (String, String) {
}
};
match m.species() {
S::Frog => (
"frog#main".into(),
format!("entity/frog/frog_{}", climate(m)),
),
S::Pig => {
let model = if baby {
"pig_baby#main".into()
@@ -18,6 +18,8 @@ pub struct BiomeFacts {
pub mushroom: bool,
pub desert: bool,
pub jungle: bool,
/// Frog variant from `spawns_warm/cold_variant_frogs` (0 temperate, 1 warm, 2 cold).
pub frog: u8,
}
/// SpawnPlacementTypes for the species.
pub fn placement_ok(species: Species, w: &MobWorld, x: i32, y: i32, z: i32) -> bool {
@@ -166,6 +168,7 @@ pub fn finalize(m: &mut Mob, biome: &BiomeFacts) {
S::Pig | S::Cow | S::Chicken => m.extra.variant = climate_index,
S::Sheep => m.extra.color = super::farm::sheep_color(biome.climate, &mut m.random),
S::Mooshroom => m.extra.variant = 0,
S::Frog => m.extra.variant = biome.frog,
S::Zombie | S::Husk | S::Drowned | S::ZombieVillager => {
// Zombie.finalizeSpawn: 5% babies (normal difficulty).
if m.random.next_float() < 0.05 {
+13
View File
@@ -5,6 +5,7 @@ use super::{Brain, Flags, anim::Anim};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Species {
Tadpole,
ZombieHorse,
SkeletonHorse,
Giant,
@@ -487,6 +488,16 @@ pub const ALL: &[Def] = &[
None,
Baby::Abs(0.5, 0.5, 0.37)
),
def!(
Tadpole,
"tadpole",
"tadpole#main",
"entity/tadpole/tadpole",
A::Fish,
["", "entity.tadpole.hurt", "entity.tadpole.death"],
None,
Baby::None
),
def!(
Cod,
"cod",
@@ -1078,6 +1089,7 @@ impl Def {
S::Squid
| S::GlowSquid
| S::Cod
| S::Tadpole
| S::Salmon
| S::TropicalFish
| S::Pufferfish
@@ -1270,6 +1282,7 @@ impl Def {
S::Squid
| S::GlowSquid
| S::Cod
| S::Tadpole
| S::Salmon
| S::TropicalFish
| S::Pufferfish