added use-item click vector to PlayerInteractEvent

now go and make some touchscreens with maps!
This commit is contained in:
Dylan K. Taylor 2017-10-27 19:00:17 +01:00
parent 747477dfcf
commit c55bc2d7e9
3 changed files with 16 additions and 12 deletions

View File

@ -2361,7 +2361,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$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);
@ -2624,7 +2624,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
break;
}
$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);
if($ev->isCancelled()){
$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));
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);
if($this->isSpectator()){

View File

@ -58,16 +58,20 @@ class PlayerInteractEvent extends PlayerEvent implements Cancellable{
/** @var int */
protected $action;
public function __construct(Player $player, Item $item, Vector3 $block, int $face, int $action = PlayerInteractEvent::RIGHT_CLICK_BLOCK){
if($block instanceof Block){
$this->blockTouched = $block;
$this->touchVector = new Vector3(0, 0, 0);
}else{
$this->touchVector = $block;
$this->blockTouched = BlockFactory::get(0, 0, new Position(0, 0, 0, $player->level));
}
/**
* @param Player $player
* @param Item $item
* @param Block|null $block
* @param Vector3|null $touchVector
* @param int $face
* @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->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->action = $action;
}

View File

@ -1746,7 +1746,7 @@ class Level implements ChunkManager, Metadatable{
}
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)){
$ev->setCancelled(); //set it to cancelled so plugins can bypass this
}