AddActorPacket: move BC hack to higher level

we shouldn't hack the protocol impl for BC.
This commit is contained in:
Dylan K. Taylor 2020-02-27 17:37:45 +00:00
parent dbaf851be7
commit c19ab97610
2 changed files with 4 additions and 10 deletions

View File

@ -1914,7 +1914,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
protected function sendSpawnPacket(Player $player) : void{ protected function sendSpawnPacket(Player $player) : void{
$pk = new AddActorPacket(); $pk = new AddActorPacket();
$pk->entityRuntimeId = $this->getId(); $pk->entityRuntimeId = $this->getId();
$pk->type = static::NETWORK_ID; $pk->type = AddActorPacket::LEGACY_ID_MAP_BC[static::NETWORK_ID];
$pk->position = $this->asVector3(); $pk->position = $this->asVector3();
$pk->motion = $this->getMotion(); $pk->motion = $this->getMotion();
$pk->yaw = $this->yaw; $pk->yaw = $this->yaw;

View File

@ -148,7 +148,7 @@ class AddActorPacket extends DataPacket{
public $entityUniqueId = null; //TODO public $entityUniqueId = null; //TODO
/** @var int */ /** @var int */
public $entityRuntimeId; public $entityRuntimeId;
/** @var int */ /** @var string */
public $type; public $type;
/** @var Vector3 */ /** @var Vector3 */
public $position; public $position;
@ -174,10 +174,7 @@ class AddActorPacket extends DataPacket{
protected function decodePayload(){ protected function decodePayload(){
$this->entityUniqueId = $this->getEntityUniqueId(); $this->entityUniqueId = $this->getEntityUniqueId();
$this->entityRuntimeId = $this->getEntityRuntimeId(); $this->entityRuntimeId = $this->getEntityRuntimeId();
$this->type = array_search($t = $this->getString(), self::LEGACY_ID_MAP_BC, true); $this->type = $this->getString();
if($this->type === false){
throw new \UnexpectedValueException("Can't map ID $t to legacy ID");
}
$this->position = $this->getVector3(); $this->position = $this->getVector3();
$this->motion = $this->getVector3(); $this->motion = $this->getVector3();
$this->pitch = $this->getLFloat(); $this->pitch = $this->getLFloat();
@ -212,10 +209,7 @@ class AddActorPacket extends DataPacket{
protected function encodePayload(){ protected function encodePayload(){
$this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); $this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId);
$this->putEntityRuntimeId($this->entityRuntimeId); $this->putEntityRuntimeId($this->entityRuntimeId);
if(!isset(self::LEGACY_ID_MAP_BC[$this->type])){ $this->putString($this->type);
throw new \InvalidArgumentException("Unknown entity numeric ID $this->type");
}
$this->putString(self::LEGACY_ID_MAP_BC[$this->type]);
$this->putVector3($this->position); $this->putVector3($this->position);
$this->putVector3Nullable($this->motion); $this->putVector3Nullable($this->motion);
$this->putLFloat($this->pitch); $this->putLFloat($this->pitch);