Skip to content

Struct Uuid

Namespace: Void.Minecraft.Profiles
Assembly: Void.Minecraft.dll

A Minecraft-compatible UUID backed by a .NET , with factory methods for the wire-format encodings used by the Java Edition protocol.

[JsonConverter(typeof(UuidJsonConverter))]
public struct Uuid : IComparable<Uuid>, IEquatable<Uuid>

Implements

IComparable<Uuid>, IEquatable<Uuid>

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Extension Methods

StructExtensions.IsDefault<Uuid>(Uuid)

Constructors

Uuid(Guid)

A Minecraft-compatible UUID backed by a .NET , with factory methods for the wire-format encodings used by the Java Edition protocol.

public Uuid(Guid guid)

Parameters

guid Guid

Properties

AsGuid

Gets the underlying .NET value.

public readonly Guid AsGuid { get; }

Property Value

Guid

Empty

Gets the zero UUID (00000000-0000-0000-0000-000000000000), wrapping .

public static Uuid Empty { get; }

Property Value

Uuid

Methods

CompareTo(Uuid)

Compares this UUID to other using the underlying comparison.

public readonly int CompareTo(Uuid other)

Parameters

other Uuid

The UUID to compare against.

Returns

int

A negative integer, zero, or a positive integer if this instance is less than, equal to, or greater than other, respectively.

Equals(Uuid)

Returns true if this UUID equals other by comparing their underlying values.

public readonly bool Equals(Uuid other)

Parameters

other Uuid

The UUID to compare against.

Returns

bool

true if the two UUIDs are equal; otherwise, false.

Equals(object?)

Returns true if obj is a equal to this instance.

public override readonly bool Equals(object? obj)

Parameters

obj object?

The object to compare against.

Returns

bool

true if obj is a with the same value; otherwise, false.

FromLongs(long, long)

Reconstructs a UUID from the Java UUID.getMostSignificantBits() and UUID.getLeastSignificantBits() long values.

public static Uuid FromLongs(long mostSig, long leastSig)

Parameters

mostSig long

The most significant 64 bits of the UUID.

leastSig long

The least significant 64 bits of the UUID.

Returns

Uuid

The equivalent to the Java UUID with the given bit halves.

Remarks

The byte reordering translates from Java’s big-endian UUID representation to the mixed-endian layout used by .NET’s .

FromStringHash(string)

Derives a deterministic UUID from a UTF-8 string by computing its MD5 hash and stamping the result with UUID Version 3 bits and the RFC 4122 variant bits.

public static Uuid FromStringHash(string text)

Parameters

text string

The input string to hash. Cannot be null.

Returns

Uuid

A UUID whose 128-bit value is the MD5 hash of text, with the version and variant fields set.

Exceptions

ArgumentNullException

text is null.

GetHashCode()

Returns the hash code of the underlying .

public override readonly int GetHashCode()

Returns

int

The hash code for this UUID.

GetVariant()

Returns the UUID variant as an integer decoded from the variant byte.

public int GetVariant()

Returns

int

0 for NCS backward compatibility, 1 for RFC 4122, 2 for Microsoft, 3 for future reserved, or -1 if the variant byte is not in an expected range.

GetVersion()

Returns the UUID version number extracted from the version nibble of the underlying 128-bit value.

public int GetVersion()

Returns

int

An integer between 1 and 5 representing the UUID version field.

NewUuid()

Creates a new random UUID (Version 4).

public static Uuid NewUuid()

Returns

Uuid

A new backed by a freshly generated .

Offline(string)

public static Uuid Offline(string name)

Parameters

name string

Returns

Uuid

Parse(string)

Parses a UUID from its standard string representation.

public static Uuid Parse(string text)

Parameters

text string

The UUID string to parse.

Returns

Uuid

The parsed .

Exceptions

FormatException

text is not in a recognized UUID format.

Parse(params int[])

Constructs a UUID from exactly four integers as encoded in the Minecraft Java Edition protocol.

public static Uuid Parse(params int[] parts)

Parameters

parts int[]

An array of exactly four int values representing the UUID.

Returns

Uuid

The reconstructed from the four integer parts.

Remarks

In the Java Edition protocol, a UUID is transmitted as two 64-bit halves, each split into two big-endian int values. This method reorders the bytes to produce the equivalent .NET representation.

Exceptions

ArgumentException

parts does not contain exactly four elements.

ToString()

Returns the standard hyphenated lowercase UUID string representation, for example “550e8400-e29b-41d4-a716-446655440000”.

public override readonly string ToString()

Returns

string

TryParse(string?, out Uuid)

Attempts to parse a UUID string. Returns true and sets uuid on success; returns false and sets uuid to the default value on failure.

public static bool TryParse(string? text, out Uuid uuid)

Parameters

text string?

The UUID string to parse, or null.

uuid Uuid

When this method returns true, contains the parsed ; otherwise, the default value.

Returns

bool

true if text was successfully parsed; otherwise, false.

Operators

operator ==(Uuid, Uuid)

Returns true if left and right are equal.

public static bool operator ==(Uuid left, Uuid right)

Parameters

left Uuid

The first UUID to compare.

right Uuid

The second UUID to compare.

Returns

bool

true if the two UUIDs are equal; otherwise, false.

operator !=(Uuid, Uuid)

Returns true if left and right are not equal.

public static bool operator !=(Uuid left, Uuid right)

Parameters

left Uuid

The first UUID to compare.

right Uuid

The second UUID to compare.

Returns

bool

true if the two UUIDs are not equal; otherwise, false.