PHPackages                             pocketmine/nbt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. pocketmine/nbt

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

pocketmine/nbt
==============

PHP library for working with Named Binary Tags

1.2.0(8mo ago)42574.4k—1.8%20[13 issues](https://github.com/pmmp/NBT/issues)[2 PRs](https://github.com/pmmp/NBT/pulls)11LGPL-3.0PHPPHP ^7.4 || ^8.0CI passing

Since Jan 11Pushed 4mo ago10 watchersCompare

[ Source](https://github.com/pmmp/NBT)[ Packagist](https://packagist.org/packages/pocketmine/nbt)[ RSS](/packages/pocketmine-nbt/feed)WikiDiscussions stable Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (35)Used By (11)

PocketMine-NBT
==============

[](#pocketmine-nbt)

[![CI](https://github.com/pmmp/NBT/workflows/CI/badge.svg)](https://github.com/pmmp/NBT/workflows/CI/badge.svg)

PHP library for working with the NBT (Named Binary Tag) data storage format, as designed by Mojang.

Examples
--------

[](#examples)

The library provides two NBT serializers: `BigEndianNbtSerializer` (typically suited for Minecraft Java) and `LittleEndianNbtSerializer` (typically used by Bedrock for storage).

Note: Bedrock network NBT (which uses varints in some places) is not implemented here. See [BedrockProtocol](https://github.com/pmmp/BedrockProtocol) for that.

Note: `TAG_LongArray` is not supported because Bedrock doesn't support it, so it's not clear how NBT trees intended for serialization by Bedrock would be restricted from using it.

### Reading data

[](#reading-data)

```
use pocketmine\nbt\LittleEndianNbtSerializer;
use pocketmine\nbt\NbtDataException;
use pocketmine\nbt\NoSuchTagException;
use pocketmine\nbt\UnexpectedTagTypeException;
use pocketmine\nbt\tag\StringTag;

$serializer = new LittleEndianNbtSerializer();
$optionalStartOffset = 0;
$optionalMaxDepth = 0; //unlimited by default
$treeRoot = $serializer->read($yourInputBytes, $optionalStartOffset, $optionalMaxDepth);

try{
    //If you expect a TAG_Compound root (the most common case)
    $data = $treeRoot->mustGetCompoundTag());
}catch(NbtDataException $e){
    var_dump("root isn't a TAG_Compound");
}
//For other, less common cases where the root tag isn't a compound
var_dump($treeRoot->getTag());

var_dump($treeRoot->getName()); //typically empty

try{
    var_dump($data->getString("hello"));
}catch(UnexpectedTagTypeException $e){
    var_dump("not a TAG_String");
}catch(NoSuchTagException $e){
    var_dump("no such tag called \"hello\"");
}

try{
    $nestedCompound = $data->getCompoundTag("nestedCompound");
}catch(UnexpectedTagTypeException $e){
    var_dump("not a TAG_Compound");
}
if($nestedCompound === null){
    //For legacy BC reasons, this works differently than the primitive type getters like getString() getInt() etc
    var_dump("no such nested tag called \"nestedCompound\"");
}

try{
    $nestedList = $data->getListTag("listOfStrings", StringTag::class);
}catch(UnexpectedTagTypeException $e){
    var_dump("not a list of strings");
}
if($nestedList === null){
    //For legacy BC reasons, getListTag() returns NULL if the tag doesn't exist
    var_dump("no such nested tag called \"listOfStrings\"");
}
var_dump($nestedList->getValue()); //StringTag[]
```

### Writing data

[](#writing-data)

```
use pocketmine\nbt\LittleEndianNbtSerializer;
use pocketmine\nbt\TreeRoot;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\StringTag;

$compound = CompoundTag::create()
    ->setByte("byte", 1)
    ->setInt("int", 2)
    ->setTag("list", new ListTag([
        new StringTag("item1"),
        new StringTag("item2")
    ]))
    ->setTag("compound", CompoundTag::create()
        ->setByte("nestedByte", 1)
    );

//empty lists infer their type from the first value added
$list = new ListTag();
$list->push(new StringTag("hello")); //list is now ListTag
try{
    $list->push(new IntTag(1));
}catch(\TypeError $e){
    var_dump("can't push an int into a string list");
}

$serializer = new LittleEndianNbtSerializer();
$bytes = $serializer->write($treeRoot);

//or if you have a Tag instance
$bytes = $serializer->write(new TreeRoot($data, "optionalRootName"));
```

###  Health Score

60

—

FairBetter than 99% of packages

Maintenance62

Regular maintenance activity

Popularity50

Moderate usage in the ecosystem

Community34

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 74% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~90 days

Recently: every ~199 days

Total

32

Last Release

241d ago

Major Versions

0.3.4 → 1.0.02023-07-14

PHP version history (3 changes)0.0.1PHP &gt;=7.2.0

0.2.16PHP ^7.2 || ^8.0

0.3.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/c8a755241617f6c78b33788a288ea7387a417410109293e3a9e3caad74720a44?d=identicon)[dktapps](/maintainers/dktapps)

![](https://www.gravatar.com/avatar/f43e76a228e4a42f099a6ac3c1dbfeadf5e94eaa77e2a70c1431fb12e753255b?d=identicon)[pmmp](/maintainers/pmmp)

---

Top Contributors

[![dktapps](https://avatars.githubusercontent.com/u/14214667?v=4)](https://github.com/dktapps "dktapps (311 commits)")[![shoghicp](https://avatars.githubusercontent.com/u/516482?v=4)](https://github.com/shoghicp "shoghicp (50 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (32 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (14 commits)")[![SOF3](https://avatars.githubusercontent.com/u/19623715?v=4)](https://github.com/SOF3 "SOF3 (6 commits)")[![Sandertv](https://avatars.githubusercontent.com/u/16114089?v=4)](https://github.com/Sandertv "Sandertv (2 commits)")[![yoraze](https://avatars.githubusercontent.com/u/25742996?v=4)](https://github.com/yoraze "yoraze (1 commits)")[![buchwasa](https://avatars.githubusercontent.com/u/17461354?v=4)](https://github.com/buchwasa "buchwasa (1 commits)")[![JackNoordhuis](https://avatars.githubusercontent.com/u/10399774?v=4)](https://github.com/JackNoordhuis "JackNoordhuis (1 commits)")[![PEMapModder](https://avatars.githubusercontent.com/u/5618466?v=4)](https://github.com/PEMapModder "PEMapModder (1 commits)")[![alex2534alex](https://avatars.githubusercontent.com/u/15706847?v=4)](https://github.com/alex2534alex "alex2534alex (1 commits)")

---

Tags

github-actions-enabledon-packagistphp81phpstan-l10phpstan-strict

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/pocketmine-nbt/health.svg)

```
[![Health](https://phpackages.com/badges/pocketmine-nbt/health.svg)](https://phpackages.com/packages/pocketmine-nbt)
```

###  Alternatives

[pocketmine/pocketmine-mp

A server software for Minecraft: Bedrock Edition written in PHP

3.5k74.6k86](/packages/pocketmine-pocketmine-mp)[godruoyi/php-snowflake

An ID Generator for PHP based on Snowflake Algorithm (Twitter announced).

8582.3M61](/packages/godruoyi-php-snowflake)[bitwasp/bitcoin

PHP Bitcoin library with functions for transactions, signatures, serialization, Random/Deterministic ECDSA keys, blocks, RPC bindings

1.1k533.2k43](/packages/bitwasp-bitcoin)[bitwasp/buffertools

Toolbox for working with binary and hex data. Similar to NodeJS Buffer.

65764.4k41](/packages/bitwasp-buffertools)[pocketmine/math

PHP library containing math related code used in PocketMine-MP

45573.2k14](/packages/pocketmine-math)[furqansiddiqui/bip39-mnemonic-php

BIP39 Mnemonics implementation in PHP

56176.9k18](/packages/furqansiddiqui-bip39-mnemonic-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
