Clean up on AddHangingEntityPacket and AddPaintingPacket

AddPainting is a subclass of AddHangingEntity in vanilla.
This commit is contained in:
Dylan K. Taylor 2018-04-07 11:34:25 +01:00
parent e85fc54037
commit 5b532fdcf5
2 changed files with 9 additions and 27 deletions

View File

@ -30,8 +30,8 @@ use pocketmine\network\mcpe\NetworkSession;
class AddHangingEntityPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::ADD_HANGING_ENTITY_PACKET;
/** @var int */
public $entityUniqueId;
/** @var int|null */
public $entityUniqueId = null;
/** @var int */
public $entityRuntimeId;
/** @var int */
@ -41,20 +41,20 @@ class AddHangingEntityPacket extends DataPacket{
/** @var int */
public $z;
/** @var int */
public $unknown; //TODO (rotation?)
public $direction;
protected function decodePayload(){
$this->entityUniqueId = $this->getEntityUniqueId();
$this->entityRuntimeId = $this->getEntityRuntimeId();
$this->getBlockPosition($this->x, $this->y, $this->z);
$this->unknown = $this->getVarInt();
$this->direction = $this->getVarInt();
}
protected function encodePayload(){
$this->putEntityUniqueId($this->entityUniqueId);
$this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId);
$this->putEntityRuntimeId($this->entityRuntimeId);
$this->putBlockPosition($this->x, $this->y, $this->z);
$this->putVarInt($this->unknown);
$this->putVarInt($this->direction);
}
public function handle(NetworkSession $session) : bool{

View File

@ -28,37 +28,19 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\network\mcpe\NetworkSession;
class AddPaintingPacket extends DataPacket{
class AddPaintingPacket extends AddHangingEntityPacket{
public const NETWORK_ID = ProtocolInfo::ADD_PAINTING_PACKET;
/** @var int|null */
public $entityUniqueId = null; //TODO
/** @var int */
public $entityRuntimeId;
/** @var int */
public $x;
/** @var int */
public $y;
/** @var int */
public $z;
/** @var int */
public $direction;
/** @var string */
public $title;
protected function decodePayload(){
$this->entityUniqueId = $this->getEntityUniqueId();
$this->entityRuntimeId = $this->getEntityRuntimeId();
$this->getBlockPosition($this->x, $this->y, $this->z);
$this->direction = $this->getVarInt();
parent::decodePayload();
$this->title = $this->getString();
}
protected function encodePayload(){
$this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId);
$this->putEntityRuntimeId($this->entityRuntimeId);
$this->putBlockPosition($this->x, $this->y, $this->z);
$this->putVarInt($this->direction);
parent::encodePayload();
$this->putString($this->title);
}