Jump to content

How to send packets to client side ?


Recommended Posts

Hello, recently i've been struggling with sending packets from the server to the client side. I understood the concept but i still don't know how to do it.

1) how do can i send a msg to the client side i did that :

public class ModPacketHandler {
	private static final String PROTOCOL_VERSION = "1";
	public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(
	    new ResourceLocation("mod", "main"),
	public static void handle(String msg, Supplier<NetworkEvent.Context> ctx) {
	    ctx.get().enqueueWork(() -> {
	        // Work that needs to be threadsafe (most work)
	        ServerPlayerEntity sender = ctx.get().getSender(); // the client that sent this packet
	        // do stuff

But i don't know how to use it. And i don't even know if it is necessary.

2) I don't know what i have to put in the "msg" variable because what i want to do is send the position of a particules that has been determinated randomly by the server side so that they can be synchronized.

Any help or documentation will be appriciated. Thank you for helping

Link to comment
Share on other sites

MinesteriousPacketHandler.INSTANCE.sendTo("something i don't know what to put here but its a string", NetworkManger "here too..." , NetworkDirection.PLAY_TO_CLIENT); // On the last one i don't know what to put between PLAY_TO_CLIENT or LOGIN_TO_CLIENT	

that's what i tried to do for now ...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.