[1.12.2] Sending Packets from Forge to Sponge

I didn’t registered.

What do you mean? Please explain it a bit more. Did you only register the channel on server side and post messages from the client without a registration on client side?

Yeah, exactly. I did that.

I got it running and received the same error as @frenchdevz. If you use the method data.getString(0) instead of data.getUTF(0) it wont crash and you’ll receive the result, in my case the “test” string.

So this fix the problem ? :o

In my case it fixed the problem :slight_smile:

Now the last question that is open from my side is, how do I receive messages in my client side mod that are sent by the server/plugin side?

I’ve told about it above.
You first register it:

NetworkRegistry.INSTANCE.newEventDrivenChannel("channelName").register(listener);
MinecraftForge.EVENT_BUS.register(listener);

Your listener class example:

public class ExampleListener {
    @SubscribeEvent
    public void onClientPacket(FMLNetworkEvent.ClientCustomPacketEvent event) {

    }
}
1 Like

Thanks, thats it! The missing part for me was the event listener :slight_smile:

Do you have a sample how to read the data out of the event data?

UPDATE

Nevermind I read the packet byte data with the ByteBufUtils class.

@SubscribeEvent
public void onClientPacket(FMLNetworkEvent.ClientCustomPacketEvent event) {
	String data = ByteBufUtils.readUTF8String(event.getPacket().payload());
	Minecraft.getMinecraft().player.sendChatMessage(data);
}
1 Like

Glad yall figured it out.
Some offtop, by the way. sendChatMessage will force the player to send the message to a server, that method is not about sending a message clientside. Use the method that has TextComponent argument.

1 Like

Thanks, for the hint. That is good to know :slight_smile:

Hi, i’am sorry to bother you.
But i got a problem. Now i want to listen incomming packets in my mod that are sent by the plugin side.
When i register the channel, i got this error : Caused by: java.lang.RuntimeException: That channel is already registered - Pastebin.com.
Here’s my code : NetworkRegistry.INSTANCE.newEventDrivenChannel("albidnetwork").register(new Iden - Pastebin.com

I’m sorry for a long reply. The exception says that the channel is already registered. This is really strange, but since I don’t know how other parts of your code look I can’t say anything different from what the exception says.
In my code, I also use one instance of the listener in both registration methods. You created two instances for each registration. I’m not sure, but this can be the case here. Check it out.