From f84500016a43540472a1ac2c64074ecedb413dec Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Wed, 3 Apr 2024 10:50:16 +0200 Subject: [PATCH 1/5] Update to simpler mod loading from latest FML --- gradle.properties | 4 +- .../client/renderer/Sheets.java.patch | 2 +- .../neoforge/client/gui/ModListScreen.java | 3 +- .../client/loading/ClientModLoader.java | 17 ++-- .../neoforge/common/NeoForgeMod.java | 4 +- .../data/loading/DatagenModLoader.java | 6 +- .../neoforge/internal/CommonModLoader.java | 87 +++++++++++++++++++ .../internal/NeoForgeStatesProvider.java | 29 ------- .../neoforge/resource/ResourcePackLoader.java | 5 +- .../server/loading/ServerModLoader.java | 9 +- .../net.neoforged.fml.IModStateProvider | 1 - .../resources/assets/neoforge/lang/en_us.json | 2 +- 12 files changed, 112 insertions(+), 57 deletions(-) create mode 100644 src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java delete mode 100644 src/main/java/net/neoforged/neoforge/internal/NeoForgeStatesProvider.java delete mode 100644 src/main/resources/META-INF/services/net.neoforged.fml.IModStateProvider diff --git a/gradle.properties b/gradle.properties index 8fdd95951f..fc20ce68d7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,7 +19,7 @@ accesstransformers_version=10.0.1 coremods_version=6.0.4 eventbus_version=7.2.0 modlauncher_version=10.1.10 -securejarhandler_version=2.1.24 +securejarhandler_version=2.1.31 bootstraplauncher_version=1.1.2 asm_version=9.5 installer_version=2.1.+ @@ -31,7 +31,7 @@ jetbrains_annotations_version=24.0.1 slf4j_api_version=2.0.7 apache_maven_artifact_version=3.8.5 jarjar_version=0.4.0 -fancy_mod_loader_version=3.0.10 +fancy_mod_loader_version=3.0.12 mojang_logging_version=1.1.1 log4j_version=2.22.1 guava_version=31.1.2-jre diff --git a/patches/net/minecraft/client/renderer/Sheets.java.patch b/patches/net/minecraft/client/renderer/Sheets.java.patch index ca6cb16d0b..7674619fae 100644 --- a/patches/net/minecraft/client/renderer/Sheets.java.patch +++ b/patches/net/minecraft/client/renderer/Sheets.java.patch @@ -32,7 +32,7 @@ + } + + static { -+ if (net.neoforged.fml.ModLoader.isLoadingStateValid() && !net.neoforged.fml.ModLoader.get().hasCompletedState("LOAD_REGISTRIES")) { ++ if (net.neoforged.fml.ModLoader.isLoadingStateValid() && !net.neoforged.neoforge.internal.CommonModLoader.areRegistriesLoaded()) { + com.mojang.logging.LogUtils.getLogger().error( + "net.minecraft.client.renderer.Sheets loaded too early, modded registry-based materials may not work correctly", + new IllegalStateException("net.minecraft.client.renderer.Sheets loaded too early") diff --git a/src/main/java/net/neoforged/neoforge/client/gui/ModListScreen.java b/src/main/java/net/neoforged/neoforge/client/gui/ModListScreen.java index 43280faedc..47ff4ecf1a 100644 --- a/src/main/java/net/neoforged/neoforge/client/gui/ModListScreen.java +++ b/src/main/java/net/neoforged/neoforge/client/gui/ModListScreen.java @@ -40,7 +40,6 @@ import net.minecraft.server.packs.repository.PackSource; import net.minecraft.server.packs.resources.IoSupplier; import net.minecraft.util.FormattedCharSequence; -import net.neoforged.fml.ModContainer; import net.neoforged.fml.ModList; import net.neoforged.fml.VersionChecker; import net.neoforged.fml.loading.FMLPaths; @@ -402,7 +401,7 @@ public void upload() { lines.add(I18nExtension.getDisplayName(selectedMod)); lines.add(I18nExtension.parseMessage("fml.menu.mods.info.version", MavenVersionStringHelper.artifactVersionToString(selectedMod.getVersion()))); - lines.add(I18nExtension.parseMessage("fml.menu.mods.info.idstate", selectedMod.getModId(), ModList.get().getModContainerById(selectedMod.getModId()).map(ModContainer::getCurrentState).map(Object::toString).orElse("NONE"))); + lines.add(I18nExtension.parseMessage("fml.menu.mods.info.idstate", selectedMod.getModId(), "LOADED")); // TODO: remove mod loading stages from here too selectedMod.getConfig().getConfigElement("credits").ifPresent(credits -> lines.add(I18nExtension.parseMessage("fml.menu.mods.info.credits", credits))); selectedMod.getConfig().getConfigElement("authors").ifPresent(authors -> lines.add(I18nExtension.parseMessage("fml.menu.mods.info.authors", authors))); 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 8bee7f4f37..d2fa6114af 100644 --- a/src/main/java/net/neoforged/neoforge/client/loading/ClientModLoader.java +++ b/src/main/java/net/neoforged/neoforge/client/loading/ClientModLoader.java @@ -31,6 +31,7 @@ import net.neoforged.neoforge.common.NeoForgeConfig; import net.neoforged.neoforge.common.util.LogicalSidedProvider; import net.neoforged.neoforge.internal.BrandingControl; +import net.neoforged.neoforge.internal.CommonModLoader; import net.neoforged.neoforge.logging.CrashReportExtender; import net.neoforged.neoforge.resource.ResourcePackLoader; import net.neoforged.neoforge.server.LanguageHook; @@ -38,7 +39,7 @@ import org.apache.logging.log4j.Logger; @OnlyIn(Dist.CLIENT) -public class ClientModLoader { +public class ClientModLoader extends CommonModLoader { private static final Logger LOGGER = LogManager.getLogger(); private static boolean loading; private static Minecraft mc; @@ -53,7 +54,7 @@ public static void begin(final Minecraft minecraft, final PackRepository default ClientModLoader.mc = minecraft; LogicalSidedProvider.setClient(() -> minecraft); LanguageHook.loadBuiltinLanguages(); - createRunnableWithCatch(() -> ModLoader.get().gatherAndInitializeMods(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor(), ImmediateWindowHandler::renderTick)).run(); + createRunnableWithCatch(() -> begin(ImmediateWindowHandler::renderTick)).run(); if (error == null) { ResourcePackLoader.populatePackRepository(defaultResourcePacks, PackType.CLIENT_RESOURCES); DataPackConfig.DEFAULT.addModPacks(ResourcePackLoader.getDataPackNames()); @@ -63,9 +64,9 @@ public static void begin(final Minecraft minecraft, final PackRepository default } private static CompletableFuture onResourceReload(final PreparableReloadListener.PreparationBarrier stage, final ResourceManager resourceManager, final ProfilerFiller prepareProfiler, final ProfilerFiller executeProfiler, final Executor asyncExecutor, final Executor syncExecutor) { - return CompletableFuture.runAsync(createRunnableWithCatch(() -> startModLoading(ModWorkManager.wrappedExecutor(syncExecutor), asyncExecutor)), ModWorkManager.parallelExecutor()) + return CompletableFuture.runAsync(createRunnableWithCatch(() -> startModLoading(syncExecutor, asyncExecutor)), ModWorkManager.parallelExecutor()) .thenCompose(stage::wait) - .thenRunAsync(() -> finishModLoading(ModWorkManager.wrappedExecutor(syncExecutor), asyncExecutor), ModWorkManager.parallelExecutor()); + .thenRunAsync(() -> finishModLoading(syncExecutor, asyncExecutor), ModWorkManager.parallelExecutor()); } private static Runnable createRunnableWithCatch(Runnable r) { @@ -79,12 +80,12 @@ private static Runnable createRunnableWithCatch(Runnable r) { }; } - private static void startModLoading(ModWorkManager.DrivenExecutor syncExecutor, Executor parallelExecutor) { - createRunnableWithCatch(() -> ModLoader.get().loadMods(syncExecutor, parallelExecutor, ImmediateWindowHandler::renderTick)).run(); + private static void startModLoading(Executor syncExecutor, Executor parallelExecutor) { + createRunnableWithCatch(() -> load(syncExecutor, parallelExecutor)).run(); } - private static void finishModLoading(ModWorkManager.DrivenExecutor syncExecutor, Executor parallelExecutor) { - createRunnableWithCatch(() -> ModLoader.get().finishMods(syncExecutor, parallelExecutor, ImmediateWindowHandler::renderTick)).run(); + private static void finishModLoading(Executor syncExecutor, Executor parallelExecutor) { + createRunnableWithCatch(() -> finish(syncExecutor, parallelExecutor)).run(); loading = false; loadingComplete = true; // reload game settings on main thread diff --git a/src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java b/src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java index 6495e3ad58..c74c079c8f 100644 --- a/src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java +++ b/src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java @@ -84,7 +84,6 @@ import net.neoforged.fml.CrashReportCallables; import net.neoforged.fml.ModContainer; import net.neoforged.fml.ModLoader; -import net.neoforged.fml.ModLoadingStage; import net.neoforged.fml.ModLoadingWarning; import net.neoforged.fml.StartupMessageManager; import net.neoforged.fml.VersionChecker; @@ -615,8 +614,7 @@ public NeoForgeMod(IEventBus modEventBus, Dist dist, ModContainer container) { if (isPRBuild(container.getModInfo().getVersion().toString())) { isPRBuild = true; ModLoader.get().addWarning(new ModLoadingWarning( - container.getModInfo(), ModLoadingStage.CONSTRUCT, - "loadwarning.neoforge.prbuild")); + container.getModInfo(), "loadwarning.neoforge.prbuild")); } } 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 f93630b021..e5fcbcd1c3 100644 --- a/src/main/java/net/neoforged/neoforge/data/loading/DatagenModLoader.java +++ b/src/main/java/net/neoforged/neoforge/data/loading/DatagenModLoader.java @@ -15,14 +15,14 @@ import net.minecraft.data.registries.VanillaRegistries; import net.minecraft.server.Bootstrap; import net.neoforged.fml.ModLoader; -import net.neoforged.fml.ModWorkManager; import net.neoforged.neoforge.client.ClientHooks; import net.neoforged.neoforge.common.data.ExistingFileHelper; import net.neoforged.neoforge.data.event.GatherDataEvent; +import net.neoforged.neoforge.internal.CommonModLoader; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -public class DatagenModLoader { +public class DatagenModLoader extends CommonModLoader { private static final Logger LOGGER = LogManager.getLogger(); private static GatherDataEvent.DataGeneratorConfig dataGeneratorConfig; private static ExistingFileHelper existingFileHelper; @@ -40,7 +40,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(); - ModLoader.get().gatherAndInitializeMods(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor(), () -> {}); + begin(() -> {}); CompletableFuture lookupProvider = CompletableFuture.supplyAsync(VanillaRegistries::createLookup, Util.backgroundExecutor()); dataGeneratorConfig = new GatherDataEvent.DataGeneratorConfig(mods, path, inputs, lookupProvider, serverGenerators, clientGenerators, devToolGenerators, reportsGenerator, structureValidator, flat); diff --git a/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java b/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java new file mode 100644 index 0000000000..3f1f3d0813 --- /dev/null +++ b/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java @@ -0,0 +1,87 @@ +/* + * 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; +import org.jetbrains.annotations.ApiStatus; + +/** + * Internal class for handling the steps of mod loading that are common for client, data and server runs. + */ +@ApiStatus.Internal +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); + + 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) { + Runnable periodicTask = () -> {}; // no need to pass something else for now + + if (!ModLoader.isLoadingStateValid()) { + 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) { + Runnable periodicTask = () -> {}; // no need to pass something else for now + + if (!ModLoader.isLoadingStateValid()) { + 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); + } +} diff --git a/src/main/java/net/neoforged/neoforge/internal/NeoForgeStatesProvider.java b/src/main/java/net/neoforged/neoforge/internal/NeoForgeStatesProvider.java deleted file mode 100644 index 50806aaca0..0000000000 --- a/src/main/java/net/neoforged/neoforge/internal/NeoForgeStatesProvider.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) Forge Development LLC and contributors - * SPDX-License-Identifier: LGPL-2.1-only - */ - -package net.neoforged.neoforge.internal; - -import java.util.List; -import net.neoforged.fml.IModLoadingState; -import net.neoforged.fml.IModStateProvider; -import net.neoforged.fml.ModLoadingPhase; -import net.neoforged.fml.ModLoadingState; -import net.neoforged.neoforge.network.registration.NetworkRegistry; -import net.neoforged.neoforge.registries.GameData; -import net.neoforged.neoforge.registries.RegistryManager; - -public class NeoForgeStatesProvider implements IModStateProvider { - final ModLoadingState CREATE_REGISTRIES = ModLoadingState.withInline("CREATE_REGISTRIES", "CONSTRUCT", ModLoadingPhase.GATHER, ml -> RegistryManager.postNewRegistryEvent()); - final ModLoadingState UNFREEZE = ModLoadingState.withInline("UNFREEZE_DATA", "CREATE_REGISTRIES", ModLoadingPhase.GATHER, ml -> GameData.unfreezeData()); - final ModLoadingState LOAD_REGISTRIES = ModLoadingState.withInline("LOAD_REGISTRIES", "UNFREEZE_DATA", ModLoadingPhase.GATHER, ml -> GameData.postRegisterEvents()); - final ModLoadingState FREEZE = ModLoadingState.withInline("FREEZE_DATA", "LOAD_REGISTRIES", ModLoadingPhase.GATHER, ml -> GameData.freezeData()); - final ModLoadingState REGISTRATION_EVENTS = ModLoadingState.withInline("REGISTRATION_EVENTS", "SIDED_SETUP", ModLoadingPhase.LOAD, ml -> RegistrationEvents.init()); - final ModLoadingState NETLOCK = ModLoadingState.withInline("NETWORK_LOCK", "COMPLETE", ModLoadingPhase.COMPLETE, ml -> NetworkRegistry.getInstance().setup()); - - @Override - public List getAllStates() { - return List.of(CREATE_REGISTRIES, UNFREEZE, LOAD_REGISTRIES, FREEZE, REGISTRATION_EVENTS, NETLOCK); - } -} diff --git a/src/main/java/net/neoforged/neoforge/resource/ResourcePackLoader.java b/src/main/java/net/neoforged/neoforge/resource/ResourcePackLoader.java index e4297e2730..45300f20f1 100644 --- a/src/main/java/net/neoforged/neoforge/resource/ResourcePackLoader.java +++ b/src/main/java/net/neoforged/neoforge/resource/ResourcePackLoader.java @@ -42,7 +42,6 @@ import net.minecraft.world.flag.FeatureFlagSet; import net.neoforged.fml.ModList; import net.neoforged.fml.ModLoader; -import net.neoforged.fml.ModLoadingStage; import net.neoforged.fml.ModLoadingWarning; import net.neoforged.neoforge.event.AddPackFindersEvent; import net.neoforged.neoforgespi.language.IModFileInfo; @@ -117,7 +116,7 @@ private static void packFinder(Map modResource MOD_PACK_SELECTION_CONFIG); if (modPack == null) { - ModLoader.get().addWarning(new ModLoadingWarning(mod, ModLoadingStage.ERROR, "fml.modloading.brokenresources", e.getKey())); + ModLoader.get().addWarning(new ModLoadingWarning(mod, "fml.modloading.brokenresources", e.getKey())); continue; } } else { @@ -135,7 +134,7 @@ private static void packFinder(Map modResource } } catch (IOException exception) { LOGGER.error("Failed to read pack.mcmeta file of mod {}", mod.getModId(), exception); - ModLoader.get().addWarning(new ModLoadingWarning(mod, ModLoadingStage.ERROR, "fml.modloading.brokenresources", e.getKey())); + ModLoader.get().addWarning(new ModLoadingWarning(mod, "fml.modloading.brokenresources", e.getKey())); } } 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 64584ce067..b261b4a217 100644 --- a/src/main/java/net/neoforged/neoforge/server/loading/ServerModLoader.java +++ b/src/main/java/net/neoforged/neoforge/server/loading/ServerModLoader.java @@ -14,12 +14,13 @@ import net.neoforged.fml.ModWorkManager; import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.common.util.LogicalSidedProvider; +import net.neoforged.neoforge.internal.CommonModLoader; import net.neoforged.neoforge.logging.CrashReportExtender; import net.neoforged.neoforge.server.LanguageHook; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -public class ServerModLoader { +public class ServerModLoader extends CommonModLoader { private static final Logger LOGGER = LogManager.getLogger(); private static boolean hasErrors = false; @@ -29,9 +30,9 @@ public static void load() { }); LanguageHook.loadBuiltinLanguages(); try { - ModLoader.get().gatherAndInitializeMods(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor(), () -> {}); - ModLoader.get().loadMods(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor(), () -> {}); - ModLoader.get().finishMods(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor(), () -> {}); + begin(() -> {}); + load(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor()); + finish(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor()); } catch (LoadingFailedException error) { ServerModLoader.hasErrors = true; // In case its not loaded properly diff --git a/src/main/resources/META-INF/services/net.neoforged.fml.IModStateProvider b/src/main/resources/META-INF/services/net.neoforged.fml.IModStateProvider deleted file mode 100644 index 5b6e0aae27..0000000000 --- a/src/main/resources/META-INF/services/net.neoforged.fml.IModStateProvider +++ /dev/null @@ -1 +0,0 @@ -net.neoforged.neoforge.internal.NeoForgeStatesProvider \ No newline at end of file diff --git a/src/main/resources/assets/neoforge/lang/en_us.json b/src/main/resources/assets/neoforge/lang/en_us.json index 42215556b7..3061fd53fc 100644 --- a/src/main/resources/assets/neoforge/lang/en_us.json +++ b/src/main/resources/assets/neoforge/lang/en_us.json @@ -65,7 +65,7 @@ "fml.modloading.failedtoloadmod":"{0,modinfo,name} ({0,modinfo,id}) has failed to load correctly\n\u00a77{2,exc,msg}", "fml.modloading.feature.missing": "{0,modinfo,name} ({0,modinfo,id}) is missing a feature it requires to run\n§7It requires {3,featurebound} but {4} is available", "fml.modloading.uncaughterror":"An uncaught parallel processing error has occurred.\n\u00a77{2,exc,msg}", - "fml.modloading.errorduringevent":"{0,modinfo,name} ({0,modinfo,id}) encountered an error during the {1,lower} event phase\n\u00a77{2,exc,msg}", + "fml.modloading.errorduringevent":"{0,modinfo,name} ({0,modinfo,id}) encountered an error while dispatching the {3} event\n\u00a77{2,exc,msg}", "fml.modloading.failedtoloadforge": "Failed to load NeoForge", "fml.modloading.missingdependency": "Mod \u00a7e{4}\u00a7r requires \u00a76{3}\u00a7r \u00a7o{5,vr}\u00a7r\n\u00a77Currently, \u00a76{3}\u00a7r\u00a77 is \u00a7o{6,i18n,fml.messages.artifactversion.ornotinstalled}§r\n{7,optional,§7Reason for the dependency: §r}", From b9f899c6501daa76f83f256eba44aa9f0903d034 Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Tue, 16 Apr 2024 23:56:02 +0200 Subject: [PATCH 2/5] Remove @Internal on class, move to package --- .../java/net/neoforged/neoforge/internal/CommonModLoader.java | 2 -- src/main/java/net/neoforged/neoforge/internal/package-info.java | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java b/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java index 3f1f3d0813..6d808f9312 100644 --- a/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java +++ b/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java @@ -23,12 +23,10 @@ import net.neoforged.neoforge.network.registration.NetworkRegistry; import net.neoforged.neoforge.registries.GameData; import net.neoforged.neoforge.registries.RegistryManager; -import org.jetbrains.annotations.ApiStatus; /** * Internal class for handling the steps of mod loading that are common for client, data and server runs. */ -@ApiStatus.Internal public abstract class CommonModLoader { private static boolean registriesLoaded = false; diff --git a/src/main/java/net/neoforged/neoforge/internal/package-info.java b/src/main/java/net/neoforged/neoforge/internal/package-info.java index fc06ff11ba..ae3fcf96ab 100644 --- a/src/main/java/net/neoforged/neoforge/internal/package-info.java +++ b/src/main/java/net/neoforged/neoforge/internal/package-info.java @@ -3,6 +3,7 @@ * SPDX-License-Identifier: LGPL-2.1-only */ +@ApiStatus.Internal @FieldsAreNonnullByDefault @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault @@ -11,3 +12,4 @@ import javax.annotation.ParametersAreNonnullByDefault; import net.minecraft.FieldsAreNonnullByDefault; import net.minecraft.MethodsReturnNonnullByDefault; +import org.jetbrains.annotations.ApiStatus; From fc71682f6afbc3bbe7b4a6447c731b73882674f0 Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Wed, 17 Apr 2024 21:38:57 +0200 Subject: [PATCH 3/5] What if all the methods in ModLoader were static --- gradle.properties | 2 +- .../net/minecraft/client/Minecraft.java.patch | 2 +- .../client/gui/screens/MenuScreens.java.patch | 2 +- .../client/renderer/GameRenderer.java.patch | 2 +- .../client/renderer/RenderBuffers.java.patch | 2 +- .../blockentity/SkullBlockRenderer.java.patch | 2 +- .../entity/EntityRenderDispatcher.java.patch | 2 +- .../client/sounds/SoundEngine.java.patch | 4 +-- .../minecraft/data/DataGenerator.java.patch | 2 +- ...ConfigurationPacketListenerImpl.java.patch | 2 +- .../world/entity/SpawnPlacements.java.patch | 2 +- .../capabilities/CapabilityHooks.java | 2 +- .../neoforge/client/ClientHooks.java | 24 +++++++------- .../neoforge/client/ColorResolverManager.java | 2 +- .../DimensionSpecialEffectsManager.java | 2 +- .../client/EntitySpectatorShaderManager.java | 2 +- .../neoforge/client/ItemDecoratorHandler.java | 2 +- .../client/NamedRenderTypeManager.java | 2 +- .../neoforge/client/PresetEditorManager.java | 2 +- .../neoforge/client/RecipeBookManager.java | 2 +- .../gui/ClientTooltipComponentManager.java | 2 +- .../neoforge/client/gui/GuiLayerManager.java | 2 +- .../client/loading/ClientModLoader.java | 2 +- .../loading/NeoForgeLoadingOverlay.java | 4 +-- .../model/geometry/GeometryLoaderManager.java | 2 +- .../neoforge/common/CommonHooks.java | 6 ++-- .../neoforge/common/NeoForgeMod.java | 6 ++-- .../world/chunk/ForcedChunkManager.java | 2 +- .../data/loading/DatagenModLoader.java | 2 +- .../neoforged/neoforge/event/EventHooks.java | 2 +- .../neoforge/fluids/CauldronFluidContent.java | 2 +- .../neoforge/gametest/GameTestHooks.java | 2 +- .../neoforge/internal/CommonModLoader.java | 31 ++++++++++++------- .../network/registration/NetworkRegistry.java | 2 +- .../neoforge/registries/GameData.java | 6 ++-- .../neoforge/registries/RegistryManager.java | 8 ++--- .../neoforge/resource/ResourcePackLoader.java | 6 ++-- .../server/loading/ServerModLoader.java | 2 +- 38 files changed, 80 insertions(+), 73 deletions(-) diff --git a/gradle.properties b/gradle.properties index fc20ce68d7..30230f2402 100644 --- a/gradle.properties +++ b/gradle.properties @@ -31,7 +31,7 @@ jetbrains_annotations_version=24.0.1 slf4j_api_version=2.0.7 apache_maven_artifact_version=3.8.5 jarjar_version=0.4.0 -fancy_mod_loader_version=3.0.12 +fancy_mod_loader_version=3.0.13-more-simplifications mojang_logging_version=1.1.1 log4j_version=2.22.1 guava_version=31.1.2-jre diff --git a/patches/net/minecraft/client/Minecraft.java.patch b/patches/net/minecraft/client/Minecraft.java.patch index cd75754134..c27cc26834 100644 --- a/patches/net/minecraft/client/Minecraft.java.patch +++ b/patches/net/minecraft/client/Minecraft.java.patch @@ -47,7 +47,7 @@ this.gameRenderer = new GameRenderer(this, this.entityRenderDispatcher.getItemInHandRenderer(), this.resourceManager, this.renderBuffers); this.resourceManager.registerReloadListener(this.gameRenderer.createReloadListener()); this.levelRenderer = new LevelRenderer(this, this.entityRenderDispatcher, this.blockEntityRenderDispatcher, this.renderBuffers); -+ net.neoforged.fml.ModLoader.get().postEvent(new net.neoforged.neoforge.client.event.RenderLevelStageEvent.RegisterStageEvent()); ++ net.neoforged.fml.ModLoader.postEvent(new net.neoforged.neoforge.client.event.RenderLevelStageEvent.RegisterStageEvent()); this.resourceManager.registerReloadListener(this.levelRenderer); - this.createSearchTrees(); + // Forge: We delay this to allow registration of modded creative mode tabs diff --git a/patches/net/minecraft/client/gui/screens/MenuScreens.java.patch b/patches/net/minecraft/client/gui/screens/MenuScreens.java.patch index 263138b9c6..abcbfe3c8b 100644 --- a/patches/net/minecraft/client/gui/screens/MenuScreens.java.patch +++ b/patches/net/minecraft/client/gui/screens/MenuScreens.java.patch @@ -40,7 +40,7 @@ + @org.jetbrains.annotations.ApiStatus.Internal + public static void init() { + var event = new net.neoforged.neoforge.client.event.RegisterMenuScreensEvent(SCREENS); -+ net.neoforged.fml.ModLoader.get().postEvent(event); ++ net.neoforged.fml.ModLoader.postEvent(event); } public static boolean selfTest() { diff --git a/patches/net/minecraft/client/renderer/GameRenderer.java.patch b/patches/net/minecraft/client/renderer/GameRenderer.java.patch index c30ee6326a..68dc3755c1 100644 --- a/patches/net/minecraft/client/renderer/GameRenderer.java.patch +++ b/patches/net/minecraft/client/renderer/GameRenderer.java.patch @@ -13,7 +13,7 @@ ) ); this.loadBlurEffect(p_250719_); -+ net.neoforged.fml.ModLoader.get().postEvent(new net.neoforged.neoforge.client.event.RegisterShadersEvent(p_250719_, list1)); ++ net.neoforged.fml.ModLoader.postEvent(new net.neoforged.neoforge.client.event.RegisterShadersEvent(p_250719_, list1)); } catch (IOException ioexception) { list1.forEach(p_172729_ -> p_172729_.getFirst().close()); throw new RuntimeException("could not reload shaders", ioexception); diff --git a/patches/net/minecraft/client/renderer/RenderBuffers.java.patch b/patches/net/minecraft/client/renderer/RenderBuffers.java.patch index adca81edd3..7f0e742c9e 100644 --- a/patches/net/minecraft/client/renderer/RenderBuffers.java.patch +++ b/patches/net/minecraft/client/renderer/RenderBuffers.java.patch @@ -4,7 +4,7 @@ put((Object2ObjectLinkedOpenHashMap)p_307112_, RenderType.waterMask()); ModelBakery.DESTROY_TYPES.forEach(p_173062_ -> put(p_307112_, p_173062_)); }); -+ net.neoforged.fml.ModLoader.get().postEvent(new net.neoforged.neoforge.client.event.RegisterRenderBuffersEvent(sortedmap)); ++ net.neoforged.fml.ModLoader.postEvent(new net.neoforged.neoforge.client.event.RegisterRenderBuffersEvent(sortedmap)); this.crumblingBufferSource = MultiBufferSource.immediate(new BufferBuilder(1536)); this.bufferSource = MultiBufferSource.immediateWithBuffers(sortedmap, new BufferBuilder(786432)); this.outlineBufferSource = new OutlineBufferSource(this.bufferSource); diff --git a/patches/net/minecraft/client/renderer/blockentity/SkullBlockRenderer.java.patch b/patches/net/minecraft/client/renderer/blockentity/SkullBlockRenderer.java.patch index 5e9bc751fd..d738262caa 100644 --- a/patches/net/minecraft/client/renderer/blockentity/SkullBlockRenderer.java.patch +++ b/patches/net/minecraft/client/renderer/blockentity/SkullBlockRenderer.java.patch @@ -4,7 +4,7 @@ builder.put(SkullBlock.Types.CREEPER, new SkullModel(p_173662_.bakeLayer(ModelLayers.CREEPER_HEAD))); builder.put(SkullBlock.Types.DRAGON, new DragonHeadModel(p_173662_.bakeLayer(ModelLayers.DRAGON_SKULL))); builder.put(SkullBlock.Types.PIGLIN, new PiglinHeadModel(p_173662_.bakeLayer(ModelLayers.PIGLIN_HEAD))); -+ net.neoforged.fml.ModLoader.get().postEvent(new net.neoforged.neoforge.client.event.EntityRenderersEvent.CreateSkullModels(builder, p_173662_)); ++ net.neoforged.fml.ModLoader.postEvent(new net.neoforged.neoforge.client.event.EntityRenderersEvent.CreateSkullModels(builder, p_173662_)); return builder.build(); } diff --git a/patches/net/minecraft/client/renderer/entity/EntityRenderDispatcher.java.patch b/patches/net/minecraft/client/renderer/entity/EntityRenderDispatcher.java.patch index d9e6dd714c..42d3c4ed65 100644 --- a/patches/net/minecraft/client/renderer/entity/EntityRenderDispatcher.java.patch +++ b/patches/net/minecraft/client/renderer/entity/EntityRenderDispatcher.java.patch @@ -30,6 +30,6 @@ ); this.renderers = EntityRenderers.createEntityRenderers(entityrendererprovider$context); this.playerRenderers = EntityRenderers.createPlayerRenderers(entityrendererprovider$context); -+ net.neoforged.fml.ModLoader.get().postEvent(new net.neoforged.neoforge.client.event.EntityRenderersEvent.AddLayers(renderers, playerRenderers, entityrendererprovider$context)); ++ net.neoforged.fml.ModLoader.postEvent(new net.neoforged.neoforge.client.event.EntityRenderersEvent.AddLayers(renderers, playerRenderers, entityrendererprovider$context)); } } diff --git a/patches/net/minecraft/client/sounds/SoundEngine.java.patch b/patches/net/minecraft/client/sounds/SoundEngine.java.patch index a83a19e45a..29678b9899 100644 --- a/patches/net/minecraft/client/sounds/SoundEngine.java.patch +++ b/patches/net/minecraft/client/sounds/SoundEngine.java.patch @@ -4,7 +4,7 @@ this.soundManager = p_120236_; this.options = p_120237_; this.soundBuffers = new SoundBufferLibrary(p_249332_); -+ net.neoforged.fml.ModLoader.get().postEvent(new net.neoforged.neoforge.client.event.sound.SoundEngineLoadEvent(this)); ++ net.neoforged.fml.ModLoader.postEvent(new net.neoforged.neoforge.client.event.sound.SoundEngineLoadEvent(this)); } public void reload() { @@ -12,7 +12,7 @@ this.destroy(); this.loadLibrary(); -+ net.neoforged.fml.ModLoader.get().postEvent(new net.neoforged.neoforge.client.event.sound.SoundEngineLoadEvent(this)); ++ net.neoforged.fml.ModLoader.postEvent(new net.neoforged.neoforge.client.event.sound.SoundEngineLoadEvent(this)); } private synchronized void loadLibrary() { diff --git a/patches/net/minecraft/data/DataGenerator.java.patch b/patches/net/minecraft/data/DataGenerator.java.patch index a7b2da7f75..b1a6783a18 100644 --- a/patches/net/minecraft/data/DataGenerator.java.patch +++ b/patches/net/minecraft/data/DataGenerator.java.patch @@ -12,7 +12,7 @@ LOGGER.debug("Generator {} already run for version {}", p_254418_, this.version.getName()); } else { LOGGER.info("Starting provider: {}", p_254418_); -+ net.neoforged.fml.StartupMessageManager.addModMessage("Generating: " + p_254418_); ++ net.neoforged.fml.loading.progress.StartupNotificationManager.addModMessage("Generating: " + p_254418_); stopwatch1.start(); hashcache.applyUpdate(hashcache.generateUpdate(p_254418_, p_253750_::run).join()); stopwatch1.stop(); diff --git a/patches/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java.patch b/patches/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java.patch index 303a11b867..eab9fa6d4a 100644 --- a/patches/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java.patch +++ b/patches/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java.patch @@ -36,7 +36,7 @@ this.server.getServerResourcePack().ifPresent(p_296496_ -> this.configurationTasks.add(new ServerResourcePackConfigurationTask(p_296496_))); + + this.configurationTasks.add(new net.neoforged.neoforge.network.configuration.ModdedConfigurationPhaseStarted(this)); -+ this.configurationTasks.addAll(net.neoforged.fml.ModLoader.get().postEventWithReturn(new net.neoforged.neoforge.network.event.OnGameConfigurationEvent(this)).getConfigurationTasks()); ++ this.configurationTasks.addAll(net.neoforged.fml.ModLoader.postEventWithReturn(new net.neoforged.neoforge.network.event.OnGameConfigurationEvent(this)).getConfigurationTasks()); + this.configurationTasks.add(new net.neoforged.neoforge.network.configuration.ModdedConfigurationPhaseCompleted(this)); + } + diff --git a/patches/net/minecraft/world/entity/SpawnPlacements.java.patch b/patches/net/minecraft/world/entity/SpawnPlacements.java.patch index c4572c7570..95abc9f52c 100644 --- a/patches/net/minecraft/world/entity/SpawnPlacements.java.patch +++ b/patches/net/minecraft/world/entity/SpawnPlacements.java.patch @@ -29,7 +29,7 @@ + { + Map, net.neoforged.neoforge.event.entity.SpawnPlacementRegisterEvent.MergedSpawnPredicate> map = Maps.newHashMap(); + DATA_BY_TYPE.forEach((type, data) -> map.put(type, new net.neoforged.neoforge.event.entity.SpawnPlacementRegisterEvent.MergedSpawnPredicate<>(data.predicate, data.placement, data.heightMap))); -+ net.neoforged.fml.ModLoader.get().postEvent(new net.neoforged.neoforge.event.entity.SpawnPlacementRegisterEvent(map)); ++ net.neoforged.fml.ModLoader.postEvent(new net.neoforged.neoforge.event.entity.SpawnPlacementRegisterEvent(map)); + map.forEach(((entityType, merged) -> DATA_BY_TYPE.put(entityType, new SpawnPlacements.Data(merged.getHeightmapType(), merged.getSpawnType(), merged.build())))); } } diff --git a/src/main/java/net/neoforged/neoforge/capabilities/CapabilityHooks.java b/src/main/java/net/neoforged/neoforge/capabilities/CapabilityHooks.java index 2da0f3734c..7f9869a35e 100644 --- a/src/main/java/net/neoforged/neoforge/capabilities/CapabilityHooks.java +++ b/src/main/java/net/neoforged/neoforge/capabilities/CapabilityHooks.java @@ -45,7 +45,7 @@ public static void init() { initialized = true; var event = new RegisterCapabilitiesEvent(); - ModLoader.get().postEventWrapContainerInModOrder(event); + ModLoader.postEventWrapContainerInModOrder(event); initFinished = true; } diff --git a/src/main/java/net/neoforged/neoforge/client/ClientHooks.java b/src/main/java/net/neoforged/neoforge/client/ClientHooks.java index 7987900a03..91332c5fbf 100644 --- a/src/main/java/net/neoforged/neoforge/client/ClientHooks.java +++ b/src/main/java/net/neoforged/neoforge/client/ClientHooks.java @@ -281,15 +281,15 @@ public static boolean renderSpecificFirstPersonArm(PoseStack poseStack, MultiBuf } public static void onTextureAtlasStitched(TextureAtlas atlas) { - ModLoader.get().postEvent(new TextureAtlasStitchedEvent(atlas)); + ModLoader.postEvent(new TextureAtlasStitchedEvent(atlas)); } public static void onBlockColorsInit(BlockColors blockColors) { - ModLoader.get().postEvent(new RegisterColorHandlersEvent.Block(blockColors)); + ModLoader.postEvent(new RegisterColorHandlersEvent.Block(blockColors)); } public static void onItemColorsInit(ItemColors itemColors, BlockColors blockColors) { - ModLoader.get().postEvent(new RegisterColorHandlersEvent.Item(itemColors, blockColors)); + ModLoader.postEvent(new RegisterColorHandlersEvent.Item(itemColors, blockColors)); } public static Model getArmorModel(LivingEntity entityLiving, ItemStack itemStack, EquipmentSlot slot, HumanoidModel _default) { @@ -440,11 +440,11 @@ public static void onModifyBakingResult(Map models LOGGER.warn("Failed to retrieve texture '{}' from atlas '{}'", material.texture(), material.atlasLocation(), new Throwable()); return stitchResult.missing(); }; - ModLoader.get().postEvent(new ModelEvent.ModifyBakingResult(models, textureGetter, modelBakery)); + ModLoader.postEvent(new ModelEvent.ModifyBakingResult(models, textureGetter, modelBakery)); } public static void onModelBake(ModelManager modelManager, Map models, ModelBakery modelBakery) { - ModLoader.get().postEvent(new ModelEvent.BakingCompleted(modelManager, Collections.unmodifiableMap(models), modelBakery)); + ModLoader.postEvent(new ModelEvent.BakingCompleted(modelManager, Collections.unmodifiableMap(models), modelBakery)); } public static BakedModel handleCameraTransforms(PoseStack poseStack, BakedModel model, ItemDisplayContext cameraTransformType, boolean applyLeftHandTransform) { @@ -706,15 +706,15 @@ public static void firePlayerRespawn(MultiPlayerGameMode pc, LocalPlayer oldPlay } public static void onRegisterParticleProviders(ParticleEngine particleEngine) { - ModLoader.get().postEvent(new RegisterParticleProvidersEvent(particleEngine)); + ModLoader.postEvent(new RegisterParticleProvidersEvent(particleEngine)); } public static void onRegisterKeyMappings(Options options) { - ModLoader.get().postEvent(new RegisterKeyMappingsEvent(options)); + ModLoader.postEvent(new RegisterKeyMappingsEvent(options)); } public static void onRegisterAdditionalModels(Set additionalModels) { - ModLoader.get().postEvent(new ModelEvent.RegisterAdditional(additionalModels)); + ModLoader.postEvent(new ModelEvent.RegisterAdditional(additionalModels)); } @Nullable @@ -909,7 +909,7 @@ public static BiMap makeSpriteSourceTypesMap @ApiStatus.Internal public static void registerSpriteSourceTypes() { - ModLoader.get().postEvent(new RegisterSpriteSourceTypesEvent(SPRITE_SOURCE_TYPES_MAP)); + ModLoader.postEvent(new RegisterSpriteSourceTypesEvent(SPRITE_SOURCE_TYPES_MAP)); } @ApiStatus.Internal @@ -992,9 +992,9 @@ public static void initClientHooks(Minecraft mc, ReloadableResourceManager resou GameTestHooks.registerGametests(); registerSpriteSourceTypes(); MenuScreens.init(); - ModLoader.get().postEvent(new RegisterClientReloadListenersEvent(resourceManager)); - ModLoader.get().postEvent(new EntityRenderersEvent.RegisterLayerDefinitions()); - ModLoader.get().postEvent(new EntityRenderersEvent.RegisterRenderers()); + ModLoader.postEvent(new RegisterClientReloadListenersEvent(resourceManager)); + ModLoader.postEvent(new EntityRenderersEvent.RegisterLayerDefinitions()); + ModLoader.postEvent(new EntityRenderersEvent.RegisterRenderers()); ClientTooltipComponentManager.init(); EntitySpectatorShaderManager.init(); ClientHooks.onRegisterKeyMappings(mc.options); diff --git a/src/main/java/net/neoforged/neoforge/client/ColorResolverManager.java b/src/main/java/net/neoforged/neoforge/client/ColorResolverManager.java index 9f9df339af..050c07101e 100644 --- a/src/main/java/net/neoforged/neoforge/client/ColorResolverManager.java +++ b/src/main/java/net/neoforged/neoforge/client/ColorResolverManager.java @@ -23,7 +23,7 @@ public final class ColorResolverManager { @ApiStatus.Internal public static void init() { ImmutableList.Builder builder = ImmutableList.builder(); - ModLoader.get().postEvent(new RegisterColorHandlersEvent.ColorResolvers(builder)); + ModLoader.postEvent(new RegisterColorHandlersEvent.ColorResolvers(builder)); colorResolvers = builder.build(); } diff --git a/src/main/java/net/neoforged/neoforge/client/DimensionSpecialEffectsManager.java b/src/main/java/net/neoforged/neoforge/client/DimensionSpecialEffectsManager.java index 6e5a773478..ee3c0bc067 100644 --- a/src/main/java/net/neoforged/neoforge/client/DimensionSpecialEffectsManager.java +++ b/src/main/java/net/neoforged/neoforge/client/DimensionSpecialEffectsManager.java @@ -36,7 +36,7 @@ public static void init() { var effects = new HashMap(); DEFAULT_EFFECTS = preRegisterVanillaEffects(effects); var event = new RegisterDimensionSpecialEffectsEvent(effects); - ModLoader.get().postEventWrapContainerInModOrder(event); + ModLoader.postEventWrapContainerInModOrder(event); EFFECTS = ImmutableMap.copyOf(effects); } diff --git a/src/main/java/net/neoforged/neoforge/client/EntitySpectatorShaderManager.java b/src/main/java/net/neoforged/neoforge/client/EntitySpectatorShaderManager.java index a7284126b0..3c1f72be1b 100644 --- a/src/main/java/net/neoforged/neoforge/client/EntitySpectatorShaderManager.java +++ b/src/main/java/net/neoforged/neoforge/client/EntitySpectatorShaderManager.java @@ -35,7 +35,7 @@ public static ResourceLocation get(EntityType entityType) { public static void init() { var shaders = new HashMap, ResourceLocation>(); var event = new RegisterEntitySpectatorShadersEvent(shaders); - ModLoader.get().postEventWrapContainerInModOrder(event); + ModLoader.postEventWrapContainerInModOrder(event); SHADERS = ImmutableMap.copyOf(shaders); } diff --git a/src/main/java/net/neoforged/neoforge/client/ItemDecoratorHandler.java b/src/main/java/net/neoforged/neoforge/client/ItemDecoratorHandler.java index d3d0453363..5be3ae2574 100644 --- a/src/main/java/net/neoforged/neoforge/client/ItemDecoratorHandler.java +++ b/src/main/java/net/neoforged/neoforge/client/ItemDecoratorHandler.java @@ -39,7 +39,7 @@ private ItemDecoratorHandler(List itemDecorators) { public static void init() { var decorators = new HashMap>(); var event = new RegisterItemDecorationsEvent(decorators); - ModLoader.get().postEventWrapContainerInModOrder(event); + ModLoader.postEventWrapContainerInModOrder(event); var builder = new ImmutableMap.Builder(); decorators.forEach((item, itemDecorators) -> builder.put(item, new ItemDecoratorHandler(itemDecorators))); DECORATOR_LOOKUP = builder.build(); diff --git a/src/main/java/net/neoforged/neoforge/client/NamedRenderTypeManager.java b/src/main/java/net/neoforged/neoforge/client/NamedRenderTypeManager.java index 19ad533c5b..cfa4534c81 100644 --- a/src/main/java/net/neoforged/neoforge/client/NamedRenderTypeManager.java +++ b/src/main/java/net/neoforged/neoforge/client/NamedRenderTypeManager.java @@ -34,7 +34,7 @@ public static void init() { var renderTypes = new HashMap(); preRegisterVanillaRenderTypes(renderTypes); var event = new RegisterNamedRenderTypesEvent(renderTypes); - ModLoader.get().postEventWrapContainerInModOrder(event); + ModLoader.postEventWrapContainerInModOrder(event); RENDER_TYPES = ImmutableMap.copyOf(renderTypes); } diff --git a/src/main/java/net/neoforged/neoforge/client/PresetEditorManager.java b/src/main/java/net/neoforged/neoforge/client/PresetEditorManager.java index 47ae648627..e9fd4a0f7f 100644 --- a/src/main/java/net/neoforged/neoforge/client/PresetEditorManager.java +++ b/src/main/java/net/neoforged/neoforge/client/PresetEditorManager.java @@ -31,7 +31,7 @@ static void init() { // Gather mods' entries RegisterPresetEditorsEvent event = new RegisterPresetEditorsEvent(gatheredEditors); - ModLoader.get().postEventWrapContainerInModOrder(event); + ModLoader.postEventWrapContainerInModOrder(event); editors = gatheredEditors; } diff --git a/src/main/java/net/neoforged/neoforge/client/RecipeBookManager.java b/src/main/java/net/neoforged/neoforge/client/RecipeBookManager.java index 90b0f0568c..829d5f27fa 100644 --- a/src/main/java/net/neoforged/neoforge/client/RecipeBookManager.java +++ b/src/main/java/net/neoforged/neoforge/client/RecipeBookManager.java @@ -65,7 +65,7 @@ public static void init() { var typeCategories = new HashMap>(); var recipeCategoryLookups = new HashMap, Function, RecipeBookCategories>>(); var event = new RegisterRecipeBookCategoriesEvent(aggregateCategories, typeCategories, recipeCategoryLookups); - ModLoader.get().postEventWrapContainerInModOrder(event); + ModLoader.postEventWrapContainerInModOrder(event); AGGREGATE_CATEGORIES.putAll(aggregateCategories); TYPE_CATEGORIES.putAll(typeCategories); RECIPE_CATEGORY_LOOKUPS.putAll(recipeCategoryLookups); diff --git a/src/main/java/net/neoforged/neoforge/client/gui/ClientTooltipComponentManager.java b/src/main/java/net/neoforged/neoforge/client/gui/ClientTooltipComponentManager.java index b125527f4b..4ca0ce7fe4 100644 --- a/src/main/java/net/neoforged/neoforge/client/gui/ClientTooltipComponentManager.java +++ b/src/main/java/net/neoforged/neoforge/client/gui/ClientTooltipComponentManager.java @@ -36,7 +36,7 @@ public static ClientTooltipComponent createClientTooltipComponent(TooltipCompone public static void init() { var factories = new HashMap, Function>(); var event = new RegisterClientTooltipComponentFactoriesEvent(factories); - ModLoader.get().postEventWrapContainerInModOrder(event); + ModLoader.postEventWrapContainerInModOrder(event); FACTORIES = ImmutableMap.copyOf(factories); } diff --git a/src/main/java/net/neoforged/neoforge/client/gui/GuiLayerManager.java b/src/main/java/net/neoforged/neoforge/client/gui/GuiLayerManager.java index deedaf66b0..23479a88ca 100644 --- a/src/main/java/net/neoforged/neoforge/client/gui/GuiLayerManager.java +++ b/src/main/java/net/neoforged/neoforge/client/gui/GuiLayerManager.java @@ -80,6 +80,6 @@ public void initModdedLayers() { throw new IllegalStateException("Duplicate initialization of NamedLayeredDraw"); } initialized = true; - ModLoader.get().postEvent(new RegisterGuiLayersEvent(this.layers)); + ModLoader.postEvent(new RegisterGuiLayersEvent(this.layers)); } } 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 d2fa6114af..61f01f3767 100644 --- a/src/main/java/net/neoforged/neoforge/client/loading/ClientModLoader.java +++ b/src/main/java/net/neoforged/neoforge/client/loading/ClientModLoader.java @@ -101,7 +101,7 @@ public static VersionChecker.Status checkForUpdates() { } public static boolean completeModLoading() { - var warnings = ModLoader.get().getWarnings(); + var warnings = ModLoader.getWarnings(); boolean showWarnings = true; try { showWarnings = NeoForgeConfig.CLIENT.showLoadWarnings.get(); diff --git a/src/main/java/net/neoforged/neoforge/client/loading/NeoForgeLoadingOverlay.java b/src/main/java/net/neoforged/neoforge/client/loading/NeoForgeLoadingOverlay.java index a558a854cb..5345ef1801 100644 --- a/src/main/java/net/neoforged/neoforge/client/loading/NeoForgeLoadingOverlay.java +++ b/src/main/java/net/neoforged/neoforge/client/loading/NeoForgeLoadingOverlay.java @@ -26,10 +26,10 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.ReloadInstance; import net.minecraft.util.Mth; -import net.neoforged.fml.StartupMessageManager; import net.neoforged.fml.earlydisplay.ColourScheme; import net.neoforged.fml.earlydisplay.DisplayWindow; import net.neoforged.fml.loading.progress.ProgressMeter; +import net.neoforged.fml.loading.progress.StartupNotificationManager; import org.joml.Matrix4f; import org.lwjgl.opengl.GL30C; @@ -57,7 +57,7 @@ public NeoForgeLoadingOverlay(final Minecraft mc, final ReloadInstance reloader, this.onFinish = errorConsumer; this.displayWindow = displayWindow; displayWindow.addMojangTexture(mc.getTextureManager().getTexture(new ResourceLocation("textures/gui/title/mojangstudios.png")).getId()); - this.progressMeter = StartupMessageManager.prependProgressBar("Minecraft Progress", 1000); + this.progressMeter = StartupNotificationManager.prependProgressBar("Minecraft Progress", 1000); } public static Supplier newInstance(Supplier mc, Supplier ri, Consumer> handler, DisplayWindow window) { diff --git a/src/main/java/net/neoforged/neoforge/client/model/geometry/GeometryLoaderManager.java b/src/main/java/net/neoforged/neoforge/client/model/geometry/GeometryLoaderManager.java index e08e4da205..1382c821c1 100644 --- a/src/main/java/net/neoforged/neoforge/client/model/geometry/GeometryLoaderManager.java +++ b/src/main/java/net/neoforged/neoforge/client/model/geometry/GeometryLoaderManager.java @@ -42,7 +42,7 @@ public static String getLoaderList() { public static void init() { var loaders = new HashMap>(); var event = new ModelEvent.RegisterGeometryLoaders(loaders); - ModLoader.get().postEventWrapContainerInModOrder(event); + ModLoader.postEventWrapContainerInModOrder(event); LOADERS = ImmutableMap.copyOf(loaders); LOADER_LIST = loaders.keySet().stream().map(ResourceLocation::toString).collect(Collectors.joining(", ")); } diff --git a/src/main/java/net/neoforged/neoforge/common/CommonHooks.java b/src/main/java/net/neoforged/neoforge/common/CommonHooks.java index fd95cf15e3..50f80516ec 100644 --- a/src/main/java/net/neoforged/neoforge/common/CommonHooks.java +++ b/src/main/java/net/neoforged/neoforge/common/CommonHooks.java @@ -1014,9 +1014,9 @@ public static Map, AttributeSupplier> getAttr /** FOR INTERNAL USE ONLY, DO NOT CALL DIRECTLY */ @Deprecated public static void modifyAttributes() { - ModLoader.get().postEvent(new EntityAttributeCreationEvent(FORGE_ATTRIBUTES)); + ModLoader.postEvent(new EntityAttributeCreationEvent(FORGE_ATTRIBUTES)); Map, AttributeSupplier.Builder> finalMap = new HashMap<>(); - ModLoader.get().postEvent(new EntityAttributeModificationEvent(finalMap)); + ModLoader.postEvent(new EntityAttributeModificationEvent(finalMap)); finalMap.forEach((k, v) -> { AttributeSupplier supplier = DefaultAttributes.getSupplier(k); @@ -1088,7 +1088,7 @@ public static void readAdditionalLevelSaveData(CompoundTag rootTag, LevelStorage } final var mismatchEvent = new ModMismatchEvent(levelDirectory, mismatchedVersions, missingVersions); - ModLoader.get().postEvent(mismatchEvent); + ModLoader.postEvent(mismatchEvent); StringBuilder resolved = new StringBuilder("The following mods have version differences that were marked resolved:"); StringBuilder unresolved = new StringBuilder("The following mods have version differences that were not resolved:"); diff --git a/src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java b/src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java index c74c079c8f..f88e445636 100644 --- a/src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java +++ b/src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java @@ -85,12 +85,12 @@ import net.neoforged.fml.ModContainer; import net.neoforged.fml.ModLoader; import net.neoforged.fml.ModLoadingWarning; -import net.neoforged.fml.StartupMessageManager; import net.neoforged.fml.VersionChecker; import net.neoforged.fml.common.Mod; import net.neoforged.fml.config.ModConfig; import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; import net.neoforged.fml.event.lifecycle.FMLLoadCompleteEvent; +import net.neoforged.fml.loading.progress.StartupNotificationManager; import net.neoforged.neoforge.capabilities.CapabilityHooks; import net.neoforged.neoforge.client.ClientCommandHandler; import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions; @@ -592,7 +592,7 @@ public NeoForgeMod(IEventBus modEventBus, Dist dist, ModContainer container) { container.registerConfig(ModConfig.Type.COMMON, NeoForgeConfig.commonSpec); modEventBus.register(NeoForgeConfig.class); NeoForgeRegistriesSetup.setup(modEventBus); - StartupMessageManager.addModMessage("NeoForge version " + NeoForgeVersion.getVersion()); + StartupNotificationManager.addModMessage("NeoForge version " + NeoForgeVersion.getVersion()); NeoForge.EVENT_BUS.addListener(VillagerTradingManager::loadTrades); NeoForge.EVENT_BUS.register(new NeoForgeEventHandler()); @@ -613,7 +613,7 @@ public NeoForgeMod(IEventBus modEventBus, Dist dist, ModContainer container) { if (isPRBuild(container.getModInfo().getVersion().toString())) { isPRBuild = true; - ModLoader.get().addWarning(new ModLoadingWarning( + ModLoader.addWarning(new ModLoadingWarning( container.getModInfo(), "loadwarning.neoforge.prbuild")); } } diff --git a/src/main/java/net/neoforged/neoforge/common/world/chunk/ForcedChunkManager.java b/src/main/java/net/neoforged/neoforge/common/world/chunk/ForcedChunkManager.java index dc6b0e8f58..703fbc6875 100644 --- a/src/main/java/net/neoforged/neoforge/common/world/chunk/ForcedChunkManager.java +++ b/src/main/java/net/neoforged/neoforge/common/world/chunk/ForcedChunkManager.java @@ -53,7 +53,7 @@ public static synchronized void init() { initialised = true; final Map controllers = new HashMap<>(); - ModLoader.get().postEvent(new RegisterTicketControllersEvent(controller -> { + ModLoader.postEvent(new RegisterTicketControllersEvent(controller -> { if (controllers.containsKey(controller.id())) { throw new IllegalArgumentException("Attempted to register two controllers with the same ID " + controller.id()); } 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 e5fcbcd1c3..8ed2d9fa0c 100644 --- a/src/main/java/net/neoforged/neoforge/data/loading/DatagenModLoader.java +++ b/src/main/java/net/neoforged/neoforge/data/loading/DatagenModLoader.java @@ -52,7 +52,7 @@ public static void begin(final Set mods, final Path path, final Collecti ClientHooks.registerSpriteSourceTypes(); } existingFileHelper = new ExistingFileHelper(existingPacks, existingMods, structureValidator, assetIndex, assetsDir); - ModLoader.get().runEventGenerator(mc -> new GatherDataEvent(mc, dataGeneratorConfig.makeGenerator(p -> dataGeneratorConfig.isFlat() ? p : p.resolve(mc.getModId()), + ModLoader.runEventGenerator(mc -> new GatherDataEvent(mc, dataGeneratorConfig.makeGenerator(p -> dataGeneratorConfig.isFlat() ? p : p.resolve(mc.getModId()), dataGeneratorConfig.getMods().contains(mc.getModId())), dataGeneratorConfig, existingFileHelper)); dataGeneratorConfig.runAll(); } diff --git a/src/main/java/net/neoforged/neoforge/event/EventHooks.java b/src/main/java/net/neoforged/neoforge/event/EventHooks.java index c3eb756b1e..a5972ce6ab 100644 --- a/src/main/java/net/neoforged/neoforge/event/EventHooks.java +++ b/src/main/java/net/neoforged/neoforge/event/EventHooks.java @@ -940,7 +940,7 @@ public static void onCreativeModeTabBuildContents(CreativeModeTab tab, ResourceK entries.put(stack, vis); }); - ModLoader.get().postEvent(new BuildCreativeModeTabContentsEvent(tab, tabKey, params, entries)); + ModLoader.postEvent(new BuildCreativeModeTabContentsEvent(tab, tabKey, params, entries)); for (var entry : entries) output.accept(entry.getKey(), entry.getValue()); diff --git a/src/main/java/net/neoforged/neoforge/fluids/CauldronFluidContent.java b/src/main/java/net/neoforged/neoforge/fluids/CauldronFluidContent.java index a2f0ea44fe..073793b94e 100644 --- a/src/main/java/net/neoforged/neoforge/fluids/CauldronFluidContent.java +++ b/src/main/java/net/neoforged/neoforge/fluids/CauldronFluidContent.java @@ -112,7 +112,7 @@ public static void init() { registerEvent.register(Blocks.WATER_CAULDRON, Fluids.WATER, FluidType.BUCKET_VOLUME, LayeredCauldronBlock.LEVEL); registerEvent.register(Blocks.LAVA_CAULDRON, Fluids.LAVA, FluidType.BUCKET_VOLUME, null); // Modded registrations - ModLoader.get().postEvent(registerEvent); + ModLoader.postEvent(registerEvent); } /** diff --git a/src/main/java/net/neoforged/neoforge/gametest/GameTestHooks.java b/src/main/java/net/neoforged/neoforge/gametest/GameTestHooks.java index 73ae5d3d89..c7755b2c03 100644 --- a/src/main/java/net/neoforged/neoforge/gametest/GameTestHooks.java +++ b/src/main/java/net/neoforged/neoforge/gametest/GameTestHooks.java @@ -46,7 +46,7 @@ public static void registerGametests() { Set gameTestMethods = new HashSet<>(); RegisterGameTestsEvent event = new RegisterGameTestsEvent(gameTestMethods); - ModLoader.get().postEvent(event); + ModLoader.postEvent(event); ModList.get().getAllScanData().stream() .map(ModFileScanData::getAnnotations) diff --git a/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java b/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java index 6d808f9312..9896f8883b 100644 --- a/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java +++ b/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java @@ -20,12 +20,19 @@ import net.neoforged.fml.event.lifecycle.InterModProcessEvent; import net.neoforged.fml.loading.FMLEnvironment; import net.neoforged.fml.loading.FMLPaths; +import net.neoforged.neoforge.client.loading.ClientModLoader; 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. + * + *

    + *
  • Client runs {@link #begin}, {@link #load} and {@link #finish} at different timings, see {@link ClientModLoader}.
  • + *
  • Server runs all 3 consecutively.
  • + *
  • Datagen only runs {@link #begin}.
  • + *
*/ public abstract class CommonModLoader { private static boolean registriesLoaded = false; @@ -37,9 +44,9 @@ public static boolean areRegistriesLoaded() { protected static void begin(Runnable periodicTask) { var syncExecutor = ModWorkManager.syncExecutor(); - ModLoader.get().gatherAndInitializeMods(syncExecutor, ModWorkManager.parallelExecutor(), periodicTask); + ModLoader.gatherAndInitializeMods(syncExecutor, ModWorkManager.parallelExecutor(), periodicTask); - ModLoader.get().runInitTask("Registry initialization", syncExecutor, periodicTask, () -> { + ModLoader.runInitTask("Registry initialization", syncExecutor, periodicTask, () -> { RegistryManager.postNewRegistryEvent(); GameData.unfreezeData(); GameData.postRegisterEvents(); @@ -49,37 +56,37 @@ protected static void begin(Runnable periodicTask) { } protected static void load(Executor syncExecutor, Executor parallelExecutor) { - Runnable periodicTask = () -> {}; // no need to pass something else for now + Runnable periodicTask = () -> {}; // the server doesn't it, and minecraft has already opened its loading screen if (!ModLoader.isLoadingStateValid()) { return; } - ModLoader.get().runInitTask("Config loading", syncExecutor, periodicTask, () -> { + ModLoader.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, + ModLoader.dispatchParallelEvent("Common setup", syncExecutor, parallelExecutor, periodicTask, FMLCommonSetupEvent::new); + ModLoader.dispatchParallelEvent("Sided setup", syncExecutor, parallelExecutor, periodicTask, FMLEnvironment.dist.isClient() ? FMLClientSetupEvent::new : FMLDedicatedServerSetupEvent::new); - ModLoader.get().runInitTask("Registration events", syncExecutor, periodicTask, RegistrationEvents::init); + ModLoader.runInitTask("Registration events", syncExecutor, periodicTask, RegistrationEvents::init); } protected static void finish(Executor syncExecutor, Executor parallelExecutor) { - Runnable periodicTask = () -> {}; // no need to pass something else for now + Runnable periodicTask = () -> {}; // the server doesn't it, and minecraft has already opened its loading screen if (!ModLoader.isLoadingStateValid()) { 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.dispatchParallelEvent("Enqueue IMC", syncExecutor, parallelExecutor, periodicTask, InterModEnqueueEvent::new); + ModLoader.dispatchParallelEvent("Process IMC", syncExecutor, parallelExecutor, periodicTask, InterModProcessEvent::new); + ModLoader.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); + ModLoader.runInitTask("Network registry lock", syncExecutor, periodicTask, NetworkRegistry.getInstance()::setup); } } diff --git a/src/main/java/net/neoforged/neoforge/network/registration/NetworkRegistry.java b/src/main/java/net/neoforged/neoforge/network/registration/NetworkRegistry.java index f4e243b29f..c468c08c17 100644 --- a/src/main/java/net/neoforged/neoforge/network/registration/NetworkRegistry.java +++ b/src/main/java/net/neoforged/neoforge/network/registration/NetworkRegistry.java @@ -126,7 +126,7 @@ public void setup() { setup = true; final Map registrarsByNamespace = Collections.synchronizedMap(new HashMap<>()); - ModLoader.get().postEvent(new RegisterPayloadHandlerEvent(namespace -> registrarsByNamespace.computeIfAbsent(namespace, ModdedPacketRegistrar::new))); + ModLoader.postEvent(new RegisterPayloadHandlerEvent(namespace -> registrarsByNamespace.computeIfAbsent(namespace, ModdedPacketRegistrar::new))); registrarsByNamespace.values().forEach(ModdedPacketRegistrar::invalidate); final ImmutableMap.Builder> configurationBuilder = ImmutableMap.builder(); diff --git a/src/main/java/net/neoforged/neoforge/registries/GameData.java b/src/main/java/net/neoforged/neoforge/registries/GameData.java index 1d6fa85e00..61e281268d 100644 --- a/src/main/java/net/neoforged/neoforge/registries/GameData.java +++ b/src/main/java/net/neoforged/neoforge/registries/GameData.java @@ -25,7 +25,7 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.neoforged.fml.ModLoader; -import net.neoforged.fml.StartupMessageManager; +import net.neoforged.fml.loading.progress.StartupNotificationManager; import net.neoforged.neoforge.common.CommonHooks; import net.neoforged.neoforge.common.CreativeModeTabRegistry; import net.neoforged.neoforge.common.NeoForge; @@ -84,9 +84,9 @@ public static void postRegisterEvents() { Registry registry = Objects.requireNonNull(BuiltInRegistries.REGISTRY.get(rootRegistryName)); RegisterEvent registerEvent = new RegisterEvent(registryKey, registry); - StartupMessageManager.modLoaderConsumer().ifPresent(s -> s.accept("REGISTERING " + registryKey.location())); + StartupNotificationManager.modLoaderMessage("REGISTERING " + registryKey.location()); - ModLoader.get().postEventWrapContainerInModOrder(registerEvent); + ModLoader.postEventWrapContainerInModOrder(registerEvent); } catch (Throwable t) { aggregate.addSuppressed(t); } diff --git a/src/main/java/net/neoforged/neoforge/registries/RegistryManager.java b/src/main/java/net/neoforged/neoforge/registries/RegistryManager.java index 608250e0f1..9fac55873a 100644 --- a/src/main/java/net/neoforged/neoforge/registries/RegistryManager.java +++ b/src/main/java/net/neoforged/neoforge/registries/RegistryManager.java @@ -80,13 +80,13 @@ public static void postNewRegistryEvent() { DataPackRegistryEvent.NewRegistry dataPackEvent = new DataPackRegistryEvent.NewRegistry(); vanillaRegistryKeys = Set.copyOf(BuiltInRegistries.REGISTRY.keySet()); - ModLoader.get().postEventWrapContainerInModOrder(event); - ModLoader.get().postEventWrapContainerInModOrder(dataPackEvent); + ModLoader.postEventWrapContainerInModOrder(event); + ModLoader.postEventWrapContainerInModOrder(dataPackEvent); event.fill(); dataPackEvent.process(); - ModLoader.get().postEvent(new ModifyRegistriesEvent()); + ModLoader.postEvent(new ModifyRegistriesEvent()); pendingModdedRegistries.removeIf(BuiltInRegistries.REGISTRY::containsKey); if (!pendingModdedRegistries.isEmpty()) { @@ -98,7 +98,7 @@ public static void postNewRegistryEvent() { public static void initDataMaps() { final Map>, Map>> dataMapTypes = new HashMap<>(); - ModLoader.get().postEvent(new RegisterDataMapTypesEvent(dataMapTypes)); + ModLoader.postEvent(new RegisterDataMapTypesEvent(dataMapTypes)); dataMaps = new IdentityHashMap<>(); dataMapTypes.forEach((key, values) -> dataMaps.put(key, Collections.unmodifiableMap(values))); dataMaps = Collections.unmodifiableMap(dataMapTypes); diff --git a/src/main/java/net/neoforged/neoforge/resource/ResourcePackLoader.java b/src/main/java/net/neoforged/neoforge/resource/ResourcePackLoader.java index 45300f20f1..12c5a431b1 100644 --- a/src/main/java/net/neoforged/neoforge/resource/ResourcePackLoader.java +++ b/src/main/java/net/neoforged/neoforge/resource/ResourcePackLoader.java @@ -66,7 +66,7 @@ public static void populatePackRepository(PackRepository resourcePacks, PackType // First add the mod's builtin packs resourcePacks.addPackFinder(buildPackFinder(modResourcePacks, packType)); // Then fire the event to add more packs - ModLoader.get().postEvent(new AddPackFindersEvent(packType, resourcePacks::addPackFinder)); + ModLoader.postEvent(new AddPackFindersEvent(packType, resourcePacks::addPackFinder)); } @Deprecated(forRemoval = true, since = "1.20.4") @@ -116,7 +116,7 @@ private static void packFinder(Map modResource MOD_PACK_SELECTION_CONFIG); if (modPack == null) { - ModLoader.get().addWarning(new ModLoadingWarning(mod, "fml.modloading.brokenresources", e.getKey())); + ModLoader.addWarning(new ModLoadingWarning(mod, "fml.modloading.brokenresources", e.getKey())); continue; } } else { @@ -134,7 +134,7 @@ private static void packFinder(Map modResource } } catch (IOException exception) { LOGGER.error("Failed to read pack.mcmeta file of mod {}", mod.getModId(), exception); - ModLoader.get().addWarning(new ModLoadingWarning(mod, "fml.modloading.brokenresources", e.getKey())); + ModLoader.addWarning(new ModLoadingWarning(mod, "fml.modloading.brokenresources", e.getKey())); } } 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 b261b4a217..4910ce16ee 100644 --- a/src/main/java/net/neoforged/neoforge/server/loading/ServerModLoader.java +++ b/src/main/java/net/neoforged/neoforge/server/loading/ServerModLoader.java @@ -40,7 +40,7 @@ public static void load() { CrashReportExtender.dumpModLoadingCrashReport(LOGGER, error, new File(".")); throw error; } - List warnings = ModLoader.get().getWarnings(); + List warnings = ModLoader.getWarnings(); if (!warnings.isEmpty()) { LOGGER.warn(Logging.LOADING, "Mods loaded with {} warnings", warnings.size()); warnings.forEach(warning -> LOGGER.warn(Logging.LOADING, warning.formatToString())); From a501d2ab39daee76761cd3145bcf2016d35ff307 Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Thu, 18 Apr 2024 00:38:15 +0200 Subject: [PATCH 4/5] Bump FML again --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 30230f2402..957c26d36a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -31,7 +31,7 @@ jetbrains_annotations_version=24.0.1 slf4j_api_version=2.0.7 apache_maven_artifact_version=3.8.5 jarjar_version=0.4.0 -fancy_mod_loader_version=3.0.13-more-simplifications +fancy_mod_loader_version=3.0.14 mojang_logging_version=1.1.1 log4j_version=2.22.1 guava_version=31.1.2-jre From ec5b1f2723752abee6c74be10ad6eb69ae9e3c6e Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Thu, 18 Apr 2024 21:19:41 +0200 Subject: [PATCH 5/5] Move client-specific loading subtleties into ClientModLoader --- .../client/gui/LoadingErrorScreen.java | 4 ++- .../client/loading/ClientModLoader.java | 34 ++++++++++++------- .../neoforge/internal/CommonModLoader.java | 12 ++----- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/client/gui/LoadingErrorScreen.java b/src/main/java/net/neoforged/neoforge/client/gui/LoadingErrorScreen.java index b38f969f9a..c9218c497f 100644 --- a/src/main/java/net/neoforged/neoforge/client/gui/LoadingErrorScreen.java +++ b/src/main/java/net/neoforged/neoforge/client/gui/LoadingErrorScreen.java @@ -29,6 +29,7 @@ import net.neoforged.neoforge.common.I18nExtension; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.Nullable; public class LoadingErrorScreen extends ErrorScreen { private static final Logger LOGGER = LogManager.getLogger(); @@ -36,12 +37,13 @@ public class LoadingErrorScreen extends ErrorScreen { private final Path logFile; private final List modLoadErrors; private final List modLoadWarnings; + @Nullable private final Path dumpedLocation; private LoadingEntryList entryList; private Component errorHeader; private Component warningHeader; - public LoadingErrorScreen(LoadingFailedException loadingException, List warnings, final File dumpedLocation) { + public LoadingErrorScreen(@Nullable LoadingFailedException loadingException, List warnings, @Nullable File dumpedLocation) { super(Component.literal("Loading Error"), null); this.modLoadWarnings = warnings; this.modLoadErrors = loadingException == null ? Collections.emptyList() : loadingException.getErrors(); 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 61f01f3767..4e6575f2cb 100644 --- a/src/main/java/net/neoforged/neoforge/client/loading/ClientModLoader.java +++ b/src/main/java/net/neoforged/neoforge/client/loading/ClientModLoader.java @@ -37,6 +37,7 @@ import net.neoforged.neoforge.server.LanguageHook; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.Nullable; @OnlyIn(Dist.CLIENT) public class ClientModLoader extends CommonModLoader { @@ -44,6 +45,7 @@ public class ClientModLoader extends CommonModLoader { private static boolean loading; private static Minecraft mc; private static boolean loadingComplete; + @Nullable private static LoadingFailedException error; public static void begin(final Minecraft minecraft, final PackRepository defaultResourcePacks, final ReloadableResourceManager mcResourceManager) { @@ -54,7 +56,11 @@ public static void begin(final Minecraft minecraft, final PackRepository default ClientModLoader.mc = minecraft; LogicalSidedProvider.setClient(() -> minecraft); LanguageHook.loadBuiltinLanguages(); - createRunnableWithCatch(() -> begin(ImmediateWindowHandler::renderTick)).run(); + try { + begin(ImmediateWindowHandler::renderTick); + } catch (LoadingFailedException e) { + error = e; + } if (error == null) { ResourcePackLoader.populatePackRepository(defaultResourcePacks, PackType.CLIENT_RESOURCES); DataPackConfig.DEFAULT.addModPacks(ResourcePackLoader.getDataPackNames()); @@ -64,28 +70,30 @@ public static void begin(final Minecraft minecraft, final PackRepository default } private static CompletableFuture onResourceReload(final PreparableReloadListener.PreparationBarrier stage, final ResourceManager resourceManager, final ProfilerFiller prepareProfiler, final ProfilerFiller executeProfiler, final Executor asyncExecutor, final Executor syncExecutor) { - return CompletableFuture.runAsync(createRunnableWithCatch(() -> startModLoading(syncExecutor, asyncExecutor)), ModWorkManager.parallelExecutor()) + return CompletableFuture.runAsync(() -> startModLoading(syncExecutor, asyncExecutor), ModWorkManager.parallelExecutor()) .thenCompose(stage::wait) .thenRunAsync(() -> finishModLoading(syncExecutor, asyncExecutor), ModWorkManager.parallelExecutor()); } - private static Runnable createRunnableWithCatch(Runnable r) { - return () -> { - if (loadingComplete) return; - try { - r.run(); - } catch (LoadingFailedException e) { - if (error == null) error = e; - } - }; + private static void catchLoadingException(Runnable r) { + // Don't load again on subsequent reloads + if (loadingComplete) return; + // If the mod loading state is invalid, skip further mod initialization + if (!ModLoader.isLoadingStateValid()) return; + + try { + r.run(); + } catch (LoadingFailedException e) { + if (error == null) error = e; + } } private static void startModLoading(Executor syncExecutor, Executor parallelExecutor) { - createRunnableWithCatch(() -> load(syncExecutor, parallelExecutor)).run(); + catchLoadingException(() -> load(syncExecutor, parallelExecutor)); } private static void finishModLoading(Executor syncExecutor, Executor parallelExecutor) { - createRunnableWithCatch(() -> finish(syncExecutor, parallelExecutor)).run(); + catchLoadingException(() -> finish(syncExecutor, parallelExecutor)); loading = false; loadingComplete = true; // reload game settings on main thread diff --git a/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java b/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java index 9896f8883b..4b86fb3a3d 100644 --- a/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java +++ b/src/main/java/net/neoforged/neoforge/internal/CommonModLoader.java @@ -56,11 +56,7 @@ protected static void begin(Runnable periodicTask) { } protected static void load(Executor syncExecutor, Executor parallelExecutor) { - Runnable periodicTask = () -> {}; // the server doesn't it, and minecraft has already opened its loading screen - - if (!ModLoader.isLoadingStateValid()) { - return; - } + Runnable periodicTask = () -> {}; // server: no progress screen; client: minecraft has already opened its loading screen and ticks it for us ModLoader.runInitTask("Config loading", syncExecutor, periodicTask, () -> { if (FMLEnvironment.dist == Dist.CLIENT) { @@ -77,11 +73,7 @@ protected static void load(Executor syncExecutor, Executor parallelExecutor) { } protected static void finish(Executor syncExecutor, Executor parallelExecutor) { - Runnable periodicTask = () -> {}; // the server doesn't it, and minecraft has already opened its loading screen - - if (!ModLoader.isLoadingStateValid()) { - return; - } + Runnable periodicTask = () -> {}; // server: no progress screen; client: minecraft has already opened its loading screen and ticks it for us ModLoader.dispatchParallelEvent("Enqueue IMC", syncExecutor, parallelExecutor, periodicTask, InterModEnqueueEvent::new); ModLoader.dispatchParallelEvent("Process IMC", syncExecutor, parallelExecutor, periodicTask, InterModProcessEvent::new);