Merge pull request #2104 from rdbtCVS/fix/1482-evoker-fangs

🤖 Agent: Gate check by Ludovic's AI agent (Claude). Checked against 26.3: the server sends entity event 4 once its warmup ends (`EvokerFangs.tick`), `handleEntityEvent(4)` starts the client's attack and plays the sound locally, and the client only counts `lifeTicks` down for the animation, while the server deals the damage and discards. Moving the host's sound to `play_unshared` matches that, since each client plays its own. It conflicted with #2094 (both hook entity events) once that merged, so I merged main into it, keeping both calls. `lan_e2e.py --check fangs` passes in both modes. It conflicted again with main in `tools/lan_e2e.py` (new checks on both sides), so I merged main in once more, keeping every check; clippy is clean. Fixes #1482. Thanks @rdbtCVS! Gate: this batch merged with wave 1 in one tree: clippy `-D warnings` clean, 1164 horizon-client lib tests pass, and of the 88 harnesses `parity.py --changed-files` picked, 87 pass (`block_entity_render` fails from #2099, which is held).
This commit is contained in:
Ludovic Marie
2026-10-27 03:56:41 +01:00
committed by GitHub
6 changed files with 138 additions and 5 deletions
@@ -1083,6 +1083,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());
+37 -5
View File
@@ -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,
@@ -304,6 +304,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));
+1
View File
@@ -2111,6 +2111,7 @@ impl Game<'_> {
if p.event == super::fireworks::FIREWORK_EXPLODE_EVENT {
self.remote_firework_explosion(p.id);
}
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)
@@ -95,6 +95,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,
@@ -296,6 +297,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
@@ -458,6 +460,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);
@@ -473,6 +476,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();
@@ -493,6 +497,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}));
}
+84
View File
@@ -7153,6 +7153,90 @@ CHECKS += ['guardian-beams']
CHECK_FNS['guardian-beams'] = check_guardian_beams
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}]')
# The evoker can summon vexes before fangs; killing it leaves those summons alive.
host('command', command=f'kill @e[type=minecraft:vex,x={x},y={y},z={z},distance=..32]')
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)
def check_sonic(host, guest, out):
"""A real warden's ray reaches connected clients once, with normal damage.