Skip to content

Commit

Permalink
Fix Data Fixers running on World Creation
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Jan 16, 2024
1 parent 5cd1f0a commit 89a785d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<String, String> mods = new HashMap<>();
NBTTagList modList;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

/**
* Definitions for all values, and all data fixes.
* <p>
* 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 {
/**
Expand Down

0 comments on commit 89a785d

Please sign in to comment.