Class ClientNetworkRegistry
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final io.netty.util.AttributeKey<Lock> private static final io.netty.util.AttributeKey<Boolean> private static final org.slf4j.Loggerprivate static booleanFields inherited from class NetworkRegistry
BUILTIN_PAYLOADS, CLIENTBOUND_HANDLERS, PAYLOAD_REGISTRATIONS, SERVERBOUND_HANDLERS, setup, SUPPORTED_COMMON_NETWORKING_VERSIONS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidprivate static voidprivate static voidUsed in place ofThread.dumpStack()as that logs toSystem.err.private static LockgetConnectionInitializationLock(Connection connection) static voidhandleModdedPayload(ClientCommonPacketListener listener, ClientboundCustomPayloadPacket packet) Handles modded payloads on the client.static voidInvoked by the client to indicate that it detect a connection to a modded server, by receiving aModdedNetworkPayload.static voidInitializes the client-side network state for a server that is not running NeoForge.static booleanisConnectionInitialized(Connection connection) static voidInvoked by the client when a modded server queries it for its available channels.static <T extends CustomPacketPayload>
voidregister(CustomPacketPayload.Type<T> type, HandlerThread thread, IPayloadHandler<T> handler) private static voidrunConnectionInitialization(Connection connection, Runnable initialization) Runsinitializationat most once forconnection.static voidInvoked by the client when it receives aMinecraftRegisterPayloadduring negotiation in the configuration phase.static voidsetup()Sets up the client network registry by firingRegisterClientPayloadHandlersEvent, updating the payload registrations for clientbound payloads inNetworkRegistry.PAYLOAD_REGISTRATIONS.Methods inherited from class NetworkRegistry
checkCommonVersion, checkPacket, checkPacket, configureMockConnection, filterGameBundlePackets, getCodec, getCommonPlayChannels, getConnectionType, getInitialListeningChannels, getInitialServerUnregisterChannels, guard, handleModdedPayload, handlePacketUnchecked, hasAdhocChannel, hasChannel, hasChannel, initializeNeoForgeConnection, initializeOtherConnection, isModdedPayload, onCommonRegister, onConfigurationFinished, onMinecraftRegister, onMinecraftUnregister, register, registerHandler
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
CONNECTION_INITIALIZATION_LOCK
-
CONNECTION_INITIALIZED
-
setupClient
private static boolean setupClient
-
-
Constructor Details
-
ClientNetworkRegistry
private ClientNetworkRegistry()
-
-
Method Details
-
setup
public static void setup()Sets up the client network registry by firingRegisterClientPayloadHandlersEvent, updating the payload registrations for clientbound payloads inNetworkRegistry.PAYLOAD_REGISTRATIONS. -
register
public static <T extends CustomPacketPayload> void register(CustomPacketPayload.Type<T> type, HandlerThread thread, IPayloadHandler<T> handler) -
handleModdedPayload
public static void handleModdedPayload(ClientCommonPacketListener listener, ClientboundCustomPayloadPacket packet) Handles modded payloads on the client. Invoked after built-in handling.Called on the network thread.
- Parameters:
listener- The listener which received the packet.packet- The packet that was received.
-
onNetworkQuery
Invoked by the client when a modded server queries it for its available channels. The negotiation happens solely on the server side, and the result is later transmitted to the client.Invoked on the network thread.
- Parameters:
listener- The listener which received the query.
-
initializeNeoForgeConnection
public static void initializeNeoForgeConnection(ClientConfigurationPacketListener listener, NetworkPayloadSetup setup) Invoked by the client to indicate that it detect a connection to a modded server, by receiving aModdedNetworkPayload. This will configure the active connection to the server to use the channels that were negotiated.Once this method completes a
NetworkPayloadSetupwill be present on the connection.Invoked on the network thread.
- Parameters:
listener- The listener which received the payload.setup- The network channels that were negotiated.
-
configureNeoForgeConnection
private static void configureNeoForgeConnection(ClientConfigurationPacketListener listener, NetworkPayloadSetup setup) -
initializeOtherConnection
Initializes the client-side network state for a server that is not running NeoForge.
The client checks its registered channels for vanilla compatibility and disconnects if any require a modded server. Initialization is performed once per connection on the network thread. If the connection has since been identified as
ConnectionType.NEOFORGE, this method does nothing.- Parameters:
listener- the active configuration listener
-
configureOtherConnection
-
sendInitialListeningChannels
Invoked by the client when it receives a
MinecraftRegisterPayloadduring negotiation in the configuration phase. This will respond to the server with the client's set of builtin and optional channels to indicate it supports the common protocol.Invoked on the network thread.
- Parameters:
listener- The listener which received the brand payload.
-
isConnectionInitialized
-
runConnectionInitialization
Runs
initializationat most once forconnection.Connection classification may run concurrently from the render thread and the Netty event loop. Both the vanilla and NeoForge paths inject network filters, so without serialization they can both remove the existing filter before either one adds its replacement, causing a duplicate-handler failure. The connection-specific lock keeps the initialization check and filter injection atomic, and the initialized attribute makes subsequent attempts no-ops.
See PR #3415 for details and steps to reproduce the issue.
- Parameters:
connection- the connection being initializedinitialization- the connection-specific initialization action
-
getConnectionInitializationLock
-
dumpStackToLog
private static void dumpStackToLog()Used in place ofThread.dumpStack()as that logs toSystem.err.
-