Jump to content

Documentation for sending message to client is incorrect or unclear.


Jontom Xire

Recommended Posts

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());

 

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