PocketMine-MP 5.30.2 git-98f04176111e5ecab5e8814ffc69d992bfb64939
Loading...
Searching...
No Matches
ResourcePacksInfoPacket.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
19use Ramsey\Uuid\UuidInterface;
20use function count;
21
23 public const NETWORK_ID = ProtocolInfo::RESOURCE_PACKS_INFO_PACKET;
24
26 public array $resourcePackEntries = [];
27 public bool $mustAccept = false; //if true, forces client to choose between accepting packs or being disconnected
28 public bool $hasAddons = false;
29 public bool $hasScripts = false; //if true, causes disconnect for any platform that doesn't support scripts yet
30 private UuidInterface $worldTemplateId;
31 private string $worldTemplateVersion;
32 private bool $forceDisableVibrantVisuals;
33
38 public static function create(
39 array $resourcePackEntries,
40 bool $mustAccept,
41 bool $hasAddons,
42 bool $hasScripts,
43 UuidInterface $worldTemplateId,
44 string $worldTemplateVersion,
45 bool $forceDisableVibrantVisuals,
46 ) : self{
47 $result = new self;
48 $result->resourcePackEntries = $resourcePackEntries;
49 $result->mustAccept = $mustAccept;
50 $result->hasAddons = $hasAddons;
51 $result->hasScripts = $hasScripts;
52 $result->worldTemplateId = $worldTemplateId;
53 $result->worldTemplateVersion = $worldTemplateVersion;
54 $result->forceDisableVibrantVisuals = $forceDisableVibrantVisuals;
55 return $result;
56 }
57
58 public function getWorldTemplateId() : UuidInterface{ return $this->worldTemplateId; }
59
60 public function getWorldTemplateVersion() : string{ return $this->worldTemplateVersion; }
61
62 public function isForceDisablingVibrantVisuals() : bool{ return $this->forceDisableVibrantVisuals; }
63
64 protected function decodePayload(PacketSerializer $in) : void{
65 $this->mustAccept = $in->getBool();
66 $this->hasAddons = $in->getBool();
67 $this->hasScripts = $in->getBool();
68 $this->forceDisableVibrantVisuals = $in->getBool();
69 $this->worldTemplateId = $in->getUUID();
70 $this->worldTemplateVersion = $in->getString();
71
72 $resourcePackCount = $in->getLShort();
73 while($resourcePackCount-- > 0){
74 $this->resourcePackEntries[] = ResourcePackInfoEntry::read($in);
75 }
76 }
77
78 protected function encodePayload(PacketSerializer $out) : void{
79 $out->putBool($this->mustAccept);
80 $out->putBool($this->hasAddons);
81 $out->putBool($this->hasScripts);
82 $out->putBool($this->forceDisableVibrantVisuals);
83 $out->putUUID($this->worldTemplateId);
84 $out->putString($this->worldTemplateVersion);
85 $out->putLShort(count($this->resourcePackEntries));
86 foreach($this->resourcePackEntries as $entry){
87 $entry->write($out);
88 }
89 }
90
91 public function handle(PacketHandlerInterface $handler) : bool{
92 return $handler->handleResourcePacksInfo($this);
93 }
94}
static create(array $resourcePackEntries, bool $mustAccept, bool $hasAddons, bool $hasScripts, UuidInterface $worldTemplateId, string $worldTemplateVersion, bool $forceDisableVibrantVisuals,)