Merge pull request #1904 from rdbtCVS/fix/remote-fireball-motion

🤖 Agent: Thanks rdbt! Matches the client's LargeFireball tick between tracker updates; the new remote_fireball harness passes and lan_e2e's fireball check sees it on both sides. Tested together with the other wave 2 contributor PRs: fmt, clippy -D warnings, and the horizon-client, horizon-world and horizon-protocol tests pass. Of the 127 harnesses the batch affects, 124 pass; the other three are a player-head mismatch fixed in #1934 and two worldgen timeouts on a loaded machine with no chunk differing. lan_e2e chat, fireball, cursor, looks, thrown, eat, shield, lava, contacts, projectiles and mobs pass with the host in-frame and on its server thread.
This commit is contained in:
Ludovic Marie
2026-10-26 04:42:27 +01:00
committed by GitHub
4 changed files with 137 additions and 14 deletions
+23
View File
@@ -1413,6 +1413,22 @@ impl Game<'_> {
m.on_ground = on_ground;
return;
}
if let Some(p) = self.creatures.projectiles.iter_mut().find(|p| {
p.id == id as u32
&& matches!(
p.kind,
horizon_client::projectiles::ProjectileKind::LargeFireball { .. }
)
}) {
if path.is_some() {
p.position = Vec3::new(position[0], position[1], position[2]);
}
if let Some((yaw, pitch)) = rotation {
p.yaw = yaw;
p.pitch = pitch;
}
return;
}
if let Some(p) = r.pending_items.get_mut(&id) {
p.0 = position;
}
@@ -2941,6 +2957,13 @@ impl Game<'_> {
f.velocity = v;
} else if let Some(t) = self.tnts.iter_mut().find(|t| t.id == id as u32) {
t.velocity = v;
} else if let Some(p) = self
.creatures
.projectiles
.iter_mut()
.find(|p| p.id == id as u32)
{
p.velocity = v;
} else if let Some(p) = self
.remote
.as_mut()
@@ -249,7 +249,25 @@ impl Game<'_> {
for p in &mut self.creatures.projectiles {
p.previous = p.position;
p.age += 1;
p.position = step(p.id, p.position);
if matches!(p.kind, ProjectileKind::LargeFireball { .. }) {
// AbstractHurtingProjectile.tick advances on the client between
// the tracker updates (ten ticks apart for a ghast's fireball).
let at = p.position;
let water = self
.res
.facts()
.get(self.world.block(
at.x.floor() as i32,
at.y.floor() as i32,
at.z.floor() as i32,
))
.fluid
== horizon_client::blocks::Fluid::Water;
p.apply_hurting_inertia(water);
p.position = p.position.add_vector(p.velocity);
} else {
p.position = step(p.id, p.position);
}
}
for t in &mut self.tridents {
let id = t.id;
+33 -13
View File
@@ -572,6 +572,23 @@ impl Projectile {
}
(self.position.y > -128.0, Hit::None)
}
/// AbstractHurtingProjectile.applyInertia, on both server and client.
pub fn apply_hurting_inertia(&mut self, water: bool) {
// WitherSkull.getInertia: 0.73 for dangerous skulls.
let inertia = match self.kind {
ProjectileKind::WitherSkull { dangerous: true } => 0.73,
_ if water => 0.8,
_ => 0.95,
};
let v = self.velocity;
let len = (v.x * v.x + v.y * v.y + v.z * v.z).sqrt().max(1.0e-9);
self.velocity = Vec3::new(
(v.x + v.x / len * self.acceleration) * inertia,
(v.y + v.y / len * self.acceleration) * inertia,
(v.z + v.z / len * self.acceleration) * inertia,
);
}
/// One tick: returns whether to keep the projectile and what it hit.
pub fn tick(&mut self, w: &impl ProjectileWorld) -> (bool, Hit) {
self.previous = self.position;
@@ -584,19 +601,7 @@ impl Projectile {
ProjectileKind::SmallFireball
| ProjectileKind::LargeFireball { .. }
| ProjectileKind::WitherSkull { .. } => {
// WitherSkull.getInertia: 0.73 for dangerous skulls.
let inertia = match self.kind {
ProjectileKind::WitherSkull { dangerous: true } => 0.73,
_ if water => 0.8,
_ => 0.95,
};
let v = self.velocity;
let len = (v.x * v.x + v.y * v.y + v.z * v.z).sqrt().max(1.0e-9);
self.velocity = Vec3::new(
(v.x + v.x / len * self.acceleration) * inertia,
(v.y + v.y / len * self.acceleration) * inertia,
(v.z + v.z / len * self.acceleration) * inertia,
);
self.apply_hurting_inertia(water);
}
// Arrows tick with `arrows::tick`.
ProjectileKind::Arrow { .. } => {}
@@ -819,6 +824,21 @@ mod tests {
// (0.1 + 0.1) * 0.95
assert!((p.velocity.x - 0.19).abs() < 1e-9);
}
#[test]
fn fireball_inertia_preserves_custom_acceleration() {
let mut p = Projectile::fireball(
ProjectileKind::SmallFireball,
Vec3::new(0.0, 100.0, 0.0),
None,
[1.0, 0.0, 0.0],
);
// A redirected projectile can carry a different acceleration power.
p.acceleration = 0.2;
p.tick(&Empty(vec![]));
assert!((p.velocity.x - 0.285).abs() < 1e-9);
assert!((p.position.x - 0.285).abs() < 1e-9);
}
}
#[cfg(test)]
+62
View File
@@ -0,0 +1,62 @@
#!/usr/bin/env python3
"""A connected client advances ghast fireballs between tracker packets.
AbstractHurtingProjectile.tick/applyInertia run on clients as well as servers.
Like lan_e2e's falling-entity check, sample motion more often than the tracker
interval; an interpolation-only client stalls for most of that interval.
"""
import json
import math
import subprocess
import lab
import lan_e2e as lan
def check_motion(host, guest, out):
x, y, z = (math.floor(v) for v in lan.pos_of(guest))
for game in (host, guest):
game('command', command='gamemode creative')
tag = 'remote_fireball_parity'
host('command', command=f'fill {x + 2} {y + 18} {z - 1} {x + 48} {y + 23} {z + 1} minecraft:air')
host('command', command=f'summon minecraft:fireball {x + 3.5} {y + 20} {z + 0.5} '
f'{{Tags:["{tag}"],Motion:[0.1d,0.0d,0.0d]}}')
samples = []
try:
for _ in range(8):
balls = [p for p in guest('status')['projectiles'] if p['kind'] == 'LargeFireball']
samples.append(balls[0]['position'][0] if balls else None)
guest.wait(2)
finally:
host('command', command=f'kill @e[tag={tag}]')
seen = [p for p in samples if p is not None]
assert len(seen) >= 6, f'fireball visible in only {len(seen)} samples: {samples}'
moves = sum(b != a for a, b in zip(seen, seen[1:]))
assert moves >= len(seen) - 2, f'fireball stalled between tracker updates: {samples}'
return {'positions': samples}
def main():
subprocess.run(['cargo', 'build', '--locked', '--profile', 'fast', '-p', 'horizon-client',
'--bin', 'horizon-client', '--bin', 'horizon-ctl'], cwd=lab.ROOT, check=True)
metadata = json.loads(subprocess.check_output(
['cargo', 'metadata', '--format-version', '1', '--no-deps'], cwd=lab.ROOT, text=True))
ctl = lab.ROOT / metadata['target_directory'] / 'fast' / 'horizon-ctl'
lan.CHECK_FNS['remote-fireball'] = check_motion
# Use the runner's current display (xvfb on Linux), with fresh isolated homes.
lan.game_env = lambda _screen, home: lab.game_env(
HORIZON_HOME=home, HORIZON_TELEMETRY_URL='off')
reports = {}
for threaded in (True, False):
lan.SERVER_THREAD = threaded
mode = 'server-thread' if threaded else 'in-frame'
out = lab.LOCAL / 'remote-fireball-parity' / mode
out.mkdir(parents=True, exist_ok=True)
# lan.Game launches each client with lab.game_env and private scratch homes.
reports[mode] = lan.run(ctl, out, lab.RESOURCES.resolve(), ['remote-fireball'])
lab.write_json(lab.LOCAL / 'remote-fireball-parity' / 'report.json', reports)
assert all(r['pass'] for mode in reports.values() for r in mode.values()), reports
if __name__ == '__main__':
main()