PocketMine-MP 5.21.2 git-b2aa6396c3cc2cafdd815eacc360e1ad89599899
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
18
20 public const NETWORK_ID = ProtocolInfo::ANIMATE_PACKET;
21
22 public const ACTION_SWING_ARM = 1;
23
24 public const ACTION_STOP_SLEEP = 3;
25 public const ACTION_CRITICAL_HIT = 4;
26 public const ACTION_MAGICAL_CRITICAL_HIT = 5;
27 public const ACTION_ROW_RIGHT = 128;
28 public const ACTION_ROW_LEFT = 129;
29
30 public int $action;
31 public int $actorRuntimeId;
32 public float $float = 0.0; //TODO (Boat rowing time?)
33
34 public static function create(int $actorRuntimeId, int $actionId) : self{
35 $result = new self;
36 $result->actorRuntimeId = $actorRuntimeId;
37 $result->action = $actionId;
38 return $result;
39 }
40
41 public static function boatHack(int $actorRuntimeId, int $actionId, float $data) : self{
42 $result = self::create($actorRuntimeId, $actionId);
43 $result->float = $data;
44 return $result;
45 }
46
47 protected function decodePayload(PacketSerializer $in) : void{
48 $this->action = $in->getVarInt();
49 $this->actorRuntimeId = $in->getActorRuntimeId();
50 if(($this->action & 0x80) !== 0){
51 $this->float = $in->getLFloat();
52 }
53 }
54
55 protected function encodePayload(PacketSerializer $out) : void{
56 $out->putVarInt($this->action);
57 $out->putActorRuntimeId($this->actorRuntimeId);
58 if(($this->action & 0x80) !== 0){
59 $out->putLFloat($this->float);
60 }
61 }
62
63 public function handle(PacketHandlerInterface $handler) : bool{
64 return $handler->handleAnimate($this);
65 }
66}
handle(PacketHandlerInterface $handler)