PocketMine-MP 5.17.1 git-df4ada81e5d74a14046f27cf44a37dcee69d657e
FeatureRegistryPacket.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 function count;
20
25 public const NETWORK_ID = ProtocolInfo::FEATURE_REGISTRY_PACKET;
26
28 private array $entries;
29
34 public static function create(array $entries) : self{
35 $result = new self;
36 $result->entries = $entries;
37 return $result;
38 }
39
41 public function getEntries() : array{ return $this->entries; }
42
43 protected function decodePayload(PacketSerializer $in) : void{
44 for($this->entries = [], $i = 0, $count = $in->getUnsignedVarInt(); $i < $count; $i++){
45 $this->entries[] = FeatureRegistryPacketEntry::read($in);
46 }
47 }
48
49 protected function encodePayload(PacketSerializer $out) : void{
50 $out->putUnsignedVarInt(count($this->entries));
51 foreach($this->entries as $entry){
52 $entry->write($out);
53 }
54 }
55
56 public function handle(PacketHandlerInterface $handler) : bool{
57 return $handler->handleFeatureRegistry($this);
58 }
59}