I'm adding listeners for _FMLClientSetupEvent_ and _InterModProcessEvent_ in the main mod class constructor, the same way it's done in the example mod. Most of the time (always?), when there's only 1 mod to load, everything works as it should. But, when there are 2 (or more?) mods, it becomes very difficult to get all of the mods to actually load properly. Multiple restarts of the game eventually help.
These 2 messages are always logged for all of the mods:
_Fired event for modid
Fired event for modid
But calling LOGGER.info("hello") on these events shows that sometimes some of the listeners are ignored. This is probably also true for the other loading events.
likely race conditions in the bus?
It definitely looks like it.
I seem to get this too. (1.13.2) I made a simple test mod to test commands and sometimes they register, other times not. The only other mods i added was jei, curios, curioofundying
This is most likely because the main thread does not wait for the BackgroundScanHandler to complete, as BackgroundScanHandler.java#getScannedFiles is never called.
So not every mod jar may have been scanned by the time forge inits all mods.
EDIT: I just found that there is another place (ModFile#getScanResult) where forge waits on the scanning thread, so that doesn't appear to be the problem.
any way to reproduce this?
OK. A question: are you on a really old build of Forge? There was a problem where this might happen, which was fixed some weeks ago. Please reproduce on a contemporary forge build.
I'm pretty sure the build was the latest one at the time of reporting this.
I've now tried reproducing it on a newer one.
25.0.204 doesn't start properly for me, even without any mods. Log:
`[12May2019 21:32:20.442] [modloading-worker-1/ERROR] [net.minecraftforge.fml.javafmlmod.FMLModContainer/LOADING]: Failed to create mod instance. ModID: forge, class net.minecraftforge.common.ForgeMod
java.lang.ExceptionInInitializerError: null
at net.minecraftforge.common.ForgeMod.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_201]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_201]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_201]
at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_201]
at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_201]
at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:130) ~[?:?]
at java.util.function.Consumer.lambda$andThen$0(Unknown Source) ~[?:1.8.0_201]
at java.util.function.Consumer.lambda$andThen$0(Unknown Source) ~[?:1.8.0_201]
at net.minecraftforge.fml.ModContainer.transitionState(ModContainer.java:111) ~[?:?]
at net.minecraftforge.fml.ModList.lambda$null$9(ModList.java:120) ~[?:?]
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(Unknown Source) ~[?:1.8.0_201]
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source) ~[?:1.8.0_201]
at java.util.stream.AbstractPipeline.copyInto(Unknown Source) ~[?:1.8.0_201]
at java.util.stream.ForEachOps$ForEachTask.compute(Unknown Source) ~[?:1.8.0_201]
at java.util.concurrent.CountedCompleter.exec(Unknown Source) ~[?:1.8.0_201]
at java.util.concurrent.ForkJoinTask.doExec(Unknown Source) ~[?:1.8.0_201]
at java.util.concurrent.ForkJoinTask.doInvoke(Unknown Source) ~[?:1.8.0_201]
at java.util.concurrent.ForkJoinTask.invoke(Unknown Source) ~[?:1.8.0_201]
at java.util.stream.ForEachOps$ForEachOp.evaluateParallel(Unknown Source) ~[?:1.8.0_201]
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(Unknown Source) ~[?:1.8.0_201]
at java.util.stream.AbstractPipeline.evaluate(Unknown Source) ~[?:1.8.0_201]
at java.util.stream.ReferencePipeline.forEach(Unknown Source) ~[?:1.8.0_201]
at java.util.stream.ReferencePipeline$Head.forEach(Unknown Source) ~[?:1.8.0_201]
at net.minecraftforge.fml.ModList.lambda$dispatchParallelEvent$10(ModList.java:120) ~[?:?]
at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(Unknown Source) [?:1.8.0_201]
at java.util.concurrent.ForkJoinTask.doExec(Unknown Source) [?:1.8.0_201]
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(Unknown Source) [?:1.8.0_201]
at java.util.concurrent.ForkJoinPool.runWorker(Unknown Source) [?:1.8.0_201]
at java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source) [?:1.8.0_201]
Caused by: java.lang.NullPointerException
at net.minecraftforge.fml.loading.JarVersionLookupHandler.getImplementationVersion(JarVersionLookupHandler.java:42) ~[forge-1.13.2-25.0.203.jar:25.0]
at net.minecraftforge.versions.forge.ForgeVersion.
... 30 more
25.0.198 is the latest version that successfully loads for me. The newer ones fail for different reasons.
Aaaand, I reproduced the issue on first try on 25.0.198. I'm testing it with the actual Minecraft launcher, by the way. The issue happens to me in dev environment too though.
Also, a lot of people who have reported this to me said that the issue had started after updating one of the mods to a newer version. Might just be a coincidence though because I know it happened with the older mod versions too.
I can confirm this as well. It seems most common in the main game, less common in a dev environment, and almost non-existent in the debug environment, which made it very difficult for me to pin down what was causing my mods not to work.
Pick up the new eventbus and it should work. We'll probably push a forge with it shortly.
Most helpful comment
Pick up the new eventbus and it should work. We'll probably push a forge with it shortly.