Class ClientConfigurationNetworking
Client-side networking functionalities include receiving clientbound packets,
sending serverbound packets, and events related to client-side packet listeners.
Packets received by this class must be registered to PayloadTypeRegistry.clientboundConfiguration() on both ends.
Packets sent by this class must be registered to PayloadTypeRegistry.serverboundConfiguration() on both ends.
Packets must be registered before registering any receivers.
This class should be only used on the physical client and for the logical client.
See ServerPlayNetworking for information on how to use the packet
object-based API.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceClientConfigurationNetworking.ConfigurationPayloadHandler<T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>A packet handler utilizingCustomPacketPayload.static interface -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanSend(net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<?> type) Checks if the connected server declared the ability to receive a packet on a specified channel name.static booleancanSend(net.minecraft.resources.Identifier channelName) Checks if the connected server declared the ability to receive a packet on a specified channel name.static Set<net.minecraft.resources.Identifier> Gets all channel names which global receivers are registered for.static Set<net.minecraft.resources.Identifier> Gets all the channel names that the client can receive packets on.static Set<net.minecraft.resources.Identifier> Gets all channel names that the connected server declared the ability to receive a packets on.static PacketSenderGets the packet sender which sends packets to the connected server.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
booleanregisterGlobalReceiver(net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<T> type, ClientConfigurationNetworking.ConfigurationPayloadHandler<T> handler) Registers a handler for a packet type.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
booleanregisterReceiver(net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<T> type, ClientConfigurationNetworking.ConfigurationPayloadHandler<T> handler) Registers a handler for a packet type.static voidsend(net.minecraft.network.protocol.common.custom.CustomPacketPayload payload) Sends a packet to the connected server.static @Nullable ClientConfigurationNetworking.ConfigurationPayloadHandler<?> unregisterGlobalReceiver(net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<?> type) Removes the handler for a packet type.static @Nullable ClientConfigurationNetworking.ConfigurationPayloadHandler<?> unregisterReceiver(net.minecraft.resources.Identifier id) Removes the handler for a packet type.
-
Method Details
-
registerGlobalReceiver
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> boolean registerGlobalReceiver(net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<T> type, ClientConfigurationNetworking.ConfigurationPayloadHandler<T> handler) Registers a handler for a packet type. A global receiver is registered to all connections, in the present and future.If a handler is already registered for the
type, this method will returnfalse, and no change will be made. UseunregisterGlobalReceiver(CustomPacketPayload.Type)to unregister the existing handler.- Parameters:
type- the packet typehandler- the handler- Returns:
- false if a handler is already registered to the channel
- Throws:
IllegalArgumentException- if the codec fortypehas not been registered yet- See Also:
-
unregisterGlobalReceiver
public static @Nullable ClientConfigurationNetworking.ConfigurationPayloadHandler<?> unregisterGlobalReceiver(net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<?> type) Removes the handler for a packet type. A global receiver is registered to all connections, in the present and future.The
typeis guaranteed not to have an associated handler after this call.- Parameters:
type- the packet type- Returns:
- the previous handler, or
nullif no handler was bound to the channel, or it was not registered usingregisterGlobalReceiver(CustomPacketPayload.Type, ConfigurationPayloadHandler) - See Also:
-
getGlobalReceivers
Gets all channel names which global receivers are registered for. A global receiver is registered to all connections, in the present and future.- Returns:
- all channel names which global receivers are registered for.
-
registerReceiver
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> boolean registerReceiver(net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<T> type, ClientConfigurationNetworking.ConfigurationPayloadHandler<T> handler) Registers a handler for a packet type.If a handler is already registered for the
type, this method will returnfalse, and no change will be made. UseunregisterReceiver(Identifier)to unregister the existing handler.For example, if you only register a receiver using this method when a ClientLoginNetworking.registerGlobalReceiver(Identifier, ClientLoginNetworking.LoginQueryRequestHandler) login query has been received, you should use
ClientPlayConnectionEvents.INITto register the channel handler.- Parameters:
type- the payload typehandler- the handler- Returns:
falseif a handler is already registered for the type- Throws:
IllegalArgumentException- if the codec fortypehas not been registered yetIllegalStateException- if the client is not connected to a server- See Also:
-
unregisterReceiver
public static @Nullable ClientConfigurationNetworking.ConfigurationPayloadHandler<?> unregisterReceiver(net.minecraft.resources.Identifier id) Removes the handler for a packet type.The
typeis guaranteed not to have an associated handler after this call.- Parameters:
id- the payload id to unregister- Returns:
- the previous handler, or
nullif no handler was bound to the channel, or it was not registered usingregisterReceiver(CustomPacketPayload.Type, ConfigurationPayloadHandler) - Throws:
IllegalStateException- if the client is not connected to a server
-
getReceived
Gets all the channel names that the client can receive packets on.- Returns:
- All the channel names that the client can receive packets on
- Throws:
IllegalStateException- if the client is not connected to a server
-
getSendable
Gets all channel names that the connected server declared the ability to receive a packets on.- Returns:
- All the channel names the connected server declared the ability to receive a packets on
- Throws:
IllegalStateException- if the client is not connected to a server
-
canSend
public static boolean canSend(net.minecraft.resources.Identifier channelName) throws IllegalArgumentException Checks if the connected server declared the ability to receive a packet on a specified channel name.- Parameters:
channelName- the channel name- Returns:
trueif the connected server has declared the ability to receive a packet on the specified channel. False if the client is not in game.- Throws:
IllegalArgumentException
-
canSend
public static boolean canSend(net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<?> type) Checks if the connected server declared the ability to receive a packet on a specified channel name. This returnsfalseif the client is not in game.- Parameters:
type- the packet type- Returns:
trueif the connected server has declared the ability to receive a packet on the specified channel
-
getSender
Gets the packet sender which sends packets to the connected server.- Returns:
- the client's packet sender
- Throws:
IllegalStateException- if the client is not connected to a server
-
send
public static void send(net.minecraft.network.protocol.common.custom.CustomPacketPayload payload) Sends a packet to the connected server.Any packets sent must be registered.
- Parameters:
payload- to be sent- Throws:
IllegalStateException- if the client is not connected to a server
-