Пример #1
0
 /**
  * Initialise entity data, if none passed in.
  *
  * @param string         $id         Tile Entity ID
  * @param \Nbt\Node|null $entityData
  */
 protected function initEntityData($id, $entityData = null)
 {
     if ($entityData === null || get_class($entityData) !== \Nbt\Node::class || $entityData->getType() !== \Nbt\Tag::TAG_COMPOUND) {
         $entityData = \Nbt\Tag::tagCompound('', []);
     }
     $this->updateChildOrCreate($entityData, 'id', Tag::TAG_STRING, $id);
     $this->setEntityData($entityData);
 }
Пример #2
0
 /**
  * Get a mob head, with the given placement. If it's a player's head, BOTH
  * the ownerName and ownerID need to be set.
  *
  * @param int    $placement   One of the PLACE_ class constants
  * @param int    $orientation One of the ORIENT_ class constants
  * @param int    $type        One of the SKULL_ class constants
  * @param string $ownerName   Name of the player's head
  * @param string $ownerID     ID of the player's heads
  *
  * @throws \Exception
  */
 public function __construct($placement, $orientation, $type, $ownerName = '', $ownerID = '')
 {
     $this->setBlockIDFor(Ref::MOB_HEAD);
     $this->initEntityData('Skull');
     // This whole placement / orientation is very similar to signs and banners,
     // but just different enough that I can't reuse code. Argh.
     $this->checkDataRefValidStartsWith($placement, 'PLACE_', 'Invalid placement for mob head');
     $this->checkOrientation($placement, $orientation);
     $this->checkDataRefValidStartsWith($type, 'SKULL_', 'Invalid skull type');
     $this->entityData->addChild(\Nbt\Tag::tagByte('SkullType', $type));
     if ($type == self::SKULL_HEAD) {
         $this->entityData->addChild(\Nbt\Tag::tagCompound('Owner', [\Nbt\Tag::tagString('Name', $ownerName), \Nbt\Tag::tagString('Id', $ownerID)]));
     }
 }
Пример #3
0
 /**
  * Set the patterns for the banner.
  *
  * @param array $patterns
  */
 protected function bannerPatterns($patterns)
 {
     if (count($patterns)) {
         // Set up the pattern list
         $patternList = \Nbt\Tag::tagList('Patterns', \Nbt\Tag::TAG_COMPOUND, []);
         $this->entityData->addChild($patternList);
         foreach ($patterns as $pattern) {
             // Check the pattern details are valid
             $this->checkDataRefValidStartsWith($pattern['color'], 'COLOR_', 'Invalid base color for banner pattern');
             $this->checkDataRefValidStartsWith($pattern['pattern'], 'PATTERN_', 'Invalid pattern reference for banner pattern');
             // Add the pattern to the list
             $patternList->addChild(\Nbt\Tag::tagCompound('', [\Nbt\Tag::tagInt('Color', $this->bannerConvertColor($pattern['color'])), \Nbt\Tag::tagString('Pattern', $pattern['pattern'])]));
         }
     }
 }
Пример #4
0
 /**
  * Get the correct section from within the Sections tag (based on Y index).
  *
  * @param int $yRef
  *
  * @return \Nbt\Node
  */
 private function getSection($yRef)
 {
     if (isset($this->sectionsList[$yRef])) {
         return $this->sectionsList[$yRef];
     }
     foreach ($this->sectionsTag->getChildren() as $childNode) {
         if ($childNode->findChildByName('Y')->getValue() == $yRef) {
             $this->prepareSection($childNode);
             $this->sectionsList[$yRef] = $childNode;
             return $childNode;
         }
     }
     // If we didn't find one, we must create one
     // Doesn't need a name, it's part of a list
     $newY = \Nbt\Tag::tagCompound('', [\Nbt\Tag::tagByte('Y', $yRef), \Nbt\Tag::tagByteArray('Blocks', array_fill(0, 4096, 0)), \Nbt\Tag::tagByteArray('Data', array_fill(0, 2048, 0)), \Nbt\Tag::tagByteArray('BlockLight', array_fill(0, 2048, 0)), \Nbt\Tag::tagByteArray('SkyLight', array_fill(0, 2048, 0))]);
     // Add it to the list
     $this->sectionsTag->addChild($newY);
     $this->sectionsList[$yRef] = $newY;
     return $newY;
 }
Пример #5
0
 /**
  * @dataProvider providerTestTagCompound
  */
 public function testTagCompoundReturnsCompoundType($name, $data)
 {
     $tag = Tag::tagCompound($name, $data);
     $this->assertEquals($tag->getType(), Tag::TAG_COMPOUND);
 }
Пример #6
0
 /**
  * Add the 'tag' compount tag, if it doesn't already exist.
  */
 protected function addTag()
 {
     if (!isset($this->tag)) {
         $this->tag = \Nbt\Tag::tagCompound('tag', []);
         $this->node->addChild($this->tag);
     }
 }