public ExampleMod() {
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
MinecraftForge.EVENT_BUS.register(this);
EventNetworkChannel channel = NetworkRegistry.ChannelBuilder
.named(new ResourceLocation("space", "a"))
.clientAcceptedVersions(PROTOCOL_VERSION::equals)
.serverAcceptedVersions(PROTOCOL_VERSION::equals)
.networkProtocolVersion(() -> PROTOCOL_VERSION)
.eventNetworkChannel();
channel.registerObject(this);
channel.addListener(this::onClientPacket);
}
public void onClientPacket(NetworkEvent.ClientCustomPayloadEvent evt){
byte[] b = new byte[evt.getPayload().readableBytes()];
evt.getPayload().getBytes(0, b);
System.out.println(b);
//String s = new String(b,"utf-8");
}
I tried to use this method to receive pluginmessage from the server, but it doesn't work