Skip to content

Commit

Permalink
Add IModListReadyCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n committed Apr 14, 2024
1 parent 1c8c324 commit 76b3c4d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions loader/src/main/java/net/neoforged/fml/IModListReadyCallback.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.neoforged.fml;

import java.util.ServiceLoader;

/**
* Callback invoked after {@link ModContainer}s are created and the {@link ModList} is populated,
* but before mods are constructed.
*
* <p>Instances are loaded via {@link ServiceLoader} from GAME and upper layers.
*/
@FunctionalInterface
public interface IModListReadyCallback {
void onModListReady(ModList modList);
}
7 changes: 7 additions & 0 deletions loader/src/main/java/net/neoforged/fml/ModLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.Executor;
Expand Down Expand Up @@ -189,6 +190,12 @@ public void gatherAndInitializeMods(final ModWorkManager.DrivenExecutor syncExec
modList.setLoadedMods(modContainers);
this.modList = modList;

runInitTask("Mod Initialization Callbacks", syncExecutor, periodicTask, () -> {
for (var callback : ServiceLoader.load(FMLLoader.getGameLayer(), IModListReadyCallback.class)) {
callback.onModListReady(modList);
}
});

constructMods(syncExecutor, parallelExecutor, periodicTask);
}

Expand Down

0 comments on commit 76b3c4d

Please sign in to comment.