mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-06 01:51:51 +00:00
added use-item click vector to PlayerInteractEvent
now go and make some touchscreens with maps!
This commit is contained in:
parent
747477dfcf
commit
c55bc2d7e9
@ -2361,7 +2361,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
$item = $this->inventory->getItemInHand();
|
$item = $this->inventory->getItemInHand();
|
||||||
}
|
}
|
||||||
|
|
||||||
$ev = new PlayerInteractEvent($this, $item, $directionVector, $face, PlayerInteractEvent::RIGHT_CLICK_AIR);
|
$ev = new PlayerInteractEvent($this, $item, null, $directionVector, $face, PlayerInteractEvent::RIGHT_CLICK_AIR);
|
||||||
|
|
||||||
$this->server->getPluginManager()->callEvent($ev);
|
$this->server->getPluginManager()->callEvent($ev);
|
||||||
|
|
||||||
@ -2624,7 +2624,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$target = $this->level->getBlock($pos);
|
$target = $this->level->getBlock($pos);
|
||||||
$ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $target, $packet->face, $target->getId() === 0 ? PlayerInteractEvent::LEFT_CLICK_AIR : PlayerInteractEvent::LEFT_CLICK_BLOCK);
|
$ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $target, null, $packet->face, $target->getId() === 0 ? PlayerInteractEvent::LEFT_CLICK_AIR : PlayerInteractEvent::LEFT_CLICK_BLOCK);
|
||||||
$this->getServer()->getPluginManager()->callEvent($ev);
|
$this->getServer()->getPluginManager()->callEvent($ev);
|
||||||
if($ev->isCancelled()){
|
if($ev->isCancelled()){
|
||||||
$this->inventory->sendHeldItem($this);
|
$this->inventory->sendHeldItem($this);
|
||||||
@ -2913,7 +2913,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
|
|
||||||
$tile = $this->level->getTile($this->temporalVector->setComponents($packet->x, $packet->y, $packet->z));
|
$tile = $this->level->getTile($this->temporalVector->setComponents($packet->x, $packet->y, $packet->z));
|
||||||
if($tile instanceof ItemFrame){
|
if($tile instanceof ItemFrame){
|
||||||
$ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $tile->getBlock(), 5 - $tile->getBlock()->getDamage(), PlayerInteractEvent::LEFT_CLICK_BLOCK);
|
$ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $tile->getBlock(), null, 5 - $tile->getBlock()->getDamage(), PlayerInteractEvent::LEFT_CLICK_BLOCK);
|
||||||
$this->server->getPluginManager()->callEvent($ev);
|
$this->server->getPluginManager()->callEvent($ev);
|
||||||
|
|
||||||
if($this->isSpectator()){
|
if($this->isSpectator()){
|
||||||
|
@ -58,16 +58,20 @@ class PlayerInteractEvent extends PlayerEvent implements Cancellable{
|
|||||||
/** @var int */
|
/** @var int */
|
||||||
protected $action;
|
protected $action;
|
||||||
|
|
||||||
public function __construct(Player $player, Item $item, Vector3 $block, int $face, int $action = PlayerInteractEvent::RIGHT_CLICK_BLOCK){
|
/**
|
||||||
if($block instanceof Block){
|
* @param Player $player
|
||||||
$this->blockTouched = $block;
|
* @param Item $item
|
||||||
$this->touchVector = new Vector3(0, 0, 0);
|
* @param Block|null $block
|
||||||
}else{
|
* @param Vector3|null $touchVector
|
||||||
$this->touchVector = $block;
|
* @param int $face
|
||||||
$this->blockTouched = BlockFactory::get(0, 0, new Position(0, 0, 0, $player->level));
|
* @param int $action
|
||||||
}
|
*/
|
||||||
|
public function __construct(Player $player, Item $item, ?Block $block, ?Vector3 $touchVector, int $face, int $action = PlayerInteractEvent::RIGHT_CLICK_BLOCK){
|
||||||
|
assert($block !== null or $touchVector !== null);
|
||||||
$this->player = $player;
|
$this->player = $player;
|
||||||
$this->item = $item;
|
$this->item = $item;
|
||||||
|
$this->blockTouched = $block ?? BlockFactory::get(0, 0, new Position(0, 0, 0, $player->level));
|
||||||
|
$this->touchVector = $touchVector ?? new Vector3(0, 0, 0);
|
||||||
$this->blockFace = $face;
|
$this->blockFace = $face;
|
||||||
$this->action = $action;
|
$this->action = $action;
|
||||||
}
|
}
|
||||||
|
@ -1746,7 +1746,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($player !== null){
|
if($player !== null){
|
||||||
$ev = new PlayerInteractEvent($player, $item, $blockClicked, $face, $blockClicked->getId() === 0 ? PlayerInteractEvent::RIGHT_CLICK_AIR : PlayerInteractEvent::RIGHT_CLICK_BLOCK);
|
$ev = new PlayerInteractEvent($player, $item, $blockClicked, $facePos, $face, $blockClicked->getId() === 0 ? PlayerInteractEvent::RIGHT_CLICK_AIR : PlayerInteractEvent::RIGHT_CLICK_BLOCK);
|
||||||
if($this->checkSpawnProtection($player, $blockClicked)){
|
if($this->checkSpawnProtection($player, $blockClicked)){
|
||||||
$ev->setCancelled(); //set it to cancelled so plugins can bypass this
|
$ev->setCancelled(); //set it to cancelled so plugins can bypass this
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user