PocketMine-MP 5.21.2 git-09bf203267aca9b83a09640e17bfac0fc7b58ff8
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
18use function count;
19
20final class UpdateAttribute{
24 public function __construct(
25 private string $id,
26 private float $min,
27 private float $max,
28 private float $current,
29 private float $defaultMin,
30 private float $defaultMax,
31 private float $default,
32 private array $modifiers
33 ){}
34
35 public function getId() : string{ return $this->id; }
36
37 public function getMin() : float{ return $this->min; }
38
39 public function getMax() : float{ return $this->max; }
40
41 public function getCurrent() : float{ return $this->current; }
42
43 public function getDefaultMin() : float{ return $this->defaultMin; }
44
45 public function getDefaultMax() : float{ return $this->defaultMax; }
46
47 public function getDefault() : float{ return $this->default; }
48
52 public function getModifiers() : array{ return $this->modifiers; }
53
54 public static function read(PacketSerializer $in) : self{
55 $min = $in->getLFloat();
56 $max = $in->getLFloat();
57 $current = $in->getLFloat();
58 $defaultMin = $in->getLFloat();
59 $defaultMax = $in->getLFloat();
60 $default = $in->getLFloat();
61 $id = $in->getString();
62
63 $modifiers = [];
64 for($j = 0, $modifierCount = $in->getUnsignedVarInt(); $j < $modifierCount; $j++){
65 $modifiers[] = AttributeModifier::read($in);
66 }
67
68 return new self($id, $min, $max, $current, $defaultMin, $defaultMax, $default, $modifiers);
69 }
70
71 public function write(PacketSerializer $out) : void{
72 $out->putLFloat($this->min);
73 $out->putLFloat($this->max);
74 $out->putLFloat($this->current);
75 $out->putLFloat($this->defaultMin);
76 $out->putLFloat($this->defaultMax);
77 $out->putLFloat($this->default);
78 $out->putString($this->id);
79
80 $out->putUnsignedVarInt(count($this->modifiers));
81 foreach($this->modifiers as $modifier){
82 $modifier->write($out);
83 }
84 }
85}
__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)