Merge branch 'parity/old-saves' (before its WIP commit) into parity-base

This commit is contained in:
Ludovic Marie
2026-10-12 17:55:17 +02:00
8 changed files with 1429 additions and 15 deletions
+1 -1
View File
@@ -130,7 +130,7 @@ pub fn upgrade_older_world(world: &Path) -> Result<()> {
}
if version < i64::from(horizon_world::datafix::OLDEST_SUPPORTED) {
return Err(format!(
"{} was saved with DataVersion {version}; worlds older than DataVersion {} (1.18.2) \
"{} was saved with DataVersion {version}; worlds older than DataVersion {} \
cannot be upgraded yet (tools/upgrade_world.py runs vanilla's own upgrader)",
world.display(),
horizon_world::datafix::OLDEST_SUPPORTED
@@ -239,3 +239,47 @@ pub fn namespaced(id: &str) -> String {
None => id.to_owned(),
}
}
/// `Dynamic.asLongStreamOpt` over `NbtOps`: a long array, or a list or array
/// whose elements are all numbers.
pub fn as_long_stream(tag: Option<&Tag>) -> Option<Vec<i64>> {
match tag? {
Tag::LongArray(v) => Some(v.clone()),
t if is_list(Some(t)) => stream(Some(t))
.iter()
.map(|e| as_number(e).map(Number::long_value))
.collect(),
_ => None,
}
}
/// `Dynamic.asIntStreamOpt` over `NbtOps`.
pub fn as_int_stream(tag: Option<&Tag>) -> Option<Vec<i32>> {
match tag? {
Tag::IntArray(v) => Some(v.clone()),
t if is_list(Some(t)) => stream(Some(t))
.iter()
.map(|e| as_number(e).map(Number::int_value))
.collect(),
_ => None,
}
}
/// `Dynamic.asByteBufferOpt` over `NbtOps`.
pub fn as_byte_buffer(tag: Option<&Tag>) -> Option<Vec<u8>> {
match tag? {
Tag::ByteArray(v) => Some(v.clone()),
t if is_list(Some(t)) => stream(Some(t))
.iter()
.map(|e| as_number(e).map(|n| n.byte_value() as u8))
.collect(),
_ => None,
}
}
/// `ChunkHeightAndBiomeFix.ceillog2` (`Math.ceil(Math.log(n) / Math.log(2))`,
/// which is exact for every palette size).
pub fn ceillog2(n: usize) -> u32 {
if n <= 1 {
0
} else {
usize::BITS - (n - 1).leading_zeros()
}
}
File diff suppressed because it is too large Load Diff
+5 -3
View File
@@ -14,6 +14,7 @@ pub mod files;
mod fixes_a;
mod fixes_b;
mod fixes_c;
mod fixes_cliffs;
mod fixes_old;
mod items;
pub mod json;
@@ -26,9 +27,9 @@ use schema::{Key, Ty, key, walk};
/// The DataVersion of the game.
pub const CURRENT: i32 = crate::DATA_VERSION;
/// Data saved before this DataVersion (1.18.2 is 2975) needs fixes that are not
/// ported (2967 and 2970, and everything before).
pub const OLDEST_SUPPORTED: i32 = 2970;
/// Data saved before this DataVersion (1.17 is 2724) needs fixes that are not
/// ported (2717 and everything before).
pub const OLDEST_SUPPORTED: i32 = 2724;
/// `Identifier.tryParse` validity, as `NamespacedSchema.ensureNamespaced` uses it.
pub fn identifier(id: &str) -> Option<(String, String)> {
@@ -176,6 +177,7 @@ type FixFn = fn(&mut Cx);
/// Every ported fix (from the 1.19 schemas on), in DataFixers order.
fn fixes() -> Vec<(Key, FixFn)> {
let mut out = Vec::new();
fixes_cliffs::register(&mut out);
fixes_old::register(&mut out);
fixes_a::register(&mut out);
fixes_b::register(&mut out);
+57 -1
View File
@@ -24,6 +24,8 @@ pub enum Ty {
DataComponents,
TextComponent,
VillagerTrade,
/// `UNTAGGED_SPAWNER`: the spawner fields of a spawner block entity or minecart.
UntaggedSpawner,
Particle,
BlockState,
FlatBlockState,
@@ -170,6 +172,11 @@ impl Walker<'_> {
self.list(Ty::Recipe, book, "toBeDisplayed");
}
}
Ty::Chunk if k < key(2842, 0) => {
if let Some(level) = v.get_mut("Level") {
self.level_chunk(level);
}
}
Ty::Chunk => {
self.list(Ty::EntityTree, v, "entities");
if let Some(Tag::List(items)) = v.get_mut("block_entities") {
@@ -201,6 +208,7 @@ impl Walker<'_> {
self.walk(Ty::Entity, v);
}
Ty::Entity => self.entity(v),
Ty::UntaggedSpawner => self.untagged_spawner(v),
Ty::BlockEntity => self.block_entity(v),
Ty::ItemStack => self.item_stack(v),
Ty::DataComponents => self.components(v),
@@ -450,8 +458,53 @@ impl Walker<'_> {
}
}
/// `UNTAGGED_SPAWNER` (V2831).
/// The `Level` of a chunk before 1.18 (V99, V1451_1, V1466, V2832).
fn level_chunk(&mut self, v: &mut Tag) {
let k = self.k;
self.list(Ty::EntityTree, v, "Entities");
if let Some(Tag::List(items)) = v.get_mut("TileEntities") {
for be in items {
if block_entity_known(be, k) {
self.walk(Ty::BlockEntity, be);
}
}
}
self.list_of_field(Ty::BlockName, v, "TileTicks", "i");
if let Some(Tag::List(sections)) = v.get_mut("Sections") {
for s in sections {
if k >= key(2832, 0) {
if let Some(b) = s.get_mut("biomes") {
self.list(Ty::Biome, b, "palette");
}
if let Some(b) = s.get_mut("block_states") {
self.list(Ty::BlockState, b, "palette");
}
} else if k >= key(1451, 1) {
self.list(Ty::BlockState, s, "Palette");
}
}
}
if k >= key(1466, 0)
&& let Some(s) = v.get_mut("Structures")
{
self.values(Ty::StructureFeature, s, "Starts");
}
}
fn spawner(&mut self, v: &mut Tag) {
self.walk(Ty::UntaggedSpawner, v);
}
/// `UNTAGGED_SPAWNER` (V106, V2831).
fn untagged_spawner(&mut self, v: &mut Tag) {
if self.k < key(106, 0) {
return;
}
if self.k < key(2831, 0) {
self.list_of_field(Ty::EntityTree, v, "SpawnPotentials", "Entity");
self.field(Ty::EntityTree, v, "SpawnData");
return;
}
if let Some(Tag::List(items)) = v.get_mut("SpawnPotentials") {
for p in items {
if let Some(d) = p.get_mut("data") {
@@ -739,6 +792,9 @@ impl Walker<'_> {
/// `WORLD_GEN_SETTINGS` (V2832).
fn world_gen(&mut self, v: &mut Tag) {
if self.k < key(2551, 0) {
return;
}
let Some(Tag::Compound(dims)) = v.get_mut("dimensions") else {
return;
};
+32
View File
@@ -18,5 +18,37 @@
"version": "0.7.1",
"url": "https://github.com/1013503897/jadx-headless-mcp/releases/download/v0.7.1/jadx-headless-mcp-0.7.1-all.jar",
"sha256": "6e5eacf500b64292bfb73c49797c1958f6ee44646e43e868039ae7feb573ff75"
},
"java_runtimes": {
"note": "Mojang's Java runtimes for the old server jars that make the datafix sample worlds (tools/datafix_worlds.py). A component a platform lacks falls back to java-runtime-gamma.",
"linux": {
"jre-legacy": {
"version": "8u202",
"manifest_url": "https://piston-meta.mojang.com/v1/packages/c529f68a6febc042e71835a579f44d55a3717c46/manifest.json",
"manifest_sha1": "c529f68a6febc042e71835a579f44d55a3717c46"
},
"java-runtime-alpha": {
"version": "16.0.1.9.1",
"manifest_url": "https://piston-meta.mojang.com/v1/packages/3bfc5fdcc28d8897aa12f372ea98a9afeb11a813/manifest.json",
"manifest_sha1": "3bfc5fdcc28d8897aa12f372ea98a9afeb11a813"
},
"java-runtime-beta": {
"version": "17.0.15",
"manifest_url": "https://piston-meta.mojang.com/v1/packages/4be835c1384c4bf1ebcb5c3bfe999ad2b1fe88ac/manifest.json",
"manifest_sha1": "4be835c1384c4bf1ebcb5c3bfe999ad2b1fe88ac"
},
"java-runtime-gamma": {
"version": "17.0.15",
"manifest_url": "https://piston-meta.mojang.com/v1/packages/71651340afda9fe593026fa7c56b1d9e2dbc1292/manifest.json",
"manifest_sha1": "71651340afda9fe593026fa7c56b1d9e2dbc1292"
}
},
"mac-os-arm64": {
"java-runtime-gamma": {
"version": "17.0.15",
"manifest_url": "https://piston-meta.mojang.com/v1/packages/e0c8d5ccfe8cfb38075ff1b7f6352d7b03fd7868/manifest.json",
"manifest_sha1": "e0c8d5ccfe8cfb38075ff1b7f6352d7b03fd7868"
}
}
}
}
+4
View File
@@ -232,6 +232,10 @@ def block_entities(e, version):
('structure_block', '{name:"x:y",posX:1,posY:2,posZ:3,sizeX:4,sizeY:5,sizeZ:6,mode:"SAVE"}'),
('skeleton_skull', '{}'),
]
if version < 2831: # 1.18: spawn data became weighted entries
out = [(b, '{SpawnData:{id:"minecraft:zombie",ArmorItems:[{},{},{},{id:"minecraft:iron_helmet",Count:1b}]},'
'SpawnPotentials:[{Weight:1,Entity:{id:"minecraft:skeleton"}}]}') if b == 'spawner' else (b, nbt)
for b, nbt in out]
if version >= 3682:
out.append(('crafter', '{Items:[{Slot:0b,id:"minecraft:stone",Count:1b}],triggered:1,crafting_ticks_remaining:2}'))
# Blocks the 1.20 experiment brought in 1.19.3 and 1.19.4.
+85 -10
View File
@@ -37,31 +37,106 @@ LOCAL = ROOT / '.local' / 'datafix'
# Old server jars and their worlds are inputs, not outputs: keep them beside the
# vanilla data, which parallel worktrees share (.local/minecraft links there).
SHARED = (ROOT / '.local' / 'minecraft').resolve().parent / 'datafix'
VERSIONS = ['1.18.2', '1.19', '1.19.2', '1.19.3', '1.19.4', '1.20.1', '1.20.2', '1.20.4', '1.20.5', '1.20.6', '1.21.1',
VERSIONS = ['1.17.1', '1.18.1', '1.18.2', '1.19', '1.19.2', '1.19.3', '1.19.4', '1.20.1', '1.20.2', '1.20.4', '1.20.5', '1.20.6', '1.21.1',
'1.21.3', '1.21.4', '1.21.5', '1.21.6', '1.21.8', '1.21.9', '1.21.10', '1.21.11', '26.1', '26.1.2', '26.2']
MANIFEST = 'https://piston-meta.mojang.com/mc/game/version_manifest_v2.json'
LOCK = json.loads((ROOT / 'research-lock.json').read_text())['java_runtimes']
BOT = 'Upgrader'
UUID_BASE = 0x6000
def server_jar(version):
path = SHARED / 'servers' / version / 'server.jar'
def version_meta(version):
path = SHARED / 'servers' / version / 'version.json'
if not path.exists():
path.parent.mkdir(parents=True, exist_ok=True)
manifest = json.load(urllib.request.urlopen(MANIFEST))
entry = next(v for v in manifest['versions'] if v['id'] == version)
meta = json.load(urllib.request.urlopen(entry['url']))
download = meta['downloads']['server']
data = urllib.request.urlopen(entry['url']).read()
if hashlib.sha1(data).hexdigest() != entry['sha1']:
sys.exit(f'{version}: version metadata checksum mismatch')
path.write_bytes(data)
return json.loads(path.read_text())
def server_jar(version):
"""The server jar, its DataVersion (None before 1.9: no DataVersion) and protocol."""
path = SHARED / 'servers' / version / 'server.jar'
if not path.exists():
path.parent.mkdir(parents=True, exist_ok=True)
download = version_meta(version)['downloads']['server']
data = urllib.request.urlopen(download['url']).read()
if hashlib.sha1(data).hexdigest() != download['sha1']:
sys.exit(f'{version}: server.jar checksum mismatch')
path.write_bytes(data)
info = json.loads(zipfile.ZipFile(path).read('version.json'))
return path, info['world_version'], info['protocol_version']
jar = zipfile.ZipFile(path)
if 'version.json' in jar.namelist():
info = json.loads(jar.read('version.json'))
return path, info['world_version'], info['protocol_version']
return path, OLD_VERSIONS[version][0], OLD_VERSIONS[version][1]
# DataVersion and protocol of servers whose jar has no version.json (before 1.14).
OLD_VERSIONS = {
'1.13.2': (1631, 404), '1.12.2': (1343, 340), '1.11.2': (922, 316), '1.10.2': (512, 210),
'1.9.4': (184, 110), '1.8.9': (None, 47),
}
def platform():
import platform as p
if sys.platform == 'darwin':
return 'mac-os-arm64' if p.machine() == 'arm64' else 'mac-os'
return 'linux'
def java(version):
"""The java executable for a server version: Mojang's runtime of the version's
component (pinned in research-lock.json), installed beside the shared data."""
meta = version_meta(version)
component = meta.get('javaVersion', {}).get('component', 'jre-legacy')
if component in ('java-runtime-delta', 'java-runtime-epsilon'):
return 'java' # 1.20.5 on: the JDK that runs 26.3 runs them
runtimes = LOCK[platform()]
if component not in runtimes:
component = 'java-runtime-gamma'
pin = runtimes[component]
home = SHARED / 'java' / f'{component}-{platform()}'
stamp = home / '.complete'
if not stamp.exists() or stamp.read_text() != pin['manifest_sha1']:
install_runtime(pin, home)
stamp.write_text(pin['manifest_sha1'])
exe = next(home.glob('**/bin/java'))
return str(exe)
def install_runtime(pin, home):
data = urllib.request.urlopen(pin['manifest_url']).read()
if hashlib.sha1(data).hexdigest() != pin['manifest_sha1']:
sys.exit(f'{pin["manifest_url"]}: checksum mismatch')
shutil.rmtree(home, ignore_errors=True)
links = []
for name, entry in sorted(json.loads(data)['files'].items()):
target = home / name
if entry['type'] == 'directory':
target.mkdir(parents=True, exist_ok=True)
elif entry['type'] == 'link':
links.append((target, entry['target']))
else:
raw = entry['downloads']['raw']
body = urllib.request.urlopen(raw['url']).read()
if hashlib.sha1(body).hexdigest() != raw['sha1']:
sys.exit(f'{name}: checksum mismatch')
target.parent.mkdir(parents=True, exist_ok=True)
target.write_bytes(body)
if entry.get('executable'):
target.chmod(0o755)
for target, to in links:
target.parent.mkdir(parents=True, exist_ok=True)
target.symlink_to(to)
class Server:
def __init__(self, directory, jar, port, packs=()):
def __init__(self, directory, jar, port, packs=(), java='java'):
directory.mkdir(parents=True, exist_ok=True)
(directory / 'eula.txt').write_text('eula=true\n')
props = {'server-port': port, 'online-mode': 'false', 'level-name': 'world', 'level-seed': '4242',
@@ -70,7 +145,7 @@ class Server:
if packs:
props['initial-enabled-packs'] = ','.join(['vanilla', *packs])
(directory / 'server.properties').write_text(''.join(f'{k}={v}\n' for k, v in props.items()))
self.process = subprocess.Popen(['java', '-Xmx2G', '-jar', str(jar), 'nogui'], cwd=directory,
self.process = subprocess.Popen([java, '-Xmx2G', '-jar', str(jar), 'nogui'], cwd=directory,
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
self.lines = []
self.queue = queue.Queue()
@@ -283,7 +358,7 @@ def build(version, force=False):
work = LOCAL / 'gen' / version
shutil.rmtree(work, ignore_errors=True)
port = 30000 + (os.getpid() + data_version) % 20000
server = Server(work, jar, port, scene.experiments(data_version))
server = Server(work, jar, port, scene.experiments(data_version), java(version))
problems = []
def run(command):