Skip to content

Commit

Permalink
Migrate from installed_datapacks to datapacks fully
Browse files Browse the repository at this point in the history
  • Loading branch information
MacaylaMarvelous81 committed Aug 1, 2024
1 parent f1014d2 commit c81a0ab
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

@Environment(EnvType.CLIENT)
public class DatapackInstallerClient implements ClientModInitializer {
Expand All @@ -20,7 +21,17 @@ public class DatapackInstallerClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
File mainFile = MAIN_PATH.toFile();
if (!mainFile.exists() && !mainFile.mkdirs())
LOGGER.warn("User intervention recommended: default search path 'datapacks' could not be created.");
File legacyFile = LEGACY_PATH.toFile();
if (!mainFile.exists() && !legacyFile.exists() && legacyFile.isDirectory() && !mainFile.mkdirs())
LOGGER.warn("User intervention recommended: default search path 'datapacks' could not be created. Please create it manually.");

if (legacyFile.exists() && legacyFile.isDirectory()) {
try {
FileUtils.moveDirectory(legacyFile, mainFile);
LOGGER.info("Migrated from installed_datapacks to datapacks.");
} catch (IOException e) {
LOGGER.error("User intervention recommended: Failed to migrate from installed_datapacks to datapacks. Please move datapacks manually.", e);
}
}
}
}

0 comments on commit c81a0ab

Please sign in to comment.