Posted December 31, 20222 yr The documentation at https://docs.minecraftforge.net/en/1.19.x/networking/simpleimpl/ for sending packets states that the code to send a message to a single player looks like this: INSTANCE.send(PacketDistributor.PLAYER.with(serverPlayer), new MyMessage()); I have wrapped this in a function in a class so that I can keep INSTANCE private and simplify all code that sends messages to the client. My function is: public static <MSG> void sendToClient(ServerPlayer player, MSG msg) { INSTANCE.send(PacketDistributor.PLAYER.with(player), msg); } This fails to compile with the error: incompatible types: ServerPlayer cannot be converted to Supplier<ServerPlayer> I have looked at the documentation for the Supplier class and there are no signs of any constructor or assignment function such as you get with Optional and similar classes. I did notice that it said that Supplier was a functional interface and changed my code to: public static <MSG> void sendToClient(ServerPlayer player, MSG msg) { INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), msg); } This compiles. I suggest you change the documentation to read: INSTANCE.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new MyMessage());
January 1, 20232 yr Create a PR for it or leave an issue on the docs repo itself. Also, if you're extending this logic to a specific piece of code, you should make sure it holds true in all cases, such as for the level chunk as well.
April 19Apr 19 Im having the same issue. 1.20.1 and yes it does effect levelchunks as well because they both use "with". the ones with no arg are fine. this is because it now takes a "supplier<t>" instead of whatever else i can probably test a workaround and call the other "sendto" code for instance however "serverPlayer.connection.getConnection()" is invalid i assume its "serverPlayer.connection.connection"?? its been 3 years how has no one had this issue before. pulled from base mincraft packet distributor public PacketTarget with(Supplier<T> input) { return new PacketTarget((Consumer)this.functor.apply(this, input), this); } public PacketTarget noArg() { return new PacketTarget((Consumer)this.functor.apply(this, () -> { return null; }), this); } Edited April 19Apr 19 by AustinPinheiro spell check. grammer, formatting
May 2May 2 The networking has been far simplified in 1.20.5+ The docs could be old, as Ash has said feel free to submit a PR updating the community docs. However the only real up-to-date reference would be the code itself. So your best bet is to just read the code and give it want it wants. I do Forge for free, however the servers to run it arn't free, so anything is appreciated. Consider supporting the team on Patreon
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.