PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
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
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
21use pocketmine\network\mcpe\protocol\types\MovementEffectType;
22
24 public const NETWORK_ID = ProtocolInfo::MOVEMENT_EFFECT_PACKET;
25
26 private int $actorRuntimeId;
27 private MovementEffectType $effectType;
28 private int $duration;
29 private int $tick;
30
34 public static function create(int $actorRuntimeId, MovementEffectType $effectType, int $duration, int $tick) : self{
35 $result = new self;
36 $result->actorRuntimeId = $actorRuntimeId;
37 $result->effectType = $effectType;
38 $result->duration = $duration;
39 $result->tick = $tick;
40 return $result;
41 }
42
43 public function getActorRuntimeId() : int{ return $this->actorRuntimeId; }
44
45 public function getEffectType() : MovementEffectType{ return $this->effectType; }
46
47 public function getDuration() : int{ return $this->duration; }
48
49 public function getTick() : int{ return $this->tick; }
50
51 protected function decodePayload(ByteBufferReader $in) : void{
52 $this->actorRuntimeId = CommonTypes::getActorRuntimeId($in);
53 $this->effectType = MovementEffectType::fromPacket(VarInt::readUnsignedInt($in));
54 $this->duration = VarInt::readUnsignedInt($in);
55 $this->tick = VarInt::readUnsignedLong($in);
56 }
57
58 protected function encodePayload(ByteBufferWriter $out) : void{
59 CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId);
60 VarInt::writeUnsignedInt($out, $this->effectType->value);
61 VarInt::writeUnsignedInt($out, $this->duration);
62 VarInt::writeUnsignedLong($out, $this->tick);
63 }
64
65 public function handle(PacketHandlerInterface $handler) : bool{
66 return $handler->handleMovementEffect($this);
67 }
68}
static create(int $actorRuntimeId, MovementEffectType $effectType, int $duration, int $tick)