Class CustomPayloadNetwork

java.lang.Object
io.github.thecsdev.tcdcommons.api.network.CustomPayloadNetwork

public final class CustomPayloadNetwork extends Object
This is a utility class that allows you to register custom payload receivers using TCDCommons's network implementation.
See Also:
  • Method Details

    • registerReceiver

      public static CustomPayloadNetworkReceiver registerReceiver(net.minecraft.network.NetworkSide side, net.minecraft.util.Identifier packetId, CustomPayloadNetworkReceiver receiver)
      Registers a CustomPayloadNetworkReceiver for a given custom payload packet.

      Important: Receivers are executed on the network thread.

      Parameters:
      side - The NetworkSide which to listen on.
      packetId - The unique Identifier of the custom payload packets to listen for.
      receiver - The listener interface.
      Returns:
      The CustomPayloadNetworkReceiver that was registered.
      Throws:
      NullPointerException - If an argument is null.
      IllegalArgumentException - If the NetworkSide is "unexpected".
      See Also:
      • ThreadExecutor.executeSync(Runnable)
    • unregisterReceiver

      public static boolean unregisterReceiver(net.minecraft.network.NetworkSide side, net.minecraft.util.Identifier packetId)
      Un-Registers a CustomPayloadNetworkReceiver for a given custom payload packet.
      Parameters:
      side - The NetworkSide the CustomPayloadNetworkReceiver is listening on.
      packetId - The unique Identifier of the custom payload packets being listened.
      Returns:
      true if the CustomPayloadNetworkReceiver was present before getting removed.
    • sendC2S

      public static final void sendC2S(net.minecraft.util.Identifier packetId, io.netty.buffer.ByteBuf packetData) throws IllegalStateException, NullPointerException
      Sends a custom payload from the client to the server, using the TCDCommons network protocol.
      Parameters:
      packetId - The custom payload packet Identifier.
      packetData - The custom payload.
      Throws:
      NullPointerException - If an argument is null.
      IllegalStateException - If (NOT_CLIENT) or (REF_CNT < 1).
    • sendS2C

      public static final void sendS2C(net.minecraft.server.network.ServerPlayerEntity player, net.minecraft.util.Identifier packetId, io.netty.buffer.ByteBuf packetData) throws IllegalStateException, NullPointerException
      Sends a custom payload from the server to the client, using the TCDCommons network protocol.
      Parameters:
      player - The ServerPlayerEntity to send the packet to.
      packetId - The custom payload packet Identifier.
      packetData - The custom payload.
      Throws:
      NullPointerException - If an argument is null.
      IllegalStateException - If (REF_CNT < 1).