PocketMine-MP 5.39.3 git-66148f13a91e4af6778ba9f200ca25ad8a04a584
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 public bool $ambient = true;
38
42 public static function create(
43 int $actorRuntimeId,
44 int $eventId,
45 int $effectId,
46 int $amplifier,
47 bool $particles,
48 int $duration,
49 int $tick,
50 bool $ambient,
51 ) : self{
52 $result = new self;
53 $result->actorRuntimeId = $actorRuntimeId;
54 $result->eventId = $eventId;
55 $result->effectId = $effectId;
56 $result->amplifier = $amplifier;
57 $result->particles = $particles;
58 $result->duration = $duration;
59 $result->tick = $tick;
60 $result->ambient = $ambient;
61 return $result;
62 }
63
64 public static function add(int $actorRuntimeId, bool $replace, int $effectId, int $amplifier, bool $particles, int $duration, int $tick, bool $ambient) : self{
65 return self::create($actorRuntimeId, $replace ? self::EVENT_MODIFY : self::EVENT_ADD, $effectId, $amplifier, $particles, $duration, $tick, $ambient);
66 }
67
68 public static function remove(int $actorRuntimeId, int $effectId, int $tick) : self{
69 return self::create($actorRuntimeId, self::EVENT_REMOVE, $effectId, 0, false, 0, $tick, false);
70 }
71
72 protected function decodePayload(ByteBufferReader $in) : void{
73 $this->actorRuntimeId = CommonTypes::getActorRuntimeId($in);
74 $this->eventId = Byte::readUnsigned($in);
75 $this->effectId = VarInt::readSignedInt($in);
76 $this->amplifier = VarInt::readSignedInt($in);
77 $this->particles = CommonTypes::getBool($in);
78 $this->duration = VarInt::readSignedInt($in);
79 $this->tick = VarInt::readUnsignedLong($in);
80 $this->ambient = CommonTypes::getBool($in);
81 }
82
83 protected function encodePayload(ByteBufferWriter $out) : void{
84 CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId);
85 Byte::writeUnsigned($out, $this->eventId);
86 VarInt::writeSignedInt($out, $this->effectId);
87 VarInt::writeSignedInt($out, $this->amplifier);
88 CommonTypes::putBool($out, $this->particles);
89 VarInt::writeSignedInt($out, $this->duration);
90 VarInt::writeUnsignedLong($out, $this->tick);
91 CommonTypes::putBool($out, $this->ambient);
92 }
93
94 public function handle(PacketHandlerInterface $handler) : bool{
95 return $handler->handleMobEffect($this);
96 }
97}
static create(int $actorRuntimeId, int $eventId, int $effectId, int $amplifier, bool $particles, int $duration, int $tick, bool $ambient,)