pocketmine\Player::dropItem PHP Method

dropItem() public method

public dropItem ( Item $item )
$item pocketmine\item\Item Drops the specified item in front of the player.
    public function dropItem(Item $item)
    {
        if ($this->spawned === false or $this->blocked === true or !$this->isAlive()) {
            return;
        }
        if ($this->isCreative() and $this->server->limitedCreative or $this->isSpectator()) {
            //Ignore for limited creative
            return;
        }
        if ($item->getId() === Item::AIR or $item->getCount() < 1) {
            //Ignore dropping air or items with bad counts
            return;
        }
        $ev = new PlayerDropItemEvent($this, $item);
        $this->server->getPluginManager()->callEvent($ev);
        if ($ev->isCancelled()) {
            $this->getFloatingInventory()->removeItem($item);
            $this->getInventory()->addItem($item);
            return;
        }
        $motion = $this->getDirectionVector()->multiply(0.4);
        $this->level->dropItem($this->add(0, 1.3, 0), $item, $motion, 40);
        $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false);
    }

Usage Example

Exemplo n.º 1
0
 public function onClose(Player $who)
 {
     foreach ($this->getContents() as $slot => $item) {
         if ($slot === $this->getResultSlotIndex()) {
             //Do not drop the item in the result slot - it is a virtual item and does not actually exist.
             continue;
         }
         $who->dropItem($item);
     }
     $this->clearAll();
 }
All Usage Examples Of pocketmine\Player::dropItem
Player