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);
|
$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);
|
$this->server->getPluginManager()->callEvent($ev);
|
||||||
|
|
||||||
@ -1807,6 +1807,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
$packet->eid = $this->id;
|
$packet->eid = $this->id;
|
||||||
|
|
||||||
switch($packet->action){
|
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
|
case 5: //Shot arrow
|
||||||
if($this->inventory->getItemInHand()->getId() === Item::BOW){
|
if($this->inventory->getItemInHand()->getId() === Item::BOW){
|
||||||
$bow = $this->inventory->getItemInHand();
|
$bow = $this->inventory->getItemInHand();
|
||||||
|
@ -32,6 +32,12 @@ use pocketmine\Player;
|
|||||||
class PlayerInteractEvent extends PlayerEvent implements Cancellable{
|
class PlayerInteractEvent extends PlayerEvent implements Cancellable{
|
||||||
public static $handlerList = null;
|
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;
|
* @var \pocketmine\block\Block;
|
||||||
*/
|
*/
|
||||||
@ -42,12 +48,19 @@ class PlayerInteractEvent extends PlayerEvent implements Cancellable{
|
|||||||
|
|
||||||
/** @var \pocketmine\item\Item */
|
/** @var \pocketmine\item\Item */
|
||||||
protected $item;
|
protected $item;
|
||||||
|
|
||||||
|
protected $action;
|
||||||
|
|
||||||
public function __construct(Player $player, Item $item, Block $block, $face){
|
public function __construct(Player $player, Item $item, Block $block, $face, $action = PlayerInteractEvent::RIGHT_CLICK){
|
||||||
$this->blockTouched = $block;
|
$this->blockTouched = $block;
|
||||||
$this->player = $player;
|
$this->player = $player;
|
||||||
$this->item = $item;
|
$this->item = $item;
|
||||||
$this->blockFace = (int) $face;
|
$this->blockFace = (int) $face;
|
||||||
|
$this->action = (int) $action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAction(){
|
||||||
|
return $this->action;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getItem(){
|
public function getItem(){
|
||||||
@ -61,4 +74,4 @@ class PlayerInteractEvent extends PlayerEvent implements Cancellable{
|
|||||||
public function getFace(){
|
public function getFace(){
|
||||||
return $this->blockFace;
|
return $this->blockFace;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1252,7 +1252,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$player->lastBreak = microtime(true);
|
$player->lastBreak = PHP_INT_MAX;
|
||||||
}elseif($item instanceof Item and !$target->isBreakable($item)){
|
}elseif($item instanceof Item and !$target->isBreakable($item)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1332,7 +1332,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($player instanceof Player){
|
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){
|
if(!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1){
|
||||||
$t = new Vector2($target->x, $target->z);
|
$t = new Vector2($target->x, $target->z);
|
||||||
$s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z);
|
$s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user