Skip to content

Commit f8f3422

Browse files
committed
Protocol changes for 1.21.111
1 parent 9fea873 commit f8f3422

15 files changed

+127
-39
lines changed

src/BiomeDefinitionListPacket.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ 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(),
103107
$entry->getFoliageSnow(),
104108
$entry->getDepth(),
105109
$entry->getScale(),
@@ -133,6 +137,10 @@ public function buildDefinitionsFromData() : array{
133137
$data->getId(),
134138
$data->getTemperature(),
135139
$data->getDownfall(),
140+
$data->getRedSporeDensity(),
141+
$data->getBlueSporeDensity(),
142+
$data->getAshDensity(),
143+
$data->getWhiteAshDensity(),
136144
$data->getFoliageSnow(),
137145
$data->getDepth(),
138146
$data->getScale(),

src/ClientMovementPredictionSyncPacket.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ public function getActorFlyingState() : bool{ return $this->actorFlyingState; }
122122

123123
protected function decodePayload(ByteBufferReader $in, int $protocolId) : void{
124124
$this->flags = BitSet::read($in, match(true) {
125-
$protocolId === ProtocolInfo::CURRENT_PROTOCOL => self::FLAG_LENGTH,
125+
$protocolId >= ProtocolInfo::PROTOCOL_1_21_111 => self::FLAG_LENGTH,
126+
$protocolId >= ProtocolInfo::PROTOCOL_1_21_90 => 125,
126127
$protocolId >= ProtocolInfo::PROTOCOL_1_21_80 => 124,
127128
$protocolId >= ProtocolInfo::PROTOCOL_1_21_70 => 123,
128129
default => 120,
@@ -144,7 +145,8 @@ protected function decodePayload(ByteBufferReader $in, int $protocolId) : void{
144145

145146
protected function encodePayload(ByteBufferWriter $out, int $protocolId) : void{
146147
$this->flags->write($out, match(true) {
147-
$protocolId === ProtocolInfo::CURRENT_PROTOCOL => self::FLAG_LENGTH,
148+
$protocolId >= ProtocolInfo::PROTOCOL_1_21_111 => self::FLAG_LENGTH,
149+
$protocolId >= ProtocolInfo::PROTOCOL_1_21_90 => 125,
148150
$protocolId >= ProtocolInfo::PROTOCOL_1_21_80 => 124,
149151
$protocolId >= ProtocolInfo::PROTOCOL_1_21_70 => 123,
150152
default => 120,

src/PlayerArmorDamagePacket.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private function maybeReadDamage(int $flags, int $flag, ByteBufferReader $in) :
5656
}
5757

5858
protected function decodePayload(ByteBufferReader $in, int $protocolId) : void{
59-
if($protocolId >= ProtocolInfo::PROTOCOL_1_21_110_OLD){
59+
if($protocolId >= ProtocolInfo::PROTOCOL_1_21_111){
6060
$length = VarInt::readUnsignedInt($in);
6161
for($i = 0; $i < $length; ++$i){
6262
$this->armorSlotAndDamagePairs[$i] = ArmorSlotAndDamagePair::read($in);
@@ -109,7 +109,7 @@ private function getDamageBySlot(ArmorSlot $slot) : ?int{
109109
}
110110

111111
protected function encodePayload(ByteBufferWriter $out, int $protocolId) : void{
112-
if($protocolId >= ProtocolInfo::PROTOCOL_1_21_110_OLD){
112+
if($protocolId >= ProtocolInfo::PROTOCOL_1_21_111){
113113
VarInt::writeUnsignedInt($out, count($this->armorSlotAndDamagePairs));
114114
foreach($this->armorSlotAndDamagePairs as $pair){
115115
$pair->write($out);

src/ServerboundPackSettingChangePacket.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function getPackId() : UuidInterface{ return $this->packId; }
4545

4646
public function getPackSetting() : PackSetting{ return $this->packSetting; }
4747

48-
protected function decodePayload(ByteBufferReader $in) : void{
48+
protected function decodePayload(ByteBufferReader $in, int $protocolId) : void{
4949
$this->packId = CommonTypes::getUUID($in);
5050

5151
$name = CommonTypes::getString($in);
@@ -57,7 +57,7 @@ protected function decodePayload(ByteBufferReader $in) : void{
5757
};
5858
}
5959

60-
protected function encodePayload(ByteBufferWriter $out) : void{
60+
protected function encodePayload(ByteBufferWriter $out, int $protocolId) : void{
6161
CommonTypes::putUUID($out, $this->packId);
6262
CommonTypes::putString($out, $this->packSetting->getName());
6363
VarInt::writeUnsignedInt($out, $this->packSetting->getTypeId()->value);

src/serializer/CommonTypes.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,11 @@ public static function putRotationByte(ByteBufferWriter $out, float $rotation) :
542542
}
543543

544544
/** @throws DataDecodeException */
545-
private static function readGameRule(ByteBufferReader $in, int $type, bool $isPlayerModifiable, bool $isStartGame) : GameRule{
545+
private static function readGameRule(ByteBufferReader $in, int $protocolId, int $type, bool $isPlayerModifiable, bool $isStartGame) : GameRule{
546546
return match($type){
547-
BoolGameRule::ID => BoolGameRule::decode($in, $isPlayerModifiable),
548-
IntGameRule::ID => IntGameRule::decode($in, $isPlayerModifiable, $isStartGame),
549-
FloatGameRule::ID => FloatGameRule::decode($in, $isPlayerModifiable),
547+
BoolGameRule::ID => BoolGameRule::decode($in, $protocolId, $isPlayerModifiable),
548+
IntGameRule::ID => IntGameRule::decode($in, $protocolId, $isPlayerModifiable, $isStartGame),
549+
FloatGameRule::ID => FloatGameRule::decode($in, $protocolId, $isPlayerModifiable),
550550
default => throw new PacketDecodeException("Unknown gamerule type $type"),
551551
};
552552
}
@@ -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, bool $isStartGame) : array{
563+
public static function getGameRules(ByteBufferReader $in, int $protocolId, 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, $isStartGame);
570+
$rules[$name] = self::readGameRule($in, $protocolId, $type, $isPlayerModifiable, $isStartGame);
571571
}
572572

573573
return $rules;
@@ -579,13 +579,13 @@ public static function getGameRules(ByteBufferReader $in, bool $isStartGame) : a
579579
* @param GameRule[] $rules
580580
* @phpstan-param array<string, GameRule> $rules
581581
*/
582-
public static function putGameRules(ByteBufferWriter $out, array $rules, bool $isStartGame) : void{
582+
public static function putGameRules(ByteBufferWriter $out, int $protocolId, 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, $isStartGame);
588+
$rule->encode($out, $protocolId, $isStartGame);
589589
}
590590
}
591591

src/types/BoolGameRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public function getValue() : bool{
3434
return $this->value;
3535
}
3636

37-
public function encode(ByteBufferWriter $out, bool $isStartGame) : void{
37+
public function encode(ByteBufferWriter $out, int $protocolId, bool $isStartGame) : void{
3838
CommonTypes::putBool($out, $this->value);
3939
}
4040

41-
public static function decode(ByteBufferReader $in, bool $isPlayerModifiable) : self{
41+
public static function decode(ByteBufferReader $in, int $protocolId, bool $isPlayerModifiable) : self{
4242
return new self(CommonTypes::getBool($in), $isPlayerModifiable);
4343
}
4444
}

src/types/FloatGameRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public function getValue() : float{
3434
return $this->value;
3535
}
3636

37-
public function encode(ByteBufferWriter $out, bool $isStartGame) : void{
37+
public function encode(ByteBufferWriter $out, int $protocolId, bool $isStartGame) : void{
3838
LE::writeFloat($out, $this->value);
3939
}
4040

41-
public static function decode(ByteBufferReader $in, bool $isPlayerModifiable) : self{
41+
public static function decode(ByteBufferReader $in, int $protocolId, bool $isPlayerModifiable) : self{
4242
return new self(LE::readFloat($in), $isPlayerModifiable);
4343
}
4444
}

src/types/GameRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ public function isPlayerModifiable() : bool{ return $this->isPlayerModifiable; }
2525

2626
abstract public function getTypeId() : int;
2727

28-
abstract public function encode(ByteBufferWriter $out, bool $isStartGame) : void;
28+
abstract public function encode(ByteBufferWriter $out, int $protocolId, bool $isStartGame) : void;
2929
}

src/types/IntGameRule.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use pmmp\encoding\ByteBufferWriter;
1919
use pmmp\encoding\LE;
2020
use pmmp\encoding\VarInt;
21+
use pocketmine\network\mcpe\protocol\ProtocolInfo;
2122

2223
final class IntGameRule extends GameRule{
2324
use GetTypeIdFromConstTrait;
@@ -35,15 +36,15 @@ public function getValue() : int{
3536
return $this->value;
3637
}
3738

38-
public function encode(ByteBufferWriter $out, bool $isStartGame) : void{
39-
if($isStartGame){
39+
public function encode(ByteBufferWriter $out, int $protocolId, bool $isStartGame) : void{
40+
if($isStartGame || $protocolId < ProtocolInfo::PROTOCOL_1_21_111){
4041
VarInt::writeUnsignedInt($out, $this->value);
4142
}else{
4243
LE::writeUnsignedInt($out, $this->value);
4344
}
4445
}
4546

46-
public static function decode(ByteBufferReader $in, bool $isPlayerModifiable, bool $isStartGame) : self{
47-
return new self($isStartGame ? VarInt::readUnsignedInt($in) : LE::readUnsignedInt($in), $isPlayerModifiable);
47+
public static function decode(ByteBufferReader $in, int $protocolId, bool $isPlayerModifiable, bool $isStartGame) : self{
48+
return new self(($isStartGame || $protocolId < ProtocolInfo::PROTOCOL_1_21_111) ? VarInt::readUnsignedInt($in) : LE::readUnsignedInt($in), $isPlayerModifiable);
4849
}
4950
}

src/types/LevelSettings.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private function internalRead(ByteBufferReader $in, int $protocolId) : void{
129129
$this->platformBroadcastMode = VarInt::readSignedInt($in);
130130
$this->commandsEnabled = CommonTypes::getBool($in);
131131
$this->isTexturePacksRequired = CommonTypes::getBool($in);
132-
$this->gameRules = CommonTypes::getGameRules($in, true);
132+
$this->gameRules = CommonTypes::getGameRules($in, $protocolId, true);
133133
$this->experiments = Experiments::read($in);
134134
$this->hasBonusChestEnabled = CommonTypes::getBool($in);
135135
$this->hasStartWithMapEnabled = CommonTypes::getBool($in);
@@ -194,7 +194,7 @@ public function write(ByteBufferWriter $out, int $protocolId) : void{
194194
VarInt::writeSignedInt($out, $this->platformBroadcastMode);
195195
CommonTypes::putBool($out, $this->commandsEnabled);
196196
CommonTypes::putBool($out, $this->isTexturePacksRequired);
197-
CommonTypes::putGameRules($out, $this->gameRules, true);
197+
CommonTypes::putGameRules($out, $protocolId, $this->gameRules, true);
198198
$this->experiments->write($out);
199199
CommonTypes::putBool($out, $this->hasBonusChestEnabled);
200200
CommonTypes::putBool($out, $this->hasStartWithMapEnabled);

0 commit comments

Comments
 (0)