PocketMine-MP 5.21.2 git-09bf203267aca9b83a09640e17bfac0fc7b58ff8
Loading...
Searching...
No Matches
MovementEffectPacket.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
18use pocketmine\network\mcpe\protocol\types\MovementEffectType;
19
21 public const NETWORK_ID = ProtocolInfo::MOVEMENT_EFFECT_PACKET;
22
23 private int $actorRuntimeId;
24 private MovementEffectType $effectType;
25 private int $duration;
26 private int $tick;
27
31 public static function create(int $actorRuntimeId, MovementEffectType $effectType, int $duration, int $tick) : self{
32 $result = new self;
33 $result->actorRuntimeId = $actorRuntimeId;
34 $result->effectType = $effectType;
35 $result->duration = $duration;
36 $result->tick = $tick;
37 return $result;
38 }
39
40 public function getActorRuntimeId() : int{ return $this->actorRuntimeId; }
41
42 public function getEffectType() : MovementEffectType{ return $this->effectType; }
43
44 public function getDuration() : int{ return $this->duration; }
45
46 public function getTick() : int{ return $this->tick; }
47
48 protected function decodePayload(PacketSerializer $in) : void{
49 $this->actorRuntimeId = $in->getActorRuntimeId();
50 $this->effectType = MovementEffectType::fromPacket($in->getUnsignedVarInt());
51 $this->duration = $in->getUnsignedVarInt();
52 $this->tick = $in->getUnsignedVarLong();
53 }
54
55 protected function encodePayload(PacketSerializer $out) : void{
56 $out->putActorRuntimeId($this->actorRuntimeId);
57 $out->putUnsignedVarInt($this->effectType->value);
58 $out->putUnsignedVarInt($this->duration);
59 $out->putUnsignedVarLong($this->tick);
60 }
61
62 public function handle(PacketHandlerInterface $handler) : bool{
63 return $handler->handleMovementEffect($this);
64 }
65}
static create(int $actorRuntimeId, MovementEffectType $effectType, int $duration, int $tick)