Posted July 17, 20214 yr 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
July 17, 20214 yr Author 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 ...
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.