Dylan K. Taylor 64ecc373be Split up session base logic and packet handling
this will allow for mutable packet handlers which can be used to cleanly implement multi-stage game sessions.
2018-07-20 12:36:44 +01:00

95 lines
2.6 KiB
PHP

<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h>
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\handler\SessionHandler;
class MovePlayerPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::MOVE_PLAYER_PACKET;
public const MODE_NORMAL = 0;
public const MODE_RESET = 1;
public const MODE_TELEPORT = 2;
public const MODE_PITCH = 3; //facepalm Mojang
/** @var int */
public $entityRuntimeId;
/** @var Vector3 */
public $position;
/** @var float */
public $pitch;
/** @var float */
public $yaw;
/** @var float */
public $headYaw;
/** @var int */
public $mode = self::MODE_NORMAL;
/** @var bool */
public $onGround = false; //TODO
/** @var int */
public $ridingEid = 0;
/** @var int */
public $teleportCause = 0;
/** @var int */
public $teleportItem = 0;
protected function decodePayload() : void{
$this->entityRuntimeId = $this->getEntityRuntimeId();
$this->position = $this->getVector3();
$this->pitch = $this->getLFloat();
$this->yaw = $this->getLFloat();
$this->headYaw = $this->getLFloat();
$this->mode = $this->getByte();
$this->onGround = $this->getBool();
$this->ridingEid = $this->getEntityRuntimeId();
if($this->mode === MovePlayerPacket::MODE_TELEPORT){
$this->teleportCause = $this->getLInt();
$this->teleportItem = $this->getLInt();
}
}
protected function encodePayload() : void{
$this->putEntityRuntimeId($this->entityRuntimeId);
$this->putVector3($this->position);
$this->putLFloat($this->pitch);
$this->putLFloat($this->yaw);
$this->putLFloat($this->headYaw); //TODO
$this->putByte($this->mode);
$this->putBool($this->onGround);
$this->putEntityRuntimeId($this->ridingEid);
if($this->mode === MovePlayerPacket::MODE_TELEPORT){
$this->putLInt($this->teleportCause);
$this->putLInt($this->teleportItem);
}
}
public function handle(SessionHandler $handler) : bool{
return $handler->handleMovePlayer($this);
}
}