mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-05 11:27:07 +00:00
Implemented hook method Item::onInteractEntity() (#5432)
this is called when the player right-clicks on an entity to do some action, such as shearing, naming etc.
This commit is contained in:
parent
4357c110c8
commit
1308cda5c2
@ -554,6 +554,13 @@ class Item implements \JsonSerializable{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player uses the item to interact with entity, for example by using a name tag.
|
||||
*/
|
||||
public function onInteractEntity(Player $player, Entity $entity, Vector3 $directionVector) : bool{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of ticks a player must wait before activating this item again.
|
||||
*/
|
||||
|
@ -1818,7 +1818,17 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
|
||||
$ev->call();
|
||||
|
||||
$item = $this->inventory->getItemInHand();
|
||||
$oldItem = clone $item;
|
||||
if(!$ev->isCancelled()){
|
||||
if($item->onInteractEntity($this, $entity, $clickPos)){
|
||||
if($this->hasFiniteResources() && !$item->equalsExact($oldItem) && $oldItem->equalsExact($this->inventory->getItemInHand())){
|
||||
if($item instanceof Durable && $item->isBroken()){
|
||||
$this->broadcastSound(new ItemBreakSound());
|
||||
}
|
||||
$this->inventory->setItemInHand($item);
|
||||
}
|
||||
}
|
||||
return $entity->onInteract($this, $clickPos);
|
||||
}
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user