From eccc7bf7b36081cdda51bfbb27ef7eeca482fd06 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 9 Oct 2017 19:15:53 +0100 Subject: [PATCH] Moved EntityLink to its own type --- .../network/mcpe/protocol/AddEntityPacket.php | 3 +- .../network/mcpe/protocol/AddPlayerPacket.php | 2 + .../network/mcpe/protocol/DataPacket.php | 25 ++++++++----- .../mcpe/protocol/SetEntityLinkPacket.php | 5 ++- .../mcpe/protocol/types/EntityLink.php | 37 +++++++++++++++++++ 5 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 src/pocketmine/network/mcpe/protocol/types/EntityLink.php diff --git a/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php b/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php index 17d74c528..8ca614fb1 100644 --- a/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php @@ -28,6 +28,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\entity\Attribute; use pocketmine\math\Vector3; use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\protocol\types\EntityLink; class AddEntityPacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::ADD_ENTITY_PACKET; @@ -51,7 +52,7 @@ class AddEntityPacket extends DataPacket{ public $attributes = []; /** @var array */ public $metadata = []; - /** @var array */ + /** @var EntityLink[] */ public $links = []; protected function decodePayload(){ diff --git a/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php b/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php index c9e3e4095..7de94d503 100644 --- a/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php @@ -28,6 +28,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\item\Item; use pocketmine\math\Vector3; use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\protocol\types\EntityLink; use pocketmine\utils\UUID; class AddPlayerPacket extends DataPacket{ @@ -65,6 +66,7 @@ class AddPlayerPacket extends DataPacket{ public $long1 = 0; + /** @var EntityLink[] */ public $links = []; protected function decodePayload(){ diff --git a/src/pocketmine/network/mcpe/protocol/DataPacket.php b/src/pocketmine/network/mcpe/protocol/DataPacket.php index 4a16885b3..7ef18142e 100644 --- a/src/pocketmine/network/mcpe/protocol/DataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/DataPacket.php @@ -30,6 +30,7 @@ use pocketmine\entity\Entity; use pocketmine\item\ItemFactory; use pocketmine\math\Vector3; use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\protocol\types\EntityLink; use pocketmine\utils\BinaryStream; use pocketmine\utils\Utils; @@ -514,20 +515,26 @@ abstract class DataPacket extends BinaryStream{ } /** - * @return array + * @return EntityLink */ - protected function getEntityLink() : array{ - return [$this->getEntityUniqueId(), $this->getEntityUniqueId(), $this->getByte(), $this->getByte()]; + protected function getEntityLink() : EntityLink{ + $link = new EntityLink(); + $link->fromEntityUniqueId = $this->getEntityUniqueId(); + $link->toEntityUniqueId = $this->getEntityUniqueId(); + $link->type = $this->getByte(); + $link->byte2 = $this->getByte(); + + return $link; } /** - * @param array $link + * @param EntityLink $link */ - protected function putEntityLink(array $link){ - $this->putEntityUniqueId($link[0]); - $this->putEntityUniqueId($link[1]); - $this->putByte($link[2]); - $this->putByte($link[3]); + protected function putEntityLink(EntityLink $link){ + $this->putEntityUniqueId($link->fromEntityUniqueId); + $this->putEntityUniqueId($link->toEntityUniqueId); + $this->putByte($link->type); + $this->putByte($link->byte2); } } diff --git a/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php b/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php index c53453208..e1108c45a 100644 --- a/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php @@ -27,12 +27,13 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\protocol\types\EntityLink; class SetEntityLinkPacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::SET_ENTITY_LINK_PACKET; - /** @var array [from, to, type, unknown byte] */ - public $link = []; + /** @var EntityLink */ + public $link; protected function decodePayload(){ $this->link = $this->getEntityLink(); diff --git a/src/pocketmine/network/mcpe/protocol/types/EntityLink.php b/src/pocketmine/network/mcpe/protocol/types/EntityLink.php new file mode 100644 index 000000000..76c3ce405 --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/types/EntityLink.php @@ -0,0 +1,37 @@ +