108 lines
3.1 KiB
PHP

<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h>
use pocketmine\item\Item;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\utils\UUID;
class AddPlayerPacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::ADD_PLAYER_PACKET;
/** @var UUID */
public $uuid;
/** @var string */
public $username;
/** @var int|null */
public $entityUniqueId = null; //TODO
/** @var int */
public $entityRuntimeId;
public $x;
public $y;
public $z;
public $speedX = 0.0;
public $speedY = 0.0;
public $speedZ = 0.0;
public $pitch = 0.0;
public $headYaw = null; //TODO
public $yaw = 0.0;
/** @var Item */
public $item;
public $metadata = [];
//TODO
public $uvarint1 = 0;
public $uvarint2 = 0;
public $uvarint3 = 0;
public $uvarint4 = 0;
public $long1 = 0;
protected function decodePayload(){
$this->uuid = $this->getUUID();
$this->username = $this->getString();
$this->entityUniqueId = $this->getEntityUniqueId();
$this->entityRuntimeId = $this->getEntityRuntimeId();
$this->getVector3f($this->x, $this->y, $this->z);
$this->getVector3f($this->speedX, $this->speedY, $this->speedZ);
$this->pitch = $this->getLFloat();
$this->headYaw = $this->getLFloat();
$this->yaw = $this->getLFloat();
$this->item = $this->getSlot();
$this->metadata = $this->getEntityMetadata();
$this->uvarint1 = $this->getUnsignedVarInt();
$this->uvarint2 = $this->getUnsignedVarInt();
$this->uvarint3 = $this->getUnsignedVarInt();
$this->uvarint4 = $this->getUnsignedVarInt();
$this->long1 = $this->getLLong();
}
protected function encodePayload(){
$this->putUUID($this->uuid);
$this->putString($this->username);
$this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId);
$this->putEntityRuntimeId($this->entityRuntimeId);
$this->putVector3f($this->x, $this->y, $this->z);
$this->putVector3f($this->speedX, $this->speedY, $this->speedZ);
$this->putLFloat($this->pitch);
$this->putLFloat($this->headYaw ?? $this->yaw);
$this->putLFloat($this->yaw);
$this->putSlot($this->item);
$this->putEntityMetadata($this->metadata);
$this->putUnsignedVarInt($this->uvarint1);
$this->putUnsignedVarInt($this->uvarint2);
$this->putUnsignedVarInt($this->uvarint3);
$this->putUnsignedVarInt($this->uvarint4);
$this->putLLong($this->long1);
}
public function handle(NetworkSession $session) : bool{
return $session->handleAddPlayer($this);
}
}