-
-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to simpler mod loading from latest FML #774
Merged
Technici4n
merged 5 commits into
neoforged:port/1.20.5
from
Technici4n:redo-mod-loading
Apr 18, 2024
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f845000
Update to simpler mod loading from latest FML
Technici4n b9f899c
Remove @Internal on class, move to package
Technici4n fc71682
What if all the methods in ModLoader were static
Technici4n a501d2a
Bump FML again
Technici4n ec5b1f2
Move client-specific loading subtleties into ClientModLoader
Technici4n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.internal; | ||
|
||
import java.util.concurrent.Executor; | ||
import net.neoforged.api.distmarker.Dist; | ||
import net.neoforged.fml.ModList; | ||
import net.neoforged.fml.ModLoader; | ||
import net.neoforged.fml.ModWorkManager; | ||
import net.neoforged.fml.config.ConfigTracker; | ||
import net.neoforged.fml.config.ModConfig; | ||
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; | ||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; | ||
import net.neoforged.fml.event.lifecycle.FMLDedicatedServerSetupEvent; | ||
import net.neoforged.fml.event.lifecycle.FMLLoadCompleteEvent; | ||
import net.neoforged.fml.event.lifecycle.InterModEnqueueEvent; | ||
import net.neoforged.fml.event.lifecycle.InterModProcessEvent; | ||
import net.neoforged.fml.loading.FMLEnvironment; | ||
import net.neoforged.fml.loading.FMLPaths; | ||
import net.neoforged.neoforge.network.registration.NetworkRegistry; | ||
import net.neoforged.neoforge.registries.GameData; | ||
import net.neoforged.neoforge.registries.RegistryManager; | ||
|
||
/** | ||
* Internal class for handling the steps of mod loading that are common for client, data and server runs. | ||
*/ | ||
public abstract class CommonModLoader { | ||
private static boolean registriesLoaded = false; | ||
|
||
public static boolean areRegistriesLoaded() { | ||
return registriesLoaded; | ||
} | ||
|
||
protected static void begin(Runnable periodicTask) { | ||
var syncExecutor = ModWorkManager.syncExecutor(); | ||
|
||
ModLoader.get().gatherAndInitializeMods(syncExecutor, ModWorkManager.parallelExecutor(), periodicTask); | ||
Technici4n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
ModLoader.get().runInitTask("Registry initialization", syncExecutor, periodicTask, () -> { | ||
RegistryManager.postNewRegistryEvent(); | ||
GameData.unfreezeData(); | ||
GameData.postRegisterEvents(); | ||
GameData.freezeData(); | ||
registriesLoaded = true; | ||
}); | ||
} | ||
|
||
protected static void load(Executor syncExecutor, Executor parallelExecutor) { | ||
Technici4n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Runnable periodicTask = () -> {}; // no need to pass something else for now | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? |
||
|
||
if (!ModLoader.isLoadingStateValid()) { | ||
Technici4n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return; | ||
} | ||
|
||
ModLoader.get().runInitTask("Config loading", syncExecutor, periodicTask, () -> { | ||
if (FMLEnvironment.dist == Dist.CLIENT) { | ||
ConfigTracker.INSTANCE.loadConfigs(ModConfig.Type.CLIENT, FMLPaths.CONFIGDIR.get()); | ||
} | ||
ConfigTracker.INSTANCE.loadConfigs(ModConfig.Type.COMMON, FMLPaths.CONFIGDIR.get()); | ||
}); | ||
|
||
ModLoader.get().dispatchParallelEvent("Common setup", syncExecutor, parallelExecutor, periodicTask, FMLCommonSetupEvent::new); | ||
ModLoader.get().dispatchParallelEvent("Sided setup", syncExecutor, parallelExecutor, periodicTask, | ||
FMLEnvironment.dist.isClient() ? FMLClientSetupEvent::new : FMLDedicatedServerSetupEvent::new); | ||
|
||
ModLoader.get().runInitTask("Registration events", syncExecutor, periodicTask, RegistrationEvents::init); | ||
} | ||
|
||
protected static void finish(Executor syncExecutor, Executor parallelExecutor) { | ||
Technici4n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Runnable periodicTask = () -> {}; // no need to pass something else for now | ||
Technici4n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (!ModLoader.isLoadingStateValid()) { | ||
Technici4n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return; | ||
} | ||
|
||
ModLoader.get().dispatchParallelEvent("Enqueue IMC", syncExecutor, parallelExecutor, periodicTask, InterModEnqueueEvent::new); | ||
ModLoader.get().dispatchParallelEvent("Process IMC", syncExecutor, parallelExecutor, periodicTask, InterModProcessEvent::new); | ||
ModLoader.get().dispatchParallelEvent("Complete loading of %d mods".formatted(ModList.get().size()), syncExecutor, parallelExecutor, periodicTask, FMLLoadCompleteEvent::new); | ||
|
||
ModLoader.get().runInitTask("Network registry lock", syncExecutor, periodicTask, NetworkRegistry.getInstance()::setup); | ||
} | ||
} |
29 changes: 0 additions & 29 deletions
29
src/main/java/net/neoforged/neoforge/internal/NeoForgeStatesProvider.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/main/resources/META-INF/services/net.neoforged.fml.IModStateProvider
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment when this is called? Or when it should be called?
Especially to explain why we have
begin
andload
and why are they split?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a vague comment - the current separation is only an artifact of how we do part of the mod loading inside a reload listener (which introduces its own set of problems btw...). I don't really want to encode it because we have discussed a potential rework of the client mod init timings.