Class ClientNetworkRegistry

java.lang.Object
net.neoforged.neoforge.network.registration.NetworkRegistry
net.neoforged.neoforge.client.network.registration.ClientNetworkRegistry

@Internal public final class ClientNetworkRegistry extends NetworkRegistry
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • CONNECTION_INITIALIZATION_LOCK

      private static final io.netty.util.AttributeKey<Lock> CONNECTION_INITIALIZATION_LOCK
    • CONNECTION_INITIALIZED

      private static final io.netty.util.AttributeKey<Boolean> 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 firing RegisterClientPayloadHandlersEvent, updating the payload registrations for clientbound payloads in NetworkRegistry.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

      public static void onNetworkQuery(ClientConfigurationPacketListener listener)
      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 a ModdedNetworkPayload. This will configure the active connection to the server to use the channels that were negotiated.

      Once this method completes a NetworkPayloadSetup will 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

      public static void initializeOtherConnection(ClientConfigurationPacketListener listener)

      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

      private static void configureOtherConnection(ClientConfigurationPacketListener listener)
    • sendInitialListeningChannels

      public static void sendInitialListeningChannels(ClientConfigurationPacketListener listener)

      Invoked by the client when it receives a MinecraftRegisterPayload during 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

      public static boolean isConnectionInitialized(Connection connection)
    • runConnectionInitialization

      private static void runConnectionInitialization(Connection connection, Runnable initialization)

      Runs initialization at most once for connection.

      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 initialized
      initialization - the connection-specific initialization action
    • getConnectionInitializationLock

      private static Lock getConnectionInitializationLock(Connection connection)
    • dumpStackToLog

      private static void dumpStackToLog()
      Used in place of Thread.dumpStack() as that logs to System.err.