Skip to content

PlayerInteractEvent ​

class · pocketmine\event\player\PlayerInteractEvent · source

Extends PlayerEvent
Implements Cancellable

Called when a player interacts or touches a block. This is called for both left click (start break) and right click (use).

Constants ​

LEFT_CLICK_BLOCK ​

php
public const LEFT_CLICK_BLOCK = 0

RIGHT_CLICK_BLOCK ​

php
public const RIGHT_CLICK_BLOCK = 1

Properties ​

$action ​

php
public int $action

$blockFace ​

php
public int $blockFace

$blockTouched ​

php
public \pocketmine\block\Block $blockTouched

$item ​

php
public \pocketmine\item\Item $item

$touchVector protected ​

php
protected \pocketmine\math\Vector3 $touchVector

$useBlock protected ​

php
protected bool $useBlock

$useItem protected ​

php
protected bool $useItem

Methods ​

__construct() ​

php
public function __construct(\pocketmine\player\Player $player, \pocketmine\item\Item $item, \pocketmine\block\Block $blockTouched, ?\pocketmine\math\Vector3 $touchVector, int $blockFace, int $action = \pocketmine\event\player\PlayerInteractEvent::RIGHT_CLICK_BLOCK)

getAction() ​

php
public function getAction() : int

getBlock() ​

php
public function getBlock() : \pocketmine\block\Block

getFace() ​

php
public function getFace() : int

getItem() ​

php
public function getItem() : \pocketmine\item\Item

getTouchVector() ​

php
public function getTouchVector() : \pocketmine\math\Vector3

setUseBlock() ​

php
public function setUseBlock(bool $useBlock) : void

Sets whether the block may react to the interaction. If false, doors, fence gates and trapdoors will not respond, containers will not open, etc.

setUseItem() ​

php
public function setUseItem(bool $useItem) : void

Sets whether the used item may react to the interaction. If false, items such as spawn eggs will not activate. This does NOT prevent blocks from being placed - it makes the item behave as if the player is sneaking.

useBlock() ​

php
public function useBlock() : bool

Returns whether the block may react to the interaction. If false, doors, fence gates and trapdoors will not respond, containers will not open, etc.

useItem() ​

php
public function useItem() : bool

Returns whether the item may react to the interaction. If disabled, items such as spawn eggs will not activate. This does NOT prevent blocks from being placed - it makes the item behave as if the player is sneaking.

VanillaMine is a fork of PocketMine-MP, maintained by Luxury Nodes. Not affiliated with the PMMP team or Mojang.