public sendHeldItem ( |
||
$target |
public function sendHeldItem($target)
{
$item = $this->getItemInHand();
$pk = new MobEquipmentPacket();
$pk->eid = $target === $this->getHolder() ? 0 : $this->getHolder()->getId();
$pk->item = $item;
$pk->slot = $this->getHeldItemSlot();
$pk->selectedSlot = $this->getHeldItemIndex();
if (!is_array($target)) {
$target->dataPacket($pk);
if ($target === $this->getHolder()) {
$this->sendSlot($this->getHeldItemSlot(), $target);
}
} else {
Server::broadcastPacket($target, $pk);
foreach ($target as $player) {
if ($player === $this->getHolder()) {
$this->sendSlot($this->getHeldItemSlot(), $player);
break;
}
}
}
}
public function spawnTo(Player $player) { if ($player !== $this and !isset($this->hasSpawned[$player->getID()])) { $this->hasSpawned[$player->getID()] = $player; $pk = new AddPlayerPacket(); $pk->clientID = 0; if ($player->getRemoveFormat()) { $pk->username = TextFormat::clean($this->nameTag); } else { $pk->username = $this->nameTag; } $pk->eid = $this->getID(); $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; $pk->yaw = $this->yaw; $pk->pitch = $this->pitch; $pk->unknown1 = 0; $pk->unknown2 = 0; $pk->metadata = $this->getData(); $player->dataPacket($pk); $pk = new SetEntityMotionPacket(); $pk->entities = [[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]]; $player->dataPacket($pk); $this->inventory->sendHeldItem($player); $this->inventory->sendArmorContents($player); } }