2017 © Pedro Peláez
 

library nbt

Parser/Writer for the NBT file format

image

rickselby/nbt

Parser/Writer for the NBT file format

  • Friday, December 18, 2015
  • by rickselby
  • Repository
  • 1 Watchers
  • 4 Stars
  • 260 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 13 Versions
  • 4 % Grown

The README.md

This is a Named Binary Tag parser based upon the specification by Markus Persson., (*1)

From the spec: "NBT (Named Binary Tag) is a tag based binary format designed to carry large amounts of binary data with smaller amounts of additional data. An NBT file consists of a single GZIPped Named Tag of type TAG_Compound.", (*2)

NBT data is also used in region files, which store the data for Minecraft worlds., (*3)

Requires the GMP Extension for PHP on 32-bit builds., (*4)

Installing

Composer

The library can be pulled in using composer; add the following to your composer.json:, (*5)

{
    "require": {
        "rickselby/nbt": "~4.0"
    }
}

Usage

Reading in from files, resources, or strings:, (*6)

$nbtService = new \Nbt\Service(new \Nbt\DataHandler());
$tree = $nbtService->loadFile('filename.nbt');
$tree = $nbtService->readFilePointer($fPtr);
$tree = $nbtService->readString($nbtString);

Then writing to a file, a resource, or returning a string:, (*7)

$nbtService->writeFile('filename.nbt', $tree);
$nbtService->writeFilePointer($fPtr, $tree);
$nbtString = $nbtService->writeString($tree);

To look through a tree:, (*8)

echo $tree->getName();
$type = $tree->getType();

// Value isn't set for Lists and Compounds; those nodes have children instead
$value = $tree->getValue();

$sectionsNode = $tree->findChildByName('Sections');

To update a tree:, (*9)

$node->setName('Name');
$node->setValue(123456);

To create new nodes:, (*10)

// This is pretty useless on it's own really
$node = \Nbt\Tag::tagByte('aByte', 0x0f);

// You'll be building trees with Compounds and Lists mostly; both take an array of nodes as their values
$tree = \Nbt\Tag::tagCompound('aCompound', [
    \Nbt\Tag::tagByte('aByte', 0x0f),
    \Nbt\Tag::tagInt('aNumber', 12345),
]);

// Child tags for lists do not require names, as they are not named - and they must match the payload of the list
$tree = \Nbt\Tag::tagList('aList', \Nbt\Tag::TAG_STRING, [
    \Nbt\Tag::tagString('', 'firstString'),
    \Nbt\Tag::tagString('', 'secondString'),
]);

History

The original PHP NBT package was written by TheFrozenFire., (*11)

This repo has been forked by many, but most forks have one of two issues; they either don't handle TAG_INT_ARRAY or don't correctly handle writing to a file pointer., (*12)

The returned format - an array - isn't ideal for creating your own NBT data, and some kind of wrapper was required to assist in creation., (*13)

I tidied up the code a little, then added nicmart/tree to store the NBT data; after much work, it's nothing like the original, so I've pulled it into it's own (non-forked) repo., (*14)

The Versions

18/12 2015

dev-master

9999999-dev https://github.com/rickselby/NBT

Parser/Writer for the NBT file format

  Sources   Download

MIT

The Requires

 

The Development Requires

  • mikey179/vfsstream ^1.6.0

binary encode decode nbt

16/12 2015

4.0.0

4.0.0.0 https://github.com/rickselby/NBT

Parser/Writer for the NBT file format

  Sources   Download

MIT

The Requires

 

The Development Requires

  • mikey179/vfsstream ^1.6.0

binary encode decode nbt

21/10 2015

3.1.1

3.1.1.0 https://github.com/rickselby/NBT

Parser/Writer for the NBT file format

  Sources   Download

GNU

The Requires

 

binary encode decode nbt

11/10 2015

3.1

3.1.0.0 https://github.com/rickselby/PHP-NBT-Decoder-Encoder

A PHP-based NBT format decoder and encoder, for the Minecraft NBT format.

  Sources   Download

GNU

The Requires

 

binary encode decode nbt

09/10 2015

3.0.3

3.0.3.0 https://github.com/rickselby/PHP-NBT-Decoder-Encoder

A PHP-based NBT format decoder and encoder, for the Minecraft NBT format.

  Sources   Download

GNU

The Requires

 

binary encode decode nbt

08/10 2015

3.0.2

3.0.2.0 https://github.com/rickselby/PHP-NBT-Decoder-Encoder

A PHP-based NBT format decoder and encoder, for the Minecraft NBT format.

  Sources   Download

GNU

The Requires

 

binary encode decode nbt

08/10 2015

3.0.1

3.0.1.0 https://github.com/rickselby/PHP-NBT-Decoder-Encoder

A PHP-based NBT format decoder and encoder, for the Minecraft NBT format.

  Sources   Download

GNU

The Requires

 

binary encode decode nbt

08/10 2015

3.0.0

3.0.0.0 https://github.com/rickselby/PHP-NBT-Decoder-Encoder

A PHP-based NBT format decoder and encoder, for the Minecraft NBT format.

  Sources   Download

GNU

The Requires

 

binary encode decode nbt

06/10 2015

2.0.0

2.0.0.0 https://github.com/rickselby/PHP-NBT-Decoder-Encoder

A PHP-based NBT format decoder and encoder, for the Minecraft NBT format.

  Sources   Download

GNU

The Requires

  • php >=5.3.0

 

binary encode decode nbt

05/10 2015

1.0.3

1.0.3.0 https://github.com/rickselby/PHP-NBT-Decoder-Encoder

A PHP-based NBT format decoder and encoder, for the Minecraft NBT format.

  Sources   Download

GNU

The Requires

  • php >=5.3.0

 

binary encode decode nbt

26/06 2013

1.0.2

1.0.2.0 https://github.com/Caffe1neAdd1ct/PHP-NBT-Decoder-Encoder

A PHP-based NBT format decoder and encoder, for the Minecraft NBT format.

  Sources   Download

GNU

The Requires

  • php >=5.3.0

 

binary encode decode nbt

26/06 2013

1.0.1

1.0.1.0 https://github.com/Caffe1neAdd1ct/PHP-NBT-Decoder-Encoder

A PHP-based NBT format decoder and encoder, for the Minecraft NBT format.

  Sources   Download

GNU

The Requires

  • php >=5.3.0

 

binary encode decode nbt

26/06 2013

1.0.0

1.0.0.0

A PHP-based NBT format decoder and encoder, for the Minecraft NBT format.

  Sources   Download

The Requires

  • php >=5.3.0