PocketMine-MP 5.44.3 git-327e8a1690982f1ac3634944d705ebad5d91f4ad
Loading...
Searching...
No Matches
AttributeEnvironment.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;
21
26
27 public function __construct(
28 private string $name,
29 private ?AttributeValue $fromAttribute,
30 private AttributeValue $attribute,
31 private ?AttributeValue $toAttribute,
32 private int $currentTransitionTicks,
33 private int $totalTransitionTicks,
34 private string $easeType,
35 private int $localTransitionTicks,
36 private bool $noiseTransition
37 ){}
38
39 public function getName() : string{ return $this->name; }
40
41 public function getFromAttribute() : ?AttributeValue{ return $this->fromAttribute; }
42
43 public function getAttribute() : AttributeValue{ return $this->attribute; }
44
45 public function getToAttribute() : ?AttributeValue{ return $this->toAttribute; }
46
47 public function getCurrentTransitionTicks() : int{ return $this->currentTransitionTicks; }
48
49 public function getTotalTransitionTicks() : int{ return $this->totalTransitionTicks; }
50
54 public function getEaseType() : string{ return $this->easeType; }
55
56 public function getLocalTransitionTicks() : int{ return $this->localTransitionTicks; }
57
58 public function isNoiseTransition() : bool{ return $this->noiseTransition; }
59
60 public static function read(ByteBufferReader $in) : self{
61 $name = CommonTypes::getString($in);
62 $fromAttribute = CommonTypes::readOptional($in, AttributeValue::read(...));
63 $attribute = AttributeValue::read($in);
64 $toAttribute = CommonTypes::readOptional($in, AttributeValue::read(...));
65 $currentTransitionTicks = LE::readUnsignedInt($in);
66 $totalTransitionTicks = LE::readUnsignedInt($in);
67 $easeType = CommonTypes::getString($in);
68 $localTransitionTicks = LE::readUnsignedInt($in);
69 $noiseTransition = CommonTypes::getBool($in);
70
71 return new self(
72 $name,
73 $fromAttribute,
74 $attribute,
75 $toAttribute,
76 $currentTransitionTicks,
77 $totalTransitionTicks,
78 $easeType,
79 $localTransitionTicks,
80 $noiseTransition
81 );
82 }
83
84 public function write(ByteBufferWriter $out) : void{
85 CommonTypes::putString($out, $this->name);
86 CommonTypes::writeOptional($out, $this->fromAttribute, fn(ByteBufferWriter $out, AttributeValue $value) => $value->write($out));
87 $this->attribute->write($out);
88 CommonTypes::writeOptional($out, $this->toAttribute, fn(ByteBufferWriter $out, AttributeValue $value) => $value->write($out));
89 LE::writeUnsignedInt($out, $this->currentTransitionTicks);
90 LE::writeUnsignedInt($out, $this->totalTransitionTicks);
91 CommonTypes::putString($out, $this->easeType);
92 LE::writeUnsignedInt($out, $this->localTransitionTicks);
93 CommonTypes::putBool($out, $this->noiseTransition);
94 }
95}