From 0b49da246674bef76848ffe3ecb7517db48f0faf Mon Sep 17 00:00:00 2001 From: rdbtCVS <87152661+rdbtCVS@users.noreply.github.com> Date: Sun, 25 Oct 2026 22:07:58 +0000 Subject: [PATCH] Fix lead drops when leashed mobs die Follow Leashable.tickLeash for dying mobs and cover trader/player-held llama leads through the death animation. Co-Authored-By: Codex --- .../examples/probe/mob_ai_probe.rs | 16 ++++++++++++++++ crates/horizon-client/src/game/leads.rs | 2 ++ crates/horizon-client/src/mobs/leash.rs | 9 +++++++++ .../horizonlab/parity/VanillaMobAiOracle.java | 8 ++++++++ tools/test_mob_ai_parity.py | 15 ++++++++++++++- 5 files changed, 49 insertions(+), 1 deletion(-) diff --git a/crates/horizon-client/examples/probe/mob_ai_probe.rs b/crates/horizon-client/examples/probe/mob_ai_probe.rs index 157baa74c..49f56c250 100644 --- a/crates/horizon-client/examples/probe/mob_ai_probe.rs +++ b/crates/horizon-client/examples/probe/mob_ai_probe.rs @@ -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!( diff --git a/crates/horizon-client/src/game/leads.rs b/crates/horizon-client/src/game/leads.rs index 3a5112967..8867157ee 100644 --- a/crates/horizon-client/src/game/leads.rs +++ b/crates/horizon-client/src/game/leads.rs @@ -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); diff --git a/crates/horizon-client/src/mobs/leash.rs b/crates/horizon-client/src/mobs/leash.rs index b7c5011ba..3bd0513d7 100644 --- a/crates/horizon-client/src/mobs/leash.rs +++ b/crates/horizon-client/src/mobs/leash.rs @@ -198,6 +198,15 @@ pub fn tick(m: &mut Mob, w: &MobWorld, events: &mut Vec) { 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) { diff --git a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaMobAiOracle.java b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaMobAiOracle.java index 5808fec0d..eb5235adf 100644 --- a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaMobAiOracle.java +++ b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaMobAiOracle.java @@ -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)); diff --git a/tools/test_mob_ai_parity.py b/tools/test_mob_ai_parity.py index 3e6ce74df..87a7a1403 100644 --- a/tools/test_mob_ai_parity.py +++ b/tools/test_mob_ai_parity.py @@ -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, []):