diff --git a/src/main/java/com/nomiceu/nomilabs/config/LabsVersionConfig.java b/src/main/java/com/nomiceu/nomilabs/config/LabsVersionConfig.java index dd189e56..b94c426f 100644 --- a/src/main/java/com/nomiceu/nomilabs/config/LabsVersionConfig.java +++ b/src/main/java/com/nomiceu/nomilabs/config/LabsVersionConfig.java @@ -16,6 +16,17 @@ public class LabsVersionConfig { @Config.RequiresMcRestart public static String formattedVersion = "v1.0.0"; + @Config.Comment({ + "Manual Fix Version. Increment this to have Data Fixers be POTENTIALLY applied.", + "Note that if a chunk or inventory is loaded on the same fix version multiple times, it will only be fixed the first time.", + "Note that no warning will be displayed before game load.", + "The data fix version itself will be this config + the Labs internal fix version.", + "[default: 0]" }) + @Config.LangKey("config.nomilabs.version.manual-fix-version") + @Config.RangeInt(min = 0) + @Config.RequiresMcRestart + public static int manualFixVersion = 0; + static { ConfigAnytime.register(LabsVersionConfig.class); } diff --git a/src/main/java/com/nomiceu/nomilabs/remap/LabsMessageHelper.java b/src/main/java/com/nomiceu/nomilabs/remap/LabsMessageHelper.java index b6020899..ba9ad6a3 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/LabsMessageHelper.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/LabsMessageHelper.java @@ -22,7 +22,6 @@ public enum MessageType { CONFIRM } - // Don't forget to update this in en_us.lang as well! public static class Components { public static String[] getIntro() { @@ -63,5 +62,12 @@ public static String[] getDoNotExit() { translate("nomilabs.fixer.do_not_revert.2") }; } + + public static String[] getInvalidManualVersion() { + return new String[] { + translate("nomilabs.fixer.invalid_manual_version.1"), + translate("nomilabs.fixer.invalid_manual_version.2") + }; + } } } diff --git a/src/main/java/com/nomiceu/nomilabs/remap/LabsRemapHelper.java b/src/main/java/com/nomiceu/nomilabs/remap/LabsRemapHelper.java index a7ab1127..3fd0b708 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/LabsRemapHelper.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/LabsRemapHelper.java @@ -13,7 +13,9 @@ import net.minecraftforge.fml.common.ZipperUtil; import com.nomiceu.nomilabs.NomiLabs; +import com.nomiceu.nomilabs.config.LabsVersionConfig; import com.nomiceu.nomilabs.remap.datafixer.DataFixerHandler; +import com.nomiceu.nomilabs.remap.datafixer.LabsFixes; import com.nomiceu.nomilabs.remap.datafixer.storage.BlockRewriter; import com.nomiceu.nomilabs.remap.datafixer.storage.BlockStateLike; import com.nomiceu.nomilabs.remap.datafixer.storage.CompoundRewriter; @@ -160,6 +162,15 @@ public static Map getPosToTileEntityMap(NBTTagCompound return posToTileEntityCache; } + /** + * This method gets the version which should be reported by all Labs Data Fixers. + *

+ * This combines the internal version with the config version, allowing for forced re-application. + */ + public static int getReportedVersion() { + return LabsFixes.CURRENT + LabsVersionConfig.manualFixVersion; + } + public static void abort() { DataFixerHandler.close(); StartupQuery.abort(); diff --git a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/DataFixerHandler.java b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/DataFixerHandler.java index 2ceef0cb..234d4ca8 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/DataFixerHandler.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/DataFixerHandler.java @@ -32,6 +32,7 @@ import com.nomiceu.nomilabs.LabsValues; import com.nomiceu.nomilabs.NomiLabs; +import com.nomiceu.nomilabs.config.LabsVersionConfig; import com.nomiceu.nomilabs.mixinhelper.RemappableForgeRegistry; import com.nomiceu.nomilabs.remap.LabsRemapHelper; import com.nomiceu.nomilabs.remap.datafixer.fixes.BlockFixer; @@ -88,7 +89,7 @@ public static void preInit() { fmlFixer.registerVanillaWalker(FixTypes.CHUNK, new ChunkWalker()); // Fixers - ModFixs fixs = fmlFixer.init(LabsValues.LABS_MODID, LabsFixes.CURRENT); + ModFixs fixs = fmlFixer.init(LabsValues.LABS_MODID, LabsRemapHelper.getReportedVersion()); fixs.registerFix(LabsFixTypes.FixerTypes.ITEM, new ItemFixer()); fixs.registerFix(LabsFixTypes.FixerTypes.CHUNK, new BlockFixer()); fixs.registerFix(LabsFixTypes.FixerTypes.TILE_ENTITY, new TileEntityFixer()); @@ -114,16 +115,39 @@ public static void onWorldLoad(SaveHandler save) { if (mapFile.exists()) { DataFixerHandler.worldSavedData = LabsWorldFixData.load(mapFile); - // Shortcut: If saved version == Current Version, Exit + // Check if manual fix version has been decremented + // This could break things, so throw an exception + if (LabsVersionConfig.manualFixVersion < DataFixerHandler.worldSavedData.savedManualFixVersion) { + NomiLabs.LOGGER.fatal("Manual Data Fix Version has been decremented. This is not supported!"); + sendMessage(MessageType.NOTIFY, Components.getInvalidManualVersion()); + LabsRemapHelper.abort(); + } + + // No need to increment version, the fix version, not the stored version, is saved + // Still need to call as otherwise it isn't actually changed + LabsWorldFixData.save(mapFile, DataFixerHandler.worldSavedData); + + // Shortcut: If saved version == Current Version, Exit (No NEW Fixes) if (DataFixerHandler.worldSavedData.savedFixVersion == LabsFixes.CURRENT) { + NomiLabs.LOGGER.info("This world's internal data version is up to date."); + + // Check only relevant if internal fix version hasn't changed + // Else, manual version increment doesn't matter + if (LabsVersionConfig.manualFixVersion != DataFixerHandler.worldSavedData.savedManualFixVersion) { + NomiLabs.LOGGER.info( + "The Manual Data Fix Version has been increased. New Version: {}. Enabling Data Fixers...", + LabsVersionConfig.manualFixVersion); + } + DataFixerHandler.worldSavedData = null; - NomiLabs.LOGGER.info("This world's data version is up to date."); return; } - NomiLabs.LOGGER.info("This world's data version needs updating. New Version: {}.", LabsFixes.CURRENT); + NomiLabs.LOGGER.info("This world's internal data version needs updating. New Version: {}.", + LabsFixes.CURRENT); } else { DataFixerHandler.worldSavedData = new LabsWorldFixData(); - NomiLabs.LOGGER.info("This world was saved without a data version. New Version: {}.", LabsFixes.CURRENT); + NomiLabs.LOGGER.info("This world was saved without a data version info. New Version: {}.", + LabsFixes.CURRENT); } determineNeededFixesAndLog(); @@ -152,10 +176,6 @@ public static void onWorldLoad(SaveHandler save) { checked = true; LabsRemapHelper.createWorldBackup(); - - // No need to increment version, the fix version, not the stored version, is saved - // Still need to call as otherwise it isn't actually changed - LabsWorldFixData.save(mapFile, DataFixerHandler.worldSavedData); } private static void getInfoFromSave(SaveHandler save) { @@ -199,6 +219,7 @@ private static void determineNeededFixesAndLog() { // This normally means it is a new world. // Sometimes the level.dat file is created first, but usually this runs after it is created. // If the level.dat file is created first, its mod list is equal to the current one. + // Regardless, NEW fixes are not required. if (LabsValues.LABS_VERSION.equals(savedLabsVersion)) return; diff --git a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/LabsFixes.java b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/LabsFixes.java index b46dafad..f595f142 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/LabsFixes.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/LabsFixes.java @@ -70,8 +70,9 @@ public class LabsFixes { public static final int NEW = Integer.MAX_VALUE; /** - * The current data format version. Increment this when breaking changes are made and the - * data mixer must be applied. If this is not incremented, nothing will be applied. + * The current data format version. Increment this when breaking changes are made and + * data fixers should be applied. If this is not incremented, nothing will be applied to loaded worlds and + * inventories. */ public static final int CURRENT = 4; diff --git a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/LabsWorldFixData.java b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/LabsWorldFixData.java index 85588a2f..c2fb2a26 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/LabsWorldFixData.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/LabsWorldFixData.java @@ -14,11 +14,13 @@ import com.nomiceu.nomilabs.NomiLabs; import com.nomiceu.nomilabs.config.LabsConfig; +import com.nomiceu.nomilabs.config.LabsVersionConfig; public class LabsWorldFixData extends WorldSavedData { - // Fix Version stored in this world. + // Fix Versions stored in this world. public int savedFixVersion; + public int savedManualFixVersion; // Base Data Key public static final String BASE_DATA_KEY = "data"; @@ -26,10 +28,16 @@ public class LabsWorldFixData extends WorldSavedData { // Key used to store fix version public static final String VERSION_KEY = "Version"; + // Key used to store manual fix version. Used for log status messages. + public static final String MANUAL_VERSION_KEY = "ManualVersion"; + public LabsWorldFixData() { super(LabsFixes.DATA_NAME); + if (LabsConfig.advanced.enableNomiCEuDataFixes) savedFixVersion = LabsFixes.DEFAULT_NOMI_CEU; else savedFixVersion = LabsFixes.DEFAULT; + + savedManualFixVersion = 0; } public void processSavedLabsVersion(String savedLabsVersion) { @@ -43,14 +51,23 @@ public void readFromNBT(NBTTagCompound nbt) { savedFixVersion = nbt.getInteger(VERSION_KEY); NomiLabs.LOGGER.info("This world was previously loaded with Fix Version {}.", savedFixVersion); } else - NomiLabs.LOGGER.info( + NomiLabs.LOGGER.warn( "This world was previously loaded without a saved Fix Version, possibly due to corruption, defaulting to {}.", savedFixVersion); + + if (nbt.hasKey(MANUAL_VERSION_KEY, Constants.NBT.TAG_ANY_NUMERIC)) { + savedManualFixVersion = nbt.getInteger(MANUAL_VERSION_KEY); + NomiLabs.LOGGER.info("This world was previously loaded with Manual Fix Version {}.", savedManualFixVersion); + } else + NomiLabs.LOGGER.info("This world was saved without a Manual Fix Version. Defaulting to {}.", + savedManualFixVersion); } @Override public @NotNull NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setInteger(VERSION_KEY, LabsFixes.CURRENT); // Save the current fix version, not the saved version + compound.setInteger(MANUAL_VERSION_KEY, LabsVersionConfig.manualFixVersion); // Save current manual fix version, + // not the saved manual version return compound; } diff --git a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/BlockFixer.java b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/BlockFixer.java index 506c4348..b3721ff9 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/BlockFixer.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/BlockFixer.java @@ -15,7 +15,7 @@ public class BlockFixer implements IFixableData { @Override public int getFixVersion() { - return LabsFixes.CURRENT; + return LabsRemapHelper.getReportedVersion(); } @Override diff --git a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/ItemFixer.java b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/ItemFixer.java index dd71daa7..4240cbea 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/ItemFixer.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/ItemFixer.java @@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull; import com.nomiceu.nomilabs.NomiLabs; +import com.nomiceu.nomilabs.remap.LabsRemapHelper; import com.nomiceu.nomilabs.remap.datafixer.DataFix; import com.nomiceu.nomilabs.remap.datafixer.LabsFixes; import com.nomiceu.nomilabs.remap.datafixer.storage.ItemStackLike; @@ -15,7 +16,7 @@ public class ItemFixer implements IFixableData { @Override public int getFixVersion() { - return LabsFixes.CURRENT; + return LabsRemapHelper.getReportedVersion(); } @Override diff --git a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/TileEntityFixer.java b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/TileEntityFixer.java index 0f5ec782..fbafd1de 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/TileEntityFixer.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/fixes/TileEntityFixer.java @@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull; import com.nomiceu.nomilabs.NomiLabs; +import com.nomiceu.nomilabs.remap.LabsRemapHelper; import com.nomiceu.nomilabs.remap.datafixer.DataFix; import com.nomiceu.nomilabs.remap.datafixer.LabsFixes; import com.nomiceu.nomilabs.remap.datafixer.types.LabsFixTypes; @@ -14,7 +15,7 @@ public class TileEntityFixer implements IFixableData { @Override public int getFixVersion() { - return LabsFixes.CURRENT; + return LabsRemapHelper.getReportedVersion(); } @Override diff --git a/src/main/resources/assets/nomilabs/lang/en_us.lang b/src/main/resources/assets/nomilabs/lang/en_us.lang index 889a9b86..4f50492c 100644 --- a/src/main/resources/assets/nomilabs/lang/en_us.lang +++ b/src/main/resources/assets/nomilabs/lang/en_us.lang @@ -13,6 +13,7 @@ nomilabs.tooltip=Normal Nomi Labs Configs nomilabs-version.tooltip=Nomi Labs Modpack Version Config config.nomilabs.version.formatted-version=Formatted Modpack Version +config.nomilabs.version.manual-fix-version=[ADVANCED] Manual Fix Version config.nomilabs.content=Content Settings config.nomilabs.content.tooltip=Content Settings @@ -163,6 +164,9 @@ nomilabs.fixer.mode_check.4=Press 'No' if you are not sure! (It will cancel worl nomilabs.fixer.do_not_exit.1=§cDo not interrupt the loading process!§r nomilabs.fixer.do_not_exit.2=If interrupted, load again from the backup, as your world may be corrupted! +nomilabs.fixer.invalid_manual_version.1=§cManual Fix Version has been Decremented!§r +nomilabs.fixer.invalid_manual_version.2=§cReport this to the Modpack Author!§r + # Commands nomilabs.command.gs_hand.material=Material ID: nomilabs.command.gs_hand.material_stack=Material Stack: