stilling/snbt-parser

Turn Minecraft SNBT data into the corresponding PHP data types.

Maintainers

Package info

github.com/m-stilling/snbt-parser-php

pkg:composer/stilling/snbt-parser

Statistics

Installs: 7

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.3.0 2026-06-13 21:51 UTC

This package is auto-updated.

Last update: 2026-06-14 11:34:57 UTC


README

tests Packagist Version

Turn Minecraft SNBT data into the corresponding PHP data types.

composer require stilling/snbt-parser

Tip

Need to fetch this data from a server first? stilling/minecraft-rcon is a lightweight Minecraft RCON client that handles multi-packet responses - run commands like data get ... and feed the output straight into this parser.

Note

Under the hood this package transposes the SNBT to JSON and decodes it with json_decode(). Numeric values keep their full precision, but the NBT type suffixes are not retained - every integer type (b/s/i/l) becomes a PHP int and every floating-point type (f/d) becomes a PHP float. A potential v2 may parse SNBT directly to preserve type information and skip the JSON round-trip.

Here's an example parsing the SNBT data of a chest using the following command: data get block -40 73 -11

use Stilling\SNBTParser\SNBTParser;

SNBTParser::parse('{z: -11, x: -40, id: "minecraft:chest", y: 73, Items: [{count: 1, Slot: 0b, id: "minecraft:golden_horse_armor"}, {count: 1, Slot: 1b, id: "minecraft:saddle"}, {count: 1, Slot: 2b, components: {"minecraft:repair_cost": 1, "minecraft:enchantments": {"minecraft:luck_of_the_sea": 2, "minecraft:lure": 2, "minecraft:unbreaking": 3}, "minecraft:damage": 10}, id: "minecraft:fishing_rod"}, {count: 1, Slot: 3b, id: "minecraft:shield"}]}')

// returns ->

[
    "z" => -11,
    "x" => -40,
    "id" => "minecraft:chest",
    "y" => 73,
    "Items" => [
        [
            "count" => 1,
            "Slot" => 0,
            "id" => "minecraft:golden_horse_armor",
        ],
        [
            "count" => 1,
            "Slot" => 1,
            "id" => "minecraft:saddle",
        ],
        [
            "count" => 1,
            "Slot" => 2,
            "components" => [
                "minecraft:repair_cost" => 1,
                "minecraft:enchantments" => [
                    "minecraft:luck_of_the_sea" => 2,
                    "minecraft:lure" => 2,
                    "minecraft:unbreaking" => 3,
                ],
                "minecraft:damage" => 10,
            ],
            "id" => "minecraft:fishing_rod",
        ],
        [
            "count" => 1,
            "Slot" => 3,
            "id" => "minecraft:shield",
        ],
    ],
]

Converting UUIDs

Minecraft stores UUIDs as four-integer arrays (e.g. UUID: [I; 110787060, 1156138790, -1514210135, 238594805]). Once parsed, pass that array to intsToUuid() to get the canonical string form:

use Stilling\SNBTParser\SNBTParser;

SNBTParser::intsToUuid([110787060, 1156138790, -1514210135, 238594805]);

// returns -> "069a79f4-44e9-4726-a5be-fca90e38aaf5"