Class PacketType<T extends FabricPacket>

java.lang.Object
net.fabricmc.fabric.api.networking.v1.PacketType<T>
Type Parameters:
T - the type of the packet

public final class PacketType<T extends FabricPacket> extends Object
A type of packet. An instance of this should be created per a FabricPacket implementation. This holds the channel ID used for the packet.
See Also:
  • Method Details

    • create

      public static <P extends FabricPacket> PacketType<P> create(Identifier id, Function<PacketByteBuf,P> constructor)
      Creates a new packet type.
      Type Parameters:
      P - the type of the packet
      Parameters:
      id - the channel ID used for the packets
      constructor - the reader that reads the received buffer
      Returns:
      the newly created type
    • getId

      public Identifier getId()
      Returns the identifier of the channel used to send the packet.
      Returns:
      the identifier of the associated channel.
    • read

      public T read(PacketByteBuf buf)
      Reads the packet from the buffer.
      Parameters:
      buf - the buffer
      Returns:
      the packet