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:
! Bryan
2022-12-15 13:30:52 -06:00
committed by GitHub
parent 4357c110c8
commit 1308cda5c2
2 changed files with 17 additions and 0 deletions

View File

@ -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;