PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
UpdateAttribute.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\entity;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
20use pmmp\encoding\VarInt;
22use function count;
23
24final class UpdateAttribute{
28 public function __construct(
29 private string $id,
30 private float $min,
31 private float $max,
32 private float $current,
33 private float $defaultMin,
34 private float $defaultMax,
35 private float $default,
36 private array $modifiers
37 ){}
38
39 public function getId() : string{ return $this->id; }
40
41 public function getMin() : float{ return $this->min; }
42
43 public function getMax() : float{ return $this->max; }
44
45 public function getCurrent() : float{ return $this->current; }
46
47 public function getDefaultMin() : float{ return $this->defaultMin; }
48
49 public function getDefaultMax() : float{ return $this->defaultMax; }
50
51 public function getDefault() : float{ return $this->default; }
52
56 public function getModifiers() : array{ return $this->modifiers; }
57
58 public static function read(ByteBufferReader $in) : self{
59 $min = LE::readFloat($in);
60 $max = LE::readFloat($in);
61 $current = LE::readFloat($in);
62 $defaultMin = LE::readFloat($in);
63 $defaultMax = LE::readFloat($in);
64 $default = LE::readFloat($in);
65 $id = CommonTypes::getString($in);
66
67 $modifiers = [];
68 for($j = 0, $modifierCount = VarInt::readUnsignedInt($in); $j < $modifierCount; $j++){
69 $modifiers[] = AttributeModifier::read($in);
70 }
71
72 return new self($id, $min, $max, $current, $defaultMin, $defaultMax, $default, $modifiers);
73 }
74
75 public function write(ByteBufferWriter $out) : void{
76 LE::writeFloat($out, $this->min);
77 LE::writeFloat($out, $this->max);
78 LE::writeFloat($out, $this->current);
79 LE::writeFloat($out, $this->defaultMin);
80 LE::writeFloat($out, $this->defaultMax);
81 LE::writeFloat($out, $this->default);
82 CommonTypes::putString($out, $this->id);
83
84 VarInt::writeUnsignedInt($out, count($this->modifiers));
85 foreach($this->modifiers as $modifier){
86 $modifier->write($out);
87 }
88 }
89}
__construct(private string $id, private float $min, private float $max, private float $current, private float $defaultMin, private float $defaultMax, private float $default, private array $modifiers)