Skip to content

Interface IMinecraftPacketIdRegistry

Namespace: Void.Minecraft.Network.Registries.PacketId
Assembly: Void.Minecraft.dll

Maintains bidirectional packet type-to-identifier mappings for one protocol version and operation.

public interface IMinecraftPacketIdRegistry

Extension Methods

MinecraftPacketIdRegistryExtensions.RegisterPacket<T>(IMinecraftPacketIdRegistry, ProtocolVersion, params MinecraftPacketIdMapping[])

Properties

IsEmpty

Gets whether both forward and reverse mapping tables contain no entries.

bool IsEmpty { get; }

Property Value

bool

PacketTypes

Gets the packet types currently mapped by numeric identifier.

IEnumerable<Type> PacketTypes { get; }

Property Value

IEnumerable<Type>

Methods

AddPackets(IReadOnlyDictionary<MinecraftPacketIdMapping[], Type>, ProtocolVersion)

Adds mappings valid for a protocol version without clearing existing entries.

IMinecraftPacketIdRegistry AddPackets(IReadOnlyDictionary<MinecraftPacketIdMapping[], Type> mappings, ProtocolVersion protocolVersion)

Parameters

mappings IReadOnlyDictionary<MinecraftPacketIdMapping[], Type>

Packet types keyed by ordered identifier mapping arrays.

protocolVersion ProtocolVersion

The protocol version for which entries are selected.

Returns

IMinecraftPacketIdRegistry

This registry.

Exceptions

ArgumentException

A mapping interval is reversed or a selected identifier or type conflicts with an existing entry.

Clear()

Removes every forward and reverse packet mapping.

void Clear()

Clear(Direction)

Removes mappings whose packet types belong to a protocol direction.

void Clear(Direction direction)

Parameters

direction Direction

The clientbound or serverbound direction to remove.

Exceptions

ArgumentOutOfRangeException

direction is not clientbound or serverbound.

Contains<T>()

Determines whether a compatible mapping exists for a packet type.

bool Contains<T>() where T : IMinecraftPacket

Returns

bool

true when a compatible type is registered; otherwise, false.

Type Parameters

T

The packet type to query.

Contains(INetworkMessage)

Determines whether a compatible mapping exists for a message’s runtime type.

bool Contains(INetworkMessage message)

Parameters

message INetworkMessage

The message to query.

Returns

bool

true when a compatible type is registered; otherwise, false.

Contains(Type)

Determines whether a compatible mapping exists for a runtime type.

bool Contains(Type type)

Parameters

type Type

The type to query.

Returns

bool

true when a compatible type is registered; otherwise, false.

ReplacePackets(IReadOnlyDictionary<MinecraftPacketIdMapping[], Type>, ProtocolVersion)

Clears existing entries and selects mappings valid for a protocol version.

IMinecraftPacketIdRegistry ReplacePackets(IReadOnlyDictionary<MinecraftPacketIdMapping[], Type> mappings, ProtocolVersion protocolVersion)

Parameters

mappings IReadOnlyDictionary<MinecraftPacketIdMapping[], Type>

Packet types keyed by ordered identifier mapping arrays.

protocolVersion ProtocolVersion

The protocol version for which entries are selected.

Returns

IMinecraftPacketIdRegistry

This registry.

Exceptions

ArgumentException

A mapping interval is reversed or a selected identifier or type conflicts with an existing selected entry.

TryCreateDecoder(int, out MinecraftPacketDecoder<IMinecraftPacket>)

Attempts to create the registered packet type’s static decoder for an identifier.

bool TryCreateDecoder(int id, out MinecraftPacketDecoder<IMinecraftPacket> packet)

Parameters

id int

The packet identifier.

packet MinecraftPacketDecoder<IMinecraftPacket>

When successful, the decoder delegate; otherwise, null.

Returns

bool

true when the identifier maps to a type with a compatible public static decode method; otherwise, false.

TryCreateDecoder(int, out Type, out MinecraftPacketDecoder<IMinecraftPacket>)

Attempts to resolve both the packet type and its static decoder for an identifier.

bool TryCreateDecoder(int id, out Type packetType, out MinecraftPacketDecoder<IMinecraftPacket> packet)

Parameters

id int

The packet identifier.

packetType Type

When successful, the registered packet type; otherwise, null.

packet MinecraftPacketDecoder<IMinecraftPacket>

When successful, the decoder delegate; otherwise, null.

Returns

bool

true when both type and decoder are available; otherwise, false.

TryGetPacketId(IMinecraftPacket, out int)

Attempts to get the identifier registered for a packet’s exact runtime type.

bool TryGetPacketId(IMinecraftPacket packet, out int id)

Parameters

packet IMinecraftPacket

The packet instance to query.

id int

When successful, the registered identifier; otherwise, the default integer value.

Returns

bool

true when the runtime type has a reverse mapping; otherwise, false.

TryGetType(int, out Type)

Attempts to get the type mapped to a packet identifier.

bool TryGetType(int id, out Type packetType)

Parameters

id int

The packet identifier.

packetType Type

When successful, the mapped type; otherwise, null.

Returns

bool

true when the identifier is registered; otherwise, false.