Merge pull request #1954 from rdbtCVS/rdbt/fix-1949-leash-death

🤖 Agent: Thanks rdbt! Matches Leashable.tickLeash / dropLeash: a leashed mob that dies drops its lead; the new mob_ai scenarios run against the vanilla oracle. Tested together with the other wave 1 contributor PRs on current main: fmt, clippy -D warnings and the horizon-client tests (1,120 lib tests and the rest) pass; the 114 harnesses the batch affects pass; lan_e2e anvil, grindstone, replant, instant_digging, digging, frames and leads pass with the host in-frame and on its server thread.
This commit is contained in:
Ludovic Marie
2026-10-26 02:26:53 +01:00
committed by GitHub
5 changed files with 49 additions and 1 deletions
@@ -598,6 +598,7 @@ fn print(out: &mut String, t: i32, i: usize, m: &Mob, player_down: bool, now: i6
let _ = writeln!(out, " removed {reason}");
return;
}
let _ = write!(out, "\tleashed {}", u8::from(m.extra.leash.is_some()));
let p = m.position;
let v = m.velocity;
let _ = write!(
@@ -977,6 +978,7 @@ pub fn main() -> horizon_client::Result<()> {
}
// Set once the brain exists (below).
x if x.starts_with("cooldown=") => {}
"dead" => m.health = 0.0,
"leashed" => m.extra.leash = Some(horizon_client::mobs::leash::Holder::Player),
x if x.starts_with("leashto=") => {
let n: u32 = x[8..].parse().unwrap();
@@ -1097,6 +1099,7 @@ pub fn main() -> horizon_client::Result<()> {
}
};
}
let mut dropped_leads = 0;
for t in 1..=s.ticks {
world.game_time += 1;
if s.daycycle {
@@ -1208,6 +1211,16 @@ pub fn main() -> horizon_client::Result<()> {
if !alive {
m.removed = true;
}
// Apply the same detach/drop event as Game::break_leash.
for event in &events[from..] {
if let MobEvent::LeashBreak { mob, drop, .. } = event
&& let Some(m) = mobs.iter_mut().find(|m| m.id == *mob)
&& horizon_client::mobs::leash::remove(m).is_some()
&& *drop
{
dropped_leads += 1;
}
}
horizon_client::mobs::apply_brain_events(&mut mobs, &mut events, from);
villager_events(
&mut mobs,
@@ -1427,6 +1440,9 @@ pub fn main() -> horizon_client::Result<()> {
world.game_time,
);
}
if s.name.starts_with("leash_death_") {
let _ = writeln!(out, "{t} leads {dropped_leads}");
}
for e in &events {
if let MobEvent::Sound(name, _, volume, pitch) = e {
let _ = writeln!(
+2
View File
@@ -79,6 +79,8 @@ impl Game<'_> {
if horizon_client::mobs::leash::remove(m).is_none() {
return;
}
// Leashable.tickLeash gates a dying entity's lead drop on entity_drops.
let drop = drop && (m.alive() || self.ui.rules.bool("entity_drops"));
let at = [m.position.x, m.position.y, m.position.z];
if sound {
self.lead_sound("break", at);
+9
View File
@@ -198,6 +198,15 @@ pub fn tick(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
m.extra.leash_spin = 0.0;
return;
};
// Leashable.tickLeash: a dying entity cannot interact with the level.
if !m.alive() {
events.push(MobEvent::LeashBreak {
mob: m.id,
drop: true,
sound: false,
});
return;
}
let Some(state) = holder_state(w, holder) else {
// The holder is gone: the lead drops.
if !matches!(holder, Holder::Player) {
@@ -604,6 +604,7 @@ public final class VanillaMobAiOracle {
case "tame" -> { if (mob instanceof net.minecraft.world.entity.animal.equine.AbstractHorse horse) horse.setTamed(true); }
case "strength" -> method(net.minecraft.world.entity.animal.equine.Llama.class, "setStrength", int.class)
.invoke(mob, Integer.parseInt(v));
case "dead" -> mob.setHealth(0.0F);
case "leashed", "leashto" -> {
// Leashed once every mob exists (below).
}
@@ -807,6 +808,12 @@ public final class VanillaMobAiOracle {
for (BlockPos h : heartPositions) printHeart(t, level, h);
for (String[] b : s.blocks) if (b[0].equals("chest")) printChest(t, s, level, b);
for (String[] b : s.blocks) if (isHive(b)) printHive(t, level, b);
if (s.name.startsWith("leash_death_")) {
int leads = level.getEntitiesOfClass(ItemEntity.class, ENTS.get(0).getBoundingBox().inflate(32.0),
item -> item.getItem().is(net.minecraft.world.item.Items.LEAD))
.stream().mapToInt(item -> item.getItem().getCount()).sum();
out.println(t + " leads " + leads);
}
for (String sound : SOUNDS) out.println(t + " sound " + sound);
for (var w : watched.entrySet()) {
BlockState now = level.getBlockState(w.getKey());
@@ -1008,6 +1015,7 @@ public final class VanillaMobAiOracle {
return;
}
Mob m = (Mob) e;
sb.append("\tleashed ").append(((net.minecraft.world.entity.Leashable) m).isLeashed() ? 1 : 0);
sb.append("\tp ").append(d(m.getX())).append(',').append(d(m.getY())).append(',').append(d(m.getZ()));
Vec3 v = m.getDeltaMovement();
sb.append("\tv ").append(d(v.x)).append(',').append(d(v.y)).append(',').append(d(v.z));
+14 -1
View File
@@ -191,6 +191,16 @@ def scenarios():
'mob minecraft:wandering_trader 0.5 -60 0.5 0 104 persistent',
'mob minecraft:trader_llama 3.5 -60 1.5 0 105 persistent leashto=0 strength=2',
'mob minecraft:trader_llama 3.5 -60 -1.5 0 106 persistent leashto=0 strength=4'])
# Death must detach immediately and drop exactly one lead throughout the corpse animation.
add('leash_death_trader_llama', 10, [
'player 14.5 -60 0.5',
'mob minecraft:wandering_trader 0.5 -60 0.5 0 104 persistent',
'mob minecraft:trader_llama 3.5 -60 1.5 0 105 persistent leashto=0 strength=2 dead',
])
add('leash_death_player_llama', 10, [
'player 0.5 -60 0.5',
'mob minecraft:llama 3.5 -60 0.5 0 101 persistent leashed strength=3 dead',
])
# Copper golems sorting chests (TransportItemsBetweenContainers): from a copper chest to a chest,
# skipping a chest without the carried item, queueing at a chest another golem has open, a double
# chest, a blocked copper chest, a part-full chest, and idling with nothing to carry.
@@ -358,6 +368,9 @@ def parse(path):
if parts[1] == 'hive':
cur.setdefault('hives', {}).setdefault(t, []).append(parts[2])
continue
if parts[1] == 'leads':
cur.setdefault('leads', {}).setdefault(t, []).append(parts[2])
continue
if parts[1] == 'chest':
cur.setdefault('chests', {}).setdefault(t, []).append(parts[2])
continue
@@ -455,7 +468,7 @@ def compare(vanilla, rust, fields=None):
clean = False
break
# Sounds, watched block changes, chest contents and hives: first differing tick.
for kind in ('sounds', 'blocks', 'chests', 'hives'):
for kind in ('sounds', 'blocks', 'chests', 'hives', 'leads'):
va, ra = v.get(kind, {}), r.get(kind, {})
for t in sorted(set(va) | set(ra)):
if va.get(t, []) != ra.get(t, []):