PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
AnimateEntityPacket.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
20use pmmp\encoding\VarInt;
22use function count;
23
25 public const NETWORK_ID = ProtocolInfo::ANIMATE_ENTITY_PACKET;
26
27 private string $animation;
28 private string $nextState;
29 private string $stopExpression;
30 private int $stopExpressionVersion;
31 private string $controller;
32 private float $blendOutTime;
37 private array $actorRuntimeIds;
38
44 public static function create(
45 string $animation,
46 string $nextState,
47 string $stopExpression,
48 int $stopExpressionVersion,
49 string $controller,
50 float $blendOutTime,
51 array $actorRuntimeIds,
52 ) : self{
53 $result = new self;
54 $result->animation = $animation;
55 $result->nextState = $nextState;
56 $result->stopExpression = $stopExpression;
57 $result->stopExpressionVersion = $stopExpressionVersion;
58 $result->controller = $controller;
59 $result->blendOutTime = $blendOutTime;
60 $result->actorRuntimeIds = $actorRuntimeIds;
61 return $result;
62 }
63
64 public function getAnimation() : string{ return $this->animation; }
65
66 public function getNextState() : string{ return $this->nextState; }
67
68 public function getStopExpression() : string{ return $this->stopExpression; }
69
70 public function getStopExpressionVersion() : int{ return $this->stopExpressionVersion; }
71
72 public function getController() : string{ return $this->controller; }
73
74 public function getBlendOutTime() : float{ return $this->blendOutTime; }
75
80 public function getActorRuntimeIds() : array{ return $this->actorRuntimeIds; }
81
82 protected function decodePayload(ByteBufferReader $in) : void{
83 $this->animation = CommonTypes::getString($in);
84 $this->nextState = CommonTypes::getString($in);
85 $this->stopExpression = CommonTypes::getString($in);
86 $this->stopExpressionVersion = LE::readSignedInt($in);
87 $this->controller = CommonTypes::getString($in);
88 $this->blendOutTime = LE::readFloat($in);
89 $this->actorRuntimeIds = [];
90 for($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; ++$i){
91 $this->actorRuntimeIds[] = CommonTypes::getActorRuntimeId($in);
92 }
93 }
94
95 protected function encodePayload(ByteBufferWriter $out) : void{
96 CommonTypes::putString($out, $this->animation);
97 CommonTypes::putString($out, $this->nextState);
98 CommonTypes::putString($out, $this->stopExpression);
99 LE::writeSignedInt($out, $this->stopExpressionVersion);
100 CommonTypes::putString($out, $this->controller);
101 LE::writeFloat($out, $this->blendOutTime);
102 VarInt::writeUnsignedInt($out, count($this->actorRuntimeIds));
103 foreach($this->actorRuntimeIds as $id){
104 CommonTypes::putActorRuntimeId($out, $id);
105 }
106 }
107
108 public function handle(PacketHandlerInterface $handler) : bool{
109 return $handler->handleAnimateEntity($this);
110 }
111}
static create(string $animation, string $nextState, string $stopExpression, int $stopExpressionVersion, string $controller, float $blendOutTime, array $actorRuntimeIds,)