Skip to content

Networking Manager

The NetworkingManager class is a singleton responsible for managing network communications within the application. It provides methods to register custom packet types for both client-to-server (C2S) and server-to-client (S2C) communications, as well as methods to send packets to the server or specific players.

To obtain the instance of the NetworkingManager, you can use the following code:

NetworkingManager networkingManager = MatthiesenCoreCommon.INSTANCE.getNetworkingManager();
  • <T extends CustomPacketPayload> void registerC2S(CustomPacketPayload.Type<T> type, StreamCodec<RegistryFriendlyByteBuf, T> codec, BiConsumer<T, PacketContext> handler)
    • Registers a custom packet type for client-to-server communication. You need to provide the packet type, a codec for encoding/decoding the packet, and a handler to process the received packet.
  • <T extends CustomPacketPayload> void registerS2C(CustomPacketPayload.Type<T> type, StreamCodec<RegistryFriendlyByteBuf, T> codec, BiConsumer<T, PacketContext> handler)
    • Registers a custom packet type for server-to-client communication. Similar to the C2S registration, you need to provide the packet type, a codec, and a handler.
  • void sendToServer(CustomPacketPayload payload)
    • Sends a custom packet payload to the server. This method is used for client-to-server communication.
  • void sendToPlayer(ServerPlayer player, CustomPacketPayload payload)
    • Sends a custom packet payload to a specific player. This method is used for server-to-client communication.