mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-08 11:01:47 +00:00
120 lines
3.5 KiB
PHP
120 lines
3.5 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\protocol\serializer\PacketSerializer;
|
|
use pocketmine\network\mcpe\protocol\types\entity\Attribute;
|
|
use pocketmine\network\mcpe\protocol\types\entity\EntityLink;
|
|
use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty;
|
|
use function count;
|
|
|
|
class AddActorPacket extends DataPacket implements ClientboundPacket{
|
|
public const NETWORK_ID = ProtocolInfo::ADD_ACTOR_PACKET;
|
|
|
|
/** @var int|null */
|
|
public $entityUniqueId = null; //TODO
|
|
/** @var int */
|
|
public $entityRuntimeId;
|
|
/** @var string */
|
|
public $type;
|
|
/** @var Vector3 */
|
|
public $position;
|
|
/** @var Vector3|null */
|
|
public $motion;
|
|
/** @var float */
|
|
public $pitch = 0.0;
|
|
/** @var float */
|
|
public $yaw = 0.0;
|
|
/** @var float */
|
|
public $headYaw = 0.0;
|
|
|
|
/** @var Attribute[] */
|
|
public $attributes = [];
|
|
/**
|
|
* @var MetadataProperty[]
|
|
* @phpstan-var array<int, MetadataProperty>
|
|
*/
|
|
public $metadata = [];
|
|
/** @var EntityLink[] */
|
|
public $links = [];
|
|
|
|
protected function decodePayload(PacketSerializer $in) : void{
|
|
$this->entityUniqueId = $in->getEntityUniqueId();
|
|
$this->entityRuntimeId = $in->getEntityRuntimeId();
|
|
$this->type = $in->getString();
|
|
$this->position = $in->getVector3();
|
|
$this->motion = $in->getVector3();
|
|
$this->pitch = $in->getLFloat();
|
|
$this->yaw = $in->getLFloat();
|
|
$this->headYaw = $in->getLFloat();
|
|
|
|
$attrCount = $in->getUnsignedVarInt();
|
|
for($i = 0; $i < $attrCount; ++$i){
|
|
$id = $in->getString();
|
|
$min = $in->getLFloat();
|
|
$current = $in->getLFloat();
|
|
$max = $in->getLFloat();
|
|
$this->attributes[] = new Attribute($id, $min, $max, $current, $current);
|
|
}
|
|
|
|
$this->metadata = $in->getEntityMetadata();
|
|
$linkCount = $in->getUnsignedVarInt();
|
|
for($i = 0; $i < $linkCount; ++$i){
|
|
$this->links[] = $in->getEntityLink();
|
|
}
|
|
}
|
|
|
|
protected function encodePayload(PacketSerializer $out) : void{
|
|
$out->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId);
|
|
$out->putEntityRuntimeId($this->entityRuntimeId);
|
|
$out->putString($this->type);
|
|
$out->putVector3($this->position);
|
|
$out->putVector3Nullable($this->motion);
|
|
$out->putLFloat($this->pitch);
|
|
$out->putLFloat($this->yaw);
|
|
$out->putLFloat($this->headYaw);
|
|
|
|
$out->putUnsignedVarInt(count($this->attributes));
|
|
foreach($this->attributes as $attribute){
|
|
$out->putString($attribute->getId());
|
|
$out->putLFloat($attribute->getMin());
|
|
$out->putLFloat($attribute->getCurrent());
|
|
$out->putLFloat($attribute->getMax());
|
|
}
|
|
|
|
$out->putEntityMetadata($this->metadata);
|
|
$out->putUnsignedVarInt(count($this->links));
|
|
foreach($this->links as $link){
|
|
$out->putEntityLink($link);
|
|
}
|
|
}
|
|
|
|
public function handle(PacketHandlerInterface $handler) : bool{
|
|
return $handler->handleAddActor($this);
|
|
}
|
|
}
|