Merge pull request #2125 from kacpherek/fix/remote-entity-events

🤖 Agent: Read against the vanilla 26.3 sources (Server players see villager hearts, taming hearts and smoke, spawn poofs and snowball crumbs) and proven in contrib-gate-21's union of 72 kacpherek PRs: 95 parity harnesses on playhorizon and the Mac mini, clippy, 1534 tests, lan_e2e 23 checks in-frame and with --server-thread. Thanks @kacpherek!
This commit is contained in:
Ludovic Marie
2026-10-27 12:22:17 +01:00
committed by GitHub
10 changed files with 135 additions and 47 deletions
+1 -1
View File
@@ -161,7 +161,7 @@ impl Game<'_> {
}
// Allay.duplicateAllay: entity event 18, three spawnHeartParticle.
let id = self.mobs[index].id;
self.particles_around_mob(id, "heart", horizon_client::particles::Burst::ALLAY);
self.mob_event_particles(id, 18);
self.audio
.play("minecraft:block.amethyst_block.chime", Some(at), 2.0, 1.0);
self.consume_held();
+26 -21
View File
@@ -1313,12 +1313,17 @@ impl Game<'_> {
}
}
MobEvent::AroundSelf {
mob,
event,
kind,
feet,
width,
height,
burst,
} => self.particles_around(kind, feet, [width, height], burst),
} => {
self.lan_entity_event(mob as i32, event, feet);
self.particles_around(kind, feet, [width, height], burst)
}
MobEvent::ParticleAt { kind, at, velocity } => {
if let Some(ty) = horizon_client::particles::ParticleType::from_name(kind) {
let options = horizon_client::particles::ParticleOptions::simple(ty);
@@ -1573,6 +1578,8 @@ impl Game<'_> {
q.extra.in_love = 0;
}
let q = self.mobs.iter().find(|m| m.id == partner).cloned();
// Animal.finalizeSpawnChildFromBreeding: entity event 18 for the parent.
self.mob_event_particles(parent, 18);
// Sniffer.spawnChildFromBreeding: an egg instead of a baby.
if p.species() == Species::Sniffer {
self.lay_sniffer_egg(&p);
@@ -2611,6 +2618,7 @@ impl Game<'_> {
};
m.damage(amount, source);
}
self.thrown_break_event(p.id, atp);
self.item_burst(atp, "minecraft:snowball");
}
(ProjectileKind::Egg, hit) => {
@@ -2636,6 +2644,7 @@ impl Game<'_> {
}
}
}
self.thrown_break_event(p.id, atp);
self.item_burst(atp, "minecraft:egg");
}
(ProjectileKind::EnderPearl, hit) => {
@@ -2885,10 +2894,17 @@ impl Game<'_> {
}
Ok(())
}
/// `Snowball`/`ThrownEgg.onHit`: entity event 3 for the guests, before the
/// projectile is discarded (the clients lose it when the tracker next runs).
fn thrown_break_event(&mut self, id: u32, at: [f64; 3]) {
if id != 0 {
self.lan_entity_event(id as i32, 3, at);
}
}
/// `Snowball`/`ThrownEgg.handleEntityEvent(3)`: eight crumbs of the
/// thrown item where it broke, at rest for a snowball, scattered by the
/// client entity's random (the particle engine's here) for an egg.
fn item_burst(&mut self, at: [f64; 3], item: &str) {
pub(super) fn item_burst(&mut self, at: [f64; 3], item: &str) {
let options = self.item_particle(&horizon_client::items::ItemStack::new(item, 1));
let egg = item != "minecraft:snowball";
for _ in 0..8 {
@@ -3182,14 +3198,8 @@ impl Game<'_> {
m.ai.target = None;
m.extra.sitting = true;
}
// TamableAnimal.spawnTamingParticles.
let kind = if tamed { "heart" } else { "smoke" };
// TamableAnimal.spawnTamingParticles (entity event 7 or 6).
self.particles_around_mob(
self.mobs[index].id,
kind,
horizon_client::particles::Burst::TAMING,
);
self.mob_event_particles(self.mobs[index].id, if tamed { 7 } else { 6 });
if tamed {
let view = self.mob_entity(&self.mobs[index]);
self.trigger_entity("minecraft:tame_animal", "entity", &view);
@@ -3256,13 +3266,8 @@ impl Game<'_> {
m.extra.sitting = true;
}
eat = eating_sound(m, &mut self.world.random);
let kind = if tamed { "heart" } else { "smoke" };
// TamableAnimal.spawnTamingParticles (entity event 7 or 6).
self.particles_around_mob(
self.mobs[index].id,
kind,
horizon_client::particles::Burst::TAMING,
);
self.mob_event_particles(self.mobs[index].id, if tamed { 7 } else { 6 });
if tamed {
let view = self.mob_entity(&self.mobs[index]);
self.trigger_entity("minecraft:tame_animal", "entity", &view);
@@ -3310,13 +3315,8 @@ impl Game<'_> {
m.extra.tame = true;
m.extra.owner = self.level.player_uuid.or(Some([0, 0, 0, 1]));
}
let kind = if tamed { "heart" } else { "smoke" };
// TamableAnimal.spawnTamingParticles (entity event 7 or 6).
self.particles_around_mob(
self.mobs[index].id,
kind,
horizon_client::particles::Burst::TAMING,
);
self.mob_event_particles(self.mobs[index].id, if tamed { 7 } else { 6 });
if tamed {
let view = self.mob_entity(&self.mobs[index]);
self.trigger_entity("minecraft:tame_animal", "entity", &view);
@@ -3347,6 +3347,11 @@ impl Game<'_> {
Some(sound) => {
consume = true;
eat = sound;
// Animal.setInLove: entity event 18 (a baby that
// only grew is not in love).
if self.mobs[index].extra.in_love > 0 {
self.mob_event_particles(self.mobs[index].id, 18);
}
}
// Animal.mobInteract still consumes the client click when
// an adult cannot breed, without swinging or taking food.
+6
View File
@@ -25,11 +25,13 @@ impl Game<'_> {
};
let m = &mut self.mobs[index];
let mut used = false;
let mut loved = false;
if item == "minecraft:hay_block" && m.extra.tame && m.extra.age == 0 && m.extra.in_love <= 0
{
m.extra.in_love = 600;
m.extra.love_player = true;
used = true;
loved = true;
}
if m.health < m.attrs.max_health {
m.health = (m.health + heal).min(m.attrs.max_health);
@@ -57,6 +59,10 @@ impl Game<'_> {
if !used {
return false;
}
// Animal.setInLove: entity event 18.
if loved {
self.mob_event_particles(self.mobs[index].id, 18);
}
self.llama_sound(index, "entity.llama.eat", 1.0);
self.consume_held();
true
+15 -6
View File
@@ -228,10 +228,12 @@ impl Game<'_> {
return false;
}
let mut used = false;
let mut loved = false;
if love && m.extra.tame && m.extra.age == 0 && m.extra.in_love <= 0 {
m.extra.in_love = 600;
m.extra.love_player = true;
used = true;
loved = true;
}
if m.health < m.attrs.max_health && heal > 0.0 {
m.health = (m.health + heal).min(m.attrs.max_health);
@@ -251,6 +253,7 @@ impl Game<'_> {
// eating(): the mouth opens and the horse eats.
m.anim.v[2] = 1.0;
let at = m.center();
let id = m.id;
let sound = match m.species() {
Species::Camel => "minecraft:entity.camel.eat",
Species::CamelHusk => "minecraft:entity.camel_husk.eat",
@@ -260,6 +263,10 @@ impl Game<'_> {
};
let pitch = (self.world.random.next_float() - self.world.random.next_float()) * 0.2 + 1.0;
self.audio.play(sound, Some(at), 1.0, pitch);
// Animal.setInLove: entity event 18.
if loved {
self.mob_event_particles(id, 18);
}
self.consume_held();
true
}
@@ -465,14 +472,16 @@ impl Game<'_> {
m.extra.owner = owner;
m.persistent = true;
// AbstractHorse.tameWithName: entity event 7, spawnTamingParticles(true).
self.particles_around_mob(
mob,
"heart",
horizon_client::particles::Burst::TAMING,
);
self.mob_event_particles(mob, 7);
}
}
MobEvent::Buck { mob } if self.riding == Some(mob) => self.dismount_mount(),
MobEvent::Buck { mob } => {
if self.riding == Some(mob) {
self.dismount_mount();
}
// RunAroundLikeCrazyGoal.tick: entity event 6, smoke.
self.mob_event_particles(mob, 6);
}
_ => {}
}
}
+3 -6
View File
@@ -85,13 +85,8 @@ impl Game<'_> {
m.ai.target = None;
}
let sound = nautilus::eat_sound(m);
let kind = if tamed { "heart" } else { "smoke" };
// TamableAnimal.spawnTamingParticles (entity event 7 or 6).
self.particles_around_mob(
self.mobs[index].id,
kind,
horizon_client::particles::Burst::TAMING,
);
self.mob_event_particles(self.mobs[index].id, if tamed { 7 } else { 6 });
self.nautilus_sound(index, sound);
if tamed {
let view = self.mob_entity(&self.mobs[index]);
@@ -145,6 +140,8 @@ impl Game<'_> {
let sound = nautilus::eat_sound(m);
self.use_nautilus_food(item);
self.nautilus_sound(index, sound);
// Animal.setInLove: entity event 18.
self.mob_event_particles(self.mobs[index].id, 18);
return true;
}
false
+31
View File
@@ -2249,6 +2249,37 @@ impl Game<'_> {
if p.event == super::totem::TOTEM_EVENT {
self.remote_totem(p.id);
}
// Mob.handleEntityEvent 20: the spawn poof.
if p.event == 20 && self.mobs.iter().any(|m| m.id == p.id as u32) {
self.poof_particles(p.id as u32);
}
// Villager 12, 13 and 14, TamableAnimal and AbstractHorse 6 and
// 7, Animal and Allay 18: the particles about the mob.
if matches!(p.event, 6 | 7 | 12 | 13 | 14 | 18) {
self.entity_event_particles(p.id as u32, p.event);
}
// Snowball and ThrownEgg.handleEntityEvent 3: the crumbs where
// the projectile is (the server removes it right after).
if p.event == 3 {
let crumbs = self
.creatures
.projectiles
.iter()
.find(|pr| pr.id == p.id as u32)
.and_then(|pr| {
let item = match pr.kind {
horizon_client::projectiles::ProjectileKind::Snowball => {
"minecraft:snowball"
}
horizon_client::projectiles::ProjectileKind::Egg => "minecraft:egg",
_ => return None,
};
Some(([pr.position.x, pr.position.y, pr.position.z], item))
});
if let Some((at, item)) = crumbs {
self.item_burst(at, item);
}
}
if p.event == super::combat::DROWN_EVENT {
self.remote_drown(p.id);
}
+10 -1
View File
@@ -257,8 +257,17 @@ impl Game<'_> {
let Some(m) = self.mobs.iter().find(|m| m.id == id) else {
return;
};
let (at, w, h) = (m.position, f64::from(m.width()), f64::from(m.height()));
let at = m.position;
self.lan_entity_event(id as i32, 20, [at.x, at.y, at.z]);
self.poof_particles(id);
}
/// `Mob.handleEntityEvent` 20 (`spawnAnim` on a client): the poof about
/// mob `id`.
pub(super) fn poof_particles(&mut self, id: u32) {
let Some(m) = self.mobs.iter().find(|m| m.id == id) else {
return;
};
let (at, w, h) = (m.position, f64::from(m.width()), f64::from(m.height()));
let options = ParticleOptions::simple(ParticleType::Poof);
for _ in 0..20 {
let r = self.particles.level_random();
+27 -8
View File
@@ -148,7 +148,7 @@ impl Game<'_> {
// VillagerMakeLove: entity event 13 for the partner, then the parent.
for i in [ib, ia] {
let id = self.mobs[i].id;
self.villager_particles(id, "angry_villager");
self.mob_event_particles(id, 13);
}
return;
};
@@ -173,12 +173,31 @@ impl Game<'_> {
child.extra.bed = Some(bed);
}
// VillagerMakeLove.giveBirth: entity event 12 for the child.
self.villager_particles(id, "heart");
self.mob_event_particles(id, 12);
}
/// `Villager.handleEntityEvent` 12, 13, 14 and 42:
/// `AbstractVillager.addParticlesAroundSelf`.
pub(super) fn villager_particles(&mut self, id: u32, kind: &'static str) {
self.particles_around_mob(id, kind, horizon_client::particles::Burst::VILLAGER);
/// `Level.broadcastEntityEvent` of an event whose `handleEntityEvent`
/// draws particles about the mob (villager 12, 13 and 14, taming 6 and 7,
/// love 18): the guests get the byte, and this game draws it as its own
/// client would.
pub(super) fn mob_event_particles(&mut self, id: u32, event: i8) {
let Some(m) = self.mobs.iter().find(|m| m.id == id) else {
return;
};
let at = [m.position.x, m.position.y, m.position.z];
self.lan_entity_event(id as i32, event, at);
self.entity_event_particles(id, event);
}
/// `handleEntityEvent(event)`'s particles about mob `id`
/// (`Villager`, `TamableAnimal`, `AbstractHorse`, `Animal`, `Allay`).
pub(super) fn entity_event_particles(&mut self, id: u32, event: i8) {
let Some(m) = self.mobs.iter().find(|m| m.id == id) else {
return;
};
if let Some((kind, burst)) =
horizon_client::particles::entity_event_burst(&m.kind.id, event as u8)
{
self.particles_around_mob(id, kind, burst);
}
}
/// `particles::around_self` about mob `id`.
pub(super) fn particles_around_mob(
@@ -315,7 +334,7 @@ impl Game<'_> {
}
// Villager.setLastHurtByMob: entity event 13.
for id in angry {
self.villager_particles(id, "angry_villager");
self.mob_event_particles(id, 13);
}
}
/// `Villager.tellWitnessesThatIWasMurdered`: the villagers that saw a
@@ -370,7 +389,7 @@ impl Game<'_> {
gossip::REPUTATION_CHANGE_PER_TRADE,
);
// Villager.customServerAiStep after a trade: entity event 14.
self.villager_particles(id, "happy_villager");
self.mob_event_particles(id, 14);
}
/// `Villager.getPlayerReputation` of the local player.
pub(super) fn villager_reputation(&self, id: u32) -> i32 {
+4 -1
View File
@@ -1092,8 +1092,11 @@ pub enum MobEvent {
at: [f64; 3],
count: u32,
},
/// Client particles about a mob's box (`particles::around_self`).
/// Client particles about a mob's box (`particles::around_self`) and the
/// entity event `event` that shows them, sent for mob `mob`.
AroundSelf {
mob: u32,
event: i8,
kind: &'static str,
feet: [f64; 3],
width: f64,
@@ -2918,11 +2918,18 @@ impl B {
let mut bodies = Vec::new();
if let Some(t) = cx.w.target_info(target) {
let (min, max) = (t.bounds.min_position(), t.bounds.max_position());
bodies.push((t.position, max.x - min.x, max.y - min.y));
bodies.push((partner, t.position, max.x - min.x, max.y - min.y));
}
bodies.push((m.position, f64::from(m.width()), f64::from(m.height())));
for (feet, width, height) in bodies {
bodies.push((
m.id,
m.position,
f64::from(m.width()),
f64::from(m.height()),
));
for (mob, feet, width, height) in bodies {
cx.events.push(MobEvent::AroundSelf {
mob,
event: 12,
kind: "heart",
feet: [feet.x, feet.y, feet.z],
width,
@@ -3605,6 +3612,8 @@ fn pois_scan_order(_m: &Mob, found: &[(Poi, [i32; 3])]) -> Vec<usize> {
/// `AbstractVillager.addParticlesAroundSelf(HAPPY_VILLAGER)` on the client.
fn happy_particles(m: &Mob, cx: &mut Bx) {
cx.events.push(MobEvent::AroundSelf {
mob: m.id,
event: 14,
kind: "happy_villager",
feet: [m.position.x, m.position.y, m.position.z],
width: f64::from(m.width()),