IDE:IntelliJ IDEA
IDE版本:2019.3
Forge版本: 31.1.9
Minecraft版本: 1.15.2
错误情况简述
服务端与客户端之间de通信问题。
报错日志
[17:44:20] [Render thread/ERROR] [ne.mi.fm.ne.si.IndexedMessageCodec/SIMPLENET]: Received empty payload on channel fml:handshake
[17:44:20] [Render thread/FATAL] [minecraft/ThreadTaskExecutor]: Error executing task on Client
java.lang.IndexOutOfBoundsException: index: 2, length: 123 (expected: range(0, 45))
at io.netty.buffer.AbstractByteBuf.checkIndex0(AbstractByteBuf.java:1362) ~[netty-all-4.1.25.Final.jar:4.1.25.Final] {}
at io.netty.buffer.AbstractByteBuf.checkIndex(AbstractByteBuf.java:1357) ~[netty-all-4.1.25.Final.jar:4.1.25.Final] {}
at io.netty.buffer.PooledUnsafeDirectByteBuf.nioBuffer(PooledUnsafeDirectByteBuf.java:324) ~[netty-all-4.1.25.Final.jar:4.1.25.Final] {}
at io.netty.buffer.ByteBufUtil.decodeString(ByteBufUtil.java:769) ~[netty-all-4.1.25.Final.jar:4.1.25.Final] {}
at io.netty.buffer.AbstractByteBuf.toString(AbstractByteBuf.java:1222) ~[netty-all-4.1.25.Final.jar:4.1.25.Final] {}
at net.minecraft.network.PacketBuffer.toString(PacketBuffer.java:1068) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading}
at net.minecraft.network.PacketBuffer.readString(PacketBuffer.java:319) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading}
at net.minecraft.network.PacketBuffer.readString(PacketBuffer.java:309) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading}
at cc.kunss.packet.ToturPacket.<init>(ToturPacket.java:16) ~[main/:?] {re:classloading}
at cc.kunss.packet.ToturPacket.decode(ToturPacket.java:43) ~[main/:?] {re:classloading}
at net.minecraftforge.fml.network.simple.IndexedMessageCodec.lambda$tryDecode$0(IndexedMessageCodec.java:116) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading}
at java.util.Optional.map(Optional.java:215) ~[?:1.8.0_202] {}
at net.minecraftforge.fml.network.simple.IndexedMessageCodec.tryDecode(IndexedMessageCodec.java:116) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading}
at net.minecraftforge.fml.network.simple.IndexedMessageCodec.consume(IndexedMessageCodec.java:157) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading}
at net.minecraftforge.fml.network.simple.SimpleChannel.networkEventListener(SimpleChannel.java:79) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading}
at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:212) ~[eventbus-2.0.0-milestone.1-service.jar:?] {}
at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:204) ~[eventbus-2.0.0-milestone.1-service.jar:?] {}
at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258) ~[eventbus-2.0.0-milestone.1-service.jar:?] {}
at net.minecraftforge.fml.network.NetworkInstance.dispatch(NetworkInstance.java:84) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading}
at net.minecraftforge.fml.network.NetworkHooks.lambda$onCustomPayload$0(NetworkHooks.java:74) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading}
at java.util.Optional.map(Optional.java:215) ~[?:1.8.0_202] {}
at net.minecraftforge.fml.network.NetworkHooks.onCustomPayload(NetworkHooks.java:74) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading}
at net.minecraft.client.network.play.ClientPlayNetHandler.handleCustomPayload(ClientPlayNetHandler.java:1868) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading,pl:runtimedistcleaner:A}
at net.minecraft.network.play.server.SCustomPayloadPlayPacket.processPacket(SCustomPayloadPlayPacket.java:59) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading}
at net.minecraft.network.play.server.SCustomPayloadPlayPacket.processPacket(SCustomPayloadPlayPacket.java:11) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading}
at net.minecraft.network.PacketThreadUtil.func_225383_a(SourceFile:21) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading}
at net.minecraft.util.concurrent.ThreadTaskExecutor.run(SourceFile:144) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading,pl:accesstransformer:B}
at net.minecraft.util.concurrent.RecursiveEventLoop.run(SourceFile:23) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading}
at net.minecraft.util.concurrent.ThreadTaskExecutor.driveOne(SourceFile:118) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading,pl:accesstransformer:B}
at net.minecraft.util.concurrent.ThreadTaskExecutor.drainTasks(SourceFile:103) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading,pl:accesstransformer:B}
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:898) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
at net.minecraft.client.Minecraft.run(Minecraft.java:554) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
at net.minecraft.client.main.Main.main(SourceFile:204) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading,pl:runtimedistcleaner:A}
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_202] {}
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_202] {}
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_202] {}
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_202] {}
at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {}
at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-5.0.0-milestone.4.jar:?] {}
at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-5.0.0-milestone.4.jar:?] {}
at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-5.0.0-milestone.4.jar:?] {}
at cpw.mods.modlauncher.Launcher.run(Launcher.java:81) [modlauncher-5.0.0-milestone.4.jar:?] {}
at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) [modlauncher-5.0.0-milestone.4.jar:?] {}
at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:102) [forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {}
相关代码
package cc.kunss.packet;
import cc.kunss.channel.ToturMessage;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.NetworkEvent;
import java.util.function.Supplier;
public class ToturPacket {
private String name;
private String json;
private ToturMessage toturMessage;
public ToturPacket(PacketBuffer packetBuffer) {
json = packetBuffer.readString();
toturMessage = new ToturMessage().fromJSON(json);
}
/**
* 序列
* @param s
* @param packetBuffer
*/
public static void encode(ToturPacket toturPacket, PacketBuffer packetBuffer) {
packetBuffer.writeString(toturPacket.toturMessage.toJson());
}
/**
* 处理 Handle
* @param s
* @param contextSupplier
* @return true
*/
public static boolean handle(ToturPacket s, Supplier<NetworkEvent.Context> contextSupplier) {
System.out.println("ToturMod Debug: "+s.toturMessage.toString());
return true;
}
public static ToturPacket decode(PacketBuffer packetBuffer) {
return new ToturPacket(packetBuffer);
}
}
at io.netty.buffer.AbstractByteBuf.checkIndex0(AbstractByteBuf.java:1362) ~[netty-all-4.1.25.Final.jar:4.1.25.Final] {}
at io.netty.buffer.AbstractByteBuf.checkIndex(AbstractByteBuf.java:1357) ~[netty-all-4.1.25.Final.jar:4.1.25.Final] {}
at io.netty.buffer.PooledUnsafeDirectByteBuf.nioBuffer(PooledUnsafeDirectByteBuf.java:324) ~[netty-all-4.1.25.Final.jar:4.1.25.Final] {}
at io.netty.buffer.ByteBufUtil.decodeString(ByteBufUtil.java:769) ~[netty-all-4.1.25.Final.jar:4.1.25.Final] {}
at io.netty.buffer.AbstractByteBuf.toString(AbstractByteBuf.java:1222) ~[netty-all-4.1.25.Final.jar:4.1.25.Final] {}
at net.minecraft.network.PacketBuffer.toString(PacketBuffer.java:1068) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading}
at net.minecraft.network.PacketBuffer.readString(PacketBuffer.java:319) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading}
at net.minecraft.network.PacketBuffer.readString(PacketBuffer.java:309) ~[forge-1.15.2-31.1.9_mapped_stable_60-1.15.jar:?] {re:classloading}