PocketMine-MP 5.39.3 git-21ae710729750cd637333d673bbbbbc598fc659e
Loading...
Searching...
No Matches
ClientboundDebugRendererPacket.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;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
21
23 public const NETWORK_ID = ProtocolInfo::CLIENTBOUND_DEBUG_RENDERER_PACKET;
24
25 public const TYPE_CLEAR = "cleardebugmarkers";
26 public const TYPE_ADD_CUBE = "adddebugmarkercube";
27
28 private string $type;
29 private ?DebugMarkerData $data = null;
30
31 private static function base(string $type) : self{
32 $result = new self;
33 $result->type = $type;
34 return $result;
35 }
36
37 public static function clear() : self{ return self::base(self::TYPE_CLEAR); }
38
39 public static function addCube(DebugMarkerData $data) : self{
40 $result = self::base(self::TYPE_ADD_CUBE);
41 $result->data = $data;
42 return $result;
43 }
44
45 public function getType() : string{ return $this->type; }
46
47 public function getData() : ?DebugMarkerData{ return $this->data; }
48
49 protected function decodePayload(ByteBufferReader $in) : void{
50 $this->type = CommonTypes::getString($in);
51 $this->data = CommonTypes::readOptional($in, DebugMarkerData::read(...));
52 }
53
54 protected function encodePayload(ByteBufferWriter $out) : void{
55 CommonTypes::putString($out, $this->type);
56 CommonTypes::writeOptional($out, $this->data, fn(ByteBufferWriter $out, DebugMarkerData $data) => $data->write($out));
57 }
58
59 public function handle(PacketHandlerInterface $handler) : bool{
60 return $handler->handleClientboundDebugRenderer($this);
61 }
62}