Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

How to send packets to client side ?


Armanse
 Share

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"),
	    () -> PROTOCOL_VERSION,
	    PROTOCOL_VERSION::equals,
	    PROTOCOL_VERSION::equals
	);
	
	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
	    });
	    ctx.get().setPacketHandled(true);
	}
}

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.

Guest
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.