我的第一篇文章

运行游戏时FML导致崩溃

于ForgeGradle 3.+版本(Forge 1.12.2-14.23.5.2854及以上版本)运行游戏时崩溃,日志提示:Caught exception from Forge Mod Loader (FML)

::: details 详细崩溃报告

 1net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Forge Mod Loader (FML)
 2Caused by: java.lang.NullPointerException
 3	at net.minecraftforge.fml.common.network.NetworkRegistry.newChannel(NetworkRegistry.java:207)
 4	at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.registerChannel(FMLNetworkHandler.java:185)
 5	at net.minecraftforge.fml.common.FMLContainer.modConstruction(FMLContainer.java:92)
 6	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 7	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 8	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 9	at java.lang.reflect.Method.invoke(Method.java:498)
10	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
11	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
12	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
13	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
14	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
15	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
16	at com.google.common.eventbus.EventBus.post(EventBus.java:217)
17	at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:219)
18	at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:197)
19	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
20	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
21	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
22	at java.lang.reflect.Method.invoke(Method.java:498)
23	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
24	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
25	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
26	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
27	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
28	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
29	at com.google.common.eventbus.EventBus.post(EventBus.java:217)
30	at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:136)
31	at net.minecraftforge.fml.common.Loader.loadMods(Loader.java:595)
32	at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:232)
33	at net.minecraft.client.Minecraft.init(Minecraft.java:467)
34	at net.minecraft.client.Minecraft.run(Minecraft.java:378)
35	at net.minecraft.client.main.Main.main(SourceFile:123)
36	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
37	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
38	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
39	at java.lang.reflect.Method.invoke(Method.java:498)
40	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
41	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
42	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
43	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
44	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
45	at java.lang.reflect.Method.invoke(Method.java:498)
46	at net.minecraftforge.legacydev.Main.start(Main.java:86)
47	at net.minecraftforge.legacydev.MainClient.main(MainClient.java:29)

:::

解决方案

build.gradle文件的dependencies块中添加以下代码:

1dependencies {
2    // 添加以下代码强制使用旧版本mergetool
3    implementation ("net.minecraftforge:mergetool:0.2.3.3") { force = true }
4
5    // 其它依赖...
6}

随后删除C:\Users\<当前用户>\.gradle\caches\forge_gradle\minecraft_user_repo\net\minecraftforge\forge\1.12.2-14.23.5.xxxx_mapped_snapshot_xxxxxxxx-1.12或正在使用的Forge版本的文件夹,重新同步Gradle后修复。

如果上述方法无法修复,则可能是类路径中包的加载顺序问题,尝试使用fg.deobf提前mergetool的加载顺序:

1dependencies {
2    // 添加以下代码强制使用旧版本mergetool
3    implementation fg.deobf("net.minecraftforge:mergetool:0.2.3.3:forge") { force = true }
4
5    // 其它依赖...
6}

参考资料