ClientToClientPacketDefinition

class ClientToClientPacketDefinition<T : Any>(id: ResourceLocation, binaryFormat: BinaryFormat, deserializer: KSerializer<T>) : AbstractPacketDefinition<T, ClientPacketContext> (source)

See c2cPacket function, which constructs this packet definition class.

Constructors

Link copied to clipboard
constructor(id: ResourceLocation, binaryFormat: BinaryFormat, deserializer: KSerializer<T>)

Types

Link copied to clipboard
value class SerializedPacket(val bytes: ByteArray)

A wrapper around a byte array containing packet data. This wrapper will be used when forwarding packets on the server, since deserialization should only happen when requested.

Properties

Link copied to clipboard
val binaryFormat: BinaryFormat
Link copied to clipboard
val id: ResourceLocation
Link copied to clipboard
val streamCodec: StreamCodec<FriendlyByteBuf, SilkPacketPayload>
Link copied to clipboard
val type: CustomPacketPayload.Type<SilkPacketPayload>

Functions

Link copied to clipboard

Deserializes this serialized packet to an instance of its original class.

Link copied to clipboard

Specifies the forward logic (on the server, as it is the instance which forwards this packet). The returned player will receive the packet. Return null if you do not wish to forward this packet.

Link copied to clipboard
fun receiveOnClient(receiver: suspend (packet: T, context: ClientPacketContext) -> Unit)

Executes the given receiver as a callback when this packet is received on the client-side.

Link copied to clipboard
fun send(value: T)

Sends the given value as a packet to the server, which will then forward it to players selected by the forwarder. You can specify the forwarder using forwardOnServer.