PlayerInventory: Send updates to viewers automatically on setItemInHand()

This commit is contained in:
Dylan K. Taylor 2018-08-05 19:31:21 +01:00
parent c90e3e351d
commit ff6d590d0c
2 changed files with 6 additions and 3 deletions

View File

@ -2227,7 +2227,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
if($this->isSurvival()){
if(!$item->equalsExact($this->inventory->getItemInHand())){
$this->inventory->setItemInHand($item);
$this->inventory->sendHeldItem($this->hasSpawned);
}
$this->exhaust(0.025, PlayerExhaustEvent::CAUSE_MINING);
}
@ -2272,7 +2271,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
if($this->level->useItemOn($pos, $item, $face, $clickOffset, $this, true)){
if($this->isSurvival() and !$item->equalsExact($this->inventory->getItemInHand())){
$this->inventory->setItemInHand($item);
$this->inventory->sendHeldItem($this->hasSpawned);
}
return true;
}

View File

@ -127,7 +127,12 @@ class PlayerInventory extends BaseInventory{
* @return bool
*/
public function setItemInHand(Item $item) : bool{
return $this->setItem($this->getHeldItemIndex(), $item);
if($this->setItem($this->getHeldItemIndex(), $item)){
$this->sendHeldItem($this->holder->getViewers());
return true;
}
return false;
}
/**