pocketmine\inventory\PlayerInventory::getHotbarSlotIndex PHP Метод

getHotbarSlotIndex() публичный Метод

public getHotbarSlotIndex ( integer $index ) : integer
$index integer
Результат integer Returns the index of the inventory slot linked to the specified hotbar slot
    public function getHotbarSlotIndex($index)
    {
        return ($index >= 0 and $index < $this->getHotbarSize()) ? $this->hotbar[$index] : -1;
    }

Usage Example

Пример #1
0
 public function saveNBT()
 {
     parent::saveNBT();
     $this->namedtag->Inventory = new Enum("Inventory", []);
     $this->namedtag->Inventory->setTagType(NBT::TAG_Compound);
     if ($this->inventory !== null) {
         for ($slot = 0; $slot < 9; ++$slot) {
             $hotbarSlot = $this->inventory->getHotbarSlotIndex($slot);
             if ($hotbarSlot !== -1) {
                 $item = $this->inventory->getItem($hotbarSlot);
                 if ($item->getId() !== 0 and $item->getCount() > 0) {
                     $this->namedtag->Inventory[$slot] = new Compound(false, [new Byte("Count", $item->getCount()), new Short("Damage", $item->getDamage()), new Byte("Slot", $slot), new Byte("TrueSlot", $hotbarSlot), new Short("id", $item->getId())]);
                     continue;
                 }
             }
             $this->namedtag->Inventory[$slot] = new Compound(false, [new Byte("Count", 0), new Short("Damage", 0), new Byte("Slot", $slot), new Byte("TrueSlot", -1), new Short("id", 0)]);
         }
         //Normal inventory
         $slotCount = Player::SURVIVAL_SLOTS + 9;
         //$slotCount = (($this instanceof Player and ($this->gamemode & 0x01) === 1) ? Player::CREATIVE_SLOTS : Player::SURVIVAL_SLOTS) + 9;
         for ($slot = 9; $slot < $slotCount; ++$slot) {
             $item = $this->inventory->getItem($slot - 9);
             $this->namedtag->Inventory[$slot] = new Compound(false, [new Byte("Count", $item->getCount()), new Short("Damage", $item->getDamage()), new Byte("Slot", $slot), new Short("id", $item->getId())]);
         }
         //Armor
         for ($slot = 100; $slot < 104; ++$slot) {
             $item = $this->inventory->getItem($this->inventory->getSize() + $slot - 100);
             if ($item instanceof ItemItem and $item->getId() !== ItemItem::AIR) {
                 $this->namedtag->Inventory[$slot] = new Compound(false, [new Byte("Count", $item->getCount()), new Short("Damage", $item->getDamage()), new Byte("Slot", $slot), new Short("id", $item->getId())]);
             }
         }
     }
 }
All Usage Examples Of pocketmine\inventory\PlayerInventory::getHotbarSlotIndex