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