PocketMine-MP 5.31.1 git-79e3f2b2814ae3676339d931f659b32a01e19783
Loading...
Searching...
No Matches
PacketShapeData.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
21
25final class PacketShapeData{
26
27 public function __construct(
28 private int $networkId,
29 private ?ScriptDebugShapeType $type,
30 private ?Vector3 $location,
31 private ?float $scale,
32 private ?Vector3 $rotation,
33 private ?float $totalTimeLeft,
34 private ?Color $color,
35 private ?string $text,
36 private ?Vector3 $boxBound,
37 private ?Vector3 $lineEndLocation,
38 private ?float $arrowHeadLength,
39 private ?float $arrowHeadRadius,
40 private ?int $segments,
41 ){}
42
43 public static function remove(int $networkId) : self{
44 return new self($networkId, null, null, null, null, null, null, null, null, null, null, null, null);
45 }
46
47 public static function line(int $networkId, Vector3 $location, Vector3 $lineEndLocation, ?Color $color = null) : self{
48 return new self(
49 networkId: $networkId,
50 type: ScriptDebugShapeType::LINE,
51 location: $location,
52 scale: null,
53 rotation: null,
54 totalTimeLeft: null,
55 color: $color,
56 text: null,
57 boxBound: null,
58 lineEndLocation: $lineEndLocation,
59 arrowHeadLength: null,
60 arrowHeadRadius: null,
61 segments: null
62 );
63 }
64
65 public static function box(int $networkId, Vector3 $location, Vector3 $boxBound, ?float $scale = null, ?Color $color = null) : self{
66 return new self(
67 networkId: $networkId,
68 type: ScriptDebugShapeType::BOX,
69 location: $location,
70 scale: $scale,
71 rotation: null,
72 totalTimeLeft: null,
73 color: $color,
74 text: null,
75 boxBound: $boxBound,
76 lineEndLocation: null,
77 arrowHeadLength: null,
78 arrowHeadRadius: null,
79 segments: null
80 );
81 }
82
83 public static function sphere(int $networkId, Vector3 $location, ?float $scale = null, ?Color $color = null, ?int $segments = null) : self{
84 return new self(
85 networkId: $networkId,
86 type: ScriptDebugShapeType::SPHERE,
87 location: $location,
88 scale: $scale,
89 rotation: null,
90 totalTimeLeft: null,
91 color: $color,
92 text: null,
93 boxBound: null,
94 lineEndLocation: null,
95 arrowHeadLength: null,
96 arrowHeadRadius: null,
97 segments: $segments
98 );
99 }
100
101 public static function circle(int $networkId, Vector3 $location, ?float $scale = null, ?Color $color = null, ?int $segments = null) : self{
102 return new self(
103 networkId: $networkId,
104 type: ScriptDebugShapeType::CIRCLE,
105 location: $location,
106 scale: $scale,
107 rotation: null,
108 totalTimeLeft: null,
109 color: $color,
110 text: null,
111 boxBound: null,
112 lineEndLocation: null,
113 arrowHeadLength: null,
114 arrowHeadRadius: null,
115 segments: $segments
116 );
117 }
118
119 public static function text(int $networkId, Vector3 $location, string $text, ?Color $color = null) : self{
120 return new self(
121 networkId: $networkId,
122 type: ScriptDebugShapeType::TEXT,
123 location: $location,
124 scale: null,
125 rotation: null,
126 totalTimeLeft: null,
127 color: $color,
128 text: $text,
129 boxBound: null,
130 lineEndLocation: null,
131 arrowHeadLength: null,
132 arrowHeadRadius: null,
133 segments: null
134 );
135 }
136
137 public static function arrow(int $networkId, Vector3 $location, Vector3 $lineEndLocation, ?float $scale = null, ?Color $color = null, ?float $arrowHeadLength = null, ?float $arrowHeadRadius = null, ?int $segments = null) : self{
138 return new self(
139 networkId: $networkId,
140 type: ScriptDebugShapeType::ARROW,
141 location: $location,
142 scale: $scale,
143 rotation: null,
144 totalTimeLeft: null,
145 color: $color,
146 text: null,
147 boxBound: null,
148 lineEndLocation: $lineEndLocation,
149 arrowHeadLength: $arrowHeadLength,
150 arrowHeadRadius: $arrowHeadRadius,
151 segments: $segments
152 );
153 }
154
155 public function getNetworkId() : int{ return $this->networkId; }
156
157 public function getType() : ?ScriptDebugShapeType{ return $this->type; }
158
159 public function getLocation() : ?Vector3{ return $this->location; }
160
161 public function getScale() : ?float{ return $this->scale; }
162
163 public function getRotation() : ?Vector3{ return $this->rotation; }
164
165 public function getTotalTimeLeft() : ?float{ return $this->totalTimeLeft; }
166
167 public function getColor() : ?Color{ return $this->color; }
168
169 public function getText() : ?string{ return $this->text; }
170
171 public function getBoxBound() : ?Vector3{ return $this->boxBound; }
172
173 public function getLineEndLocation() : ?Vector3{ return $this->lineEndLocation; }
174
175 public function getArrowHeadLength() : ?float{ return $this->arrowHeadLength; }
176
177 public function getArrowHeadRadius() : ?float{ return $this->arrowHeadRadius; }
178
179 public function getSegments() : ?int{ return $this->segments; }
180
181 public static function read(PacketSerializer $in) : self{
182 $networkId = $in->getUnsignedVarLong();
183 $type = $in->readOptional(fn() => ScriptDebugShapeType::fromPacket($in->getByte()));
184 $location = $in->readOptional($in->getVector3(...));
185 $scale = $in->readOptional($in->getLFloat(...));
186 $rotation = $in->readOptional($in->getVector3(...));
187 $totalTimeLeft = $in->readOptional($in->getLFloat(...));
188 $color = $in->readOptional(fn() => Color::fromARGB($in->getLInt()));
189 $text = $in->readOptional($in->getString(...));
190 $boxBound = $in->readOptional($in->getVector3(...));
191 $lineEndLocation = $in->readOptional($in->getVector3(...));
192 $arrowHeadLength = $in->readOptional($in->getLFloat(...));
193 $arrowHeadRadius = $in->readOptional($in->getLFloat(...));
194 $segments = $in->readOptional($in->getByte(...));
195
196 return new self(
197 $networkId,
198 $type,
199 $location,
200 $scale,
201 $rotation,
202 $totalTimeLeft,
203 $color,
204 $text,
205 $boxBound,
206 $lineEndLocation,
207 $arrowHeadLength,
208 $arrowHeadRadius,
209 $segments
210 );
211 }
212
213 public function write(PacketSerializer $out) : void{
214 $out->putUnsignedVarLong($this->networkId);
215 $out->writeOptional($this->type, fn(ScriptDebugShapeType $type) => $out->putByte($type->value));
216 $out->writeOptional($this->location, $out->putVector3(...));
217 $out->writeOptional($this->scale, $out->putLFloat(...));
218 $out->writeOptional($this->rotation, $out->putVector3(...));
219 $out->writeOptional($this->totalTimeLeft, $out->putLFloat(...));
220 $out->writeOptional($this->color, fn(Color $color) => $out->putLInt($color->toARGB()));
221 $out->writeOptional($this->text, $out->putString(...));
222 $out->writeOptional($this->boxBound, $out->putVector3(...));
223 $out->writeOptional($this->lineEndLocation, $out->putVector3(...));
224 $out->writeOptional($this->arrowHeadLength, $out->putLFloat(...));
225 $out->writeOptional($this->arrowHeadRadius, $out->putLFloat(...));
226 $out->writeOptional($this->segments, $out->putByte(...));
227 }
228}