當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Item::nbtSerialize方法代碼示例

本文整理匯總了PHP中pocketmine\item\Item::nbtSerialize方法的典型用法代碼示例。如果您正苦於以下問題:PHP Item::nbtSerialize方法的具體用法?PHP Item::nbtSerialize怎麽用?PHP Item::nbtSerialize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pocketmine\item\Item的用法示例。


在下文中一共展示了Item::nbtSerialize方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: saveNBT

 public function saveNBT()
 {
     parent::saveNBT();
     $this->namedtag->Item = $this->item->nbtSerialize();
     $this->namedtag->Health = new ShortTag("Health", $this->getHealth());
     $this->namedtag->Age = new ShortTag("Age", $this->age);
     $this->namedtag->PickupDelay = new ShortTag("PickupDelay", $this->pickupDelay);
     if ($this->owner !== null) {
         $this->namedtag->Owner = new StringTag("Owner", $this->owner);
     }
     if ($this->thrower !== null) {
         $this->namedtag->Thrower = new StringTag("Thrower", $this->thrower);
     }
 }
開發者ID:robske110,項目名稱:ClearSky,代碼行數:14,代碼來源:Item.php

示例2: setItem

 /**
  * This method should not be used by plugins, use the Inventory
  *
  * @param int  $index
  * @param Item $item
  *
  * @return bool
  */
 public function setItem($index, Item $item)
 {
     $i = $this->getSlotIndex($index);
     $d = $item->nbtSerialize($index);
     if ($item->getId() === Item::AIR or $item->getCount() <= 0) {
         if ($i >= 0) {
             unset($this->namedtag->Items[$i]);
         }
     } elseif ($i < 0) {
         for ($i = 0; $i <= $this->getSize(); ++$i) {
             if (!isset($this->namedtag->Items[$i])) {
                 break;
             }
         }
         $this->namedtag->Items[$i] = $d;
     } else {
         $this->namedtag->Items[$i] = $d;
     }
     return true;
 }
開發者ID:robske110,項目名稱:ClearSky,代碼行數:28,代碼來源:Furnace.php

示例3: dropItem

 /**
  * @param Vector3 $source
  * @param Item    $item
  * @param Vector3 $motion
  * @param int     $delay
  */
 public function dropItem(Vector3 $source, Item $item, Vector3 $motion = null, int $delay = 10)
 {
     $motion = $motion === null ? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1) : $motion;
     $itemTag = $item->nbtSerialize();
     $itemTag->setName("Item");
     if ($item->getId() > 0 and $item->getCount() > 0) {
         $itemEntity = Entity::createEntity("Item", $this->getChunk($source->getX() >> 4, $source->getZ() >> 4, true), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $source->getX()), new DoubleTag("", $source->getY()), new DoubleTag("", $source->getZ())]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion->x), new DoubleTag("", $motion->y), new DoubleTag("", $motion->z)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)]), "Health" => new ShortTag("Health", 5), "Item" => $itemTag, "PickupDelay" => new ShortTag("PickupDelay", $delay)]));
         $itemEntity->spawnToAll();
     }
 }
開發者ID:robske110,項目名稱:ClearSky,代碼行數:16,代碼來源:Level.php


注:本文中的pocketmine\item\Item::nbtSerialize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。