public interface ScreenNetworking
ScreenNetworking handles screen-related network messages sent between the server and the client.
receive(Identifier, MessageReceiver)
on a ScreenNetworking for the receiving side. The message ID is a unique ID that matches between
the sender and the receiver.
Message receivers should be registered in the constructor of a SyncedGuiDescription.
send(Identifier, Consumer) on a ScreenNetworking
for the sending side. The message ID should match up with a receiver registered on the opposite
side.
private static final Identifier MESSAGE_ID = new Identifier("my_mod", "some_message");
// Receiver
ScreenNetworking.of(this, NetworkSide.SERVER).receive(MESSAGE_ID, buf -> {
// Example data: a lucky number as an int
System.out.println("Your lucky number is " + buf.readInt() + "!");
});
// Sending
// We're sending from a button. The packet data is our lucky number, 123.
WButton button = ...;
button.setOnClick(() -> {
ScreenNetworking.of(this, NetworkSide.CLIENT).send(MESSAGE_ID, buf -> buf.writeInt(123));
});
| Modifier and Type | Interface and Description |
|---|---|
static interface |
ScreenNetworking.MessageReceiver
A handler for received screen messages.
|
| Modifier and Type | Method and Description |
|---|---|
static ScreenNetworking |
of(SyncedGuiDescription description,
NetworkSide networkSide)
Gets a networking handler for the GUI description that is active on the specified side.
|
void |
receive(net.minecraft.util.Identifier message,
ScreenNetworking.MessageReceiver receiver)
Registers a message receiver for the message.
|
void |
send(net.minecraft.util.Identifier message,
java.util.function.Consumer<net.minecraft.network.PacketByteBuf> writer)
Sends a screen message to the other side of the connection.
|
static ScreenNetworking of(SyncedGuiDescription description, NetworkSide networkSide)
description - the GUI descriptionnetworkSide - the network sidejava.lang.NullPointerException - if either parameter is nullvoid receive(net.minecraft.util.Identifier message,
ScreenNetworking.MessageReceiver receiver)
message - the screen message IDreceiver - the message receiverjava.lang.IllegalStateException - if the message has already been registeredjava.lang.NullPointerException - if either parameter is nullvoid send(net.minecraft.util.Identifier message,
java.util.function.Consumer<net.minecraft.network.PacketByteBuf> writer)
message - the screen message IDwriter - a writer that writes the message contents to a packet buffer;
should not read the bufferjava.lang.NullPointerException - if either parameter is null