PHP code example of rickselby / nbt

1. Go to this page and download the library: Download rickselby/nbt library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rickselby / nbt example snippets


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

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

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');

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

// 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