Ejemplo n.º 1
0
 /**
  * A flower pot, optionally containing a flower
  *
  * @param \MME\Block $contains The flower the block contains
  */
 public function __construct($contains = null)
 {
     // This is going to define the plant in the tile entity data
     // - which is to be done...
     $this->setBlockIDAndDataFor(Ref::FLOWER_POT);
     $this->initEntityData('FlowerPot');
     $this->entityData->addChild(\Nbt\Tag::tagString('Item', $contains ? Names::$list[$contains->ref] : ''));
     $this->entityData->addChild(\Nbt\Tag::tagInt('Data', $contains ? $contains->data : 0));
 }
 /**
  * Add a command block.
  *
  * @param string         $command      Command that the block will run
  * @param int            $trackOutput  [optional] Either CommandBlock::TRACK_OUTPUT or CommandBlock::NO_TRACK_OUTPUT
  * @param \Nbt\Node|null $commandStats [optional] Command stats compound tag, if required.
  * @param string|null    $customName   [optional]
  * @param string|null    $lock         [optional]
  *
  * @throws \Exception
  */
 public function __construct($command, $trackOutput = self::TRACK_OUTPUT, $commandStats = null, $customName = null, $lock = null)
 {
     $this->setBlockIDAndDataFor(Ref::COMMAND_BLOCK);
     $this->initEntityData('Control');
     $this->entityData->addChild(\Nbt\Tag::tagString('Command', $command));
     $this->entityData->addChild(\Nbt\Tag::tagByte('TrackOutput', $trackOutput));
     $this->setCustomName($customName);
     $this->setLock($lock);
     if ($commandStats !== null) {
         $this->entityData->addChild($commandStats);
     }
 }
Ejemplo n.º 3
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)]));
     }
 }
Ejemplo n.º 4
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'])]));
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Create a mob spawner. There's no checking of the information passed yet.
  * I don't know the valid values, etc; proper error checking is still to come.
  * Test your creations well!
  *
  * @param \Nbt\Node|null $spawnPotentials     List of potential spawns
  * @param string         $entityID            Entity name to spawn
  * @param \Nbt\Node|null $spawnData           Data to pass to the spawned mobs
  * @param int            $spawnCount          Number of mobs to attempt to spawn
  * @param int            $spawnRange          Radius of the spawn range
  * @param int            $delay               Ticks until next spawn
  * @param int            $minSpawnDelay       Minimum random delay to the next spawn
  * @param int            $maxSpawnDelay       Maximum random delay to the next spawn
  * @param int            $maxNearbyEntities   Can override the max number of entities nearby
  * @param int            $requiredPlayerRange Override the activation radius
  *
  * @throws \Exception
  */
 public function __construct($spawnPotentials, $entityID, $spawnData, $spawnCount, $spawnRange, $delay, $minSpawnDelay, $maxSpawnDelay, $maxNearbyEntities, $requiredPlayerRange)
 {
     $this->setBlockIDAndDataFor(Ref::MOB_SPAWNER);
     $this->initEntityData('MobSpawner');
     if ($spawnPotentials) {
         $this->entityData->addChild($spawnPotentials);
     }
     $this->entityData->addChild(\Nbt\Tag::tagString('EntityId', $entityID));
     if ($spawnData) {
         $this->entityData->addChild($spawnData);
     }
     $this->entityData->addChild(\Nbt\Tag::tagShort('SpawnCount', $spawnCount));
     $this->entityData->addChild(\Nbt\Tag::tagShort('SpawnRange', $spawnRange));
     $this->entityData->addChild(\Nbt\Tag::tagShort('Delay', $delay));
     $this->entityData->addChild(\Nbt\Tag::tagShort('MinSpawnDelay', $minSpawnDelay));
     $this->entityData->addChild(\Nbt\Tag::tagShort('MaxSpawnDelay', $maxSpawnDelay));
     $this->entityData->addChild(\Nbt\Tag::tagShort('MaxNearbyEntities', $maxNearbyEntities));
     $this->entityData->addChild(\Nbt\Tag::tagShort('RequiredPlayerRange', $requiredPlayerRange));
 }
Ejemplo n.º 6
0
 /**
  * Set options in the display properties compound tag.
  *
  * @param string $name  Name of the item
  * @param string $lore  List of strings to display as lore for the item
  * @param int    $color Color, for leather armour.
  */
 public function setDisplayProperties($name, $lore = '', $color = null)
 {
     $this->addTag();
     $display = \Nbt\Tag::tagCompound('display', []);
     if ($name) {
         $display->addChild(\Nbt\Tag::tagString('Name', $name));
     }
     if ($lore) {
         $loreTag = \Nbt\Tag::tagList('Lore', \Nbt\Tag::TAG_STRING, []);
         foreach ($lore as $line) {
             $loreTag->addChild(\Nbt\Tag::tagString('', $line));
         }
         $display->addChild($loreTag);
     }
     if ($color) {
         $display->addChild(\Nbt\Tag::tagInt('color', $color));
     }
     $this->tag->addChild($display);
 }
Ejemplo n.º 7
0
 public function providerTestTagCompound()
 {
     return [['CompoundTag', [\Nbt\Tag::tagByte('b1', 0x1), \Nbt\Tag::tagString('s2', 'astring')]]];
 }