diff --git a/tests/test_gen_version_consts.py b/tests/test_gen_version_consts.py index 61b12e62f..36daee849 100644 --- a/tests/test_gen_version_consts.py +++ b/tests/test_gen_version_consts.py @@ -33,7 +33,7 @@ class GenVersionConstsTests(unittest.TestCase): jar = Path(directory) / "client.jar" with zipfile.ZipFile(jar, "w") as archive: archive.writestr("version.json", json.dumps(INFO)) - self.assertEqual(gen.jar_info(jar), INFO) + self.assertEqual(lab.version_info(jar), INFO) def test_committed_file_is_the_pinned_version(self): """A pin bump regenerates version.rs: the lock and the constants never disagree.""" diff --git a/tools/agent_control_e2e.py b/tools/agent_control_e2e.py index cf4f95900..e51969654 100644 --- a/tools/agent_control_e2e.py +++ b/tools/agent_control_e2e.py @@ -34,6 +34,11 @@ import tempfile import time from pathlib import Path +try: + from . import lab +except ImportError: + import lab + ROOT = Path(__file__).resolve().parents[1] LAVAPIPE = Path('/run/opengl-driver/share/vulkan/icd.d/lvp_icd.x86_64.json') LOG_KINDS = ['oak_log', 'birch_log', 'spruce_log', 'jungle_log', 'acacia_log', 'dark_oak_log', @@ -480,7 +485,7 @@ def run(mode, ctl, out, resources, which='survival'): work = Path(tempfile.mkdtemp(prefix=f'hzac-{mode}-')) (work / '.local').mkdir() (work / '.local/horizon-client').mkdir() - os.symlink(resources, work / '.local/horizon-client/26.3') + os.symlink(resources, work / '.local/horizon-client' / lab.VERSION) socket = work / 'c.sock' env = game_env(os.environ.get('VSCREEN', 'agent-control')) driver = (Cli if mode == 'cli' else Mcp)(ctl, socket, work, env) @@ -521,7 +526,7 @@ def main(): meta = json.loads(subprocess.run(['cargo', 'metadata', '--format-version', '1', '--no-deps'], cwd=ROOT, capture_output=True, text=True, check=True).stdout) bins = Path(meta['target_directory']) / 'fast' - resources = (ROOT / '.local/horizon-client/26.3').resolve() + resources = (lab.RESOURCES).resolve() if not (resources / 'horizon-resources.json').exists(): sys.exit(f'no prepared resources in {resources}') out = Path(args.out) diff --git a/tools/audio_harness.py b/tools/audio_harness.py index 52054c2f2..6a26f2d44 100644 --- a/tools/audio_harness.py +++ b/tools/audio_harness.py @@ -18,7 +18,7 @@ try: except ImportError: import lab, test_rust_parity as base, test_model_baking_parity as baking -RESOURCES = lab.LOCAL / 'horizon-client/26.3' +RESOURCES = lab.RESOURCES COMMON_SOURCES = [ lab.ROOT / 'tools/audio_harness.py', lab.ROOT / 'tools/test_rust_parity.py', diff --git a/tools/bench_sprite_mips.py b/tools/bench_sprite_mips.py index 93e6e8899..68024d6d2 100644 --- a/tools/bench_sprite_mips.py +++ b/tools/bench_sprite_mips.py @@ -10,6 +10,11 @@ import os from pathlib import Path import subprocess +try: + from . import lab +except ImportError: + import lab + ROOT = Path(__file__).resolve().parents[1] @@ -31,7 +36,7 @@ def main(): mode.add_argument('--test', action='store_true', help='run extracted production upload tests') mode.add_argument('--build-only', action='store_true', help='build without measuring') parser.add_argument('--label', default='candidate') - parser.add_argument('--resources', type=Path, default=ROOT / '.local/horizon-client/26.3') + parser.add_argument('--resources', type=Path, default=lab.RESOURCES) args = parser.parse_args() path = 'crates/horizon-client/src/gfx.rs' source = (subprocess.check_output(['git', 'show', f'{args.ref}:{path}'], cwd=ROOT, text=True) diff --git a/tools/fetch_client_assets.py b/tools/fetch_client_assets.py index 513925374..2027593c5 100644 --- a/tools/fetch_client_assets.py +++ b/tools/fetch_client_assets.py @@ -21,8 +21,8 @@ def wanted(name): def main(): parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument('--target', type=Path, default=lab.LOCAL / 'horizon-client/26.3', - help='prepared resource directory (default: .local/horizon-client/26.3)') + parser.add_argument('--target', type=Path, default=lab.RESOURCES, + help='prepared resource directory (default: .local/horizon-client/)') parser.add_argument('--minecraft-dir', type=Path, help="official launcher game directory (default: the launcher's own)") args = parser.parse_args() diff --git a/tools/gen_block_state_data.py b/tools/gen_block_state_data.py index 5a4ab4072..0f2db7a63 100644 --- a/tools/gen_block_state_data.py +++ b/tools/gen_block_state_data.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """Convert vanilla's BlockStateData.java into a plain data file. -Reads .local/minecraft/26.3/sources/server/net/minecraft/util/datafix/fixes/BlockStateData.java +Reads .local/minecraft//sources/server/net/minecraft/util/datafix/fixes/BlockStateData.java Writes crates/horizon-world/src/datafix/block_state_data.txt Output: UTF-8, '#' header lines, then one line per register() call, in the order the @@ -20,8 +20,13 @@ import re import sys from pathlib import Path +try: + from . import lab +except ImportError: + import lab + REPO = Path(__file__).resolve().parent.parent -DEFAULT_JAVA = REPO / ".local/minecraft/26.3/sources/server/net/minecraft/util/datafix/fixes/BlockStateData.java" +DEFAULT_JAVA = lab.GAME / "sources/server/net/minecraft/util/datafix/fixes/BlockStateData.java" DEFAULT_OUT = REPO / "crates/horizon-world/src/datafix/block_state_data.txt" TOKEN_RE = re.compile( @@ -305,7 +310,7 @@ def main(): raise SystemExit(f"create count mismatch: textual {textual_create}, parsed {total_create}") header = [ - "# Generated by tools/gen_block_state_data.py from vanilla 26.3 BlockStateData.java. Do not edit.", + f"# Generated by tools/gen_block_state_data.py from vanilla {lab.VERSION} BlockStateData.java. Do not edit.", "# One line per register(ID, new, legacy...) call, in execution order of the static initializer", "# (bootstrap0, 1, 2, 3_1, 3_2, 4 .. 9, A .. F).", "# Format (tab separated): ID newName newProps [ legacyName legacyProps]...", diff --git a/tools/gen_flat_tables.py b/tools/gen_flat_tables.py index 396209199..78582960f 100644 --- a/tools/gen_flat_tables.py +++ b/tools/gen_flat_tables.py @@ -11,8 +11,13 @@ import subprocess import sys from pathlib import Path +try: + from . import lab +except ImportError: + import lab + ROOT = Path(__file__).resolve().parent.parent -FIXES = ROOT / '.local' / 'minecraft' / '26.3' / 'sources' / 'server' / 'net' / 'minecraft' / 'util' / 'datafix' / 'fixes' +FIXES = lab.GAME / 'sources' / 'server' / 'net' / 'minecraft' / 'util' / 'datafix' / 'fixes' OUT = ROOT / 'crates' / 'horizon-world' / 'src' / 'datafix' / 'flat_tables.rs' STR = r'"((?:[^"\\]|\\.)*)"' diff --git a/tools/gen_version_consts.py b/tools/gen_version_consts.py index 07cecd747..41e0b1192 100644 --- a/tools/gen_version_consts.py +++ b/tools/gen_version_consts.py @@ -15,7 +15,6 @@ from datetime import datetime, timezone import json from pathlib import Path import sys -import zipfile try: from . import lab @@ -25,11 +24,6 @@ except ImportError: OUT = lab.ROOT / "crates/horizon-core/src/version.rs" -def jar_info(client_jar): - with zipfile.ZipFile(client_jar) as archive: - return json.loads(archive.read("version.json")) - - def java_date(iso): """`Date.toString()` of an ISO-8601 instant, in UTC (Locale.ROOT names).""" return datetime.fromisoformat(iso).astimezone(timezone.utc).strftime("%a %b %d %H:%M:%S UTC %Y") @@ -69,8 +63,8 @@ def main(): parser.add_argument("--out", type=Path, default=OUT) parser.add_argument("--check", action="store_true", help="exit 1 if --out differs instead of writing it") args = parser.parse_args() - jar = args.jar or lab.config()[1] / "jars" / "client.jar" - text = render(jar_info(jar)) + jar = args.jar or lab.GAME / "jars" / "client.jar" + text = render(lab.version_info(jar)) if args.check: if not args.out.exists() or args.out.read_text() != text: print(f"{args.out} does not match {jar}; run tools/gen_version_consts.py", file=sys.stderr) diff --git a/tools/generate_entity_tracking.py b/tools/generate_entity_tracking.py index 434033b37..06beb144a 100644 --- a/tools/generate_entity_tracking.py +++ b/tools/generate_entity_tracking.py @@ -5,12 +5,17 @@ trackDeltas, which ChunkMap.TrackedEntity and ServerEntity use to decide who sees an entity and how often its movement is sent), read from the decompiled EntityTypes.java. - generate_entity_tracking.py [--sources .local/minecraft/26.3/sources/client] + generate_entity_tracking.py [--sources .local/minecraft//sources/client] """ import argparse import re from pathlib import Path +try: + from . import lab +except ImportError: + import lab + ROOT = Path(__file__).resolve().parents[1] INT_MAX = 2147483647 @@ -34,7 +39,7 @@ def parse(sources): def main(): parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--sources", type=Path, default=ROOT / ".local/minecraft/26.3/sources/client") + parser.add_argument("--sources", type=Path, default=lab.GAME / "sources/client") parser.add_argument("--out", type=Path, default=ROOT / "crates/horizon-client/src/lan/tracking.rs") args = parser.parse_args() rows = parse(args.sources) diff --git a/tools/generate_packet_ids.py b/tools/generate_packet_ids.py index c5c0b90f8..eddcc12fc 100644 --- a/tools/generate_packet_ids.py +++ b/tools/generate_packet_ids.py @@ -10,6 +10,11 @@ import argparse import json from pathlib import Path +try: + from . import lab +except ImportError: + import lab + ROOT = Path(__file__).resolve().parents[1] STATES = ["handshake", "status", "login", "configuration", "play"] DIRECTIONS = ["clientbound", "serverbound"] @@ -25,8 +30,9 @@ def main(): parser.add_argument("--out", type=Path, default=ROOT / "crates/horizon-protocol/src/ids.rs") args = parser.parse_args() report = json.loads(args.report.read_text()) + info = lab.version_info() lines = [ - "//! Packet ids per connection state and direction for protocol 777 (26.3).", + f"//! Packet ids per connection state and direction for protocol {info['protocol_version']} ({info['name']}).", "//! Generated by tools/generate_packet_ids.py from the data generator's", "//! packets report; do not edit by hand.", "#![allow(missing_docs)]", diff --git a/tools/graphics_bench.py b/tools/graphics_bench.py index 3de8be73a..202a5ea3c 100644 --- a/tools/graphics_bench.py +++ b/tools/graphics_bench.py @@ -25,6 +25,11 @@ import sys import time from pathlib import Path +try: + from . import lab +except ImportError: + import lab + ROOT = Path(__file__).resolve().parent.parent SEED = "1234" WORLD = "GraphicsBench" @@ -153,7 +158,7 @@ def main(): p.add_argument("--seconds", type=float, default=12.0, help="flight duration per scene") p.add_argument("--settle", type=float, default=2.0, help="seconds to wait before each flight") p.add_argument("--offscreen", action="store_true", help="render offscreen on the discrete GPU") - p.add_argument("--resources", default=str(ROOT / ".local/horizon-client/26.3")) + p.add_argument("--resources", default=str(lab.RESOURCES)) p.add_argument("--build", default=str(ROOT / "target/release")) p.add_argument("--out", help="JSON file (default benchmarks/graphics/