当前位置: 首页>>代码示例>>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;未经允许,请勿转载。