PocketMine-MP 5.42.1 git-443151900a14fe9dc682cbf786fa441be1294fab
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 ){}
36
37 public function getName() : string{ return $this->name; }
38
39 public function getFromAttribute() : ?AttributeValue{ return $this->fromAttribute; }
40
41 public function getAttribute() : AttributeValue{ return $this->attribute; }
42
43 public function getToAttribute() : ?AttributeValue{ return $this->toAttribute; }
44
45 public function getCurrentTransitionTicks() : int{ return $this->currentTransitionTicks; }
46
47 public function getTotalTransitionTicks() : int{ return $this->totalTransitionTicks; }
48
52 public function getEaseType() : string{ return $this->easeType; }
53
54 public static function read(ByteBufferReader $in) : self{
55 $name = CommonTypes::getString($in);
56 $fromAttribute = CommonTypes::getBool($in) ? AttributeValue::read($in) : null;
57 $attribute = AttributeValue::read($in);
58 $toAttribute = CommonTypes::getBool($in) ? AttributeValue::read($in) : null;
59 $currentTransitionTicks = LE::readUnsignedInt($in);
60 $totalTransitionTicks = LE::readUnsignedInt($in);
61 $easeType = CommonTypes::getString($in);
62
63 return new self(
64 $name,
65 $fromAttribute,
66 $attribute,
67 $toAttribute,
68 $currentTransitionTicks,
69 $totalTransitionTicks,
70 $easeType
71 );
72 }
73
74 public function write(ByteBufferWriter $out) : void{
75 CommonTypes::putString($out, $this->name);
76 CommonTypes::writeOptional($out, $this->fromAttribute, fn(ByteBufferWriter $out, AttributeValue $value) => $value->write($out));
77 $this->attribute->write($out);
78 CommonTypes::writeOptional($out, $this->toAttribute, fn(ByteBufferWriter $out, AttributeValue $value) => $value->write($out));
79 LE::writeUnsignedInt($out, $this->currentTransitionTicks);
80 LE::writeUnsignedInt($out, $this->totalTransitionTicks);
81 CommonTypes::putString($out, $this->easeType);
82 }
83}