PocketMine-MP 5.44.3 git-327e8a1690982f1ac3634944d705ebad5d91f4ad
Loading...
Searching...
No Matches
PrimitiveShapeTextPayload.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\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
22use pocketmine\network\mcpe\protocol\types\GetTypeIdFromConstTrait;
23
25 use GetTypeIdFromConstTrait;
26
27 public const ID = PrimitiveShapeType::PAYLOAD_TYPE_TEXT;
28
29 public function __construct(
30 private string $text,
31 private bool $useRotation,
32 private ?Color $backgroundColor,
33 private bool $depthTest,
34 private bool $showBackface,
35 private bool $showTextBackface,
36 ){}
37
38 public function getText() : string{ return $this->text; }
39
40 public function useRotation() : bool{ return $this->useRotation; }
41
42 public function getBackgroundColor() : ?Color{ return $this->backgroundColor; }
43
44 public function hasDepthTest() : bool{ return $this->depthTest; }
45
46 public function hasShowBackface() : bool{ return $this->showBackface; }
47
48 public function hasShowTextBackface() : bool{ return $this->showTextBackface; }
49
50 public static function read(ByteBufferReader $in) : self{
51 $text = CommonTypes::getString($in);
52 $useRotation = CommonTypes::getBool($in);
53 $backgroundColor = CommonTypes::readOptional($in, fn() => Color::fromARGB(LE::readUnsignedInt($in)));
54 $depthTest = CommonTypes::getBool($in);
55 $showBackface = CommonTypes::getBool($in);
56 $showTextBackface = CommonTypes::getBool($in);
57
58 return new self($text, $useRotation, $backgroundColor, $depthTest, $showBackface, $showTextBackface,);
59 }
60
61 public function write(ByteBufferWriter $out) : void{
62 CommonTypes::putString($out, $this->text);
63 CommonTypes::putBool($out, $this->useRotation);
64 CommonTypes::writeOptional($out, $this->backgroundColor, fn(ByteBufferWriter $out, Color $color) => LE::writeUnsignedInt($out, $color->toARGB()));
65 CommonTypes::putBool($out, $this->depthTest);
66 CommonTypes::putBool($out, $this->showBackface);
67 CommonTypes::putBool($out, $this->showTextBackface);
68 }
69}