PocketMine-MP 5.39.3 git-66148f13a91e4af6778ba9f200ca25ad8a04a584
Loading...
Searching...
No Matches
ResourcePackStackPacket.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\VarInt;
23use function count;
24
26 public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_STACK_PACKET;
27
29 public array $resourcePackStack = [];
30 public bool $mustAccept = false;
31 public string $baseGameVersion = ProtocolInfo::MINECRAFT_VERSION_NETWORK;
32 public Experiments $experiments;
33 public bool $useVanillaEditorPacks;
34
39 public static function create(array $resourcePackStack, bool $mustAccept, string $baseGameVersion, Experiments $experiments, bool $useVanillaEditorPacks) : self{
40 $result = new self;
41 $result->resourcePackStack = $resourcePackStack;
42 $result->mustAccept = $mustAccept;
43 $result->baseGameVersion = $baseGameVersion;
44 $result->experiments = $experiments;
45 $result->useVanillaEditorPacks = $useVanillaEditorPacks;
46 return $result;
47 }
48
49 protected function decodePayload(ByteBufferReader $in) : void{
50 $this->mustAccept = CommonTypes::getBool($in);
51
52 $resourcePackCount = VarInt::readUnsignedInt($in);
53 while($resourcePackCount-- > 0){
54 $this->resourcePackStack[] = ResourcePackStackEntry::read($in);
55 }
56
57 $this->baseGameVersion = CommonTypes::getString($in);
58 $this->experiments = Experiments::read($in);
59 $this->useVanillaEditorPacks = CommonTypes::getBool($in);
60 }
61
62 protected function encodePayload(ByteBufferWriter $out) : void{
63 CommonTypes::putBool($out, $this->mustAccept);
64
65 VarInt::writeUnsignedInt($out, count($this->resourcePackStack));
66 foreach($this->resourcePackStack as $entry){
67 $entry->write($out);
68 }
69
70 CommonTypes::putString($out, $this->baseGameVersion);
71 $this->experiments->write($out);
72 CommonTypes::putBool($out, $this->useVanillaEditorPacks);
73 }
74
75 public function handle(PacketHandlerInterface $handler) : bool{
76 return $handler->handleResourcePackStack($this);
77 }
78}
static create(array $resourcePackStack, bool $mustAccept, string $baseGameVersion, Experiments $experiments, bool $useVanillaEditorPacks)