Package net.mezzdev.config.api.migration


@NullMarked package net.mezzdev.config.api.migration
Import settings and persistent sort orders from files that a mod used before adopting MezzConfig.

Declare the destination values, then register the old file locations and a parser on the schema builder:


 IConfigRegistration registration = Configs.forMod("example");
 IConfigSchemaBuilder schema = registration.createClientSchemaBuilder("example.ini", "config.example");
 IConfigValue<Boolean> enabled = schema.addCategory("general")
     .addBoolean("enabled", true)
     .build();

 schema.setLegacyMigration(List.of(oldConfigPath), (path, migration) -> {
     List<String> oldLines = Files.readAllLines(path);
     migration.set(enabled, oldLines.contains("enabled=true"));
 });
 schema.build();
 
The parser only needs to understand the old format. MezzConfig backs up the source, validates all migrated values, and writes its current format without exposing that format to the mod.

To load a MezzConfig file from an older location, use IConfigSchemaBuilder.setLegacySources(List). To rename, move, or convert a value while importing that legacy source, use the legacy methods on IConfigValueBuilder.