Skip to content

Commit 2851a2d

Browse files
committed
Protocol changes for 1.21.110
1 parent 3bc0cee commit 2851a2d

29 files changed

Lines changed: 411 additions & 152 deletions

src/BiomeDefinitionListPacket.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ public static function fromDefinitions(array $definitions) : self{
7676
$entry->getId(),
7777
$entry->getTemperature(),
7878
$entry->getDownfall(),
79-
$entry->getRedSporeDensity(),
80-
$entry->getBlueSporeDensity(),
81-
$entry->getAshDensity(),
82-
$entry->getWhiteAshDensity(),
79+
$entry->getFoliageSnow(),
8380
$entry->getDepth(),
8481
$entry->getScale(),
8582
$entry->getMapWaterColor(),
@@ -112,10 +109,7 @@ public function buildDefinitionsFromData() : array{
112109
$data->getId(),
113110
$data->getTemperature(),
114111
$data->getDownfall(),
115-
$data->getRedSporeDensity(),
116-
$data->getBlueSporeDensity(),
117-
$data->getAshDensity(),
118-
$data->getWhiteAshDensity(),
112+
$data->getFoliageSnow(),
119113
$data->getDepth(),
120114
$data->getScale(),
121115
$data->getMapWaterColor(),

src/GameRulesChangedPacket.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public static function create(array $gameRules) : self{
4040
}
4141

4242
protected function decodePayload(ByteBufferReader $in) : void{
43-
$this->gameRules = CommonTypes::getGameRules($in);
43+
$this->gameRules = CommonTypes::getGameRules($in, false);
4444
}
4545

4646
protected function encodePayload(ByteBufferWriter $out) : void{
47-
CommonTypes::putGameRules($out, $this->gameRules);
47+
CommonTypes::putGameRules($out, $this->gameRules, false);
4848
}
4949

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

src/PacketHandlerDefaultImplTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,4 +849,8 @@ public function handleClientboundControlSchemeSet(ClientboundControlSchemeSetPac
849849
public function handleServerScriptDebugDrawer(ServerScriptDebugDrawerPacket $packet) : bool{
850850
return false;
851851
}
852+
853+
public function handleServerboundPackSettingChange(ServerboundPackSettingChangePacket $packet) : bool{
854+
return false;
855+
}
852856
}

src/PacketHandlerInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,4 +431,6 @@ public function handlePlayerLocation(PlayerLocationPacket $packet) : bool;
431431
public function handleClientboundControlSchemeSet(ClientboundControlSchemeSetPacket $packet) : bool;
432432

433433
public function handleServerScriptDebugDrawer(ServerScriptDebugDrawerPacket $packet) : bool;
434+
435+
public function handleServerboundPackSettingChange(ServerboundPackSettingChangePacket $packet) : bool;
434436
}

src/PacketPool.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ public function __construct(){
240240
$this->registerPacket(new PlayerLocationPacket());
241241
$this->registerPacket(new ClientboundControlSchemeSetPacket());
242242
$this->registerPacket(new ServerScriptDebugDrawerPacket());
243+
$this->registerPacket(new ServerboundPackSettingChangePacket());
243244
}
244245

245246
public function registerPacket(Packet $packet) : void{

src/PlayerArmorDamagePacket.php

Lines changed: 17 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -14,90 +14,43 @@
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\VarInt;
20+
use pocketmine\network\mcpe\protocol\types\ArmorSlotAndDamagePair;
21+
use function count;
2122

2223
class PlayerArmorDamagePacket extends DataPacket implements ClientboundPacket{
2324
public const NETWORK_ID = ProtocolInfo::PLAYER_ARMOR_DAMAGE_PACKET;
2425

25-
private const FLAG_HEAD = 0;
26-
private const FLAG_CHEST = 1;
27-
private const FLAG_LEGS = 2;
28-
private const FLAG_FEET = 3;
29-
private const FLAG_BODY = 4;
30-
31-
private ?int $headSlotDamage;
32-
private ?int $chestSlotDamage;
33-
private ?int $legsSlotDamage;
34-
private ?int $feetSlotDamage;
35-
private ?int $bodySlotDamage;
26+
/**
27+
* @var ArmorSlotAndDamagePair[]
28+
* @phpstan-var list<ArmorSlotAndDamagePair>
29+
*/
30+
private array $armorSlotAndDamagePairs = [];
3631

3732
/**
3833
* @generate-create-func
34+
* @param ArmorSlotAndDamagePair[] $armorSlotAndDamagePairs
35+
* @phpstan-param list<ArmorSlotAndDamagePair> $armorSlotAndDamagePairs
3936
*/
40-
public static function create(?int $headSlotDamage, ?int $chestSlotDamage, ?int $legsSlotDamage, ?int $feetSlotDamage, ?int $bodySlotDamage) : self{
37+
public static function create(array $armorSlotAndDamagePairs) : self{
4138
$result = new self;
42-
$result->headSlotDamage = $headSlotDamage;
43-
$result->chestSlotDamage = $chestSlotDamage;
44-
$result->legsSlotDamage = $legsSlotDamage;
45-
$result->feetSlotDamage = $feetSlotDamage;
46-
$result->bodySlotDamage = $bodySlotDamage;
39+
$result->armorSlotAndDamagePairs = $armorSlotAndDamagePairs;
4740
return $result;
4841
}
4942

50-
public function getHeadSlotDamage() : ?int{ return $this->headSlotDamage; }
51-
52-
public function getChestSlotDamage() : ?int{ return $this->chestSlotDamage; }
53-
54-
public function getLegsSlotDamage() : ?int{ return $this->legsSlotDamage; }
55-
56-
public function getFeetSlotDamage() : ?int{ return $this->feetSlotDamage; }
57-
58-
public function getBodySlotDamage() : ?int{ return $this->bodySlotDamage; }
59-
60-
private function maybeReadDamage(int $flags, int $flag, ByteBufferReader $in) : ?int{
61-
if(($flags & (1 << $flag)) !== 0){
62-
return VarInt::readSignedInt($in);
63-
}
64-
return null;
65-
}
66-
6743
protected function decodePayload(ByteBufferReader $in) : void{
68-
$flags = Byte::readUnsigned($in);
69-
70-
$this->headSlotDamage = $this->maybeReadDamage($flags, self::FLAG_HEAD, $in);
71-
$this->chestSlotDamage = $this->maybeReadDamage($flags, self::FLAG_CHEST, $in);
72-
$this->legsSlotDamage = $this->maybeReadDamage($flags, self::FLAG_LEGS, $in);
73-
$this->feetSlotDamage = $this->maybeReadDamage($flags, self::FLAG_FEET, $in);
74-
$this->bodySlotDamage = $this->maybeReadDamage($flags, self::FLAG_BODY, $in);
75-
}
76-
77-
private function composeFlag(?int $field, int $flag) : int{
78-
return $field !== null ? (1 << $flag) : 0;
79-
}
80-
81-
private function maybeWriteDamage(?int $field, ByteBufferWriter $out) : void{
82-
if($field !== null){
83-
VarInt::writeSignedInt($out, $field);
44+
for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
45+
$this->armorSlotAndDamagePairs[] = ArmorSlotAndDamagePair::read($in);
8446
}
8547
}
8648

8749
protected function encodePayload(ByteBufferWriter $out) : void{
88-
Byte::writeUnsigned($out,
89-
$this->composeFlag($this->headSlotDamage, self::FLAG_HEAD) |
90-
$this->composeFlag($this->chestSlotDamage, self::FLAG_CHEST) |
91-
$this->composeFlag($this->legsSlotDamage, self::FLAG_LEGS) |
92-
$this->composeFlag($this->feetSlotDamage, self::FLAG_FEET) |
93-
$this->composeFlag($this->bodySlotDamage, self::FLAG_BODY)
94-
);
95-
96-
$this->maybeWriteDamage($this->headSlotDamage, $out);
97-
$this->maybeWriteDamage($this->chestSlotDamage, $out);
98-
$this->maybeWriteDamage($this->legsSlotDamage, $out);
99-
$this->maybeWriteDamage($this->feetSlotDamage, $out);
100-
$this->maybeWriteDamage($this->bodySlotDamage, $out);
50+
VarInt::writeUnsignedInt($out, count($this->armorSlotAndDamagePairs));
51+
foreach($this->armorSlotAndDamagePairs as $pair){
52+
$pair->write($out);
53+
}
10154
}
10255

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

src/ProtocolInfo.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ private function __construct(){
3232
*/
3333

3434
/** Actual Minecraft: PE protocol version */
35-
public const CURRENT_PROTOCOL = 827;
35+
public const CURRENT_PROTOCOL = 844;
3636
/** Current Minecraft PE version reported by the server. This is usually the earliest currently supported version. */
37-
public const MINECRAFT_VERSION = 'v1.21.100';
37+
public const MINECRAFT_VERSION = 'v1.21.110';
3838
/** Version number sent to clients in ping responses. */
39-
public const MINECRAFT_VERSION_NETWORK = '1.21.100';
39+
public const MINECRAFT_VERSION_NETWORK = '1.21.110';
4040

4141
public const LOGIN_PACKET = 0x01;
4242
public const PLAY_STATUS_PACKET = 0x02;
@@ -263,5 +263,6 @@ private function __construct(){
263263
public const PLAYER_LOCATION_PACKET = 0x146;
264264
public const CLIENTBOUND_CONTROL_SCHEME_SET_PACKET = 0x147;
265265
public const SERVER_SCRIPT_DEBUG_DRAWER_PACKET = 0x148;
266+
public const SERVERBOUND_PACK_SETTING_CHANGE_PACKET = 0x149;
266267

267268
}
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\serializer\CommonTypes;
21+
use pocketmine\network\mcpe\protocol\types\BoolPackSetting;
22+
use pocketmine\network\mcpe\protocol\types\FloatPackSetting;
23+
use pocketmine\network\mcpe\protocol\types\PackSetting;
24+
use pocketmine\network\mcpe\protocol\types\PackSettingType;
25+
use pocketmine\network\mcpe\protocol\types\StringPackSetting;
26+
use Ramsey\Uuid\UuidInterface;
27+
28+
class ServerboundPackSettingChangePacket extends DataPacket implements ServerboundPacket{
29+
public const NETWORK_ID = ProtocolInfo::SERVERBOUND_PACK_SETTING_CHANGE_PACKET;
30+
31+
private UuidInterface $packId;
32+
private PackSetting $packSetting;
33+
34+
/**
35+
* @generate-create-func
36+
*/
37+
public static function create(UuidInterface $packId, PackSetting $packSetting) : self{
38+
$result = new self;
39+
$result->packId = $packId;
40+
$result->packSetting = $packSetting;
41+
return $result;
42+
}
43+
44+
public function getPackId() : UuidInterface{ return $this->packId; }
45+
46+
public function getPackSetting() : PackSetting{ return $this->packSetting; }
47+
48+
protected function decodePayload(ByteBufferReader $in) : void{
49+
$this->packId = CommonTypes::getUUID($in);
50+
51+
$name = CommonTypes::getString($in);
52+
$typeId = PackSettingType::from(VarInt::readUnsignedInt($in));
53+
$this->packSetting = match($typeId){
54+
PackSettingType::FLOAT => FloatPackSetting::read($in, $name),
55+
PackSettingType::BOOL => BoolPackSetting::read($in, $name),
56+
PackSettingType::STRING => StringPackSetting::read($in, $name),
57+
};
58+
}
59+
60+
protected function encodePayload(ByteBufferWriter $out) : void{
61+
CommonTypes::putUUID($out, $this->packId);
62+
CommonTypes::putString($out, $this->packSetting->getName());
63+
VarInt::writeUnsignedInt($out, $this->packSetting->getTypeId()->value);
64+
$this->packSetting->write($out);
65+
}
66+
67+
public function handle(PacketHandlerInterface $handler) : bool{
68+
return $handler->handleServerboundPackSettingChange($this);
69+
}
70+
}

src/serializer/CommonTypes.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,10 @@ public static function putRotationByte(ByteBufferWriter $out, float $rotation) :
541541
}
542542

543543
/** @throws DataDecodeException */
544-
private static function readGameRule(ByteBufferReader $in, int $type, bool $isPlayerModifiable) : GameRule{
544+
private static function readGameRule(ByteBufferReader $in, int $type, bool $isPlayerModifiable, bool $isStartGame) : GameRule{
545545
return match($type){
546546
BoolGameRule::ID => BoolGameRule::decode($in, $isPlayerModifiable),
547-
IntGameRule::ID => IntGameRule::decode($in, $isPlayerModifiable),
547+
IntGameRule::ID => IntGameRule::decode($in, $isPlayerModifiable, $isStartGame),
548548
FloatGameRule::ID => FloatGameRule::decode($in, $isPlayerModifiable),
549549
default => throw new PacketDecodeException("Unknown gamerule type $type"),
550550
};
@@ -559,14 +559,14 @@ private static function readGameRule(ByteBufferReader $in, int $type, bool $isPl
559559
* @throws PacketDecodeException
560560
* @throws DataDecodeException
561561
*/
562-
public static function getGameRules(ByteBufferReader $in) : array{
562+
public static function getGameRules(ByteBufferReader $in, bool $isStartGame) : array{
563563
$count = VarInt::readUnsignedInt($in);
564564
$rules = [];
565565
for($i = 0; $i < $count; ++$i){
566566
$name = self::getString($in);
567567
$isPlayerModifiable = self::getBool($in);
568568
$type = VarInt::readUnsignedInt($in);
569-
$rules[$name] = self::readGameRule($in, $type, $isPlayerModifiable);
569+
$rules[$name] = self::readGameRule($in, $type, $isPlayerModifiable, $isStartGame);
570570
}
571571

572572
return $rules;
@@ -578,13 +578,13 @@ public static function getGameRules(ByteBufferReader $in) : array{
578578
* @param GameRule[] $rules
579579
* @phpstan-param array<string, GameRule> $rules
580580
*/
581-
public static function putGameRules(ByteBufferWriter $out, array $rules) : void{
581+
public static function putGameRules(ByteBufferWriter $out, array $rules, bool $isStartGame) : void{
582582
VarInt::writeUnsignedInt($out, count($rules));
583583
foreach($rules as $name => $rule){
584584
self::putString($out, $name);
585585
self::putBool($out, $rule->isPlayerModifiable());
586586
VarInt::writeUnsignedInt($out, $rule->getTypeId());
587-
$rule->encode($out);
587+
$rule->encode($out, $isStartGame);
588588
}
589589
}
590590

src/types/ArmorSlot.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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\types;
16+
17+
enum ArmorSlot : int{
18+
use PacketIntEnumTrait;
19+
20+
case HEAD = 0;
21+
case TORSO = 1;
22+
case LEGS = 2;
23+
case FEET = 3;
24+
case BODY = 4;
25+
}

0 commit comments

Comments
 (0)