pocketmine\block\Door::onActivate PHP Méthode

onActivate() public méthode

public onActivate ( Item $item, Player $player = null )
$item pocketmine\item\Item
$player pocketmine\Player
    public function onActivate(Item $item, Player $player = null)
    {
        if (($this->getDamage() & 0x8) === 0x8) {
            //Top
            $down = $this->getSide(Vector3::SIDE_DOWN);
            if ($down->getId() === $this->getId()) {
                $meta = $down->getDamage() ^ 0x4;
                $this->getLevel()->setBlock($down, Block::get($this->getId(), $meta), true);
                $players = $this->getLevel()->getChunkPlayers($this->x >> 4, $this->z >> 4);
                if ($player instanceof Player) {
                    unset($players[$player->getLoaderId()]);
                }
                $this->level->addSound(new DoorSound($this));
                return true;
            }
            return false;
        } else {
            $this->meta ^= 0x4;
            $this->getLevel()->setBlock($this, $this, true);
            $players = $this->getLevel()->getChunkPlayers($this->x >> 4, $this->z >> 4);
            if ($player instanceof Player) {
                unset($players[$player->getLoaderId()]);
            }
            $this->level->addSound(new DoorSound($this));
        }
        return true;
    }

Usage Example

Exemple #1
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         return true;
     } else {
         return parent::onActivate($item, $player);
     }
 }