Struct Uuid
Namespace: Void.Minecraft.Profiles
Assembly: Void.Minecraft.dll
A Minecraft-compatible UUID backed by a .NET
[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
public Uuid(Guid guid)Parameters
guid Guid
Properties
AsGuid
Gets the underlying .NET
public readonly Guid AsGuid { get; }Property Value
Empty
Gets the zero UUID (00000000-0000-0000-0000-000000000000), wrapping
public static Uuid Empty { get; }Property Value
Methods
CompareTo(Uuid)
Compares this UUID to other using the underlying
public readonly int CompareTo(Uuid other)Parameters
other Uuid
The UUID to compare against.
Returns
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
public readonly bool Equals(Uuid other)Parameters
other Uuid
The UUID to compare against.
Returns
true if the two UUIDs are equal; otherwise, false.
Equals(object?)
Returns true if obj is a
public override readonly bool Equals(object? obj)Parameters
obj object?
The object to compare against.
Returns
true if obj is a
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
The
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
A UUID whose 128-bit value is the MD5 hash of text, with the version and variant fields set.
Exceptions
text is null.
GetHashCode()
Returns the hash code of the underlying
public override readonly int GetHashCode()Returns
The hash code for this UUID.
GetVariant()
Returns the UUID variant as an integer decoded from the variant byte.
public int GetVariant()Returns
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
An integer between 1 and 5 representing the UUID version field.
NewUuid()
Creates a new random UUID (Version 4).
public static Uuid NewUuid()Returns
A new
Offline(string)
public static Uuid Offline(string name)Parameters
name string
Returns
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
The parsed
Exceptions
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
The
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
Exceptions
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
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
Returns
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
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.