PocketMine-MP 5.42.1 git-443151900a14fe9dc682cbf786fa441be1294fab
Loading...
Searching...
No Matches
AttributeLayerSettings.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\LE;
20use pmmp\encoding\VarInt;
23
28
29 public function __construct(
30 private int $priority,
31 private AttributeLayerSettingsWeight $weight,
32 private bool $enabled,
33 private bool $transitionsPaused,
34 ){}
35
36 public function getPriority() : int{ return $this->priority; }
37
38 public function getWeight() : AttributeLayerSettingsWeight{ return $this->weight; }
39
40 public function isEnabled() : bool{ return $this->enabled; }
41
42 public function isTransitionsPaused() : bool{ return $this->transitionsPaused; }
43
44 public static function read(ByteBufferReader $in) : self{
45 $priority = LE::readSignedInt($in);
46 $weight = match (VarInt::readUnsignedInt($in)){
47 AttributeLayerSettingsWeightFloat::ID => AttributeLayerSettingsWeightFloat::read($in),
48 AttributeLayerSettingsWeightString::ID => AttributeLayerSettingsWeightString::read($in),
49 default => throw new PacketDecodeException("Unknown AttributeLayerSettingsWeight type"),
50 };
51 $enabled = CommonTypes::getBool($in);
52 $transitionsPaused = CommonTypes::getBool($in);
53
54 return new self(
55 $priority,
56 $weight,
57 $enabled,
58 $transitionsPaused,
59 );
60 }
61
62 public function write(ByteBufferWriter $out) : void{
63 LE::writeSignedInt($out, $this->priority);
64 VarInt::writeUnsignedInt($out, $this->weight->getTypeId());
65 $this->weight->write($out);
66 CommonTypes::putBool($out, $this->enabled);
67 CommonTypes::putBool($out, $this->transitionsPaused);
68 }
69}