33 public function __construct(
34 private int $networkId,
35 private ?ScriptDebugShapeType $type,
37 private ?
float $scale,
39 private ?
float $totalTimeLeft,
40 private ?
Color $color,
41 private ?
string $text,
43 private ?
Vector3 $lineEndLocation,
44 private ?
float $arrowHeadLength,
45 private ?
float $arrowHeadRadius,
46 private ?
int $segments,
47 private int $dimensionId = DimensionIds::OVERWORLD,
50 public static function remove(
int $networkId,
int $dimensionId = DimensionIds::OVERWORLD) :
self{
51 return new self($networkId,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null, $dimensionId);
54 public static function line(
int $networkId,
Vector3 $location,
Vector3 $lineEndLocation, ?
Color $color =
null,
int $dimensionId = DimensionIds::OVERWORLD) :
self{
56 networkId: $networkId,
57 type: ScriptDebugShapeType::LINE,
65 lineEndLocation: $lineEndLocation,
66 arrowHeadLength:
null,
67 arrowHeadRadius:
null,
69 dimensionId: $dimensionId
73 public static function box(
int $networkId,
Vector3 $location,
Vector3 $boxBound, ?
float $scale =
null, ?
Color $color =
null,
int $dimensionId = DimensionIds::OVERWORLD) :
self{
75 networkId: $networkId,
76 type: ScriptDebugShapeType::BOX,
84 lineEndLocation:
null,
85 arrowHeadLength:
null,
86 arrowHeadRadius:
null,
88 dimensionId: $dimensionId
92 public static function sphere(
int $networkId,
Vector3 $location, ?
float $scale =
null, ?
Color $color =
null, ?
int $segments =
null,
int $dimensionId = DimensionIds::OVERWORLD) :
self{
94 networkId: $networkId,
95 type: ScriptDebugShapeType::SPHERE,
103 lineEndLocation:
null,
104 arrowHeadLength:
null,
105 arrowHeadRadius:
null,
107 dimensionId: $dimensionId
111 public static function circle(
int $networkId,
Vector3 $location, ?
float $scale =
null, ?
Color $color =
null, ?
int $segments =
null,
int $dimensionId = DimensionIds::OVERWORLD) :
self{
113 networkId: $networkId,
114 type: ScriptDebugShapeType::CIRCLE,
122 lineEndLocation:
null,
123 arrowHeadLength:
null,
124 arrowHeadRadius:
null,
126 dimensionId: $dimensionId
130 public static function text(
int $networkId,
Vector3 $location,
string $text, ?
Color $color =
null,
int $dimensionId = DimensionIds::OVERWORLD) :
self{
132 networkId: $networkId,
133 type: ScriptDebugShapeType::TEXT,
141 lineEndLocation:
null,
142 arrowHeadLength:
null,
143 arrowHeadRadius:
null,
145 dimensionId: $dimensionId
149 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,
int $dimensionId = DimensionIds::OVERWORLD) :
self{
151 networkId: $networkId,
152 type: ScriptDebugShapeType::ARROW,
160 lineEndLocation: $lineEndLocation,
161 arrowHeadLength: $arrowHeadLength,
162 arrowHeadRadius: $arrowHeadRadius,
164 dimensionId: $dimensionId
168 public function getNetworkId() :
int{
return $this->networkId; }
170 public function getType() : ?ScriptDebugShapeType{
return $this->type; }
172 public function getLocation() : ?
Vector3{
return $this->location; }
174 public function getScale() : ?
float{
return $this->scale; }
176 public function getRotation() : ?
Vector3{
return $this->rotation; }
178 public function getTotalTimeLeft() : ?
float{
return $this->totalTimeLeft; }
180 public function getColor() : ?
Color{
return $this->color; }
182 public function getDimensionId() :
int{
return $this->dimensionId; }
184 public function getText() : ?
string{
return $this->text; }
186 public function getBoxBound() : ?
Vector3{
return $this->boxBound; }
188 public function getLineEndLocation() : ?
Vector3{
return $this->lineEndLocation; }
190 public function getArrowHeadLength() : ?
float{
return $this->arrowHeadLength; }
192 public function getArrowHeadRadius() : ?
float{
return $this->arrowHeadRadius; }
194 public function getSegments() : ?
int{
return $this->segments; }
196 public static function read(ByteBufferReader $in) :
self{
197 $networkId = VarInt::readUnsignedLong($in);
198 $shapeType = CommonTypes::readOptional($in, fn() => ScriptDebugShapeType::fromPacket(Byte::readUnsigned($in)));
199 $location = CommonTypes::readOptional($in, CommonTypes::getVector3(...));
200 $scale = CommonTypes::readOptional($in, LE::readFloat(...));
201 $rotation = CommonTypes::readOptional($in, CommonTypes::getVector3(...));
202 $totalTimeLeft = CommonTypes::readOptional($in, LE::readFloat(...));
203 $color = CommonTypes::readOptional($in, fn() => Color::fromARGB(LE::readUnsignedInt($in)));
204 $dimensionId = VarInt::readSignedInt($in);
206 $payloadType = VarInt::readUnsignedInt($in);
209 ($shapeType !==
null && $payloadType !== $shapeType->getPayloadType() && $payloadType !== ScriptDebugShapeType::PAYLOAD_TYPE_NONE) ||
210 ($shapeType ===
null && $payloadType !== ScriptDebugShapeType::PAYLOAD_TYPE_NONE)
212 throw new PacketDecodeException(
"Unexpected payload type $payloadType for provided shape type " . ($shapeType->name ??
"(not set)"));
216 $lineEndLocation =
null;
217 $arrowHeadLength =
null;
218 $arrowHeadRadius =
null;
220 switch($payloadType){
221 case ScriptDebugShapeType::PAYLOAD_TYPE_NONE:
223 case ScriptDebugShapeType::PAYLOAD_TYPE_ARROW:
224 $lineEndLocation = CommonTypes::readOptional($in, CommonTypes::getVector3(...));
225 $arrowHeadLength = CommonTypes::readOptional($in, LE::readFloat(...));
226 $arrowHeadRadius = CommonTypes::readOptional($in, LE::readFloat(...));
227 $segments = CommonTypes::readOptional($in, Byte::readUnsigned(...));
229 case ScriptDebugShapeType::PAYLOAD_TYPE_TEXT:
230 $text = CommonTypes::getString($in);
232 case ScriptDebugShapeType::PAYLOAD_TYPE_BOX:
233 $boxBound = CommonTypes::getVector3($in);
235 case ScriptDebugShapeType::PAYLOAD_TYPE_LINE:
236 $lineEndLocation = CommonTypes::getVector3($in);
238 case ScriptDebugShapeType::PAYLOAD_TYPE_CIRCLE_OR_SPHERE:
239 $segments = Byte::readUnsigned($in);
263 public function write(ByteBufferWriter $out) :
void{
264 VarInt::writeUnsignedLong($out, $this->networkId);
265 CommonTypes::writeOptional($out, $this->type, fn(ByteBufferWriter $out, ScriptDebugShapeType $type) => Byte::writeUnsigned($out, $type->value));
266 CommonTypes::writeOptional($out, $this->location, CommonTypes::putVector3(...));
267 CommonTypes::writeOptional($out, $this->scale, LE::writeFloat(...));
268 CommonTypes::writeOptional($out, $this->rotation, CommonTypes::putVector3(...));
269 CommonTypes::writeOptional($out, $this->totalTimeLeft, LE::writeFloat(...));
270 CommonTypes::writeOptional($out, $this->color, fn(ByteBufferWriter $out,
Color $color) => LE::writeUnsignedInt($out, $color->
toARGB()));
271 VarInt::writeSignedInt($out, $this->dimensionId);
274 $payloadType = $this->type?->getPayloadType() ?? ScriptDebugShapeType::PAYLOAD_TYPE_NONE;
275 if($this->type ===
null){
276 VarInt::writeUnsignedInt($out, ScriptDebugShapeType::PAYLOAD_TYPE_NONE);
279 case ScriptDebugShapeType::ARROW:
280 VarInt::writeUnsignedInt($out, $this->type->getPayloadType());
281 CommonTypes::writeOptional($out, $this->lineEndLocation, CommonTypes::putVector3(...));
282 CommonTypes::writeOptional($out, $this->arrowHeadLength, LE::writeFloat(...));
283 CommonTypes::writeOptional($out, $this->arrowHeadRadius, LE::writeFloat(...));
284 CommonTypes::writeOptional($out, $this->segments, Byte::writeUnsigned(...));
286 case ScriptDebugShapeType::TEXT:
287 if($this->text !==
null){
288 VarInt::writeUnsignedInt($out, $this->type->getPayloadType());
289 CommonTypes::putString($out, $this->text);
291 VarInt::writeUnsignedInt($out, ScriptDebugShapeType::PAYLOAD_TYPE_NONE);
294 case ScriptDebugShapeType::BOX:
295 if($this->boxBound !==
null){
296 VarInt::writeUnsignedInt($out, $this->type->getPayloadType());
297 CommonTypes::putVector3($out, $this->boxBound);
299 VarInt::writeUnsignedInt($out, ScriptDebugShapeType::PAYLOAD_TYPE_NONE);
302 case ScriptDebugShapeType::LINE:
303 if($this->lineEndLocation !==
null){
304 VarInt::writeUnsignedInt($out, $this->type->getPayloadType());
305 CommonTypes::putVector3($out, $this->lineEndLocation);
307 VarInt::writeUnsignedInt($out, ScriptDebugShapeType::PAYLOAD_TYPE_NONE);
310 case ScriptDebugShapeType::CIRCLE:
311 case ScriptDebugShapeType::SPHERE:
312 if($this->segments !==
null){
313 VarInt::writeUnsignedInt($out, $this->type->getPayloadType());
314 Byte::writeUnsigned($out, $this->segments);
316 VarInt::writeUnsignedInt($out, ScriptDebugShapeType::PAYLOAD_TYPE_NONE);
320 throw new \LogicException(
"Unknown payload type $payloadType");