Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

 

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.

  • 2 years later...

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 by AustinPinheiro
spell check. grammer, formatting

  • 2 weeks later...

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.