Skip to content

Commit 62fcc59

Browse files
authored
Bedrock 1.21.130 (#337)
1 parent 87b9f47 commit 62fcc59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+945
-254
lines changed

src/AnimatePacket.php

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
namespace pocketmine\network\mcpe\protocol;
1616

17+
use pmmp\encoding\Byte;
1718
use pmmp\encoding\ByteBufferReader;
1819
use pmmp\encoding\ByteBufferWriter;
1920
use pmmp\encoding\LE;
20-
use pmmp\encoding\VarInt;
2121
use pocketmine\network\mcpe\protocol\serializer\CommonTypes;
2222

2323
class AnimatePacket extends DataPacket implements ClientboundPacket, ServerboundPacket{
@@ -28,48 +28,33 @@ class AnimatePacket extends DataPacket implements ClientboundPacket, Serverbound
2828
public const ACTION_STOP_SLEEP = 3;
2929
public const ACTION_CRITICAL_HIT = 4;
3030
public const ACTION_MAGICAL_CRITICAL_HIT = 5;
31-
public const ACTION_ROW_RIGHT = 128;
32-
public const ACTION_ROW_LEFT = 129;
3331

3432
public int $action;
3533
public int $actorRuntimeId;
3634
public float $data = 0.0;
37-
public float $rowingTime = 0.0;
35+
public ?string $swingSource = null;
3836

39-
public static function create(int $actorRuntimeId, int $actionId, float $data = 0.0) : self{
37+
public static function create(int $actorRuntimeId, int $action, float $data = 0.0, ?string $swingSource = null) : self{
4038
$result = new self;
4139
$result->actorRuntimeId = $actorRuntimeId;
42-
$result->action = $actionId;
40+
$result->action = $action;
4341
$result->data = $data;
44-
return $result;
45-
}
46-
47-
public static function boatHack(int $actorRuntimeId, int $actionId, float $rowingTime) : self{
48-
if($actionId !== self::ACTION_ROW_LEFT && $actionId !== self::ACTION_ROW_RIGHT){
49-
throw new \InvalidArgumentException("Invalid actionId for boatHack: $actionId");
50-
}
51-
52-
$result = self::create($actorRuntimeId, $actionId);
53-
$result->rowingTime = $rowingTime;
42+
$result->swingSource = $swingSource;
5443
return $result;
5544
}
5645

5746
protected function decodePayload(ByteBufferReader $in) : void{
58-
$this->action = VarInt::readSignedInt($in);
47+
$this->action = Byte::readUnsigned($in);
5948
$this->actorRuntimeId = CommonTypes::getActorRuntimeId($in);
6049
$this->data = LE::readFloat($in);
61-
if($this->action === self::ACTION_ROW_LEFT || $this->action === self::ACTION_ROW_RIGHT){
62-
$this->rowingTime = LE::readFloat($in);
63-
}
50+
$this->swingSource = CommonTypes::readOptional($in, CommonTypes::getString(...));
6451
}
6552

6653
protected function encodePayload(ByteBufferWriter $out) : void{
67-
VarInt::writeSignedInt($out, $this->action);
54+
Byte::writeUnsigned($out, $this->action);
6855
CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId);
6956
LE::writeFloat($out, $this->data);
70-
if($this->action === self::ACTION_ROW_LEFT || $this->action === self::ACTION_ROW_RIGHT){
71-
LE::writeFloat($out, $this->rowingTime);
72-
}
57+
CommonTypes::writeOptional($out, $this->swingSource, CommonTypes::putString(...));
7358
}
7459

7560
public function handle(PacketHandlerInterface $handler) : bool{

src/AvailableCommandsPacket.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,8 @@ protected function decodePayload(ByteBufferReader $in) : void{
188188
}
189189

190190
$this->enums = [];
191-
$valueListSize = count($this->enumValues);
192191
for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
193-
$this->enums[] = CommandEnumRawData::read($in, $valueListSize);
192+
$this->enums[] = CommandEnumRawData::read($in);
194193
}
195194

196195
$this->chainedSubCommandData = [];
@@ -231,9 +230,8 @@ protected function encodePayload(ByteBufferWriter $out) : void{
231230
}
232231

233232
VarInt::writeUnsignedInt($out, count($this->enums));
234-
$valueListSize = count($this->enumValues);
235233
foreach($this->enums as $enum){
236-
$enum->write($out, $valueListSize);
234+
$enum->write($out);
237235
}
238236

239237
VarInt::writeUnsignedInt($out, count($this->chainedSubCommandData));

src/ClientboundDataStorePacket.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
13+
declare(strict_types=1);
14+
15+
namespace pocketmine\network\mcpe\protocol;
16+
17+
use pmmp\encoding\ByteBufferReader;
18+
use pmmp\encoding\ByteBufferWriter;
19+
use pmmp\encoding\VarInt;
20+
use pocketmine\network\mcpe\protocol\types\DataStore;
21+
use pocketmine\network\mcpe\protocol\types\DataStoreChange;
22+
use pocketmine\network\mcpe\protocol\types\DataStoreRemoval;
23+
use pocketmine\network\mcpe\protocol\types\DataStoreType;
24+
use pocketmine\network\mcpe\protocol\types\DataStoreUpdate;
25+
use function count;
26+
27+
class ClientboundDataStorePacket extends DataPacket{
28+
public const NETWORK_ID = ProtocolInfo::CLIENTBOUND_DATA_STORE_PACKET;
29+
30+
/**
31+
* @var DataStore[]
32+
* @phpstan-var list<DataStore>
33+
*/
34+
public array $values = [];
35+
36+
/**
37+
* @generate-create-func
38+
* @param DataStore[] $values
39+
* @phpstan-param list<DataStore> $values
40+
*/
41+
public static function create(array $values) : self{
42+
$result = new self;
43+
$result->values = $values;
44+
return $result;
45+
}
46+
47+
protected function decodePayload(ByteBufferReader $in) : void{
48+
$this->values = [];
49+
for($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; ++$i){
50+
$this->values[] = match(VarInt::readUnsignedInt($in)){
51+
DataStoreType::UPDATE => DataStoreUpdate::read($in),
52+
DataStoreType::CHANGE => DataStoreChange::read($in),
53+
DataStoreType::REMOVAL => DataStoreRemoval::read($in),
54+
default => throw new PacketDecodeException("Unknown DataStore type"),
55+
};
56+
}
57+
}
58+
59+
protected function encodePayload(ByteBufferWriter $out) : void{
60+
VarInt::writeUnsignedInt($out, count($this->values));
61+
foreach($this->values as $value){
62+
VarInt::writeUnsignedInt($out, $value->getTypeId());
63+
$value->write($out);
64+
}
65+
}
66+
67+
public function handle(PacketHandlerInterface $handler) : bool{
68+
return $handler->handleClientboundDataStore($this);
69+
}
70+
}

src/ClientboundDebugRendererPacket.php

Lines changed: 14 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -16,103 +16,44 @@
1616

1717
use pmmp\encoding\ByteBufferReader;
1818
use pmmp\encoding\ByteBufferWriter;
19-
use pmmp\encoding\LE;
20-
use pocketmine\math\Vector3;
2119
use pocketmine\network\mcpe\protocol\serializer\CommonTypes;
20+
use pocketmine\network\mcpe\protocol\types\DebugMarkerData;
2221

2322
class ClientboundDebugRendererPacket extends DataPacket implements ClientboundPacket{
2423
public const NETWORK_ID = ProtocolInfo::CLIENTBOUND_DEBUG_RENDERER_PACKET;
2524

26-
public const TYPE_CLEAR = 1;
27-
public const TYPE_ADD_CUBE = 2;
25+
public const TYPE_CLEAR = "cleardebugmarkers";
26+
public const TYPE_ADD_CUBE = "adddebugmarkercube";
2827

29-
private int $type;
28+
private string $type;
29+
private ?DebugMarkerData $data = null;
3030

31-
//TODO: if more types are added, we'll probably want to make a separate data type and interfaces
32-
private string $text;
33-
private Vector3 $position;
34-
private float $red;
35-
private float $green;
36-
private float $blue;
37-
private float $alpha;
38-
private int $durationMillis;
39-
40-
private static function base(int $type) : self{
31+
private static function base(string $type) : self{
4132
$result = new self;
4233
$result->type = $type;
4334
return $result;
4435
}
4536

4637
public static function clear() : self{ return self::base(self::TYPE_CLEAR); }
4738

48-
public static function addCube(string $text, Vector3 $position, float $red, float $green, float $blue, float $alpha, int $durationMillis) : self{
39+
public static function addCube(DebugMarkerData $data) : self{
4940
$result = self::base(self::TYPE_ADD_CUBE);
50-
$result->text = $text;
51-
$result->position = $position;
52-
$result->red = $red;
53-
$result->green = $green;
54-
$result->blue = $blue;
55-
$result->alpha = $alpha;
56-
$result->durationMillis = $durationMillis;
41+
$result->data = $data;
5742
return $result;
5843
}
5944

60-
public function getType() : int{ return $this->type; }
61-
62-
public function getText() : string{ return $this->text; }
63-
64-
public function getPosition() : Vector3{ return $this->position; }
65-
66-
public function getRed() : float{ return $this->red; }
67-
68-
public function getGreen() : float{ return $this->green; }
45+
public function getType() : string{ return $this->type; }
6946

70-
public function getBlue() : float{ return $this->blue; }
71-
72-
public function getAlpha() : float{ return $this->alpha; }
73-
74-
public function getDurationMillis() : int{ return $this->durationMillis; }
47+
public function getData() : ?DebugMarkerData{ return $this->data; }
7548

7649
protected function decodePayload(ByteBufferReader $in) : void{
77-
$this->type = LE::readUnsignedInt($in);
78-
79-
switch($this->type){
80-
case self::TYPE_CLEAR:
81-
//NOOP
82-
break;
83-
case self::TYPE_ADD_CUBE:
84-
$this->text = CommonTypes::getString($in);
85-
$this->position = CommonTypes::getVector3($in);
86-
$this->red = LE::readFloat($in);
87-
$this->green = LE::readFloat($in);
88-
$this->blue = LE::readFloat($in);
89-
$this->alpha = LE::readFloat($in);
90-
$this->durationMillis = LE::readUnsignedLong($in);
91-
break;
92-
default:
93-
throw new PacketDecodeException("Unknown type " . $this->type);
94-
}
50+
$this->type = CommonTypes::getString($in);
51+
$this->data = CommonTypes::readOptional($in, DebugMarkerData::read(...));
9552
}
9653

9754
protected function encodePayload(ByteBufferWriter $out) : void{
98-
LE::writeUnsignedInt($out, $this->type);
99-
100-
switch($this->type){
101-
case self::TYPE_CLEAR:
102-
//NOOP
103-
break;
104-
case self::TYPE_ADD_CUBE:
105-
CommonTypes::putString($out, $this->text);
106-
CommonTypes::putVector3($out, $this->position);
107-
LE::writeFloat($out, $this->red);
108-
LE::writeFloat($out, $this->green);
109-
LE::writeFloat($out, $this->blue);
110-
LE::writeFloat($out, $this->alpha);
111-
LE::writeUnsignedLong($out, $this->durationMillis);
112-
break;
113-
default:
114-
throw new \InvalidArgumentException("Unknown type " . $this->type);
115-
}
55+
CommonTypes::putString($out, $this->type);
56+
CommonTypes::writeOptional($out, $this->data, fn(ByteBufferWriter $out, DebugMarkerData $data) => $data->write($out));
11657
}
11758

11859
public function handle(PacketHandlerInterface $handler) : bool{

src/CommandOutputPacket.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
namespace pocketmine\network\mcpe\protocol;
1616

17-
use pmmp\encoding\Byte;
1817
use pmmp\encoding\ByteBufferReader;
1918
use pmmp\encoding\ByteBufferWriter;
2019
use pmmp\encoding\DataDecodeException;
20+
use pmmp\encoding\LE;
2121
use pmmp\encoding\VarInt;
2222
use pocketmine\network\mcpe\protocol\serializer\CommonTypes;
2323
use pocketmine\network\mcpe\protocol\types\command\CommandOriginData;
@@ -27,30 +27,28 @@
2727
class CommandOutputPacket extends DataPacket implements ClientboundPacket{
2828
public const NETWORK_ID = ProtocolInfo::COMMAND_OUTPUT_PACKET;
2929

30-
public const TYPE_LAST = 1;
31-
public const TYPE_SILENT = 2;
32-
public const TYPE_ALL = 3;
33-
public const TYPE_DATA_SET = 4;
30+
public const TYPE_LAST = "lastoutput";
31+
public const TYPE_SILENT = "silent";
32+
public const TYPE_ALL = "alloutput";
33+
public const TYPE_DATA_SET = "dataset";
3434

3535
public CommandOriginData $originData;
36-
public int $outputType;
36+
public string $outputType;
3737
public int $successCount;
3838
/** @var CommandOutputMessage[] */
3939
public array $messages = [];
40-
public string $unknownString;
40+
public ?string $data;
4141

4242
protected function decodePayload(ByteBufferReader $in) : void{
4343
$this->originData = CommonTypes::getCommandOriginData($in);
44-
$this->outputType = Byte::readUnsigned($in);
45-
$this->successCount = VarInt::readUnsignedInt($in);
44+
$this->outputType = CommonTypes::getString($in);
45+
$this->successCount = LE::readUnsignedInt($in);
4646

4747
for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; ++$i){
4848
$this->messages[] = $this->getCommandMessage($in);
4949
}
5050

51-
if($this->outputType === self::TYPE_DATA_SET){
52-
$this->unknownString = CommonTypes::getString($in);
53-
}
51+
$this->data = CommonTypes::readOptional($in, CommonTypes::getString(...));
5452
}
5553

5654
/**
@@ -59,8 +57,8 @@ protected function decodePayload(ByteBufferReader $in) : void{
5957
protected function getCommandMessage(ByteBufferReader $in) : CommandOutputMessage{
6058
$message = new CommandOutputMessage();
6159

62-
$message->isInternal = CommonTypes::getBool($in);
6360
$message->messageId = CommonTypes::getString($in);
61+
$message->isInternal = CommonTypes::getBool($in);
6462

6563
for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; ++$i){
6664
$message->parameters[] = CommonTypes::getString($in);
@@ -71,22 +69,20 @@ protected function getCommandMessage(ByteBufferReader $in) : CommandOutputMessag
7169

7270
protected function encodePayload(ByteBufferWriter $out) : void{
7371
CommonTypes::putCommandOriginData($out, $this->originData);
74-
Byte::writeUnsigned($out, $this->outputType);
75-
VarInt::writeUnsignedInt($out, $this->successCount);
72+
CommonTypes::putString($out, $this->outputType);
73+
LE::writeUnsignedInt($out, $this->successCount);
7674

7775
VarInt::writeUnsignedInt($out, count($this->messages));
7876
foreach($this->messages as $message){
7977
$this->putCommandMessage($message, $out);
8078
}
8179

82-
if($this->outputType === self::TYPE_DATA_SET){
83-
CommonTypes::putString($out, $this->unknownString);
84-
}
80+
CommonTypes::writeOptional($out, $this->data, CommonTypes::putString(...));
8581
}
8682

8783
protected function putCommandMessage(CommandOutputMessage $message, ByteBufferWriter $out) : void{
88-
CommonTypes::putBool($out, $message->isInternal);
8984
CommonTypes::putString($out, $message->messageId);
85+
CommonTypes::putBool($out, $message->isInternal);
9086

9187
VarInt::writeUnsignedInt($out, count($message->parameters));
9288
foreach($message->parameters as $parameter){

0 commit comments

Comments
 (0)