From 7946bfc2154586ca5faf13d99c0b40c0367a1b4b Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Tue, 14 Jan 2025 19:07:58 +0100 Subject: [PATCH] Split off mod construction and registry+config loading. Not sure it is necessary --- patches/net/minecraft/client/Minecraft.java.patch | 2 +- .../neoforge/client/loading/ClientModLoader.java | 12 ++++++++++-- .../neoforge/data/loading/DatagenModLoader.java | 1 + .../neoforged/neoforge/internal/CommonModLoader.java | 12 +++++++----- .../neoforge/server/loading/ServerModLoader.java | 1 + 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/patches/net/minecraft/client/Minecraft.java.patch b/patches/net/minecraft/client/Minecraft.java.patch index 30d5573d241..2d310b302eb 100644 --- a/patches/net/minecraft/client/Minecraft.java.patch +++ b/patches/net/minecraft/client/Minecraft.java.patch @@ -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); diff --git a/src/main/java/net/neoforged/neoforge/client/loading/ClientModLoader.java b/src/main/java/net/neoforged/neoforge/client/loading/ClientModLoader.java index 4ee4d48b270..d3e6e914a1d 100644 --- a/src/main/java/net/neoforged/neoforge/client/loading/ClientModLoader.java +++ b/src/main/java/net/neoforged/neoforge/client/loading/ClientModLoader.java @@ -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"); @@ -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)); diff --git a/src/main/java/net/neoforged/neoforge/data/loading/DatagenModLoader.java b/src/main/java/net/neoforged/neoforge/data/loading/DatagenModLoader.java index 6540788c64d..9241bfffc4f 100644 --- a/src/main/java/net/neoforged/neoforge/data/loading/DatagenModLoader.java +++ b/src/main/java/net/neoforged/neoforge/data/loading/DatagenModLoader.java @@ -43,6 +43,7 @@ public static void begin(final Set 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(); diff --git a/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java b/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java index 583a4cb5796..8c3931c8cfc 100644 --- a/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java +++ b/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java @@ -30,9 +30,9 @@ * Internal class for handling the steps of mod loading that are common for client, data and server runs. * *

*/ @ApiStatus.Internal @@ -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(); diff --git a/src/main/java/net/neoforged/neoforge/server/loading/ServerModLoader.java b/src/main/java/net/neoforged/neoforge/server/loading/ServerModLoader.java index 67820326016..37fe5199275 100644 --- a/src/main/java/net/neoforged/neoforge/server/loading/ServerModLoader.java +++ b/src/main/java/net/neoforged/neoforge/server/loading/ServerModLoader.java @@ -31,6 +31,7 @@ public static void load() { }); LanguageHook.loadBuiltinLanguages(); try { + constructMods(() -> {}); begin(() -> {}, false); load(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor()); finish(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor());