PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
GameTestRequestPacket.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\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\VarInt;
23
25 public const NETWORK_ID = ProtocolInfo::GAME_TEST_REQUEST_PACKET;
26
27 public const ROTATION_0 = 0;
28 public const ROTATION_90 = 1;
29 public const ROTATION_180 = 2;
30 public const ROTATION_270 = 3;
31
32 private int $maxTestsPerBatch;
33 private int $repeatCount;
34 private int $rotation;
35 private bool $stopOnFailure;
36 private BlockPosition $testPosition;
37 private int $testsPerRow;
38 private string $testName;
39
43 public static function create(
44 int $maxTestsPerBatch,
45 int $repeatCount,
46 int $rotation,
47 bool $stopOnFailure,
48 BlockPosition $testPosition,
49 int $testsPerRow,
50 string $testName,
51 ) : self{
52 $result = new self;
53 $result->maxTestsPerBatch = $maxTestsPerBatch;
54 $result->repeatCount = $repeatCount;
55 $result->rotation = $rotation;
56 $result->stopOnFailure = $stopOnFailure;
57 $result->testPosition = $testPosition;
58 $result->testsPerRow = $testsPerRow;
59 $result->testName = $testName;
60 return $result;
61 }
62
63 public function getMaxTestsPerBatch() : int{ return $this->maxTestsPerBatch; }
64
65 public function getRepeatCount() : int{ return $this->repeatCount; }
66
70 public function getRotation() : int{ return $this->rotation; }
71
72 public function isStopOnFailure() : bool{ return $this->stopOnFailure; }
73
74 public function getTestPosition() : BlockPosition{ return $this->testPosition; }
75
76 public function getTestsPerRow() : int{ return $this->testsPerRow; }
77
78 public function getTestName() : string{ return $this->testName; }
79
80 protected function decodePayload(ByteBufferReader $in) : void{
81 $this->maxTestsPerBatch = VarInt::readSignedInt($in);
82 $this->repeatCount = VarInt::readSignedInt($in);
83 $this->rotation = Byte::readUnsigned($in);
84 $this->stopOnFailure = CommonTypes::getBool($in);
85 $this->testPosition = CommonTypes::getSignedBlockPosition($in);
86 $this->testsPerRow = VarInt::readSignedInt($in);
87 $this->testName = CommonTypes::getString($in);
88 }
89
90 protected function encodePayload(ByteBufferWriter $out) : void{
91 VarInt::writeSignedInt($out, $this->maxTestsPerBatch);
92 VarInt::writeSignedInt($out, $this->repeatCount);
93 Byte::writeUnsigned($out, $this->rotation);
94 CommonTypes::putBool($out, $this->stopOnFailure);
95 CommonTypes::putSignedBlockPosition($out, $this->testPosition);
96 VarInt::writeSignedInt($out, $this->testsPerRow);
97 CommonTypes::putString($out, $this->testName);
98 }
99
100 public function handle(PacketHandlerInterface $handler) : bool{
101 return $handler->handleGameTestRequest($this);
102 }
103}
static create(int $maxTestsPerBatch, int $repeatCount, int $rotation, bool $stopOnFailure, BlockPosition $testPosition, int $testsPerRow, string $testName,)