PocketMine-MP 5.25.1 git-694aa17cc916a954b10fe12721c81b1dc73eecd5
Loading...
Searching...
No Matches
ItemRegistryPacket.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::ITEM_REGISTRY_PACKET;
24
29 private array $entries;
30
36 public static function create(array $entries) : self{
37 $result = new self;
38 $result->entries = $entries;
39 return $result;
40 }
41
46 public function getEntries() : array{ return $this->entries; }
47
48 protected function decodePayload(PacketSerializer $in) : void{
49 $this->entries = [];
50 for($i = 0, $len = $in->getUnsignedVarInt(); $i < $len; ++$i){
51 $stringId = $in->getString();
52 $numericId = $in->getSignedLShort();
53 $isComponentBased = $in->getBool();
54 $version = $in->getVarInt();
55 $nbt = $in->getNbtCompoundRoot();
56 $this->entries[] = new ItemTypeEntry($stringId, $numericId, $isComponentBased, $version, new CacheableNbt($nbt));
57 }
58 }
59
60 protected function encodePayload(PacketSerializer $out) : void{
61 $out->putUnsignedVarInt(count($this->entries));
62 foreach($this->entries as $entry){
63 $out->putString($entry->getStringId());
64 $out->putLShort($entry->getNumericId());
65 $out->putBool($entry->isComponentBased());
66 $out->putVarInt($entry->getVersion());
67 $out->put($entry->getComponentNbt()->getEncodedNbt());
68 }
69 }
70
71 public function handle(PacketHandlerInterface $handler) : bool{
72 return $handler->handleItemRegistry($this);
73 }
74}