Files
horizon-airdef/tools/test_held_drop_parity.py
T

43 lines
2.0 KiB
Python

#!/usr/bin/env python3
"""Compare selected-slot drops with Minecraft.handleKeybinds in all four game modes.
The oracle invokes the unmodified native key handler, consuming real drop-key
clicks. Its controlled dropItem callback removes from the real player Inventory;
other keys are idle and execution stops at the following item-use boundary.
Checks Q/Ctrl+Q, slots 0/8, empty/single/partial/full stacks and repeated drops.
Packet delivery, item entities, swing animation and statistics are outside scope.
"""
import os
import subprocess
try:
from . import lab, test_rust_parity as base
except ImportError:
import lab
import test_rust_parity as base
def main():
lock, jars, libraries = base.verify_artifacts()
build = lab.LOCAL / 'held-drop-parity'
build.mkdir(parents=True, exist_ok=True)
classes = build / 'classes'
classes.mkdir(exist_ok=True)
# Minecraft's key handler also links client-only libraries.
_, game_dir = lab.config()
libraries += sorted((game_dir / 'libraries/client').rglob('*.jar'))
classpath = os.pathsep.join(map(str, [jars['client'], *libraries]))
oracle = lab.ROOT / 'mods/horizon/src/test/java/dev/horizonlab/parity/VanillaHeldDropOracle.java'
subprocess.run(['javac', '--release', str(lock['minecraft']['java_major']), '-proc:none',
'-cp', classpath, '-d', str(classes), str(oracle)], check=True)
subprocess.run(['java', '-Xmx512M', '-cp', str(classes) + os.pathsep + classpath,
'dev.horizonlab.parity.VanillaHeldDropOracle', str(build / 'vanilla.txt')], check=True)
with (build / 'rust.txt').open('w') as out:
subprocess.run(['cargo', 'run', '--quiet', '-p', 'horizon-client', '--example',
'held_drop_fixture'], cwd=lab.ROOT, stdout=out, check=True)
matched = base.compare(build / 'vanilla.txt', build / 'rust.txt')
print(f'Held drop parity passed: {matched} selected-stack/drop-count snapshots match vanilla')
if __name__ == '__main__':
main()