修复Minecraft的IndexOutOfBoundsException报错

Mod: Minecraft Transit Railway

Issue: Refresh Path button not working on multiplayer server #352

非常好的一个mod,但是用的时候刷新路径按键一直不正常, 看了mod的源码也没看出来什么问题. 尝试打开客户端日志, 有一个错误消息非常让人在意:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
[15:37:50] [Render thread/ERROR]: Error executing task on Client
java.lang.IndexOutOfBoundsException: readerIndex(23) + length(1) exceeds writerIndex(23): PooledUnsafeDirectByteBuf(ridx: 23, widx: 23, cap: 23)
at io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractByteBuf.java:1442) ~[netty-all-4.1.68.Final.jar%2326!/:4.1.68.Final]
at io.netty.buffer.AbstractByteBuf.readByte(AbstractByteBuf.java:730) ~[netty-all-4.1.68.Final.jar%2326!/:4.1.68.Final]
at net.minecraft.network.FriendlyByteBuf.readByte(FriendlyByteBuf.java:909) ~[client-1.18.2-20220404.173914-srg.jar%2380!/:?]
at net.minecraft.network.FriendlyByteBuf.m_130242_(FriendlyByteBuf.java:344) ~[client-1.18.2-20220404.173914-srg.jar%2380!/:?]
at net.minecraft.network.FriendlyByteBuf.m_130136_(FriendlyByteBuf.java:486) ~[client-1.18.2-20220404.173914-srg.jar%2380!/:?]
at net.minecraft.network.FriendlyByteBuf.m_130277_(FriendlyByteBuf.java:482) ~[client-1.18.2-20220404.173914-srg.jar%2380!/:?]
at mtr.packet.PacketTrainDataGuiClient.createRailS2C(PacketTrainDataGuiClient.java:120) ~[MTR-forge-1.18.2-3.0.0.jar%2372!/:?]
at mtr.MTRClient.lambda$init$22(MTRClient.java:288) ~[MTR-forge-1.18.2-3.0.0.jar%2372!/:?]
at mtr.forge.RegistryClientImpl.lambda$registerNetworkReceiver$0(RegistryClientImpl.java:47) ~[MTR-forge-1.18.2-3.0.0.jar%2372!/:?]
at dev.architectury.networking.forge.NetworkManagerImpl.lambda$createPacketHandler$6(NetworkManagerImpl.java:150) ~[architectury-4.3.53.jar%2354!/:?]
at dev.architectury.networking.transformers.PacketTransformer$1.inbound(PacketTransformer.java:47) ~[architectury-4.3.53.jar%2354!/:?]
at dev.architectury.networking.forge.NetworkManagerImpl.lambda$createPacketHandler$7(NetworkManagerImpl.java:145) ~[architectury-4.3.53.jar%2354!/:?]
at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:247) ~[eventbus-5.0.3.jar%232!/:?]
at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:239) ~[eventbus-5.0.3.jar%232!/:?]
at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) ~[eventbus-5.0.3.jar%232!/:?]
at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) ~[eventbus-5.0.3.jar%232!/:?]
at net.minecraftforge.network.NetworkInstance.dispatch(NetworkInstance.java:68) ~[forge-1.18.2-40.1.0-universal.jar%2384!/:?]
at net.minecraftforge.network.NetworkHooks.lambda$onCustomPayload$1(NetworkHooks.java:75) ~[forge-1.18.2-40.1.0-universal.jar%2384!/:?]
at java.util.Optional.map(Optional.java:260) ~[?:?]
at net.minecraftforge.network.NetworkHooks.onCustomPayload(NetworkHooks.java:75) ~[forge-1.18.2-40.1.0-universal.jar%2384!/:?]
at net.minecraft.client.multiplayer.ClientPacketListener.m_7413_(ClientPacketListener.java:1824) ~[client-1.18.2-20220404.173914-srg.jar%2380!/:?]
at net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket.m_5797_(ClientboundCustomPayloadPacket.java:57) ~[client-1.18.2-20220404.173914-srg.jar%2380!/:?]
at net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket.m_5797_(ClientboundCustomPayloadPacket.java:7) ~[client-1.18.2-20220404.173914-srg.jar%2380!/:?]
at net.minecraft.network.protocol.PacketUtils.m_131356_(PacketUtils.java:22) ~[client-1.18.2-20220404.173914-srg.jar%2380!/:?]
at net.minecraft.util.thread.BlockableEventLoop.m_6367_(BlockableEventLoop.java:157) ~[client-1.18.2-20220404.173914-srg.jar%2380!/:?]
at net.minecraft.util.thread.ReentrantBlockableEventLoop.m_6367_(ReentrantBlockableEventLoop.java:23) ~[client-1.18.2-20220404.173914-srg.jar%2380!/:?]
at net.minecraft.util.thread.BlockableEventLoop.m_7245_(BlockableEventLoop.java:131) ~[client-1.18.2-20220404.173914-srg.jar%2380!/:?]
at net.minecraft.util.thread.BlockableEventLoop.m_18699_(BlockableEventLoop.java:116) ~[client-1.18.2-20220404.173914-srg.jar%2380!/:?]
at net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1013) ~[client-1.18.2-20220404.173914-srg.jar%2380!/:?]
at net.minecraft.client.Minecraft.m_91374_(Minecraft.java:663) ~[client-1.18.2-20220404.173914-srg.jar%2380!/:?]
at net.minecraft.client.main.Main.main(Main.java:205) ~[client-1.18.2-20220404.173914-srg.jar%2380!/:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
at net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:31) ~[fmlloader-1.18.2-40.1.0.jar%2316!/:?]
at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-9.1.3.jar%235!/:?]
at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-9.1.3.jar%235!/:?]
at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-9.1.3.jar%235!/:?]
at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-9.1.3.jar%235!/:?]
at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.1.3.jar%235!/:?]
at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.1.3.jar%235!/:?]
at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.1.3.jar%235!/:?]
at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149) [bootstraplauncher-1.0.0.jar:?]

从这个错误消息入手, 找到一个非常简短且冷门的帖子: I cannot connect to a modded server 帖子里面提到删除玩家对应的dat文件. 尝试停服删除之后重启, 一切正常. 推测是之前停电导致的服务器未正确关闭引起的玩家数据异常.