Merge pull request #2343 from kacpherek/fix/endermite-lifetime

🤖 Agent: Merged by Ludovic's AI agent (orchestrator). rdbtCVS's requested changes are addressed (he said on #2215 not to wait for his re-review), and this head is proven in union/cg19-r2 and union/cg19-r3 (clippy, 1722 tests, 135 + 96 harnesses, lan_e2e). Thanks @kacpherek!
This commit is contained in:
Ludovic Marie
2026-10-27 17:25:51 +01:00
committed by GitHub
2 changed files with 26 additions and 1 deletions
+6
View File
@@ -606,6 +606,9 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag {
map.insert("life_ticks".into(), Tag::Int(m.extra.egg_time));
}
}
"minecraft:endermite" => {
map.insert("Lifetime".into(), Tag::Int(m.extra.counter));
}
"minecraft:shulker" => {
map.insert("AttachFace".into(), Tag::Byte(m.extra.variant3 as i8));
map.insert("Peek".into(), Tag::Byte(m.extra.counter as i8));
@@ -1230,6 +1233,9 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap<String, Arc<MobType>>, id: u32) -
m.extra.counter2 = number(tag.get("StunTick")).unwrap_or(0) as i32;
m.extra.anim_ticks = number(tag.get("RoarTick")).unwrap_or(0) as i32;
}
if m.species() == crate::mobs::Species::Endermite {
m.extra.counter = number(tag.get("Lifetime")).unwrap_or(0) as i32;
}
if m.species() == crate::mobs::Species::Vex {
if let Some(Tag::IntArray(v)) = tag.get("bound_pos")
&& v.len() == 3
+20 -1
View File
@@ -442,7 +442,13 @@ pub fn tick(
}
return false;
}
if !m.no_ai {
if m.no_ai {
// Mob.aiStep still runs without AI (only serverAiStep is skipped),
// so the endermite's life keeps counting.
if m.species() == Species::Endermite {
endermite_lifetime(m);
}
} else {
ai_step(m, w, level_random, events);
}
effects_from_blocks(m, w);
@@ -1195,6 +1201,16 @@ fn custom_server_ai_step(m: &mut Mob, cx: &mut Cx) {
_ => {}
}
}
/// Endermite.aiStep: `counter` is the life; an endermite not required to
/// persist is discarded at 2400.
fn endermite_lifetime(m: &mut Mob) {
if !m.persistent {
m.extra.counter += 1;
}
if m.extra.counter >= 2400 {
m.removed = true;
}
}
fn species_ai_step(
m: &mut Mob,
w: &MobWorld,
@@ -1206,6 +1222,9 @@ fn species_ai_step(
}
match m.species() {
Species::Enderman => super::enderman::ai_step(m, w, events),
// Endermite.aiStep: `counter` is the life; an endermite not required
// to persist is discarded at 2400.
Species::Endermite => endermite_lifetime(m),
Species::Wolf => super::tame::ai_step(m, w, events),
Species::Cat => super::tame::cat_ai_step(m, events),
Species::Blaze => super::nether::blaze_ai_step(m, events),