Files
horizon-airdef/tools/test_remote_fireball_parity.py
T
levzzz 4c9075a072 Keep the thrown-item reproduction for #1762
A server's client ticks a projectile itself between the entity tracker's
updates, as vanilla's Entity no-op interpolation handler does; before #2086 it
only eased towards the server's position, so a thrown egg, ender pearl or wind
charge hung in the air for half a second. The client tick is now a named
function with unit tests for that flight, and the parity harness keeps the
reproduction the issue asked for: a connected client throws each of them and
samples their position twice as often as the tracker's interval. The LAN
harness can also run headless now (HORIZON_E2E_HEADLESS), so the games render
offscreen and never pause on the focus loss on a machine with no focused
window.

Co-Authored-By: minimax-m3.1-flash (Claude Code) <noreply@users.noreply.github.com>
2026-10-27 04:08:31 +05:00

103 lines
4.9 KiB
Python

#!/usr/bin/env python3
"""A connected client advances ghast fireballs and thrown items between tracker packets.
AbstractHurtingProjectile.tick/applyInertia run on clients as well as servers, and
a thrown item ticks itself on the client too. 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 (#1762).
"""
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 check_thrown(host, guest, out):
"""A thrown egg, an ender pearl and a wind charge fly on between tracker packets.
The server sends a thrown item's position every 10 ticks; a client that only
eased towards it hung in the air for half a second (#1762). Vanilla's client
ticks the projectile itself, as Entity's no-op interpolation handler does.
"""
x, y, z = (math.floor(v) for v in lan.pos_of(guest))
for game in (host, guest):
game('command', command='gamemode survival')
results = {}
for item, kind in (('minecraft:egg', 'Egg'), ('minecraft:ender_pearl', 'EnderPearl'),
('minecraft:wind_charge', 'WindCharge')):
# A clear lane along +X at the guest's eye height, with room to fall.
host('command', command=f'fill {x + 2} {y - 7} {z - 2} {x + 60} {y - 7} {z + 2} minecraft:stone')
host('command', command=f'fill {x + 2} {y - 6} {z - 2} {x + 60} {y + 3} {z + 2} minecraft:air')
guest('command', command=f'tp @s {x + 0.5:.2f} {y:.2f} {z + 0.5:.2f}')
guest.wait(20)
guest('command', command='clear @s')
guest('command', command=f'item replace entity @s weapon.mainhand with {item}')
guest.wait(10)
# The server throws along the rotation it has: let it arrive first.
guest.raw('look-at', f'{x + 40:.2f}', f'{y + 1.62:.2f}', f'{z + 0.5:.2f}')
guest.wait(5)
guest.raw('use-item')
samples = []
for _ in range(6):
shots = [p for p in guest('status')['projectiles'] if p['kind'] == kind]
samples.append(shots[0]['position'][0] if shots else None)
guest.wait(2)
seen = [p for p in samples if p is not None]
moves = sum(b != a for a, b in zip(seen, seen[1:]))
results[item] = {'positions': samples, 'moves': moves}
assert len(seen) >= 4, f'{item} visible in only {len(seen)} samples: {samples}'
assert moves >= len(seen) - 2, f'{item} stalled between tracker updates: {samples}'
return results
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
lan.CHECK_FNS['remote-thrown'] = check_thrown
# 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', 'remote-thrown'])
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()