PocketMine-MP 5.39.3 git-9a46a8bd745880ddf8eebaf28cda326bb97d2efa
Loading...
Searching...
No Matches
AnimatePacket.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\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\LE;
22
24 public const NETWORK_ID = ProtocolInfo::ANIMATE_PACKET;
25
26 public const ACTION_SWING_ARM = 1;
27
28 public const ACTION_STOP_SLEEP = 3;
29 public const ACTION_CRITICAL_HIT = 4;
30 public const ACTION_MAGICAL_CRITICAL_HIT = 5;
31
32 public int $action;
33 public int $actorRuntimeId;
34 public float $data = 0.0;
35 public ?string $swingSource = null;
36
37 public static function create(int $actorRuntimeId, int $action, float $data = 0.0, ?string $swingSource = null) : self{
38 $result = new self;
39 $result->actorRuntimeId = $actorRuntimeId;
40 $result->action = $action;
41 $result->data = $data;
42 $result->swingSource = $swingSource;
43 return $result;
44 }
45
46 protected function decodePayload(ByteBufferReader $in) : void{
47 $this->action = Byte::readUnsigned($in);
48 $this->actorRuntimeId = CommonTypes::getActorRuntimeId($in);
49 $this->data = LE::readFloat($in);
50 $this->swingSource = CommonTypes::readOptional($in, CommonTypes::getString(...));
51 }
52
53 protected function encodePayload(ByteBufferWriter $out) : void{
54 Byte::writeUnsigned($out, $this->action);
55 CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId);
56 LE::writeFloat($out, $this->data);
57 CommonTypes::writeOptional($out, $this->swingSource, CommonTypes::putString(...));
58 }
59
60 public function handle(PacketHandlerInterface $handler) : bool{
61 return $handler->handleAnimate($this);
62 }
63}
handle(PacketHandlerInterface $handler)