33 public function __construct(
34 private int $networkId,
35 private ?ScriptDebugShapeType $type,
37 private ?
float $scale,
39 private ?
float $totalTimeLeft,
40 private ?
float $maximumRenderDistance,
41 private ?
Color $color,
42 private ?
string $text,
43 private ?
bool $useRotation,
44 private ?
Color $backgroundColor,
45 private ?
bool $depthTest,
46 private ?
bool $showBackface,
47 private ?
bool $showTextBackface,
49 private ?
Vector3 $lineEndLocation,
50 private ?
float $arrowHeadLength,
51 private ?
float $arrowHeadRadius,
52 private ?
int $segments,
53 private ?
int $dimensionId,
54 private ?
int $attachedToEntityId,
57 public static function remove(
int $networkId, ?
int $dimensionId =
null) :
self{
58 return new self($networkId,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null, $dimensionId,
null);
61 public static function line(
int $networkId,
Vector3 $location,
Vector3 $lineEndLocation, ?
Color $color =
null, ?
int $dimensionId =
null, ?
int $attachedToEntityId =
null) :
self{
63 networkId: $networkId,
64 type: ScriptDebugShapeType::LINE,
69 maximumRenderDistance:
null,
73 backgroundColor:
null,
76 showTextBackface:
null,
78 lineEndLocation: $lineEndLocation,
79 arrowHeadLength:
null,
80 arrowHeadRadius:
null,
82 dimensionId: $dimensionId,
83 attachedToEntityId: $attachedToEntityId
87 public static function box(
int $networkId,
Vector3 $location,
Vector3 $boxBound, ?
float $scale =
null, ?
Color $color =
null, ?
int $dimensionId =
null, ?
int $attachedToEntityId =
null) :
self{
89 networkId: $networkId,
90 type: ScriptDebugShapeType::BOX,
95 maximumRenderDistance:
null,
99 backgroundColor:
null,
102 showTextBackface:
null,
104 lineEndLocation:
null,
105 arrowHeadLength:
null,
106 arrowHeadRadius:
null,
108 dimensionId: $dimensionId,
109 attachedToEntityId: $attachedToEntityId
113 public static function sphere(
int $networkId,
Vector3 $location, ?
float $scale =
null, ?
Color $color =
null, ?
int $segments =
null, ?
int $dimensionId =
null, ?
int $attachedToEntityId =
null) :
self{
115 networkId: $networkId,
116 type: ScriptDebugShapeType::SPHERE,
121 maximumRenderDistance:
null,
125 backgroundColor:
null,
128 showTextBackface:
null,
130 lineEndLocation:
null,
131 arrowHeadLength:
null,
132 arrowHeadRadius:
null,
134 dimensionId: $dimensionId,
135 attachedToEntityId: $attachedToEntityId
139 public static function circle(
int $networkId,
Vector3 $location, ?
float $scale =
null, ?
Color $color =
null, ?
int $segments =
null, ?
int $dimensionId =
null, ?
int $attachedToEntityId =
null) :
self{
141 networkId: $networkId,
142 type: ScriptDebugShapeType::CIRCLE,
147 maximumRenderDistance:
null,
151 backgroundColor:
null,
154 showTextBackface:
null,
156 lineEndLocation:
null,
157 arrowHeadLength:
null,
158 arrowHeadRadius:
null,
160 dimensionId: $dimensionId,
161 attachedToEntityId: $attachedToEntityId
165 public static function text(
int $networkId,
Vector3 $location,
string $text,
bool $useRotation =
false, ?
Color $backgroundColor =
null,
bool $depthTest =
true,
bool $showBackface =
true,
bool $showTextBackface =
true, ?
Color $color =
null, ?
int $dimensionId =
null, ?
int $attachedToEntityId =
null) :
self{
167 networkId: $networkId,
168 type: ScriptDebugShapeType::TEXT,
173 maximumRenderDistance:
null,
176 useRotation: $useRotation,
177 backgroundColor: $backgroundColor,
178 depthTest: $depthTest,
179 showBackface: $showBackface,
180 showTextBackface: $showTextBackface,
182 lineEndLocation:
null,
183 arrowHeadLength:
null,
184 arrowHeadRadius:
null,
186 dimensionId: $dimensionId,
187 attachedToEntityId: $attachedToEntityId
191 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 =
null, ?
int $attachedToEntityId =
null) :
self{
193 networkId: $networkId,
194 type: ScriptDebugShapeType::ARROW,
199 maximumRenderDistance:
null,
203 backgroundColor:
null,
206 showTextBackface:
null,
208 lineEndLocation: $lineEndLocation,
209 arrowHeadLength: $arrowHeadLength,
210 arrowHeadRadius: $arrowHeadRadius,
212 dimensionId: $dimensionId,
213 attachedToEntityId: $attachedToEntityId
217 public function getNetworkId() :
int{
return $this->networkId; }
219 public function getType() : ?ScriptDebugShapeType{
return $this->type; }
221 public function getLocation() : ?
Vector3{
return $this->location; }
223 public function getScale() : ?
float{
return $this->scale; }
225 public function getRotation() : ?
Vector3{
return $this->rotation; }
227 public function getTotalTimeLeft() : ?
float{
return $this->totalTimeLeft; }
229 public function getMaximumRenderDistance() : ?
float{
return $this->maximumRenderDistance; }
231 public function getColor() : ?
Color{
return $this->color; }
233 public function getDimensionId() : ?
int{
return $this->dimensionId; }
235 public function getAttachedToEntityId() : ?
int{
return $this->attachedToEntityId; }
237 public function getText() : ?
string{
return $this->text; }
239 public function getUseRotation() : ?
bool{
return $this->useRotation; }
241 public function getBackgroundColor() : ?
Color{
return $this->backgroundColor; }
243 public function getDepthTest() : ?
bool{
return $this->depthTest; }
245 public function getShowBackface() : ?
bool{
return $this->showBackface; }
247 public function getShowTextBackface() : ?
bool{
return $this->showTextBackface; }
249 public function getBoxBound() : ?
Vector3{
return $this->boxBound; }
251 public function getLineEndLocation() : ?
Vector3{
return $this->lineEndLocation; }
253 public function getArrowHeadLength() : ?
float{
return $this->arrowHeadLength; }
255 public function getArrowHeadRadius() : ?
float{
return $this->arrowHeadRadius; }
257 public function getSegments() : ?
int{
return $this->segments; }
259 public static function read(ByteBufferReader $in) :
self{
260 $networkId = VarInt::readUnsignedLong($in);
261 $shapeType = CommonTypes::readOptional($in, fn() => ScriptDebugShapeType::fromPacket(Byte::readUnsigned($in)));
262 $location = CommonTypes::readOptional($in, CommonTypes::getVector3(...));
263 $scale = CommonTypes::readOptional($in, LE::readFloat(...));
264 $rotation = CommonTypes::readOptional($in, CommonTypes::getVector3(...));
265 $totalTimeLeft = CommonTypes::readOptional($in, LE::readFloat(...));
266 $maximumRenderDistance = CommonTypes::readOptional($in, LE::readFloat(...));
267 $color = CommonTypes::readOptional($in, fn() => Color::fromARGB(LE::readUnsignedInt($in)));
268 $dimensionId = CommonTypes::readOptional($in, fn() => VarInt::readSignedInt($in));
269 $attachedToEntityId = CommonTypes::readOptional($in, fn() => CommonTypes::getActorRuntimeId($in));
271 $payloadType = VarInt::readUnsignedInt($in);
274 ($shapeType !==
null && $payloadType !== $shapeType->getPayloadType() && $payloadType !== ScriptDebugShapeType::PAYLOAD_TYPE_NONE) ||
275 ($shapeType ===
null && $payloadType !== ScriptDebugShapeType::PAYLOAD_TYPE_NONE)
277 throw new PacketDecodeException(
"Unexpected payload type $payloadType for provided shape type " . ($shapeType->name ??
"(not set)"));
281 $backgroundColor =
null;
283 $showBackface =
null;
284 $showTextBackface =
null;
286 $lineEndLocation =
null;
287 $arrowHeadLength =
null;
288 $arrowHeadRadius =
null;
290 switch($payloadType){
291 case ScriptDebugShapeType::PAYLOAD_TYPE_NONE:
293 case ScriptDebugShapeType::PAYLOAD_TYPE_ARROW:
294 $lineEndLocation = CommonTypes::readOptional($in, CommonTypes::getVector3(...));
295 $arrowHeadLength = CommonTypes::readOptional($in, LE::readFloat(...));
296 $arrowHeadRadius = CommonTypes::readOptional($in, LE::readFloat(...));
297 $segments = CommonTypes::readOptional($in, Byte::readUnsigned(...));
299 case ScriptDebugShapeType::PAYLOAD_TYPE_TEXT:
300 $text = CommonTypes::getString($in);
301 $useRotation = CommonTypes::getBool($in);
302 $backgroundColor = CommonTypes::readOptional($in, fn() => Color::fromARGB(LE::readUnsignedInt($in)));
303 $depthTest = CommonTypes::getBool($in);
304 $showBackface = CommonTypes::getBool($in);
305 $showTextBackface = CommonTypes::getBool($in);
307 case ScriptDebugShapeType::PAYLOAD_TYPE_BOX:
308 $boxBound = CommonTypes::getVector3($in);
310 case ScriptDebugShapeType::PAYLOAD_TYPE_LINE:
311 $lineEndLocation = CommonTypes::getVector3($in);
313 case ScriptDebugShapeType::PAYLOAD_TYPE_CIRCLE_OR_SPHERE:
314 $segments = Byte::readUnsigned($in);
327 $maximumRenderDistance,
345 public function write(ByteBufferWriter $out) :
void{
346 VarInt::writeUnsignedLong($out, $this->networkId);
347 CommonTypes::writeOptional($out, $this->type, fn(ByteBufferWriter $out, ScriptDebugShapeType $type) => Byte::writeUnsigned($out, $type->value));
348 CommonTypes::writeOptional($out, $this->location, CommonTypes::putVector3(...));
349 CommonTypes::writeOptional($out, $this->scale, LE::writeFloat(...));
350 CommonTypes::writeOptional($out, $this->rotation, CommonTypes::putVector3(...));
351 CommonTypes::writeOptional($out, $this->totalTimeLeft, LE::writeFloat(...));
352 CommonTypes::writeOptional($out, $this->maximumRenderDistance, LE::writeFloat(...));
353 CommonTypes::writeOptional($out, $this->color, fn(ByteBufferWriter $out,
Color $color) => LE::writeUnsignedInt($out, $color->
toARGB()));
354 CommonTypes::writeOptional($out, $this->dimensionId, fn(ByteBufferWriter $out,
int $dimensionId) => VarInt::writeSignedInt($out, $dimensionId));
355 CommonTypes::writeOptional($out, $this->attachedToEntityId, fn(ByteBufferWriter $out,
int $entityId) => CommonTypes::putActorRuntimeId($out, $entityId));
358 $payloadType = $this->type?->getPayloadType() ?? ScriptDebugShapeType::PAYLOAD_TYPE_NONE;
359 if($this->type ===
null){
360 VarInt::writeUnsignedInt($out, ScriptDebugShapeType::PAYLOAD_TYPE_NONE);
363 case ScriptDebugShapeType::ARROW:
364 VarInt::writeUnsignedInt($out, $this->type->getPayloadType());
365 CommonTypes::writeOptional($out, $this->lineEndLocation, CommonTypes::putVector3(...));
366 CommonTypes::writeOptional($out, $this->arrowHeadLength, LE::writeFloat(...));
367 CommonTypes::writeOptional($out, $this->arrowHeadRadius, LE::writeFloat(...));
368 CommonTypes::writeOptional($out, $this->segments, Byte::writeUnsigned(...));
370 case ScriptDebugShapeType::TEXT:
371 if($this->text !==
null){
372 VarInt::writeUnsignedInt($out, $this->type->getPayloadType());
373 CommonTypes::putString($out, $this->text);
374 CommonTypes::putBool($out, $this->useRotation ??
false);
375 CommonTypes::writeOptional($out, $this->backgroundColor, fn(ByteBufferWriter $out,
Color $color) => LE::writeUnsignedInt($out, $color->
toARGB()));
376 CommonTypes::putBool($out, $this->depthTest ??
true);
377 CommonTypes::putBool($out, $this->showBackface ??
true);
378 CommonTypes::putBool($out, $this->showTextBackface ??
true);
380 VarInt::writeUnsignedInt($out, ScriptDebugShapeType::PAYLOAD_TYPE_NONE);
383 case ScriptDebugShapeType::BOX:
384 if($this->boxBound !==
null){
385 VarInt::writeUnsignedInt($out, $this->type->getPayloadType());
386 CommonTypes::putVector3($out, $this->boxBound);
388 VarInt::writeUnsignedInt($out, ScriptDebugShapeType::PAYLOAD_TYPE_NONE);
391 case ScriptDebugShapeType::LINE:
392 if($this->lineEndLocation !==
null){
393 VarInt::writeUnsignedInt($out, $this->type->getPayloadType());
394 CommonTypes::putVector3($out, $this->lineEndLocation);
396 VarInt::writeUnsignedInt($out, ScriptDebugShapeType::PAYLOAD_TYPE_NONE);
399 case ScriptDebugShapeType::CIRCLE:
400 case ScriptDebugShapeType::SPHERE:
401 if($this->segments !==
null){
402 VarInt::writeUnsignedInt($out, $this->type->getPayloadType());
403 Byte::writeUnsigned($out, $this->segments);
405 VarInt::writeUnsignedInt($out, ScriptDebugShapeType::PAYLOAD_TYPE_NONE);
409 throw new \LogicException(
"Unknown payload type $payloadType");