pocketmine\nbt\NBT::getItemHelper PHP Метод

getItemHelper() публичный статический Метод

public static getItemHelper ( CompoundTag $tag ) : Item
$tag pocketmine\nbt\tag\CompoundTag
Результат pocketmine\item\Item
    public static function getItemHelper(CompoundTag $tag)
    {
        if (!isset($tag->id) or !isset($tag->Count)) {
            return Item::get(0);
        }
        $item = Item::get($tag->id->getValue(), !isset($tag->Damage) ? 0 : $tag->Damage->getValue(), $tag->Count->getValue());
        if (isset($tag->tag) and $tag->tag instanceof CompoundTag) {
            $item->setNamedTag($tag->tag);
        }
        return $item;
    }

Usage Example

Пример #1
0
 protected function initEntity()
 {
     parent::initEntity();
     $this->setMaxHealth(5);
     $this->setHealth($this->namedtag["Health"]);
     if (isset($this->namedtag->Age)) {
         $this->age = $this->namedtag["Age"];
     }
     if (isset($this->namedtag->PickupDelay)) {
         $this->pickupDelay = $this->namedtag["PickupDelay"];
     }
     if (isset($this->namedtag->Owner)) {
         $this->owner = $this->namedtag["Owner"];
     }
     if (isset($this->namedtag->Thrower)) {
         $this->thrower = $this->namedtag["Thrower"];
     }
     if (!isset($this->namedtag->Item)) {
         $this->close();
         return;
     }
     assert($this->namedtag->Item instanceof CompoundTag);
     $this->item = NBT::getItemHelper($this->namedtag->Item);
     $this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
 }
All Usage Examples Of pocketmine\nbt\NBT::getItemHelper