Interface NetworkChannel
- All Known Subinterfaces:
PacketChannel
A network channel can either be an external channel or a packet channel. External channels are identified by a unique key and are used for custom payloads over the network. Packet channels will represent data from packets, identified by a packet ID and type.
For constructing an external NetworkChannel, the following can be done:
private final NetworkChannel myChannel = NetworkChannel.of("example", "my_channel", MyMessage.class);
Or when inside an extension, with 'this' being the extension instance:
private final NetworkChannel myChannel = NetworkChannel.of(this, "my_channel", MyMessage.class);
For packet channels, it can get slightly more complex as you need to know the packet ID, understand the constructed message type and have an extension available. The following example demonstrates this with the animate packet, assuming the AnimateMessage class represents the correct packet structure:
private final NetworkChannel animateChannel = PacketChannel.bedrock(this, 44, AnimateMessage.class);
Packet channels can also be registered against packet objects from external protocol libraries, such as the ones provided in Geyser. For an example on how to do this, please see the Networking API documentation.
- Since:
- 2.9.2
-
Method Summary
Modifier and TypeMethodDescriptionGets the identifier that owns this channel.booleanisPacket()Checks if this channel is a packet channel.static NetworkChannelCreates a new externalNetworkChannelinstance.static NetworkChannelCreates a new externalNetworkChannelinstance.static NetworkChannelof(Identifier identifier, Class<?> messageType) Creates a new externalNetworkChannelinstance.
-
Method Details
-
identifier
Identifier identifier()Gets the identifier that owns this channel.- Returns:
- the identifier that owns this channel
-
isPacket
boolean isPacket()Checks if this channel is a packet channel.- Returns:
- true if this channel is a packet channel, false otherwise
-
of
Creates a new externalNetworkChannelinstance.Extensions should use this method to register their own channels for more robust identification.
- Parameters:
extension- the extension that registered this channelchannel- the name of the channelmessageType- the type of the message sent over this channel- Returns:
- a new external
NetworkChannelinstance
-
of
Creates a new externalNetworkChannelinstance.This method is used for external channels provided by third parties, such as plugins or mods.
- Parameters:
id- the channel idchannel- the name of the channelmessageType- the type of the message sent over this channel- Returns:
- a new external
NetworkChannelinstance
-
of
Creates a new externalNetworkChannelinstance.This method is used for external channels provided by third parties, such as plugins or mods.
- Parameters:
identifier- theIdentifierof the channelmessageType- the type of the message sent over this channel- Returns:
- a new external
NetworkChannelinstance
-