diff --git a/crates/horizon-client/src/game/control.rs b/crates/horizon-client/src/game/control.rs index 7a632e308..6139ccd37 100644 --- a/crates/horizon-client/src/game/control.rs +++ b/crates/horizon-client/src/game/control.rs @@ -1023,6 +1023,9 @@ impl Game<'_> { "flashes": self.lightning_seen[1], "flash": self.flash}); // Primed TNT, falling blocks, projectiles, tridents and end crystals. status["projectiles"] = json!(self.projectiles_status()); + let mut fangs_vertices = Vec::new(); + self.fangs_geometry(glam::DVec3::ZERO, 0.5, &mut fangs_vertices); + status["fangs_vertices"] = json!(fangs_vertices.len()); status["maps"] = json!(self.maps_status()); // The particles made so far, by type. status["particles"] = json!(self.particles.made()); diff --git a/crates/horizon-client/src/game/fangs.rs b/crates/horizon-client/src/game/fangs.rs index cdf2d17a5..9aa687032 100644 --- a/crates/horizon-client/src/game/fangs.rs +++ b/crates/horizon-client/src/game/fangs.rs @@ -7,12 +7,13 @@ use std::sync::Arc; #[derive(Clone, Debug)] pub(super) struct Fangs { - pos: [f64; 3], - yaw: f32, + pub id: u32, + pub pos: [f64; 3], + pub yaw: f32, warmup: i32, - life: i32, + pub life: i32, owner: u32, - started: bool, + pub started: bool, } #[derive(Default)] pub(super) struct FangState { @@ -21,6 +22,11 @@ pub(super) struct FangState { } impl Game<'_> { pub(super) fn add_fangs(&mut self, at: [f64; 3], yaw: f32, delay: i32, owner: u32) { + self.next_entity += 1; + self.insert_fangs(self.next_entity, at, yaw, delay, owner); + } + + pub(super) fn insert_fangs(&mut self, id: u32, at: [f64; 3], yaw: f32, delay: i32, owner: u32) { if self.fangs.model.is_none() { self.fangs.model = horizon_client::mobs::load_model( &self.options.resources, @@ -29,6 +35,7 @@ impl Game<'_> { .map(Arc::new); } self.fangs.list.push(Fangs { + id, pos: at, yaw, warmup: delay, @@ -37,6 +44,30 @@ impl Game<'_> { started: false, }); } + /// `EvokerFangs.handleEntityEvent`: only event 4 starts a client attack. + pub(super) fn remote_fangs_event(&mut self, id: u32, event: i8) { + if event == 4 + && let Some(f) = self.fangs.list.iter_mut().find(|f| f.id == id) + { + f.started = true; + self.audio.play_unshared( + "minecraft:entity.evoker_fangs.attack", + Some(f.pos), + 1.0, + 1.0, + ); + } + } + + /// `EvokerFangs.tick`: clients only advance animation, never damage or discard. + pub(super) fn tick_remote_fangs(&mut self) { + for f in &mut self.fangs.list { + if f.started { + f.life -= 1; + } + } + } + /// `EvokerFangs.tick`. pub(super) fn tick_fangs(&mut self) { let mut list = std::mem::take(&mut self.fangs.list); @@ -50,7 +81,8 @@ impl Game<'_> { } if !f.started { f.started = true; - self.audio.play( + self.lan_entity_event(f.id as i32, 4, f.pos); + self.audio.play_unshared( "minecraft:entity.evoker_fangs.attack", Some(f.pos), 1.0, diff --git a/crates/horizon-client/src/game/lan_entities.rs b/crates/horizon-client/src/game/lan_entities.rs index cd4ba2fb8..a389e6a99 100644 --- a/crates/horizon-client/src/game/lan_entities.rs +++ b/crates/horizon-client/src/game/lan_entities.rs @@ -290,6 +290,9 @@ impl Game<'_> { None => 0, }; let at = |p: horizon_core::geometry::Vec3| [p.x, p.y, p.z]; + for f in &self.fangs.list { + out.push(state(f.id, "minecraft:evoker_fangs", f.pos, f.yaw, false)); + } // LightningBolt: each client draws and flashes its own. for b in self.bolts.iter().filter(|b| b.id != 0) { out.push(state(b.id, "minecraft:lightning_bolt", b.at, 0.0, false)); diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 20c307720..88f36bdf2 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -2050,6 +2050,7 @@ impl Game<'_> { } } C::EntityEvent(p) => { + self.remote_fangs_event(p.id as u32, p.event); // LocalPlayer.setPermissions also refreshes an open World Options screen. if (24..=28).contains(&p.event) && self.remote.as_ref().is_some_and(|r| r.entity_id == p.id) diff --git a/crates/horizon-client/src/game/remote_projectiles.rs b/crates/horizon-client/src/game/remote_projectiles.rs index 2ba4510ea..f033c5a8b 100644 --- a/crates/horizon-client/src/game/remote_projectiles.rs +++ b/crates/horizon-client/src/game/remote_projectiles.rs @@ -54,6 +54,7 @@ impl Game<'_> { let (yaw, pitch) = rotation; self.remove_remote_projectile(id); match kind { + "minecraft:evoker_fangs" => self.insert_fangs(id, position, yaw, 0, 0), "minecraft:tnt" => self.tnts.push(super::tnt::PrimedTnt { id, position: at, @@ -220,6 +221,7 @@ impl Game<'_> { /// One tick of interpolation, as `tick_remote_objects`. pub(super) fn tick_remote_projectiles(&mut self, mut step: impl FnMut(u32, Vec3) -> Vec3) { + self.tick_remote_fangs(); // PrimedTnt.tick runs on a client too: it falls, bounces and burns its // fuse down (the swell and flash follow it) between the server's // updates (every 10 ticks), and a client discards it when the fuse @@ -311,6 +313,7 @@ impl Game<'_> { } pub(super) fn remove_remote_projectile(&mut self, id: u32) { + self.fangs.list.retain(|f| f.id != id); self.tnts.retain(|t| t.id != id); self.falling.retain(|f| f.id != id); self.creatures.projectiles.retain(|p| p.id != id); @@ -324,6 +327,7 @@ impl Game<'_> { /// Every one a server sent (a new connection, level or dimension). pub(super) fn clear_remote_projectiles(&mut self) { + self.fangs.list.clear(); self.tnts.clear(); self.falling.clear(); self.creatures.projectiles.clear(); @@ -340,6 +344,12 @@ impl Game<'_> { use serde_json::json; let at = |p: Vec3| [p.x, p.y, p.z]; let mut out = Vec::new(); + for f in &self.fangs.list { + out.push( + json!({"id": f.id, "kind": "minecraft:evoker_fangs", "position": f.pos, + "yaw": f.yaw, "started": f.started, "life": f.life}), + ); + } for t in &self.tnts { out.push(json!({"id": t.id, "kind": "minecraft:tnt", "position": at(t.position), "fuse": t.fuse})); } diff --git a/tools/lan_e2e.py b/tools/lan_e2e.py index 804add98a..b4a89eb1d 100755 --- a/tools/lan_e2e.py +++ b/tools/lan_e2e.py @@ -6591,5 +6591,88 @@ CHECKS += ['replant'] CHECK_FNS['replant'] = check_replant + +def check_fangs(host, guest, out): + """EvokerFangs: authoritative spawn, event 4, client animation and server removal (#1482).""" + x, y, z = (int(v // 1) for v in pos_of(host)) + tag = 'lan_evoker_fangs' + selector = f'@e[type=minecraft:evoker,tag={tag},limit=1]' + paths = {g.name: {} for g in (host, guest)} + warmup = dict.fromkeys(paths, False) + drawn = dict.fromkeys(paths, False) + stopped = False + photographed = False + + def fangs(status): + return [p for p in status['projectiles'] if p['kind'] == 'minecraft:evoker_fangs'] + + try: + host('command', command='difficulty normal') + host('command', command='gamemode creative') + guest('command', command='gamemode survival') + guest('command', command='effect give @s minecraft:resistance 120 4 true') + host('command', command=f'fill {x - 10} {y - 1} {z - 10} {x + 10} {y - 1} {z + 18} minecraft:stone') + host('command', command=f'fill {x - 10} {y} {z - 10} {x + 10} {y + 8} {z + 18} minecraft:air') + host('command', command=f'tp @s {x + 4.5} {y} {z - 2.5}') + guest('command', command=f'tp @s {x + 0.5} {y} {z + 0.5}') + guest.wait(10) + host('command', command=f'summon minecraft:evoker {x + 0.5} {y} {z + 9.5} ' + f'{{PersistenceRequired:1b,Tags:["{tag}"]}}') + for game in (host, guest): + game.raw('look-at', x + 0.5, y + 0.5, z + 5.5) + for _ in range(200): + guest.wait(2) + statuses = {g.name: g('status') for g in (host, guest)} + for name, status in statuses.items(): + live = fangs(status) + ids = [f['id'] for f in live] + assert all(ids) and len(ids) == len(set(ids)), f'{name}: invalid fang ids {ids}' + warmup[name] |= any(not f['started'] for f in live) + drawn[name] |= status['fangs_vertices'] > 0 + for f in live: + paths[name].setdefault(f['id'], []).append(f) + if paths['host'] and not stopped: + host('command', command=f'data merge entity {selector} {{NoAI:1b}}') + stopped = True + if (all(drawn.values()) and not photographed + and any(f['started'] and 8 <= f['life'] <= 16 + for f in fangs(statuses['guest']))): + host('command', command='tick freeze') + try: + for game in (host, guest): + game.raw('key', 'f1', 'tap') + try: + game.shot(out, 'evoker-fangs') + finally: + game.raw('key', 'f1', 'tap') + finally: + host('command', command='tick unfreeze') + photographed = True + if stopped and not any(fangs(s) for s in statuses.values()): + break + lab.write_json(out / 'evoker-fangs.json', {'paths': paths, 'warmup': warmup, 'drawn': drawn}) + assert all(warmup.values()), f'fang warmup not received: {warmup}' + assert all(drawn.values()), f'fang renderer produced no geometry: {drawn}' + assert paths['host'].keys() == paths['guest'].keys(), 'clients received different fang ids' + for id, samples in paths['host'].items(): + other = paths['guest'][id] + assert all(f['position'] == samples[0]['position'] for f in samples + other), \ + f'fang {id} is not at its authoritative position' + for name, frames in (('host', samples), ('guest', other)): + life = {f['life'] for f in frames if f['started']} + assert len(life) > 1, f'{name}: fang {id} did not animate: {frames}' + assert not any(fangs(g('status')) for g in (host, guest)), 'fangs survived server removal' + finally: + host('command', command='tick unfreeze') + host('command', command=f'kill @e[tag={tag}]') + guest('command', command='effect clear @s') + face_each_other(host, guest) + return {'fangs': len(paths['host']), 'warmup': warmup, 'drawn': drawn, 'removed': True} + + +CHECKS += ['fangs'] +CHECK_FNS.update(fangs=check_fangs) + + if __name__ == '__main__': main()