From 89a785dcff9f4230203c93bf4099d5fc9c261a0a Mon Sep 17 00:00:00 2001 From: Integer Limit <103940576+IntegerLimit@users.noreply.github.com> Date: Tue, 16 Jan 2024 22:32:10 +0800 Subject: [PATCH] Fix Data Fixers running on World Creation --- .../remap/datafixer/DataFixerHandler.java | 17 ++++++++++++++--- .../nomilabs/remap/datafixer/LabsFixes.java | 3 +++ 2 files changed, 17 insertions(+), 3 deletions(-) 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 beb90104..139f025b 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/DataFixerHandler.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/DataFixerHandler.java @@ -95,7 +95,7 @@ public static void onWorldLoad(SaveHandler save) { LabsFixes.init(); determineNeededFixesAndLog(save); if (neededFixes.isEmpty()) { - NomiLabs.LOGGER.info("This world does not need any data fixers, but it has no saved version or it is old."); + NomiLabs.LOGGER.info("This world does not need any data fixers, but it has no saved version, it is old, or this is a new world."); LabsWorldFixData.save(mapFile, DataFixerHandler.worldSavedData); return; } @@ -139,9 +139,13 @@ public static void onWorldLoad(SaveHandler save) { private static void determineNeededFixesAndLog(SaveHandler save) { neededFixes = new Object2ObjectOpenHashMap<>(); File levelDat = new File(save.getWorldDirectory(), "level.dat"); - if (!levelDat.exists()) { + + // If level.dat file does not exist, return. + // 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. + if (!levelDat.exists()) return; - } Map mods = new HashMap<>(); NBTTagList modList; @@ -163,6 +167,13 @@ private static void determineNeededFixesAndLog(SaveHandler save) { mods.put(compound.getString("ModId"), compound.getString("ModVersion")); } + // If Nomi Labs Version is same as current version, exit. + // 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. + if (mods.containsKey(LabsValues.LABS_MODID) && mods.get(LabsValues.LABS_MODID).equals(LabsValues.LABS_VERSION)) + return; + NomiLabs.LOGGER.info("NEEDED DATA FIXES: ----------------------------------------"); for (var fixType : LabsFixes.fixes.keySet()) { NomiLabs.LOGGER.info("SECTION: {} -------------------------------------------", fixType); 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 039fc960..bc43793b 100644 --- a/src/main/java/com/nomiceu/nomilabs/remap/datafixer/LabsFixes.java +++ b/src/main/java/com/nomiceu/nomilabs/remap/datafixer/LabsFixes.java @@ -23,6 +23,9 @@ /** * Definitions for all values, and all data fixes. + *

+ * No Data Fixes are loaded if the 'FIX_VERSION' is below the version saved in the world, or the Nomi Labs Version in world + * is the same as the current Nomi Labs Version. */ public class LabsFixes { /**