PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
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
20use function count;
21
23 public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_STACK_PACKET;
24
26 public array $resourcePackStack = [];
28 public array $behaviorPackStack = [];
29 public bool $mustAccept = false;
30 public string $baseGameVersion = ProtocolInfo::MINECRAFT_VERSION_NETWORK;
31 public Experiments $experiments;
32 public bool $useVanillaEditorPacks;
33
39 public static function create(array $resourcePackStack, array $behaviorPackStack, bool $mustAccept, string $baseGameVersion, Experiments $experiments, bool $useVanillaEditorPacks) : self{
40 $result = new self;
41 $result->resourcePackStack = $resourcePackStack;
42 $result->behaviorPackStack = $behaviorPackStack;
43 $result->mustAccept = $mustAccept;
44 $result->baseGameVersion = $baseGameVersion;
45 $result->experiments = $experiments;
46 $result->useVanillaEditorPacks = $useVanillaEditorPacks;
47 return $result;
48 }
49
50 protected function decodePayload(PacketSerializer $in) : void{
51 $this->mustAccept = $in->getBool();
52 $behaviorPackCount = $in->getUnsignedVarInt();
53 while($behaviorPackCount-- > 0){
54 $this->behaviorPackStack[] = ResourcePackStackEntry::read($in);
55 }
56
57 $resourcePackCount = $in->getUnsignedVarInt();
58 while($resourcePackCount-- > 0){
59 $this->resourcePackStack[] = ResourcePackStackEntry::read($in);
60 }
61
62 $this->baseGameVersion = $in->getString();
63 $this->experiments = Experiments::read($in);
64 $this->useVanillaEditorPacks = $in->getBool();
65 }
66
67 protected function encodePayload(PacketSerializer $out) : void{
68 $out->putBool($this->mustAccept);
69
70 $out->putUnsignedVarInt(count($this->behaviorPackStack));
71 foreach($this->behaviorPackStack as $entry){
72 $entry->write($out);
73 }
74
75 $out->putUnsignedVarInt(count($this->resourcePackStack));
76 foreach($this->resourcePackStack as $entry){
77 $entry->write($out);
78 }
79
80 $out->putString($this->baseGameVersion);
81 $this->experiments->write($out);
82 $out->putBool($this->useVanillaEditorPacks);
83 }
84
85 public function handle(PacketHandlerInterface $handler) : bool{
86 return $handler->handleResourcePackStack($this);
87 }
88}
static create(array $resourcePackStack, array $behaviorPackStack, bool $mustAccept, string $baseGameVersion, Experiments $experiments, bool $useVanillaEditorPacks)