Skip to content

Commit

Permalink
1.21.50 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dries-c committed Dec 3, 2024
1 parent 48d512e commit a863f27
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
8 changes: 6 additions & 2 deletions src/CameraAimAssistPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@ public function getTargetMode() : CameraAimAssistTargetMode{ return $this->targe
public function getActionType() : CameraAimAssistActionType{ return $this->actionType; }

protected function decodePayload(PacketSerializer $in) : void{
$this->presetId = $in->getString();
if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_50){
$this->presetId = $in->getString();
}
$this->viewAngle = $in->getVector2();
$this->distance = $in->getLFloat();
$this->targetMode = CameraAimAssistTargetMode::fromPacket($in->getByte());
$this->actionType = CameraAimAssistActionType::fromPacket($in->getByte());
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putString($this->presetId);
if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_50){
$out->putString($this->presetId);
}
$out->putVector2($this->viewAngle);
$out->putLFloat($this->distance);
$out->putByte($this->targetMode->value);
Expand Down
8 changes: 6 additions & 2 deletions src/serializer/BitSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,13 @@ public static function read(PacketSerializer $in, int $length) : self{
return new self($length, array_slice($result, 0, self::getExpectedPartsCount($length)));
}

public function write(PacketSerializer $out) : void{
public function write(PacketSerializer $out, int $length = null) : void{
$parts = $this->parts;
$length = $this->length;
$length ??= $this->length;

if($length > $this->length){
throw new \InvalidArgumentException("Cannot write more bits than the BitSet contains");
}

$currentIndex = 0;
$currentShift = 0;
Expand Down
11 changes: 8 additions & 3 deletions src/types/inventory/stackresponse/ItemStackResponseSlotInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace pocketmine\network\mcpe\protocol\types\inventory\stackresponse;

use pocketmine\network\mcpe\protocol\ProtocolInfo;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;

final class ItemStackResponseSlotInfo{
Expand Down Expand Up @@ -47,9 +48,11 @@ public static function read(PacketSerializer $in) : self{
$count = $in->getByte();
$itemStackId = $in->readServerItemStackId();
$customName = $in->getString();
$filteredCustomName = $in->getString();
if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_50){
$filteredCustomName = $in->getString();
}
$durabilityCorrection = $in->getVarInt();
return new self($slot, $hotbarSlot, $count, $itemStackId, $customName, $filteredCustomName, $durabilityCorrection);
return new self($slot, $hotbarSlot, $count, $itemStackId, $customName, $filteredCustomName ?? $customName, $durabilityCorrection);
}

public function write(PacketSerializer $out) : void{
Expand All @@ -58,7 +61,9 @@ public function write(PacketSerializer $out) : void{
$out->putByte($this->count);
$out->writeServerItemStackId($this->itemStackId);
$out->putString($this->customName);
$out->putString($this->filteredCustomName);
if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_50){
$out->putString($this->filteredCustomName);
}
$out->putVarInt($this->durabilityCorrection);
}
}
16 changes: 8 additions & 8 deletions tests/phpunit/BitSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public function testBitSet() : void{
$writeTest->set(0, true);
$writeTest->set(64, true);

$packetSerializer = PacketSerializer::encoder();
$packetSerializer = PacketSerializer::encoder(ProtocolInfo::CURRENT_PROTOCOL);
$writeTest->write($packetSerializer);

$packetSerializer = PacketSerializer::decoder($packetSerializer->getBuffer(), 0);
$packetSerializer = PacketSerializer::decoder(ProtocolInfo::CURRENT_PROTOCOL, $packetSerializer->getBuffer(), 0);
$readTest = BitSet::read($packetSerializer, 65);

assertTrue($this->setsEqual($writeTest, $readTest));
Expand All @@ -43,10 +43,10 @@ public function testBitSetConstructor() : void{

$test2->set(64, true);

$packetSerializer = PacketSerializer::encoder();
$packetSerializer = PacketSerializer::encoder(ProtocolInfo::CURRENT_PROTOCOL);
$test->write($packetSerializer);

$packetSerializer2 = PacketSerializer::encoder();
$packetSerializer2 = PacketSerializer::encoder(ProtocolInfo::CURRENT_PROTOCOL);
$test2->write($packetSerializer2);

self::assertEquals($packetSerializer->getBuffer(), $packetSerializer2->getBuffer());
Expand All @@ -56,20 +56,20 @@ public function testBitSetParts() : void{
$writeTest = new BitSet(128);
$writeTest->set(127, true);

$packetSerializer = PacketSerializer::encoder();
$packetSerializer = PacketSerializer::encoder(ProtocolInfo::CURRENT_PROTOCOL);
$writeTest->write($packetSerializer);

$packetSerializer = PacketSerializer::decoder($packetSerializer->getBuffer(), 0);
$packetSerializer = PacketSerializer::decoder(ProtocolInfo::CURRENT_PROTOCOL, $packetSerializer->getBuffer(), 0);
$readTest = BitSet::read($packetSerializer, 128);

assertTrue($this->setsEqual($writeTest, $readTest));
}

public function testVarUnsignedLongCompatibility() : void{
$packetSerializer = PacketSerializer::encoder();
$packetSerializer = PacketSerializer::encoder(ProtocolInfo::CURRENT_PROTOCOL);
$packetSerializer->putUnsignedVarLong(0 | 1 << 63);

$packetSerializer = PacketSerializer::decoder($packetSerializer->getBuffer(), 0);
$packetSerializer = PacketSerializer::decoder(ProtocolInfo::CURRENT_PROTOCOL, $packetSerializer->getBuffer(), 0);
$readTest = BitSet::read($packetSerializer, 64);

$expectedResult = new BitSet(64);
Expand Down

0 comments on commit a863f27

Please sign in to comment.