Skip to content

Commit

Permalink
Split off mod construction and registry+config loading. Not sure it i…
Browse files Browse the repository at this point in the history
…s necessary
  • Loading branch information
Technici4n committed Jan 14, 2025
1 parent d4e0484 commit 7946bfc
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion patches/net/minecraft/client/Minecraft.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
this.keyboardHandler = new KeyboardHandler(this);
- this.keyboardHandler.setup(this.window.getWindow());
RenderSystem.initRenderer(this.options.glDebugVerbosity, false);
+ net.neoforged.neoforge.client.loading.ClientModLoader.begin(this);
+ net.neoforged.neoforge.client.loading.ClientModLoader.constructMods(this);
+ net.neoforged.neoforge.client.ClientHooks.configureMainRenderTarget();
this.mainRenderTarget = new MainTarget(this.window.getWidth(), this.window.getHeight());
this.mainRenderTarget.setClearColor(0.0F, 0.0F, 0.0F, 0.0F);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class ClientModLoader extends CommonModLoader {
@Nullable
private static ModLoadingException error;

public static void begin(final Minecraft minecraft) {
public static void constructMods(Minecraft minecraft) {
// force log4j to shutdown logging in a shutdown hook. This is because we disable default shutdown hook so the server properly logs it's shutdown
Runtime.getRuntime().addShutdownHook(new Thread(LogManager::shutdown));
ImmediateWindowHandler.updateProgress("Loading mods");
Expand All @@ -56,13 +56,21 @@ public static void begin(final Minecraft minecraft) {
LogicalSidedProvider.setClient(() -> minecraft);
LanguageHook.loadBuiltinLanguages();
try {
begin(ImmediateWindowHandler::renderTick, false);
constructMods(ImmediateWindowHandler::renderTick);
} catch (ModLoadingException e) {
error = e;
}
}

public static void finish(final PackRepository defaultResourcePacks, final ReloadableResourceManager mcResourceManager) {
if (error == null) {
try {
begin(ImmediateWindowHandler::renderTick, false);
} catch (ModLoadingException e) {
error = e;
}
}

if (error == null) {
ResourcePackLoader.populatePackRepository(defaultResourcePacks, PackType.CLIENT_RESOURCES, false);
DataPackConfig.DEFAULT.addModPacks(ResourcePackLoader.getPackNames(PackType.SERVER_DATA));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static void begin(final Set<String> mods, final Path path, final Collecti
LOGGER.info("Initializing Data Gatherer for mods {}", mods);
runningDataGen = true;
Bootstrap.bootStrap();
constructMods(() -> {});
begin(() -> {}, true);
// Modify components as the (modified) defaults may be required in datagen, i.e. stack size
RegistrationEvents.modifyComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
* Internal class for handling the steps of mod loading that are common for client, data and server runs.
*
* <p><ul>
* <li>Client runs {@link #begin}, {@link #load} and {@link #finish} at different timings, see {@link ClientModLoader}.</li>
* <li>Server runs all 3 consecutively.</li>
* <li>Datagen only runs {@link #begin}.</li>
* <li>Client runs {@link #constructMods}, {@link #begin}, {@link #load} and {@link #finish} at different timings, see {@link ClientModLoader}.</li>
* <li>Server runs all 4 consecutively.</li>
* <li>Datagen only runs {@link #constructMods} and {@link #begin}.</li>
* </ul>
*/
@ApiStatus.Internal
Expand All @@ -43,11 +43,13 @@ public static boolean areRegistriesLoaded() {
return registriesLoaded;
}

protected static void constructMods(Runnable periodicTask) {
ModLoader.gatherAndInitializeMods(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor(), periodicTask);
}

protected static void begin(Runnable periodicTask, boolean datagen) {
var syncExecutor = ModWorkManager.syncExecutor();

ModLoader.gatherAndInitializeMods(syncExecutor, ModWorkManager.parallelExecutor(), periodicTask);

ModLoader.runInitTask("Registry initialization", syncExecutor, periodicTask, () -> {
RegistryManager.postNewRegistryEvent();
GameData.unfreezeData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static void load() {
});
LanguageHook.loadBuiltinLanguages();
try {
constructMods(() -> {});
begin(() -> {}, false);
load(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor());
finish(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor());
Expand Down

0 comments on commit 7946bfc

Please sign in to comment.