Skip to content

Commit

Permalink
Add 1.21.20 BC support
Browse files Browse the repository at this point in the history
  • Loading branch information
dries-c committed Sep 17, 2024
1 parent db73c98 commit b63b507
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/EmotePacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public function getFlags() : int{
protected function decodePayload(PacketSerializer $in) : void{
$this->actorRuntimeId = $in->getActorRuntimeId();
$this->emoteId = $in->getString();
$this->emoteLengthTicks = $in->getUnsignedVarInt();
if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_30){
$this->emoteLengthTicks = $in->getUnsignedVarInt();
}
$this->xboxUserId = $in->getString();
$this->platformChatId = $in->getString();
$this->flags = $in->getByte();
Expand All @@ -73,7 +75,9 @@ protected function decodePayload(PacketSerializer $in) : void{
protected function encodePayload(PacketSerializer $out) : void{
$out->putActorRuntimeId($this->actorRuntimeId);
$out->putString($this->emoteId);
$out->putUnsignedVarInt($this->emoteLengthTicks);
if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_30){
$out->putUnsignedVarInt($this->emoteLengthTicks);
}
$out->putString($this->xboxUserId);
$out->putString($this->platformChatId);
$out->putByte($this->flags);
Expand Down
31 changes: 30 additions & 1 deletion src/ResourcePacksInfoPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace pocketmine\network\mcpe\protocol;

use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\resourcepacks\BehaviorPackInfoEntry;
use pocketmine\network\mcpe\protocol\types\resourcepacks\ResourcePackInfoEntry;
use function count;

Expand All @@ -23,9 +24,12 @@ class ResourcePacksInfoPacket extends DataPacket implements ClientboundPacket{

/** @var ResourcePackInfoEntry[] */
public array $resourcePackEntries = [];
/** @var BehaviorPackInfoEntry[] */
public array $behaviorPackEntries = [];
public bool $mustAccept = false; //if true, forces client to choose between accepting packs or being disconnected
public bool $hasAddons = false;
public bool $hasScripts = false; //if true, causes disconnect for any platform that doesn't support scripts yet
public bool $forceServerPacks = false;
/**
* @var string[]
* @phpstan-var array<string, string>
Expand All @@ -35,15 +39,26 @@ class ResourcePacksInfoPacket extends DataPacket implements ClientboundPacket{
/**
* @generate-create-func
* @param ResourcePackInfoEntry[] $resourcePackEntries
* @param BehaviorPackInfoEntry[] $behaviorPackEntries
* @param string[] $cdnUrls
* @phpstan-param array<string, string> $cdnUrls
*/
public static function create(array $resourcePackEntries, bool $mustAccept, bool $hasAddons, bool $hasScripts, array $cdnUrls) : self{
public static function create(
array $resourcePackEntries,
array $behaviorPackEntries,
bool $mustAccept,
bool $hasAddons,
bool $hasScripts,
bool $forceServerPacks,
array $cdnUrls,
) : self{
$result = new self;
$result->resourcePackEntries = $resourcePackEntries;
$result->behaviorPackEntries = $behaviorPackEntries;
$result->mustAccept = $mustAccept;
$result->hasAddons = $hasAddons;
$result->hasScripts = $hasScripts;
$result->forceServerPacks = $forceServerPacks;
$result->cdnUrls = $cdnUrls;
return $result;
}
Expand All @@ -54,6 +69,13 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->hasAddons = $in->getBool();
}
$this->hasScripts = $in->getBool();
if($in->getProtocolId() <= ProtocolInfo::PROTOCOL_1_21_20){
$this->forceServerPacks = $in->getBool();
$behaviorPackCount = $in->getLShort();
while($behaviorPackCount-- > 0){
$this->behaviorPackEntries[] = BehaviorPackInfoEntry::read($in);
}
}

$resourcePackCount = $in->getLShort();
while($resourcePackCount-- > 0){
Expand All @@ -76,6 +98,13 @@ protected function encodePayload(PacketSerializer $out) : void{
$out->putBool($this->hasAddons);
}
$out->putBool($this->hasScripts);
if($out->getProtocolId() <= ProtocolInfo::PROTOCOL_1_21_20){
$out->putBool($this->forceServerPacks);
$out->putLShort(count($this->behaviorPackEntries));
foreach($this->behaviorPackEntries as $entry){
$entry->write($out);
}
}
$out->putLShort(count($this->resourcePackEntries));
foreach($this->resourcePackEntries as $entry){
$entry->write($out);
Expand Down
8 changes: 6 additions & 2 deletions src/TransferPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ public static function create(string $address, int $port, bool $reloadWorld) : s
protected function decodePayload(PacketSerializer $in) : void{
$this->address = $in->getString();
$this->port = $in->getLShort();
$this->reloadWorld = $in->getBool();
if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_30){
$this->reloadWorld = $in->getBool();
}
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putString($this->address);
$out->putLShort($this->port);
$out->putBool($this->reloadWorld);
if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_30){
$out->putBool($this->reloadWorld);
}
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
3 changes: 3 additions & 0 deletions src/types/camera/CameraPreset.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public static function fromNBT(CompoundTag $nbt) : self{
$nbt->getTag("rot_y") === null ? null : $nbt->getFloat("rot_y"),
null,
null,
null,
null,
null,
$nbt->getTag("audio_listener_type") === null ? null : match($nbt->getString("audio_listener_type")){
"camera" => self::AUDIO_LISTENER_TYPE_CAMERA,
"player" => self::AUDIO_LISTENER_TYPE_PLAYER,
Expand Down
15 changes: 10 additions & 5 deletions src/types/entity/UpdateAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace pocketmine\network\mcpe\protocol\types\entity;

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

Expand Down Expand Up @@ -55,8 +56,10 @@ public static function read(PacketSerializer $in) : self{
$min = $in->getLFloat();
$max = $in->getLFloat();
$current = $in->getLFloat();
$defaultMin = $in->getLFloat();
$defaultMax = $in->getLFloat();
if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_30){
$defaultMin = $in->getLFloat();
$defaultMax = $in->getLFloat();
}
$default = $in->getLFloat();
$id = $in->getString();

Expand All @@ -65,15 +68,17 @@ public static function read(PacketSerializer $in) : self{
$modifiers[] = AttributeModifier::read($in);
}

return new self($id, $min, $max, $current, $defaultMin, $defaultMax, $default, $modifiers);
return new self($id, $min, $max, $current, $defaultMin ?? $min, $defaultMax ?? $max, $default, $modifiers);
}

public function write(PacketSerializer $out) : void{
$out->putLFloat($this->min);
$out->putLFloat($this->max);
$out->putLFloat($this->current);
$out->putLFloat($this->defaultMin);
$out->putLFloat($this->defaultMax);
if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_30){
$out->putLFloat($this->defaultMin);
$out->putLFloat($this->defaultMax);
}
$out->putLFloat($this->default);
$out->putString($this->id);

Expand Down

0 comments on commit b63b507

Please sign in to comment.