mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-18 11:45:30 +00:00
Added right and left click interaction events
This commit is contained in:
parent
e48a3e5713
commit
9e0b9a6e5b
@ -1749,7 +1749,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
$target = $this->level->getBlock($blockVector);
|
||||
|
||||
$ev = new PlayerInteractEvent($this, $item, $target, $packet->face);
|
||||
$ev = new PlayerInteractEvent($this, $item, $target, $packet->face, PlayerInteractEvent::RIGHT_CLICK_AIR);
|
||||
|
||||
$this->server->getPluginManager()->callEvent($ev);
|
||||
|
||||
@ -1807,6 +1807,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$packet->eid = $this->id;
|
||||
|
||||
switch($packet->action){
|
||||
case 0: //Start break
|
||||
$target = $this->level->getBlock(new Vector3($packet->x, $packet->y, $packet->z));
|
||||
$ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $target, $packet->face, $target->getId() === 0 ? PlayerInteractEvent::LEFT_CLICK_AIR : PlayerInteractEvent::LEFT_CLICK_BLOCK);
|
||||
$this->lastBreak = microtime(true);
|
||||
break;
|
||||
case 5: //Shot arrow
|
||||
if($this->inventory->getItemInHand()->getId() === Item::BOW){
|
||||
$bow = $this->inventory->getItemInHand();
|
||||
|
@ -32,6 +32,12 @@ use pocketmine\Player;
|
||||
class PlayerInteractEvent extends PlayerEvent implements Cancellable{
|
||||
public static $handlerList = null;
|
||||
|
||||
const LEFT_CLICK_BLOCK = 0;
|
||||
const RIGHT_CLICK_BLOCK = 1;
|
||||
const LEFT_CLICK_AIR = 2;
|
||||
const RIGHT_CLICK_AIR = 3;
|
||||
const PHYSICAL = 4;
|
||||
|
||||
/**
|
||||
* @var \pocketmine\block\Block;
|
||||
*/
|
||||
@ -43,11 +49,18 @@ class PlayerInteractEvent extends PlayerEvent implements Cancellable{
|
||||
/** @var \pocketmine\item\Item */
|
||||
protected $item;
|
||||
|
||||
public function __construct(Player $player, Item $item, Block $block, $face){
|
||||
protected $action;
|
||||
|
||||
public function __construct(Player $player, Item $item, Block $block, $face, $action = PlayerInteractEvent::RIGHT_CLICK){
|
||||
$this->blockTouched = $block;
|
||||
$this->player = $player;
|
||||
$this->item = $item;
|
||||
$this->blockFace = (int) $face;
|
||||
$this->action = (int) $action;
|
||||
}
|
||||
|
||||
public function getAction(){
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
public function getItem(){
|
||||
|
@ -1252,7 +1252,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
return false;
|
||||
}
|
||||
|
||||
$player->lastBreak = microtime(true);
|
||||
$player->lastBreak = PHP_INT_MAX;
|
||||
}elseif($item instanceof Item and !$target->isBreakable($item)){
|
||||
return false;
|
||||
}
|
||||
@ -1332,7 +1332,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
}
|
||||
|
||||
if($player instanceof Player){
|
||||
$ev = new PlayerInteractEvent($player, $item, $target, $face);
|
||||
$ev = new PlayerInteractEvent($player, $item, $target, $face, $target->getId() === 0 ? PlayerInteractEvent::RIGHT_CLICK_AIR : PlayerInteractEvent::RIGHT_CLICK_BLOCK);
|
||||
if(!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1){
|
||||
$t = new Vector2($target->x, $target->z);
|
||||
$s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z);
|
||||
|
Loading…
x
Reference in New Issue
Block a user