Files
horizon-airdef/tools/vanilla_world_check.py
T
Ludovic Marie 94539db425 Light with vanilla shape occlusion and incremental relighting
Port LightEngine.shapeOccludes / getFaceOcclusionShape (occlusion.nbt) so
slabs, stairs, snow layers, paths etc. block light directionally, and use
ChunkSkyLightSources.isEdgeOccluded for sky sources. Block light now rises
into the section above the highest occupied one.

Block edits on lit chunks are relit in place with vanilla's decrease and
increase passes instead of recomputing the 3x3 chunks (and remeshing every
section of them); edits that race a chunk light job are replayed onto it.

examples/light_parity compares Horizon light with the SkyLight/BlockLight
arrays of worlds saved by the vanilla 26.3 server (0 differences on
villages, outposts and a slab/stair/snow scene; 181 of 113M sky values
differ where vanilla's worldgen light is stale) and checks incremental
relighting against full relights. tools/vanilla_world_check.py runs the
vanilla server headless; tools/anvil_dump.py prints NBT and region chunks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 15:25:41 +02:00

99 lines
3.7 KiB
Python

#!/usr/bin/env python3
"""Run the vanilla 26.3 dedicated server headless on a world folder, optionally
send console commands (`sleep SECONDS` pauses between them), then stop it cleanly and report problems from its log.
vanilla_world_check.py --jar server.jar --dir RUN_DIR [--world NAME]
[--seed N] [--port P] [--command CMD ...]
[--wait-after SECONDS]
RUN_DIR receives eula.txt, server.properties and logs/. An existing
RUN_DIR/NAME world is opened as is (this is how Horizon saves are checked); a
missing one is generated by vanilla (this is how reference worlds are made).
Exit status 1 when the log contains errors, upgrade/datafix work or chunk
load failures.
"""
import argparse
import os
import re
import subprocess
import sys
import threading
import time
SUSPICIOUS = re.compile(
r'(ERROR|Exception|Couldn\'t load|Failed to|Skipping|Invalid|Unknown|corrupt|'
r'Recreating|upgrad|DataFix|out of bounds|missing|Mismatch)', re.IGNORECASE)
# Benign lines the server prints on every start.
BENIGN = re.compile(r'(OFFLINE/INSECURE|online-mode|authenticate usernames|hackers|'
r'Failed to load properties|Failed to load eula)')
def main():
p = argparse.ArgumentParser()
p.add_argument('--jar', required=True)
p.add_argument('--dir', required=True)
p.add_argument('--world', default='world')
p.add_argument('--seed', default='12345')
p.add_argument('--port', default='25671')
p.add_argument('--command', action='append', default=[])
p.add_argument('--wait-after', type=float, default=1.0)
p.add_argument('--timeout', type=float, default=240)
args = p.parse_args()
os.makedirs(args.dir, exist_ok=True)
with open(os.path.join(args.dir, 'eula.txt'), 'w') as f:
f.write('eula=true\n')
props = {
'server-port': args.port, 'online-mode': 'false', 'level-seed': args.seed,
'level-name': args.world, 'spawn-protection': '0', 'view-distance': '4',
'simulation-distance': '4', 'sync-chunk-writes': 'true', 'enable-query': 'false',
'enable-rcon': 'false', 'management-server-enabled': 'false',
'pause-when-empty-seconds': '-1',
}
with open(os.path.join(args.dir, 'server.properties'), 'w') as f:
f.writelines(f'{k}={v}\n' for k, v in props.items())
proc = subprocess.Popen(
['java', '-Xmx2G', '-jar', os.path.abspath(args.jar), '--nogui'], cwd=args.dir,
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
lines = []
done = threading.Event()
def pump():
for line in proc.stdout:
lines.append(line.rstrip('\n'))
if 'Done (' in line:
done.set()
done.set()
threading.Thread(target=pump, daemon=True).start()
if not done.wait(args.timeout) or proc.poll() is not None:
proc.kill()
print('\n'.join(lines))
print('server did not start', file=sys.stderr)
return 1
for command in args.command:
if command.startswith('sleep '):
time.sleep(float(command.split()[1]))
continue
proc.stdin.write(command + '\n')
proc.stdin.flush()
time.sleep(0.5)
time.sleep(args.wait_after)
proc.stdin.write('stop\n')
proc.stdin.flush()
try:
proc.wait(args.timeout)
except subprocess.TimeoutExpired:
proc.kill()
time.sleep(0.2)
problems = [l for l in lines if SUSPICIOUS.search(l) and not BENIGN.search(l)]
with open(os.path.join(args.dir, 'check.log'), 'w') as f:
f.write('\n'.join(lines) + '\n')
for l in problems:
print(l)
print(f'{len(lines)} log lines, {len(problems)} suspicious')
return 1 if problems else 0
if __name__ == '__main__':
sys.exit(main())