diff --git a/src/EmotePacket.php b/src/EmotePacket.php index 52b072be..49d601ef 100644 --- a/src/EmotePacket.php +++ b/src/EmotePacket.php @@ -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(); @@ -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); diff --git a/src/ResourcePacksInfoPacket.php b/src/ResourcePacksInfoPacket.php index fb991316..9102ea07 100644 --- a/src/ResourcePacksInfoPacket.php +++ b/src/ResourcePacksInfoPacket.php @@ -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; @@ -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 @@ -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 $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; } @@ -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){ @@ -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); diff --git a/src/TransferPacket.php b/src/TransferPacket.php index eaf54985..74dd7ffb 100644 --- a/src/TransferPacket.php +++ b/src/TransferPacket.php @@ -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{ diff --git a/src/types/camera/CameraPreset.php b/src/types/camera/CameraPreset.php index b0f63166..f5074d2c 100644 --- a/src/types/camera/CameraPreset.php +++ b/src/types/camera/CameraPreset.php @@ -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, diff --git a/src/types/entity/UpdateAttribute.php b/src/types/entity/UpdateAttribute.php index 15425433..e53761c1 100644 --- a/src/types/entity/UpdateAttribute.php +++ b/src/types/entity/UpdateAttribute.php @@ -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; @@ -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(); @@ -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);