PocketMine-MP 5.44.3 git-327e8a1690982f1ac3634944d705ebad5d91f4ad
Loading...
Searching...
No Matches
PrimitiveShapeArrowPayload.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\shape;
16
17use pmmp\encoding\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\LE;
23use pocketmine\network\mcpe\protocol\types\GetTypeIdFromConstTrait;
24
26 use GetTypeIdFromConstTrait;
27
28 public const ID = PrimitiveShapeType::PAYLOAD_TYPE_ARROW;
29
30 public function __construct(
31 private ?Vector3 $lineEndLocation,
32 private ?float $arrowHeadLength,
33 private ?float $arrowHeadRadius,
34 private ?int $segments,
35 ){}
36
37 public function getLineEndLocation() : ?Vector3{ return $this->lineEndLocation; }
38
39 public function getArrowHeadLength() : ?float{ return $this->arrowHeadLength; }
40
41 public function getArrowHeadRadius() : ?float{ return $this->arrowHeadRadius; }
42
43 public function getSegments() : ?int{ return $this->segments; }
44
45 public static function read(ByteBufferReader $in) : self{
46 $lineEndLocation = CommonTypes::readOptional($in, CommonTypes::getVector3(...));
47 $arrowHeadLength = CommonTypes::readOptional($in, LE::readFloat(...));
48 $arrowHeadRadius = CommonTypes::readOptional($in, LE::readFloat(...));
49 $segments = CommonTypes::readOptional($in, Byte::readUnsigned(...));
50
51 return new self(
52 $lineEndLocation,
53 $arrowHeadLength,
54 $arrowHeadRadius,
55 $segments,
56 );
57 }
58
59 public function write(ByteBufferWriter $out) : void{
60 CommonTypes::writeOptional($out, $this->lineEndLocation, CommonTypes::putVector3(...));
61 CommonTypes::writeOptional($out, $this->arrowHeadLength, LE::writeFloat(...));
62 CommonTypes::writeOptional($out, $this->arrowHeadRadius, LE::writeFloat(...));
63 CommonTypes::writeOptional($out, $this->segments, Byte::writeUnsigned(...));
64 }
65}