Skip to content

Commit 9fea873

Browse files
committed
Merge remote-tracking branch 'upstream/bedrock-1.21.110'
2 parents f78f78d + e97b222 commit 9fea873

31 files changed

Lines changed: 477 additions & 132 deletions

src/BiomeDefinitionListPacket.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,7 @@ public static function fromDefinitions(array $definitions) : self{
100100
$entry->getId(),
101101
$entry->getTemperature(),
102102
$entry->getDownfall(),
103-
$entry->getRedSporeDensity(),
104-
$entry->getBlueSporeDensity(),
105-
$entry->getAshDensity(),
106-
$entry->getWhiteAshDensity(),
103+
$entry->getFoliageSnow(),
107104
$entry->getDepth(),
108105
$entry->getScale(),
109106
$entry->getMapWaterColor(),
@@ -136,10 +133,7 @@ public function buildDefinitionsFromData() : array{
136133
$data->getId(),
137134
$data->getTemperature(),
138135
$data->getDownfall(),
139-
$data->getRedSporeDensity(),
140-
$data->getBlueSporeDensity(),
141-
$data->getAshDensity(),
142-
$data->getWhiteAshDensity(),
136+
$data->getFoliageSnow(),
143137
$data->getDepth(),
144138
$data->getScale(),
145139
$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, int $protocolId) : void{
43-
$this->gameRules = CommonTypes::getGameRules($in);
43+
$this->gameRules = CommonTypes::getGameRules($in, $protocolId, false);
4444
}
4545

4646
protected function encodePayload(ByteBufferWriter $out, int $protocolId) : void{
47-
CommonTypes::putGameRules($out, $this->gameRules);
47+
CommonTypes::putGameRules($out, $protocolId, $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
@@ -881,4 +881,8 @@ public function handleClientboundControlSchemeSet(ClientboundControlSchemeSetPac
881881
public function handleServerScriptDebugDrawer(ServerScriptDebugDrawerPacket $packet) : bool{
882882
return false;
883883
}
884+
885+
public function handleServerboundPackSettingChange(ServerboundPackSettingChangePacket $packet) : bool{
886+
return false;
887+
}
884888
}

src/PacketHandlerInterface.php

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

449449
public function handleServerScriptDebugDrawer(ServerScriptDebugDrawerPacket $packet) : bool;
450+
451+
public function handleServerboundPackSettingChange(ServerboundPackSettingChangePacket $packet) : bool;
450452
}

src/PacketPool.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ public function __construct(){
248248
$this->registerPacket(new PlayerLocationPacket());
249249
$this->registerPacket(new ClientboundControlSchemeSetPacket());
250250
$this->registerPacket(new ServerScriptDebugDrawerPacket());
251+
$this->registerPacket(new ServerboundPackSettingChangePacket());
251252
}
252253

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

src/PlayerArmorDamagePacket.php

Lines changed: 79 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
use pmmp\encoding\ByteBufferReader;
1919
use pmmp\encoding\ByteBufferWriter;
2020
use pmmp\encoding\VarInt;
21+
use pocketmine\network\mcpe\protocol\types\ArmorSlot;
22+
use pocketmine\network\mcpe\protocol\types\ArmorSlotAndDamagePair;
23+
use function count;
2124

2225
class PlayerArmorDamagePacket extends DataPacket implements ClientboundPacket{
2326
public const NETWORK_ID = ProtocolInfo::PLAYER_ARMOR_DAMAGE_PACKET;
@@ -28,35 +31,23 @@ class PlayerArmorDamagePacket extends DataPacket implements ClientboundPacket{
2831
private const FLAG_FEET = 3;
2932
private const FLAG_BODY = 4;
3033

31-
private ?int $headSlotDamage;
32-
private ?int $chestSlotDamage;
33-
private ?int $legsSlotDamage;
34-
private ?int $feetSlotDamage;
35-
private ?int $bodySlotDamage;
34+
/**
35+
* @var ArmorSlotAndDamagePair[]
36+
* @phpstan-var list<ArmorSlotAndDamagePair>
37+
*/
38+
private array $armorSlotAndDamagePairs = [];
3639

3740
/**
3841
* @generate-create-func
42+
* @param ArmorSlotAndDamagePair[] $armorSlotAndDamagePairs
43+
* @phpstan-param list<ArmorSlotAndDamagePair> $armorSlotAndDamagePairs
3944
*/
40-
public static function create(?int $headSlotDamage, ?int $chestSlotDamage, ?int $legsSlotDamage, ?int $feetSlotDamage, ?int $bodySlotDamage) : self{
45+
public static function create(array $armorSlotAndDamagePairs) : self{
4146
$result = new self;
42-
$result->headSlotDamage = $headSlotDamage;
43-
$result->chestSlotDamage = $chestSlotDamage;
44-
$result->legsSlotDamage = $legsSlotDamage;
45-
$result->feetSlotDamage = $feetSlotDamage;
46-
$result->bodySlotDamage = $bodySlotDamage;
47+
$result->armorSlotAndDamagePairs = $armorSlotAndDamagePairs;
4748
return $result;
4849
}
4950

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-
6051
private function maybeReadDamage(int $flags, int $flag, ByteBufferReader $in) : ?int{
6152
if(($flags & (1 << $flag)) !== 0){
6253
return VarInt::readSignedInt($in);
@@ -65,14 +56,35 @@ private function maybeReadDamage(int $flags, int $flag, ByteBufferReader $in) :
6556
}
6657

6758
protected function decodePayload(ByteBufferReader $in, int $protocolId) : 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-
if($protocolId >= ProtocolInfo::PROTOCOL_1_21_20){
75-
$this->bodySlotDamage = $this->maybeReadDamage($flags, self::FLAG_BODY, $in);
59+
if($protocolId >= ProtocolInfo::PROTOCOL_1_21_110_OLD){
60+
$length = VarInt::readUnsignedInt($in);
61+
for($i = 0; $i < $length; ++$i){
62+
$this->armorSlotAndDamagePairs[$i] = ArmorSlotAndDamagePair::read($in);
63+
}
64+
}else{
65+
$flags = Byte::readUnsigned($in);
66+
67+
if(($headSlotDamage = $this->maybeReadDamage($flags, self::FLAG_HEAD, $in)) !== null){
68+
$this->armorSlotAndDamagePairs[] = new ArmorSlotAndDamagePair(ArmorSlot::HEAD, $headSlotDamage);
69+
}
70+
71+
if(($chestSlotDamage = $this->maybeReadDamage($flags, self::FLAG_CHEST, $in)) !== null){
72+
$this->armorSlotAndDamagePairs[] = new ArmorSlotAndDamagePair(ArmorSlot::TORSO, $chestSlotDamage);
73+
}
74+
75+
if(($legsSlotDamage = $this->maybeReadDamage($flags, self::FLAG_LEGS, $in)) !== null){
76+
$this->armorSlotAndDamagePairs[] = new ArmorSlotAndDamagePair(ArmorSlot::LEGS, $legsSlotDamage);
77+
}
78+
79+
if(($feetSlotDamage = $this->maybeReadDamage($flags, self::FLAG_FEET, $in)) !== null){
80+
$this->armorSlotAndDamagePairs[] = new ArmorSlotAndDamagePair(ArmorSlot::FEET, $feetSlotDamage);
81+
}
82+
83+
if($protocolId >= ProtocolInfo::PROTOCOL_1_21_20){
84+
if(($bodySlotDamage = $this->maybeReadDamage($flags, self::FLAG_BODY, $in)) !== null){
85+
$this->armorSlotAndDamagePairs[] = new ArmorSlotAndDamagePair(ArmorSlot::BODY, $bodySlotDamage);
86+
}
87+
}
7688
}
7789
}
7890

@@ -86,21 +98,45 @@ private function maybeWriteDamage(?int $field, ByteBufferWriter $out) : void{
8698
}
8799
}
88100

101+
private function getDamageBySlot(ArmorSlot $slot) : ?int{
102+
foreach($this->armorSlotAndDamagePairs as $pair){
103+
if($pair->getSlot() === $slot){
104+
return $pair->getDamage();
105+
}
106+
}
107+
108+
return null;
109+
}
110+
89111
protected function encodePayload(ByteBufferWriter $out, int $protocolId) : void{
90-
Byte::writeUnsigned($out,
91-
$this->composeFlag($this->headSlotDamage, self::FLAG_HEAD) |
92-
$this->composeFlag($this->chestSlotDamage, self::FLAG_CHEST) |
93-
$this->composeFlag($this->legsSlotDamage, self::FLAG_LEGS) |
94-
$this->composeFlag($this->feetSlotDamage, self::FLAG_FEET) |
95-
($protocolId >= ProtocolInfo::PROTOCOL_1_21_20 ? $this->composeFlag($this->bodySlotDamage, self::FLAG_BODY) : 0)
96-
);
97-
98-
$this->maybeWriteDamage($this->headSlotDamage, $out);
99-
$this->maybeWriteDamage($this->chestSlotDamage, $out);
100-
$this->maybeWriteDamage($this->legsSlotDamage, $out);
101-
$this->maybeWriteDamage($this->feetSlotDamage, $out);
102-
if($protocolId >= ProtocolInfo::PROTOCOL_1_21_20){
103-
$this->maybeWriteDamage($this->bodySlotDamage, $out);
112+
if($protocolId >= ProtocolInfo::PROTOCOL_1_21_110_OLD){
113+
VarInt::writeUnsignedInt($out, count($this->armorSlotAndDamagePairs));
114+
foreach($this->armorSlotAndDamagePairs as $pair){
115+
$pair->write($out);
116+
}
117+
}else{
118+
$headSlotDamage = $this->getDamageBySlot(ArmorSlot::HEAD);
119+
$chestSlotDamage = $this->getDamageBySlot(ArmorSlot::TORSO);
120+
$legsSlotDamage = $this->getDamageBySlot(ArmorSlot::LEGS);
121+
$feetSlotDamage = $this->getDamageBySlot(ArmorSlot::FEET);
122+
$bodySlotDamage = $this->getDamageBySlot(ArmorSlot::BODY);
123+
124+
Byte::writeUnsigned(
125+
$out,
126+
$this->composeFlag($headSlotDamage, self::FLAG_HEAD) |
127+
$this->composeFlag($chestSlotDamage, self::FLAG_CHEST) |
128+
$this->composeFlag($legsSlotDamage, self::FLAG_LEGS) |
129+
$this->composeFlag($feetSlotDamage, self::FLAG_FEET) |
130+
($protocolId >= ProtocolInfo::PROTOCOL_1_21_20 ? $this->composeFlag($bodySlotDamage, self::FLAG_BODY) : 0)
131+
);
132+
133+
$this->maybeWriteDamage($headSlotDamage, $out);
134+
$this->maybeWriteDamage($chestSlotDamage, $out);
135+
$this->maybeWriteDamage($legsSlotDamage, $out);
136+
$this->maybeWriteDamage($feetSlotDamage, $out);
137+
if($protocolId >= ProtocolInfo::PROTOCOL_1_21_20){
138+
$this->maybeWriteDamage($bodySlotDamage, $out);
139+
}
104140
}
105141
}
106142

src/PlayerAuthInputPacket.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use pocketmine\network\mcpe\protocol\types\ItemInteractionData;
2929
use pocketmine\network\mcpe\protocol\types\PlayerAction;
3030
use pocketmine\network\mcpe\protocol\types\PlayerAuthInputFlags;
31+
use pocketmine\network\mcpe\protocol\types\PlayerAuthInputVehicleInfo;
3132
use pocketmine\network\mcpe\protocol\types\PlayerBlockAction;
3233
use pocketmine\network\mcpe\protocol\types\PlayerBlockActionStopBreak;
3334
use pocketmine\network\mcpe\protocol\types\PlayerBlockActionWithBlockInfo;

src/ProtocolInfo.php

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

3434
/** Actual Minecraft: PE protocol version */
35-
public const CURRENT_PROTOCOL = self::PROTOCOL_1_21_100;
35+
public const CURRENT_PROTOCOL = self::PROTOCOL_1_21_111;
3636
public const ACCEPTED_PROTOCOL = [
3737
self::PROTOCOL_1_20_0,
3838
self::PROTOCOL_1_20_10,
@@ -53,14 +53,16 @@ private function __construct(){
5353
self::PROTOCOL_1_21_80,
5454
self::PROTOCOL_1_21_90,
5555
self::PROTOCOL_1_21_93,
56+
self::PROTOCOL_1_21_100,
5657
self::CURRENT_PROTOCOL,
5758
];
5859

5960
/** Current Minecraft PE version reported by the server. This is usually the earliest currently supported version. */
60-
public const MINECRAFT_VERSION = 'v1.21.100';
61+
public const MINECRAFT_VERSION = 'v1.21.111';
6162
/** Version number sent to clients in ping responses. */
62-
public const MINECRAFT_VERSION_NETWORK = '1.21.100';
63+
public const MINECRAFT_VERSION_NETWORK = '1.21.111';
6364

65+
public const PROTOCOL_1_21_111 = 844;
6466
public const PROTOCOL_1_21_100 = 827;
6567
public const PROTOCOL_1_21_93 = 819;
6668
public const PROTOCOL_1_21_90 = 818;
@@ -308,5 +310,6 @@ private function __construct(){
308310
public const PLAYER_LOCATION_PACKET = 0x146;
309311
public const CLIENTBOUND_CONTROL_SCHEME_SET_PACKET = 0x147;
310312
public const SERVER_SCRIPT_DEBUG_DRAWER_PACKET = 0x148;
313+
public const SERVERBOUND_PACK_SETTING_CHANGE_PACKET = 0x149;
311314

312315
}
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
@@ -542,10 +542,10 @@ public static function putRotationByte(ByteBufferWriter $out, float $rotation) :
542542
}
543543

544544
/** @throws DataDecodeException */
545-
private static function readGameRule(ByteBufferReader $in, int $type, bool $isPlayerModifiable) : GameRule{
545+
private static function readGameRule(ByteBufferReader $in, int $type, bool $isPlayerModifiable, bool $isStartGame) : GameRule{
546546
return match($type){
547547
BoolGameRule::ID => BoolGameRule::decode($in, $isPlayerModifiable),
548-
IntGameRule::ID => IntGameRule::decode($in, $isPlayerModifiable),
548+
IntGameRule::ID => IntGameRule::decode($in, $isPlayerModifiable, $isStartGame),
549549
FloatGameRule::ID => FloatGameRule::decode($in, $isPlayerModifiable),
550550
default => throw new PacketDecodeException("Unknown gamerule type $type"),
551551
};
@@ -560,14 +560,14 @@ private static function readGameRule(ByteBufferReader $in, int $type, bool $isPl
560560
* @throws PacketDecodeException
561561
* @throws DataDecodeException
562562
*/
563-
public static function getGameRules(ByteBufferReader $in) : array{
563+
public static function getGameRules(ByteBufferReader $in, bool $isStartGame) : array{
564564
$count = VarInt::readUnsignedInt($in);
565565
$rules = [];
566566
for($i = 0; $i < $count; ++$i){
567567
$name = self::getString($in);
568568
$isPlayerModifiable = self::getBool($in);
569569
$type = VarInt::readUnsignedInt($in);
570-
$rules[$name] = self::readGameRule($in, $type, $isPlayerModifiable);
570+
$rules[$name] = self::readGameRule($in, $type, $isPlayerModifiable, $isStartGame);
571571
}
572572

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

0 commit comments

Comments
 (0)