PocketMine-MP 5.23.2 git-45917d495c14f3ce37bbf0848262ad8a470030f3
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
18
20 public const NETWORK_ID = ProtocolInfo::MOB_EFFECT_PACKET;
21
22 public const EVENT_ADD = 1;
23 public const EVENT_MODIFY = 2;
24 public const EVENT_REMOVE = 3;
25
26 public int $actorRuntimeId;
27 public int $eventId;
28 public int $effectId;
29 public int $amplifier = 0;
30 public bool $particles = true;
31 public int $duration = 0;
32 public int $tick = 0;
33
37 public static function create(
38 int $actorRuntimeId,
39 int $eventId,
40 int $effectId,
41 int $amplifier,
42 bool $particles,
43 int $duration,
44 int $tick,
45 ) : self{
46 $result = new self;
47 $result->actorRuntimeId = $actorRuntimeId;
48 $result->eventId = $eventId;
49 $result->effectId = $effectId;
50 $result->amplifier = $amplifier;
51 $result->particles = $particles;
52 $result->duration = $duration;
53 $result->tick = $tick;
54 return $result;
55 }
56
57 public static function add(int $actorRuntimeId, bool $replace, int $effectId, int $amplifier, bool $particles, int $duration, int $tick) : self{
58 return self::create($actorRuntimeId, $replace ? self::EVENT_MODIFY : self::EVENT_ADD, $effectId, $amplifier, $particles, $duration, $tick);
59 }
60
61 public static function remove(int $actorRuntimeId, int $effectId, int $tick) : self{
62 return self::create($actorRuntimeId, self::EVENT_REMOVE, $effectId, 0, false, 0, $tick);
63 }
64
65 protected function decodePayload(PacketSerializer $in) : void{
66 $this->actorRuntimeId = $in->getActorRuntimeId();
67 $this->eventId = $in->getByte();
68 $this->effectId = $in->getVarInt();
69 $this->amplifier = $in->getVarInt();
70 $this->particles = $in->getBool();
71 $this->duration = $in->getVarInt();
72 $this->tick = $in->getUnsignedVarLong();
73 }
74
75 protected function encodePayload(PacketSerializer $out) : void{
76 $out->putActorRuntimeId($this->actorRuntimeId);
77 $out->putByte($this->eventId);
78 $out->putVarInt($this->effectId);
79 $out->putVarInt($this->amplifier);
80 $out->putBool($this->particles);
81 $out->putVarInt($this->duration);
82 $out->putUnsignedVarLong($this->tick);
83 }
84
85 public function handle(PacketHandlerInterface $handler) : bool{
86 return $handler->handleMobEffect($this);
87 }
88}
static create(int $actorRuntimeId, int $eventId, int $effectId, int $amplifier, bool $particles, int $duration, int $tick,)