PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
MobEffectPacket.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\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\VarInt;
22
24 public const NETWORK_ID = ProtocolInfo::MOB_EFFECT_PACKET;
25
26 public const EVENT_ADD = 1;
27 public const EVENT_MODIFY = 2;
28 public const EVENT_REMOVE = 3;
29
30 public int $actorRuntimeId;
31 public int $eventId;
32 public int $effectId;
33 public int $amplifier = 0;
34 public bool $particles = true;
35 public int $duration = 0;
36 public int $tick = 0;
37
41 public static function create(
42 int $actorRuntimeId,
43 int $eventId,
44 int $effectId,
45 int $amplifier,
46 bool $particles,
47 int $duration,
48 int $tick,
49 ) : self{
50 $result = new self;
51 $result->actorRuntimeId = $actorRuntimeId;
52 $result->eventId = $eventId;
53 $result->effectId = $effectId;
54 $result->amplifier = $amplifier;
55 $result->particles = $particles;
56 $result->duration = $duration;
57 $result->tick = $tick;
58 return $result;
59 }
60
61 public static function add(int $actorRuntimeId, bool $replace, int $effectId, int $amplifier, bool $particles, int $duration, int $tick) : self{
62 return self::create($actorRuntimeId, $replace ? self::EVENT_MODIFY : self::EVENT_ADD, $effectId, $amplifier, $particles, $duration, $tick);
63 }
64
65 public static function remove(int $actorRuntimeId, int $effectId, int $tick) : self{
66 return self::create($actorRuntimeId, self::EVENT_REMOVE, $effectId, 0, false, 0, $tick);
67 }
68
69 protected function decodePayload(ByteBufferReader $in) : void{
70 $this->actorRuntimeId = CommonTypes::getActorRuntimeId($in);
71 $this->eventId = Byte::readUnsigned($in);
72 $this->effectId = VarInt::readSignedInt($in);
73 $this->amplifier = VarInt::readSignedInt($in);
74 $this->particles = CommonTypes::getBool($in);
75 $this->duration = VarInt::readSignedInt($in);
76 $this->tick = VarInt::readUnsignedLong($in);
77 }
78
79 protected function encodePayload(ByteBufferWriter $out) : void{
80 CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId);
81 Byte::writeUnsigned($out, $this->eventId);
82 VarInt::writeSignedInt($out, $this->effectId);
83 VarInt::writeSignedInt($out, $this->amplifier);
84 CommonTypes::putBool($out, $this->particles);
85 VarInt::writeSignedInt($out, $this->duration);
86 VarInt::writeUnsignedLong($out, $this->tick);
87 }
88
89 public function handle(PacketHandlerInterface $handler) : bool{
90 return $handler->handleMobEffect($this);
91 }
92}
static create(int $actorRuntimeId, int $eventId, int $effectId, int $amplifier, bool $particles, int $duration, int $tick,)