1ec6f0f928
The vanilla differential run showed Horizon writing fields vanilla leaves out: empty scoreboard parts, recipe book settings at their default, an empty warden anger list. These are now omitted, and mobs loaded without saved equipment no longer receive the default bow. Opening a world whose level.dat is older than 26.3 now fails with a message naming tools/upgrade_world.py, which runs vanilla's own forceUpgrade on a copy. The roundtrip harness lists the timing-dependent differences it tolerates, and horizon-ctl waits up to five minutes for the control socket on a loaded machine. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
54 lines
2.0 KiB
Python
Executable File
54 lines
2.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Upgrade a world saved by an older Minecraft version to the 26.3 DataVersion.
|
|
|
|
Horizon reads chunks only at the current DataVersion and has not ported the
|
|
DataFixerUpper chain. This runs vanilla's own upgrader (`server.jar --forceUpgrade
|
|
--eraseCache`) on a copy of the world, so every fix vanilla applies (chunk, entity, POI,
|
|
level.dat, player and data/*.dat files) is applied exactly. The original is kept.
|
|
|
|
upgrade_world.py SOURCE_WORLD DEST_WORLD
|
|
"""
|
|
import random
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
SERVER = ROOT / '.local' / 'minecraft' / '26.3' / 'jars' / 'server.jar'
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) != 3:
|
|
sys.exit(__doc__)
|
|
source, dest = Path(sys.argv[1]), Path(sys.argv[2])
|
|
if not (source / 'level.dat').is_file():
|
|
sys.exit(f'{source} is not a world (no level.dat)')
|
|
if dest.exists():
|
|
sys.exit(f'{dest} exists already')
|
|
with tempfile.TemporaryDirectory(prefix='hzupgrade') as scratch:
|
|
scratch = Path(scratch)
|
|
(scratch / 'eula.txt').write_text('eula=true\n')
|
|
(scratch / 'server.properties').write_text(
|
|
f'level-name=world\nonline-mode=false\nserver-port={random.randint(30000, 60000)}\n')
|
|
shutil.copytree(source, scratch / 'world')
|
|
# The server upgrades at startup, then keeps running as a normal server: stop it
|
|
# once it reports "Done".
|
|
server = subprocess.Popen(
|
|
['java', '-jar', str(SERVER), '--nogui', '--forceUpgrade', '--eraseCache'],
|
|
cwd=scratch, stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True)
|
|
for line in server.stdout:
|
|
sys.stdout.write(line)
|
|
if 'Done (' in line:
|
|
server.stdin.write('stop\n')
|
|
server.stdin.flush()
|
|
if server.wait():
|
|
sys.exit('vanilla upgrade failed')
|
|
shutil.move(str(scratch / 'world'), str(dest))
|
|
print(f'upgraded world written to {dest}')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|