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,
48 private ?
int $attachedToEntityId,
51 public static function remove(
int $networkId, ?
int $dimensionId =
null) :
self{
52 return new self($networkId,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null, $dimensionId,
null);
55 public static function line(
int $networkId,
Vector3 $location,
Vector3 $lineEndLocation, ?
Color $color =
null, ?
int $dimensionId =
null, ?
int $attachedToEntityId =
null) :
self{
57 networkId: $networkId,
58 type: ScriptDebugShapeType::LINE,
66 lineEndLocation: $lineEndLocation,
67 arrowHeadLength:
null,
68 arrowHeadRadius:
null,
70 dimensionId: $dimensionId,
71 attachedToEntityId: $attachedToEntityId
75 public static function box(
int $networkId,
Vector3 $location,
Vector3 $boxBound, ?
float $scale =
null, ?
Color $color =
null, ?
int $dimensionId =
null, ?
int $attachedToEntityId =
null) :
self{
77 networkId: $networkId,
78 type: ScriptDebugShapeType::BOX,
86 lineEndLocation:
null,
87 arrowHeadLength:
null,
88 arrowHeadRadius:
null,
90 dimensionId: $dimensionId,
91 attachedToEntityId: $attachedToEntityId
95 public static function sphere(
int $networkId,
Vector3 $location, ?
float $scale =
null, ?
Color $color =
null, ?
int $segments =
null, ?
int $dimensionId =
null, ?
int $attachedToEntityId =
null) :
self{
97 networkId: $networkId,
98 type: ScriptDebugShapeType::SPHERE,
106 lineEndLocation:
null,
107 arrowHeadLength:
null,
108 arrowHeadRadius:
null,
110 dimensionId: $dimensionId,
111 attachedToEntityId: $attachedToEntityId
115 public static function circle(
int $networkId,
Vector3 $location, ?
float $scale =
null, ?
Color $color =
null, ?
int $segments =
null, ?
int $dimensionId =
null, ?
int $attachedToEntityId =
null) :
self{
117 networkId: $networkId,
118 type: ScriptDebugShapeType::CIRCLE,
126 lineEndLocation:
null,
127 arrowHeadLength:
null,
128 arrowHeadRadius:
null,
130 dimensionId: $dimensionId,
131 attachedToEntityId: $attachedToEntityId
135 public static function text(
int $networkId,
Vector3 $location,
string $text, ?
Color $color =
null, ?
int $dimensionId =
null, ?
int $attachedToEntityId =
null) :
self{
137 networkId: $networkId,
138 type: ScriptDebugShapeType::TEXT,
146 lineEndLocation:
null,
147 arrowHeadLength:
null,
148 arrowHeadRadius:
null,
150 dimensionId: $dimensionId,
151 attachedToEntityId: $attachedToEntityId
155 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{
157 networkId: $networkId,
158 type: ScriptDebugShapeType::ARROW,
166 lineEndLocation: $lineEndLocation,
167 arrowHeadLength: $arrowHeadLength,
168 arrowHeadRadius: $arrowHeadRadius,
170 dimensionId: $dimensionId,
171 attachedToEntityId: $attachedToEntityId
175 public function getNetworkId() :
int{
return $this->networkId; }
177 public function getType() : ?ScriptDebugShapeType{
return $this->type; }
179 public function getLocation() : ?
Vector3{
return $this->location; }
181 public function getScale() : ?
float{
return $this->scale; }
183 public function getRotation() : ?
Vector3{
return $this->rotation; }
185 public function getTotalTimeLeft() : ?
float{
return $this->totalTimeLeft; }
187 public function getColor() : ?
Color{
return $this->color; }
189 public function getDimensionId() : ?
int{
return $this->dimensionId; }
191 public function getText() : ?
string{
return $this->text; }
193 public function getBoxBound() : ?
Vector3{
return $this->boxBound; }
195 public function getLineEndLocation() : ?
Vector3{
return $this->lineEndLocation; }
197 public function getArrowHeadLength() : ?
float{
return $this->arrowHeadLength; }
199 public function getArrowHeadRadius() : ?
float{
return $this->arrowHeadRadius; }
201 public function getSegments() : ?
int{
return $this->segments; }
203 public static function read(ByteBufferReader $in) :
self{
204 $networkId = VarInt::readUnsignedLong($in);
205 $shapeType = CommonTypes::readOptional($in, fn() => ScriptDebugShapeType::fromPacket(Byte::readUnsigned($in)));
206 $location = CommonTypes::readOptional($in, CommonTypes::getVector3(...));
207 $scale = CommonTypes::readOptional($in, LE::readFloat(...));
208 $rotation = CommonTypes::readOptional($in, CommonTypes::getVector3(...));
209 $totalTimeLeft = CommonTypes::readOptional($in, LE::readFloat(...));
210 $color = CommonTypes::readOptional($in, fn() => Color::fromARGB(LE::readUnsignedInt($in)));
211 $dimensionId = CommonTypes::readOptional($in, fn() => VarInt::readSignedInt($in));
212 $attachedToEntityId = CommonTypes::readOptional($in, fn() => CommonTypes::getActorRuntimeId($in));
214 $payloadType = VarInt::readUnsignedInt($in);
217 ($shapeType !==
null && $payloadType !== $shapeType->getPayloadType() && $payloadType !== ScriptDebugShapeType::PAYLOAD_TYPE_NONE) ||
218 ($shapeType ===
null && $payloadType !== ScriptDebugShapeType::PAYLOAD_TYPE_NONE)
220 throw new PacketDecodeException(
"Unexpected payload type $payloadType for provided shape type " . ($shapeType->name ??
"(not set)"));
224 $lineEndLocation =
null;
225 $arrowHeadLength =
null;
226 $arrowHeadRadius =
null;
228 switch($payloadType){
229 case ScriptDebugShapeType::PAYLOAD_TYPE_NONE:
231 case ScriptDebugShapeType::PAYLOAD_TYPE_ARROW:
232 $lineEndLocation = CommonTypes::readOptional($in, CommonTypes::getVector3(...));
233 $arrowHeadLength = CommonTypes::readOptional($in, LE::readFloat(...));
234 $arrowHeadRadius = CommonTypes::readOptional($in, LE::readFloat(...));
235 $segments = CommonTypes::readOptional($in, Byte::readUnsigned(...));
237 case ScriptDebugShapeType::PAYLOAD_TYPE_TEXT:
238 $text = CommonTypes::getString($in);
240 case ScriptDebugShapeType::PAYLOAD_TYPE_BOX:
241 $boxBound = CommonTypes::getVector3($in);
243 case ScriptDebugShapeType::PAYLOAD_TYPE_LINE:
244 $lineEndLocation = CommonTypes::getVector3($in);
246 case ScriptDebugShapeType::PAYLOAD_TYPE_CIRCLE_OR_SPHERE:
247 $segments = Byte::readUnsigned($in);
272 public function write(ByteBufferWriter $out) :
void{
273 VarInt::writeUnsignedLong($out, $this->networkId);
274 CommonTypes::writeOptional($out, $this->type, fn(ByteBufferWriter $out, ScriptDebugShapeType $type) => Byte::writeUnsigned($out, $type->value));
275 CommonTypes::writeOptional($out, $this->location, CommonTypes::putVector3(...));
276 CommonTypes::writeOptional($out, $this->scale, LE::writeFloat(...));
277 CommonTypes::writeOptional($out, $this->rotation, CommonTypes::putVector3(...));
278 CommonTypes::writeOptional($out, $this->totalTimeLeft, LE::writeFloat(...));
279 CommonTypes::writeOptional($out, $this->color, fn(ByteBufferWriter $out,
Color $color) => LE::writeUnsignedInt($out, $color->
toARGB()));
280 CommonTypes::writeOptional($out, $this->dimensionId, fn(ByteBufferWriter $out,
int $dimensionId) => VarInt::writeSignedInt($out, $dimensionId));
281 CommonTypes::writeOptional($out, $this->attachedToEntityId, fn(ByteBufferWriter $out,
int $entityId) => CommonTypes::putActorRuntimeId($out, $entityId));
284 $payloadType = $this->type?->getPayloadType() ?? ScriptDebugShapeType::PAYLOAD_TYPE_NONE;
285 if($this->type ===
null){
286 VarInt::writeUnsignedInt($out, ScriptDebugShapeType::PAYLOAD_TYPE_NONE);
289 case ScriptDebugShapeType::ARROW:
290 VarInt::writeUnsignedInt($out, $this->type->getPayloadType());
291 CommonTypes::writeOptional($out, $this->lineEndLocation, CommonTypes::putVector3(...));
292 CommonTypes::writeOptional($out, $this->arrowHeadLength, LE::writeFloat(...));
293 CommonTypes::writeOptional($out, $this->arrowHeadRadius, LE::writeFloat(...));
294 CommonTypes::writeOptional($out, $this->segments, Byte::writeUnsigned(...));
296 case ScriptDebugShapeType::TEXT:
297 if($this->text !==
null){
298 VarInt::writeUnsignedInt($out, $this->type->getPayloadType());
299 CommonTypes::putString($out, $this->text);
301 VarInt::writeUnsignedInt($out, ScriptDebugShapeType::PAYLOAD_TYPE_NONE);
304 case ScriptDebugShapeType::BOX:
305 if($this->boxBound !==
null){
306 VarInt::writeUnsignedInt($out, $this->type->getPayloadType());
307 CommonTypes::putVector3($out, $this->boxBound);
309 VarInt::writeUnsignedInt($out, ScriptDebugShapeType::PAYLOAD_TYPE_NONE);
312 case ScriptDebugShapeType::LINE:
313 if($this->lineEndLocation !==
null){
314 VarInt::writeUnsignedInt($out, $this->type->getPayloadType());
315 CommonTypes::putVector3($out, $this->lineEndLocation);
317 VarInt::writeUnsignedInt($out, ScriptDebugShapeType::PAYLOAD_TYPE_NONE);
320 case ScriptDebugShapeType::CIRCLE:
321 case ScriptDebugShapeType::SPHERE:
322 if($this->segments !==
null){
323 VarInt::writeUnsignedInt($out, $this->type->getPayloadType());
324 Byte::writeUnsigned($out, $this->segments);
326 VarInt::writeUnsignedInt($out, ScriptDebugShapeType::PAYLOAD_TYPE_NONE);
330 throw new \LogicException(
"Unknown payload type $payloadType");