PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
SpawnParticleEffectPacket.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;
23
25 public const NETWORK_ID = ProtocolInfo::SPAWN_PARTICLE_EFFECT_PACKET;
26
27 public int $dimensionId = DimensionIds::OVERWORLD; //wtf mojang
28 public int $actorUniqueId = -1; //default none
29 public Vector3 $position;
30 public string $particleName;
31 public ?string $molangVariablesJson = null;
32
36 public static function create(int $dimensionId, int $actorUniqueId, Vector3 $position, string $particleName, ?string $molangVariablesJson) : self{
37 $result = new self;
38 $result->dimensionId = $dimensionId;
39 $result->actorUniqueId = $actorUniqueId;
40 $result->position = $position;
41 $result->particleName = $particleName;
42 $result->molangVariablesJson = $molangVariablesJson;
43 return $result;
44 }
45
46 protected function decodePayload(ByteBufferReader $in) : void{
47 $this->dimensionId = Byte::readUnsigned($in);
48 $this->actorUniqueId = CommonTypes::getActorUniqueId($in);
49 $this->position = CommonTypes::getVector3($in);
50 $this->particleName = CommonTypes::getString($in);
51 $this->molangVariablesJson = CommonTypes::getBool($in) ? CommonTypes::getString($in) : null;
52 }
53
54 protected function encodePayload(ByteBufferWriter $out) : void{
55 Byte::writeUnsigned($out, $this->dimensionId);
56 CommonTypes::putActorUniqueId($out, $this->actorUniqueId);
57 CommonTypes::putVector3($out, $this->position);
58 CommonTypes::putString($out, $this->particleName);
59 CommonTypes::putBool($out, $this->molangVariablesJson !== null);
60 if($this->molangVariablesJson !== null){
61 CommonTypes::putString($out, $this->molangVariablesJson);
62 }
63 }
64
65 public function handle(PacketHandlerInterface $handler) : bool{
66 return $handler->handleSpawnParticleEffect($this);
67 }
68}
static create(int $dimensionId, int $actorUniqueId, Vector3 $position, string $particleName, ?string $molangVariablesJson)