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


PHP Item::getCreativeItem方法代碼示例

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


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

示例1: sendContents

 /**
  * @param Player|Player[] $target
  */
 public function sendContents($target)
 {
     if ($target instanceof Player) {
         $target = [$target];
     }
     $pk = new ContainerSetContentPacket();
     $pk->slots = [];
     $holder = $this->getHolder();
     if ($holder instanceof Player and $holder->isCreative()) {
         //TODO: Remove this workaround because of broken client
         foreach (Item::getCreativeItems() as $i => $item) {
             $pk->slots[$i] = Item::getCreativeItem($i);
         }
     } else {
         for ($i = 0; $i < $this->getSize(); ++$i) {
             //Do not send armor by error here
             $pk->slots[$i] = $this->getItem($i);
         }
     }
     foreach ($target as $player) {
         $pk->hotbar = [];
         if ($player === $this->getHolder()) {
             for ($i = 0; $i < $this->getHotbarSize(); ++$i) {
                 $index = $this->getHotbarSlotIndex($i);
                 $pk->hotbar[] = $index <= -1 ? -1 : $index + 9;
             }
         }
         if (($id = $player->getWindowId($this)) === -1 or $player->spawned !== true) {
             $this->close($player);
             continue;
         }
         $pk->windowid = $id;
         $player->dataPacket(clone $pk);
     }
 }
開發者ID:onebone,項目名稱:PocketMine-MP,代碼行數:38,代碼來源:PlayerInventory.php

示例2: handleDataPacket


//.........這裏部分代碼省略.........
                 $revert = true;
                 $this->forceMovement = new Vector3($this->x, $this->y, $this->z);
             }
             if ($this->teleportPosition !== null or $this->forceMovement instanceof Vector3 and (($dist = $newPos->distanceSquared($this->forceMovement)) > 0.1 or $revert)) {
                 $this->sendPosition($this->forceMovement, $packet->yaw, $packet->pitch);
             } else {
                 $packet->yaw %= 360;
                 $packet->pitch %= 360;
                 if ($packet->yaw < 0) {
                     $packet->yaw += 360;
                 }
                 $this->setRotation($packet->yaw, $packet->pitch);
                 $this->newPosition = $newPos;
                 $this->forceMovement = null;
             }
             break;
         case ProtocolInfo::MOB_EQUIPMENT_PACKET:
             if ($this->spawned === false or !$this->isAlive()) {
                 break;
             }
             if ($packet->slot === 0x28 or $packet->slot === 0 or $packet->slot === 255) {
                 // 0 for 0.8.0 compatibility
                 $packet->slot = -1;
                 // Air
             } else {
                 $packet->slot -= 9;
                 // Get real block slot
             }
             /** @var Item $item */
             $item = null;
             if ($this->isCreative()) {
                 // Creative mode match
                 $item = $packet->item;
                 $slot = Item::getCreativeItemIndex($item);
             } else {
                 $item = $this->inventory->getItem($packet->slot);
                 $slot = $packet->slot;
             }
             if ($packet->slot === -1) {
                 // Air
                 if ($this->isCreative()) {
                     $found = false;
                     for ($i = 0; $i < $this->inventory->getHotbarSize(); ++$i) {
                         if ($this->inventory->getHotbarSlotIndex($i) === -1) {
                             $this->inventory->setHeldItemIndex($i);
                             $found = true;
                             break;
                         }
                     }
                     if (!$found) {
                         // couldn't find a empty slot (error)
                         $this->inventory->sendContents($this);
                         break;
                     }
                 } else {
                     if ($packet->selectedSlot >= 0 and $packet->selectedSlot < 9) {
                         $this->inventory->setHeldItemIndex($packet->selectedSlot);
                         $this->inventory->setHeldItemSlot($packet->slot);
                     } else {
                         $this->inventory->sendContents($this);
                         break;
                     }
                 }
             } elseif ($item === null or $slot === -1 or !$item->deepEquals($packet->item)) {
                 // packet error or not implemented
                 $this->inventory->sendContents($this);
開發者ID:maa123,項目名稱:NIGHTMARE,代碼行數:67,代碼來源:Player.php


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