Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Allow loading mods from version-specified directory i.e. mods/rift/1.13/ #65

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ minecraft {

replace "@VERSION@", project.version
replaceIn "org/dimdev/riftloader/Main.java"

replace "@MCVERSION@", project.minecraft.version
replaceIn "org/dimdev/riftloader/RiftLoader.java"
}

mixin {
Expand Down
51 changes: 40 additions & 11 deletions src/main/java/org/dimdev/riftloader/RiftLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public class RiftLoader {
public static final RiftLoader instance = new RiftLoader();
private static final Logger log = LogManager.getLogger("RiftLoader");

public final File modsDir = new File(Launch.minecraftHome, "mods");
public File modsDir = new File(Launch.minecraftHome, "mods");
k-jiang marked this conversation as resolved.
Show resolved Hide resolved
public final File modsVersionSpecifiedDir = new File(Launch.minecraftHome, "mods/rift/@MCVERSION@");
k-jiang marked this conversation as resolved.
Show resolved Hide resolved
public final File modsRiftDir = new File(Launch.minecraftHome, "mods/rift");
k-jiang marked this conversation as resolved.
Show resolved Hide resolved
public final File configDir = new File(Launch.minecraftHome, "config");
private Side side;
private boolean loaded;
Expand All @@ -49,19 +51,32 @@ public void load(boolean isClient) {

side = isClient ? Side.CLIENT : Side.SERVER;

findMods(modsDir);
// load mods from classpath
findClasspathMods();
// test if mods/rift/"version"/ contains any .jar files, then load from it
if (modsVersionSpecifiedDir.exists() && modsVersionSpecifiedDir.isDirectory()) {
k-jiang marked this conversation as resolved.
Show resolved Hide resolved
// search and load mods from mods/rift/"version"/ if there are mods inside
for (File tempFile : modsVersionSpecifiedDir.listFiles()) {
if (tempFile.getName().toLowerCase().endsWith((".jar"))) {
findJarMods(modsVersionSpecifiedDir);
break;
}
}
}
// load mods from folder mods/rift/, create the folder if not exists
findJarMods(modsRiftDir,true);
k-jiang marked this conversation as resolved.
Show resolved Hide resolved
// load mods from mods/, create the folder if not exists
findJarMods(modsDir,true);
k-jiang marked this conversation as resolved.
Show resolved Hide resolved
sortMods();
initMods();
initAccessTransformer();
}

/**
* Looks for Rift mods (jars containing a 'riftmod.json' at their root) in
* the 'modsDir' directory (creating it if it doesn't exist) and loads them
* into the 'modInfoMap'.
**/
private void findMods(File modsDir) {
// Load classpath mods
* Load mods from classpath
*/
private void findClasspathMods() {
int modCount = modInfoMap.size();
log.info("Searching mods on classpath");
try {
Enumeration<URL> urls = ClassLoader.getSystemResources("riftmod.json");
Expand Down Expand Up @@ -94,9 +109,22 @@ private void findMods(File modsDir) {
throw new RuntimeException(e);
}

// Load jar mods
modCount = modInfoMap.size() - modCount;
log.info("Loaded " + modCount + " mods");
}

/**
* Looks for Rift mods (jars containing a 'riftmod.json' at their root) in
* the 'modsDir' directory (creating it if it doesn't exist) and loads them
* into the 'modInfoMap'.
**/
private void findJarMods(File modsDir) {
this.findJarMods(modsDir, false);
}
private void findJarMods(File modsDir, Boolean createDir) {
k-jiang marked this conversation as resolved.
Show resolved Hide resolved
int modCount = modInfoMap.size();
log.info("Searching for mods in " + modsDir);
modsDir.mkdirs();
if (createDir) modsDir.mkdirs();
k-jiang marked this conversation as resolved.
Show resolved Hide resolved
for (File file : modsDir.listFiles()) {
if (!file.getName().endsWith(".jar")) continue;
k-jiang marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -128,7 +156,8 @@ private void findMods(File modsDir) {
}
}

log.info("Loaded " + modInfoMap.size() + " mods");
modCount = modInfoMap.size() - modCount;
log.info("Loaded " + modCount + " mods");
}

private void loadModFromJson(InputStream in, File source) {
Expand Down