Skip to content

v1.1.0

Choose a tag to compare

@m-stilling m-stilling released this 25 Sep 09:55
· 22 commits to main since this release

This release adds three helpers that convert between UUID strings and the four-integer arrays Minecraft stores them as. It completes the round trip that intsToUuid() started. No existing behavior changes.

Added

  • SNBTParser::uuidToInts(string $uuid): array returns the four signed 32-bit integers for a UUID. It accepts the hyphenated form or 32 bare hex digits, in either case, and throws InvalidArgumentException for any other input.
  • SNBTParser::uuidToSnbt(string $uuid, SNBTFormat $format = SNBTFormat::Compact): string returns the same integers as a ready-made SNBT int array, for example [I;110787060,1156138790,-1514210135,238594805]. The format argument works the same as on toSnbt().
  • IntArrayTag::toUuid(): string reads a parsed int array as a UUID string. It throws InvalidArgumentException unless the array holds exactly four integers.

Example

use Stilling\SNBTParser\SNBTParser;

SNBTParser::uuidToInts("069a79f4-44e9-4726-a5be-fca90e38aaf5");
// [110787060, 1156138790, -1514210135, 238594805]

SNBTParser::uuidToSnbt("069a79f4-44e9-4726-a5be-fca90e38aaf5");
// "[I;110787060,1156138790,-1514210135,238594805]"

SNBTParser::parseTyped('{UUID: [I; 110787060, 1156138790, -1514210135, 238594805]}')->get("UUID")->toUuid();
// "069a79f4-44e9-4726-a5be-fca90e38aaf5"

Full Changelog: v1.0.0...v1.1.0