PocketMine-MP 5.28.1 git-88cdc2eb67c40075559c3ef51418b418cd5488e9
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
28 public int $action;
29 public int $actorRuntimeId;
30 public float $float = 0.0; //TODO (Boat rowing time?)
31
32 public static function create(int $actorRuntimeId, int $actionId) : self{
33 $result = new self;
34 $result->actorRuntimeId = $actorRuntimeId;
35 $result->action = $actionId;
36 return $result;
37 }
38
39 public static function boatHack(int $actorRuntimeId, int $actionId, float $data) : self{
40 $result = self::create($actorRuntimeId, $actionId);
41 $result->float = $data;
42 return $result;
43 }
44
45 protected function decodePayload(PacketSerializer $in) : void{
46 $this->action = $in->getVarInt();
47 $this->actorRuntimeId = $in->getActorRuntimeId();
48 if(($this->action & 0x80) !== 0){
49 $this->float = $in->getLFloat();
50 }
51 }
52
53 protected function encodePayload(PacketSerializer $out) : void{
54 $out->putVarInt($this->action);
55 $out->putActorRuntimeId($this->actorRuntimeId);
56 if(($this->action & 0x80) !== 0){
57 $out->putLFloat($this->float);
58 }
59 }
60
61 public function handle(PacketHandlerInterface $handler) : bool{
62 return $handler->handleAnimate($this);
63 }
64}
handle(PacketHandlerInterface $handler)