PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
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 = [];
31 public array $behaviorPackStack = [];
32 public bool $mustAccept = false;
33 public string $baseGameVersion = ProtocolInfo::MINECRAFT_VERSION_NETWORK;
34 public Experiments $experiments;
35 public bool $useVanillaEditorPacks;
36
42 public static function create(array $resourcePackStack, array $behaviorPackStack, bool $mustAccept, string $baseGameVersion, Experiments $experiments, bool $useVanillaEditorPacks) : self{
43 $result = new self;
44 $result->resourcePackStack = $resourcePackStack;
45 $result->behaviorPackStack = $behaviorPackStack;
46 $result->mustAccept = $mustAccept;
47 $result->baseGameVersion = $baseGameVersion;
48 $result->experiments = $experiments;
49 $result->useVanillaEditorPacks = $useVanillaEditorPacks;
50 return $result;
51 }
52
53 protected function decodePayload(ByteBufferReader $in) : void{
54 $this->mustAccept = CommonTypes::getBool($in);
55 $behaviorPackCount = VarInt::readUnsignedInt($in);
56 while($behaviorPackCount-- > 0){
57 $this->behaviorPackStack[] = ResourcePackStackEntry::read($in);
58 }
59
60 $resourcePackCount = VarInt::readUnsignedInt($in);
61 while($resourcePackCount-- > 0){
62 $this->resourcePackStack[] = ResourcePackStackEntry::read($in);
63 }
64
65 $this->baseGameVersion = CommonTypes::getString($in);
66 $this->experiments = Experiments::read($in);
67 $this->useVanillaEditorPacks = CommonTypes::getBool($in);
68 }
69
70 protected function encodePayload(ByteBufferWriter $out) : void{
71 CommonTypes::putBool($out, $this->mustAccept);
72
73 VarInt::writeUnsignedInt($out, count($this->behaviorPackStack));
74 foreach($this->behaviorPackStack as $entry){
75 $entry->write($out);
76 }
77
78 VarInt::writeUnsignedInt($out, count($this->resourcePackStack));
79 foreach($this->resourcePackStack as $entry){
80 $entry->write($out);
81 }
82
83 CommonTypes::putString($out, $this->baseGameVersion);
84 $this->experiments->write($out);
85 CommonTypes::putBool($out, $this->useVanillaEditorPacks);
86 }
87
88 public function handle(PacketHandlerInterface $handler) : bool{
89 return $handler->handleResourcePackStack($this);
90 }
91}
static create(array $resourcePackStack, array $behaviorPackStack, bool $mustAccept, string $baseGameVersion, Experiments $experiments, bool $useVanillaEditorPacks)