From c19ab976107446b629e586add9983db83496f0e6 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 27 Feb 2020 17:37:45 +0000 Subject: [PATCH] AddActorPacket: move BC hack to higher level we shouldn't hack the protocol impl for BC. --- src/pocketmine/entity/Entity.php | 2 +- .../network/mcpe/protocol/AddActorPacket.php | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index cfb8be6b7..8838433ba 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1914,7 +1914,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ protected function sendSpawnPacket(Player $player) : void{ $pk = new AddActorPacket(); $pk->entityRuntimeId = $this->getId(); - $pk->type = static::NETWORK_ID; + $pk->type = AddActorPacket::LEGACY_ID_MAP_BC[static::NETWORK_ID]; $pk->position = $this->asVector3(); $pk->motion = $this->getMotion(); $pk->yaw = $this->yaw; diff --git a/src/pocketmine/network/mcpe/protocol/AddActorPacket.php b/src/pocketmine/network/mcpe/protocol/AddActorPacket.php index e3122dc05..cb0e72374 100644 --- a/src/pocketmine/network/mcpe/protocol/AddActorPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddActorPacket.php @@ -148,7 +148,7 @@ class AddActorPacket extends DataPacket{ public $entityUniqueId = null; //TODO /** @var int */ public $entityRuntimeId; - /** @var int */ + /** @var string */ public $type; /** @var Vector3 */ public $position; @@ -174,10 +174,7 @@ class AddActorPacket extends DataPacket{ protected function decodePayload(){ $this->entityUniqueId = $this->getEntityUniqueId(); $this->entityRuntimeId = $this->getEntityRuntimeId(); - $this->type = array_search($t = $this->getString(), self::LEGACY_ID_MAP_BC, true); - if($this->type === false){ - throw new \UnexpectedValueException("Can't map ID $t to legacy ID"); - } + $this->type = $this->getString(); $this->position = $this->getVector3(); $this->motion = $this->getVector3(); $this->pitch = $this->getLFloat(); @@ -212,10 +209,7 @@ class AddActorPacket extends DataPacket{ protected function encodePayload(){ $this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); $this->putEntityRuntimeId($this->entityRuntimeId); - if(!isset(self::LEGACY_ID_MAP_BC[$this->type])){ - throw new \InvalidArgumentException("Unknown entity numeric ID $this->type"); - } - $this->putString(self::LEGACY_ID_MAP_BC[$this->type]); + $this->putString($this->type); $this->putVector3($this->position); $this->putVector3Nullable($this->motion); $this->putLFloat($this->pitch);