/** * @param Player|Player[] $target */ public function sendHeldItem($target) { $item = $this->getItemInHand(); $pk = new PlayerEquipmentPacket(); $pk->eid = $target === $this->getHolder() ? 0 : $this->getHolder()->getId(); $pk->item = $item->getId(); $pk->meta = $item->getDamage(); $pk->slot = $this->getHeldItemSlot(); $pk->selectedSlot = $this->getHeldItemIndex(); if (!is_array($target)) { $target->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING)); if ($target === $this->getHolder()) { $this->sendSlot($this->getHeldItemSlot(), $target); } } else { Server::broadcastPacket($target, $pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING)); foreach ($target as $player) { if ($player === $this->getHolder()) { $this->sendSlot($this->getHeldItemSlot(), $player); break; } } } }
/** * @param Player|Player[] $target */ public function sendHeldItem($target) { if ($target instanceof Player) { $target = [$target]; } $item = $this->getItemInHand(); $pk = new PlayerEquipmentPacket(); $pk->eid = $this->getHolder()->getId(); $pk->item = $item->getId(); $pk->meta = $item->getDamage(); $pk->slot = 0; $pk->isEncoded = true; $pk->encode(); foreach ($target as $player) { if ($player === $this->getHolder()) { //TODO: Check if Mojang enabled sending a single slot this //$this->sendSlot($this->getHeldItemSlot()); $this->sendContents($player); } else { $player->dataPacket($pk); } } }
/** * @param Player|Player[] $target */ public function sendHeldItem($target) { if ($target instanceof Player) { $target = [$target]; } $item = $this->getItemInHand(); $pk = new PlayerEquipmentPacket(); $pk->eid = $this->getHolder()->getId(); $pk->item = $item->getId(); $pk->meta = $item->getDamage(); $pk->slot = $this->getHeldItemSlot(); $pk->selectedSlot = $this->getHeldItemIndex(); $pk->isEncoded = true; Server::broadcastPacket($target, $pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING)); foreach ($target as $player) { if ($player === $this->getHolder()) { $this->sendSlot($this->getHeldItemSlot(), $player); break; } } }
/** * @param Player|Player[] $target */ public function sendHeldItem($target) { if ($target instanceof Player) { $target = [$target]; } $item = $this->getItemInHand(); $pk = new PlayerEquipmentPacket(); $pk->eid = $this->getHolder()->getId(); $pk->item = $item->getId(); $pk->meta = $item->getDamage(); $pk->slot = 0; $pk->isEncoded = \true; $pk->encode(); foreach ($target as $player) { if ($player === $this->getHolder()) { $this->sendSlot($this->getHeldItemSlot(), $player); } else { $player->dataPacket($pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING)); } } }