PocketMine-MP 5.42.1 git-443151900a14fe9dc682cbf786fa441be1294fab
Loading...
Searching...
No Matches
AttributeValueFloat.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 public const ID = AttributeValueType::FLOAT;
27
28 public const OPERATION_OVERRIDE = "override";
29 public const OPERATION_ALPHA_BLEND = "alpha_blend";
30 public const OPERATION_ADD = "add";
31 public const OPERATION_SUBTRACT = "subtract";
32 public const OPERATION_MULTIPLY = "multiply";
33 public const OPERATION_MINIMUM = "minimum";
34 public const OPERATION_MAXIMUM = "maximum";
35
36 public function __construct(
37 private float $value,
38 private string $operation,
39 ){}
40
41 public function getTypeId() : int{
42 return self::ID;
43 }
44
45 public function getValue() : float{ return $this->value; }
46
47 public function getOperation() : string{ return $this->operation; }
48
49 public static function read(ByteBufferReader $in) : self{
50 $value = LE::readFloat($in);
51 $operation = CommonTypes::getString($in);
52
53 return new self(
54 $value,
55 $operation
56 );
57 }
58
59 public function write(ByteBufferWriter $out) : void{
60 LE::writeFloat($out, $this->value);
61 CommonTypes::putString($out, $this->operation);
62 }
63}