PocketMine-MP 5.44.3 git-327e8a1690982f1ac3634944d705ebad5d91f4ad
Loading...
Searching...
No Matches
AttributeLayer.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
26final class AttributeLayer{
27
32 public function __construct(
33 private string $name,
34 private ?string $noiseName,
35 private int $dimension,
36 private AttributeLayerSettings $settings,
37 private array $attributes,
38 ){}
39
40 public function getName() : string{ return $this->name; }
41
42 public function getNoiseName() : ?string{ return $this->noiseName; }
43
44 public function getDimension() : int{ return $this->dimension; }
45
46 public function getSettings() : AttributeLayerSettings{ return $this->settings; }
47
52 public function getAttributes() : array{ return $this->attributes; }
53
54 public static function read(ByteBufferReader $in) : self{
55 $name = CommonTypes::getString($in);
56 $noiseName = CommonTypes::readOptional($in, CommonTypes::getString(...));
57 $dimension = VarInt::readUnsignedInt($in);
58 $settings = AttributeLayerSettings::read($in);
59
60 $attributes = [];
61 for($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; ++$i){
62 $attributes[] = AttributeEnvironment::read($in);
63 }
64
65 return new self(
66 $name,
67 $noiseName,
68 $dimension,
69 $settings,
70 $attributes,
71 );
72 }
73
74 public function write(ByteBufferWriter $out) : void{
75 CommonTypes::putString($out, $this->name);
76 CommonTypes::writeOptional($out, $this->name, CommonTypes::putString(...));
77 VarInt::writeUnsignedInt($out, $this->dimension);
78 $this->settings->write($out);
79
80 VarInt::writeUnsignedInt($out, count($this->attributes));
81 foreach($this->attributes as $attribute){
82 $attribute->write($out);
83 }
84 }
85}
__construct(private string $name, private ?string $noiseName, private int $dimension, private AttributeLayerSettings $settings, private array $attributes,)