use pocketmine\network\mcpe\NetworkSession; class MoveEntityDeltaPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::MOVE_ENTITY_DELTA_PACKET; public const FLAG_HAS_X = 0x01; public const FLAG_HAS_Y = 0x02; public const FLAG_HAS_Z = 0x04; public const FLAG_HAS_ROT_X = 0x08; public const FLAG_HAS_ROT_Y = 0x10; public const FLAG_HAS_ROT_Z = 0x20; /** @var int */ public $flags; /** @var int */ public $xDiff = 0; /** @var int */ public $yDiff = 0; /** @var int */ public $zDiff = 0; /** @var float */ public $xRot = 0.0; /** @var float */ public $yRot = 0.0; /** @var float */ public $zRot = 0.0; private function maybeReadCoord(int $flag) : int{ if($this->flags & $flag){ return $this->getVarInt(); } return 0; } private function maybeReadRotation(int $flag) : float{ if($this->flags & $flag){ return $this->getByteRotation(); } return 0.0; } protected function decodePayload(){ $this->flags = $this->getByte(); $this->xDiff = $this->maybeReadCoord(self::FLAG_HAS_X); $this->yDiff = $this->maybeReadCoord(self::FLAG_HAS_Y); $this->zDiff = $this->maybeReadCoord(self::FLAG_HAS_Z); $this->xRot = $this->maybeReadRotation(self::FLAG_HAS_ROT_X); $this->yRot = $this->maybeReadRotation(self::FLAG_HAS_ROT_Y); $this->zRot = $this->maybeReadRotation(self::FLAG_HAS_ROT_Z); } private function maybeWriteCoord(int $flag, int $val) : void{ if($this->flags & $flag){ $this->putVarInt($val); } } private function maybeWriteRotation(int $flag, float $val) : void{ if($this->flags & $flag){ $this->putByteRotation($val); } } protected function encodePayload(){ $this->putByte($this->flags); $this->maybeWriteCoord(self::FLAG_HAS_X, $this->xDiff); $this->maybeWriteCoord(self::FLAG_HAS_Y, $this->yDiff); $this->maybeWriteCoord(self::FLAG_HAS_Z, $this->zDiff); $this->maybeWriteRotation(self::FLAG_HAS_ROT_X, $this->xRot); $this->maybeWriteRotation(self::FLAG_HAS_ROT_Y, $this->yRot); $this->maybeWriteRotation(self::FLAG_HAS_ROT_Z, $this->zRot); } public function handle(NetworkSession $session) : bool{ return $session->handleMoveEntityDelta($this); } }