PocketMine-MP 5.37.1 git-cef37e7835c666594588f957a47b27d521c6a58e
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\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
20use pmmp\encoding\VarInt;
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 public const ACTION_ROW_RIGHT = 128;
32 public const ACTION_ROW_LEFT = 129;
33
34 public int $action;
35 public int $actorRuntimeId;
36 public float $data = 0.0;
37 public float $rowingTime = 0.0;
38
39 public static function create(int $actorRuntimeId, int $actionId, float $data = 0.0) : self{
40 $result = new self;
41 $result->actorRuntimeId = $actorRuntimeId;
42 $result->action = $actionId;
43 $result->data = $data;
44 return $result;
45 }
46
47 public static function boatHack(int $actorRuntimeId, int $actionId, float $rowingTime) : self{
48 if($actionId !== self::ACTION_ROW_LEFT && $actionId !== self::ACTION_ROW_RIGHT){
49 throw new \InvalidArgumentException("Invalid actionId for boatHack: $actionId");
50 }
51
52 $result = self::create($actorRuntimeId, $actionId);
53 $result->rowingTime = $rowingTime;
54 return $result;
55 }
56
57 protected function decodePayload(ByteBufferReader $in) : void{
58 $this->action = VarInt::readSignedInt($in);
59 $this->actorRuntimeId = CommonTypes::getActorRuntimeId($in);
60 $this->data = LE::readFloat($in);
61 if($this->action === self::ACTION_ROW_LEFT || $this->action === self::ACTION_ROW_RIGHT){
62 $this->rowingTime = LE::readFloat($in);
63 }
64 }
65
66 protected function encodePayload(ByteBufferWriter $out) : void{
67 VarInt::writeSignedInt($out, $this->action);
68 CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId);
69 LE::writeFloat($out, $this->data);
70 if($this->action === self::ACTION_ROW_LEFT || $this->action === self::ACTION_ROW_RIGHT){
71 LE::writeFloat($out, $this->rowingTime);
72 }
73 }
74
75 public function handle(PacketHandlerInterface $handler) : bool{
76 return $handler->handleAnimate($this);
77 }
78}
handle(PacketHandlerInterface $handler)