diff --git a/tools/test_upgrade_datapack_26.py b/tools/test_upgrade_datapack_26.py index 32cf1331..1613a354 100644 --- a/tools/test_upgrade_datapack_26.py +++ b/tools/test_upgrade_datapack_26.py @@ -11,6 +11,16 @@ spec.loader.exec_module(upgrade) class PackUpgradeTests(unittest.TestCase): + def test_26_2_preserves_native_legacy_spawn_table(self): + source = {'effects': {'sky_color': 8364543}, 'creature_spawn_probability': 0.07, + 'spawners': {'creature': [], 'monster': [ + {'type': 'minecraft:stray', 'minCount': 1, 'maxCount': 4, 'weight': 80}]}, 'spawn_costs': {}} + result = upgrade.convert_biome(source, '26.2') + self.assertEqual(result['spawners'], source['spawners']) + self.assertEqual(result['creature_spawn_probability'], 0.07) + self.assertNotIn('minecraft:gameplay/natural_mob_spawns', result['attributes']) + self.assertEqual(result['attributes']['minecraft:visual/sky_color'], '#7fa1ff') + def test_keeps_planet_features_and_empty_spawn_categories(self): source = {'features': [['minecraft:ore_coal_upper']], 'temperature': -0.5, 'effects': {'sky_color': 8364543, 'water_color': 4159204}, diff --git a/tools/upgrade-datapack-26.py b/tools/upgrade-datapack-26.py index a89a0e49..f4ad51c7 100644 --- a/tools/upgrade-datapack-26.py +++ b/tools/upgrade-datapack-26.py @@ -1,4 +1,4 @@ -"""Convert the deployed Dune biome packs to Minecraft 26.3 without touching chunks. +"""Convert the deployed Dune biome packs to Minecraft 26.2/26.3 without touching chunks. Uses the 26.3 native biome attribute format. Writes a separate deterministic ZIP; the caller must stage/load it before replacing a production datapack. @@ -14,7 +14,9 @@ def color(value): return f'#{value:06x}' if isinstance(value, int) else value -def convert_biome(original): +def convert_biome(original, target='26.3'): + if target not in ('26.2', '26.3'): + raise ValueError('Unsupported target version') biome = copy.deepcopy(original) attributes = biome.setdefault('attributes', {}) effects = biome.setdefault('effects', {}) @@ -48,9 +50,9 @@ def convert_biome(original): attributes['minecraft:visual/ambient_particles'] = {'argument': [ {'particle': particle['options'], 'probability': particle['probability']} ], 'modifier': 'append'} - if 'creature_spawn_probability' in biome: + if target == '26.3' and 'creature_spawn_probability' in biome: attributes['minecraft:gameplay/creature_world_gen_spawn_probability'] = biome.pop('creature_spawn_probability') - if 'spawners' in biome: + if target == '26.3' and 'spawners' in biome: categories = {} for category, entries in biome.pop('spawners').items(): categories[category] = [] @@ -71,7 +73,9 @@ def convert_biome(original): return biome -def convert_pack(source, destination): +def convert_pack(source, destination, target='26.3'): + if target not in ('26.2', '26.3'): + raise ValueError('Unsupported target version') source, destination = Path(source), Path(destination) if source.resolve() == destination.resolve() or destination.exists(): raise ValueError('Use a new destination; source packs must remain intact') @@ -83,10 +87,11 @@ def convert_pack(source, destination): meta = json.loads(data) for key in ('pack_format', 'supported_formats'): meta['pack'].pop(key, None) - meta['pack'].update(min_format=[121, 0], max_format=[121, 0]) + version = [107, 1] if target == '26.2' else [121, 0] + meta['pack'].update(min_format=version, max_format=version) data = (json.dumps(meta, indent=2) + '\n').encode() elif '/worldgen/biome/' in name and '/tags/' not in name and name.endswith('.json'): - data = (json.dumps(convert_biome(json.loads(data)), indent=2) + '\n').encode() + data = (json.dumps(convert_biome(json.loads(data), target), indent=2) + '\n').encode() changed.append(name) info = zipfile.ZipInfo(name, date_time=(2026, 1, 1, 0, 0, 0)) info.compress_type = zipfile.ZIP_DEFLATED @@ -98,5 +103,6 @@ if __name__ == '__main__': parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('source') parser.add_argument('destination') + parser.add_argument('--target', choices=['26.2', '26.3'], default='26.3') args = parser.parse_args() - print(json.dumps({'convertedBiomes': convert_pack(args.source, args.destination)})) + print(json.dumps({'convertedBiomes': convert_pack(args.source, args.destination, args.target)}))