PocketMine-MP 5.25.1 git-694aa17cc916a954b10fe12721c81b1dc73eecd5
Loading...
Searching...
No Matches
CreativeContentPacket.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::CREATIVE_CONTENT_PACKET;
24
25 public const CATEGORY_CONSTRUCTION = 1;
26 public const CATEGORY_NATURE = 2;
27 public const CATEGORY_EQUIPMENT = 3;
28 public const CATEGORY_ITEMS = 4;
29
31 private array $groups;
33 private array $items;
34
40 public static function create(array $groups, array $items) : self{
41 $result = new self;
42 $result->groups = $groups;
43 $result->items = $items;
44 return $result;
45 }
46
48 public function getGroups() : array{ return $this->groups; }
49
51 public function getItems() : array{ return $this->items; }
52
53 protected function decodePayload(PacketSerializer $in) : void{
54 $this->groups = [];
55 for($i = 0, $len = $in->getUnsignedVarInt(); $i < $len; ++$i){
56 $this->groups[] = CreativeGroupEntry::read($in);
57 }
58
59 $this->items = [];
60 for($i = 0, $len = $in->getUnsignedVarInt(); $i < $len; ++$i){
61 $this->items[] = CreativeItemEntry::read($in);
62 }
63 }
64
65 protected function encodePayload(PacketSerializer $out) : void{
66 $out->putUnsignedVarInt(count($this->groups));
67 foreach($this->groups as $entry){
68 $entry->write($out);
69 }
70
71 $out->putUnsignedVarInt(count($this->items));
72 foreach($this->items as $entry){
73 $entry->write($out);
74 }
75 }
76
77 public function handle(PacketHandlerInterface $handler) : bool{
78 return $handler->handleCreativeContent($this);
79 }
80}