PocketMine-MP 5.42.1 git-443151900a14fe9dc682cbf786fa441be1294fab
Loading...
Searching...
No Matches
AttributesUpdateEnvironment.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;
21use function count;
22
27 public const ID = AttributeLayerSyncType::UPDATE_ENVIRONMENT;
28
33 public function __construct(
34 private string $name,
35 private int $dimension,
36 private array $attributes,
37 ){}
38
39 public function getTypeId() : int{
40 return self::ID;
41 }
42
43 public function getName() : string{ return $this->name; }
44
45 public function getDimension() : int{ return $this->dimension; }
46
51 public function getAttributes() : array{ return $this->attributes; }
52
53 public static function read(ByteBufferReader $in) : self{
54 $name = CommonTypes::getString($in);
55 $dimension = VarInt::readUnsignedInt($in);
56
57 $attributes = [];
58 for($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; ++$i){
59 $attributes[] = AttributeEnvironment::read($in);
60 }
61
62 return new self(
63 $name,
64 $dimension,
65 $attributes,
66 );
67 }
68
69 public function write(ByteBufferWriter $out) : void{
70 CommonTypes::putString($out, $this->name);
71 VarInt::writeUnsignedInt($out, $this->dimension);
72
73 VarInt::writeUnsignedInt($out, count($this->attributes));
74 foreach($this->attributes as $attribute){
75 $attribute->write($out);
76 }
77 }
78}
__construct(private string $name, private int $dimension, private array $attributes,)