PocketMine-MP 5.42.1 git-443151900a14fe9dc682cbf786fa441be1294fab
Loading...
Searching...
No Matches
AttributeUpdateLayers.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\types;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
20use function count;
21
26 public const ID = AttributeLayerSyncType::UPDATE_LAYERS;
27
32 public function __construct(
33 private array $layers,
34 ){}
35
36 public function getTypeId() : int{
37 return self::ID;
38 }
39
44 public function getLayers() : array{ return $this->layers; }
45
46 public static function read(ByteBufferReader $in) : self{
47 $layers = [];
48 for($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; ++$i){
49 $layers[] = AttributeLayer::read($in);
50 }
51
52 return new self(
53 $layers,
54 );
55 }
56
57 public function write(ByteBufferWriter $out) : void{
58 VarInt::writeUnsignedInt($out, count($this->layers));
59 foreach($this->layers as $layer){
60 $layer->write($out);
61 }
62 }
63}