Skip to content

Commit

Permalink
1.21.40 support
Browse files Browse the repository at this point in the history
  • Loading branch information
AkmalFairuz committed Oct 23, 2024
1 parent db5ff45 commit cd22875
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 30 deletions.
14 changes: 12 additions & 2 deletions src/InventoryContentPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\inventory\FullContainerName;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStack;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;
use function count;

Expand Down Expand Up @@ -49,7 +50,12 @@ protected function decodePayload(PacketSerializer $in) : void{
}
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_729){
$this->containerName = FullContainerName::read($in);
$this->dynamicContainerSize = $in->getUnsignedVarInt();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_748) {
ItemStackWrapper::read($in); // Storage
$this->dynamicContainerSize = 0;
}else{
$this->dynamicContainerSize = $in->getUnsignedVarInt();
}
}elseif($in->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$dynamicId = $in->getUnsignedVarInt();
$this->containerName = new FullContainerName(0, $dynamicId);
Expand All @@ -64,7 +70,11 @@ protected function encodePayload(PacketSerializer $out) : void{
}
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_729){
$this->containerName->write($out);
$out->putUnsignedVarInt($this->dynamicContainerSize);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_748){
ItemStackWrapper::legacy(ItemStack::null())->write($out); // Storage
}else {
$out->putUnsignedVarInt($this->dynamicContainerSize);
}
}elseif($out->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$out->putUnsignedVarInt($this->containerName->getDynamicId() ?? 0);
}
Expand Down
14 changes: 12 additions & 2 deletions src/InventorySlotPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\inventory\FullContainerName;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStack;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;

class InventorySlotPacket extends DataPacket implements ClientboundPacket{
Expand Down Expand Up @@ -45,7 +46,12 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->inventorySlot = $in->getUnsignedVarInt();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_729){
$this->containerName = FullContainerName::read($in);
$this->dynamicContainerSize = $in->getUnsignedVarInt();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_748) {
ItemStackWrapper::read($in); // Storage
$this->dynamicContainerSize = 0;
}else{
$this->dynamicContainerSize = $in->getUnsignedVarInt();
}
}elseif($in->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$dynamicId = $this->containerName->getDynamicId();
$this->containerName = new FullContainerName(0, $dynamicId);
Expand All @@ -58,7 +64,11 @@ protected function encodePayload(PacketSerializer $out) : void{
$out->putUnsignedVarInt($this->inventorySlot);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_729){
$this->containerName->write($out);
$out->putUnsignedVarInt($this->dynamicContainerSize);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_748){
ItemStackWrapper::legacy(ItemStack::null())->write($out); // Storage
}else {
$out->putUnsignedVarInt($this->dynamicContainerSize);
}
}elseif($out->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$out->putUnsignedVarInt($this->containerName->getDynamicId() ?? 0);
}
Expand Down
12 changes: 10 additions & 2 deletions src/MobEffectPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->particles = $in->getBool();
$this->duration = $in->getVarInt();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_662){
$this->tick = $in->getLLong();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_748) {
$this->tick = $in->getUnsignedVarLong();
}else{
$this->tick = $in->getLLong();
}
}
}

Expand All @@ -74,7 +78,11 @@ protected function encodePayload(PacketSerializer $out) : void{
$out->putBool($this->particles);
$out->putVarInt($this->duration);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_662){
$out->putLLong($this->tick);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_748) {
$out->putUnsignedVarLong($this->tick);
}else{
$out->putLLong($this->tick);
}
}
}

Expand Down
50 changes: 33 additions & 17 deletions src/PlayerAuthInputPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace pocketmine\network\mcpe\protocol;

use pocketmine\math\Vector2;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\InputMode;
Expand Down Expand Up @@ -42,7 +43,7 @@ class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{
private int $inputMode;
private int $playMode;
private int $interactionMode;
private ?Vector3 $vrGazeDirection = null;
private Vector2 $interactRotation;
private int $tick;
private Vector3 $delta;
private ?ItemInteractionData $itemInteractionData = null;
Expand All @@ -52,6 +53,7 @@ class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{
private ?PlayerAuthInputVehicleInfo $vehicleInfo = null;
private float $analogMoveVecX;
private float $analogMoveVecZ;
private Vector3 $cameraOrientation;

/**
* @param int $inputFlags @see PlayerAuthInputFlags
Expand All @@ -72,20 +74,17 @@ public static function create(
int $inputMode,
int $playMode,
int $interactionMode,
?Vector3 $vrGazeDirection,
Vector2 $interactRotation,
int $tick,
Vector3 $delta,
?ItemInteractionData $itemInteractionData,
?ItemStackRequest $itemStackRequest,
?array $blockActions,
?PlayerAuthInputVehicleInfo $vehicleInfo,
float $analogMoveVecX,
float $analogMoveVecZ
float $analogMoveVecZ,
Vector3 $cameraOrientation,
) : self{
if($playMode === PlayMode::VR and $vrGazeDirection === null){
//yuck, can we get a properly written packet just once? ...
throw new \InvalidArgumentException("Gaze direction must be provided for VR play mode");
}
$result = new self;
$result->position = $position->asVector3();
$result->pitch = $pitch;
Expand All @@ -111,9 +110,7 @@ public static function create(
$result->inputMode = $inputMode;
$result->playMode = $playMode;
$result->interactionMode = $interactionMode;
if($vrGazeDirection !== null){
$result->vrGazeDirection = $vrGazeDirection->asVector3();
}
$result->interactRotation = $interactRotation;
$result->tick = $tick;
$result->delta = $delta;
$result->itemInteractionData = $itemInteractionData;
Expand All @@ -122,6 +119,7 @@ public static function create(
$result->vehicleInfo = $vehicleInfo;
$result->analogMoveVecX = $analogMoveVecX;
$result->analogMoveVecZ = $analogMoveVecZ;
$result->cameraOrientation = $cameraOrientation;
return $result;
}

Expand Down Expand Up @@ -177,8 +175,8 @@ public function getInteractionMode() : int{
return $this->interactionMode;
}

public function getVrGazeDirection() : ?Vector3{
return $this->vrGazeDirection;
public function getInteractRotation(): Vector2 {
return $this->interactRotation;
}

public function getTick() : int{
Expand Down Expand Up @@ -212,6 +210,10 @@ public function getAnalogMoveVecX() : float{ return $this->analogMoveVecX; }

public function getAnalogMoveVecZ() : float{ return $this->analogMoveVecZ; }

public function getCameraOrientation(): Vector3 {
return $this->cameraOrientation;
}

public function hasFlag(int $flag) : bool{
return ($this->inputFlags & (1 << $flag)) !== 0;
}
Expand All @@ -229,8 +231,13 @@ protected function decodePayload(PacketSerializer $in) : void{
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_527){
$this->interactionMode = $in->getUnsignedVarInt();
}
if($this->playMode === PlayMode::VR){
$this->vrGazeDirection = $in->getVector3();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_748) {
$this->interactRotation = $in->getVector2();
}else{
$this->interactRotation = new Vector2(0, 0);
if($this->playMode === PlayMode::VR) {
$in->getVector3(); // VRGazeDirection
}
}
$this->tick = $in->getUnsignedVarLong();
$this->delta = $in->getVector3();
Expand Down Expand Up @@ -261,6 +268,9 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->analogMoveVecX = $in->getLFloat();
$this->analogMoveVecZ = $in->getLFloat();
}
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_748){
$this->cameraOrientation = $in->getVector3();
}
}

protected function encodePayload(PacketSerializer $out) : void{
Expand All @@ -276,9 +286,12 @@ protected function encodePayload(PacketSerializer $out) : void{
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_527){
$out->putUnsignedVarInt($this->interactionMode);
}
if($this->playMode === PlayMode::VR){
assert($this->vrGazeDirection !== null);
$out->putVector3($this->vrGazeDirection);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_748) {
$out->putVector2($this->interactRotation);
}else{
if($this->playMode === PlayMode::VR) {
$out->putVector3(Vector3::zero());
}
}
$out->putUnsignedVarLong($this->tick);
$out->putVector3($this->delta);
Expand All @@ -304,6 +317,9 @@ protected function encodePayload(PacketSerializer $out) : void{
$out->putLFloat($this->analogMoveVecX);
$out->putLFloat($this->analogMoveVecZ);
}
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_748){
$out->putVector3($this->cameraOrientation);
}
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
8 changes: 5 additions & 3 deletions src/ProtocolInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ private function __construct(){
*/

/** Actual Minecraft: PE protocol version */
public const CURRENT_PROTOCOL = 729;
public const CURRENT_PROTOCOL = 748;
/** Current Minecraft PE version reported by the server. This is usually the earliest currently supported version. */
public const MINECRAFT_VERSION = 'v1.21.30';
public const MINECRAFT_VERSION = 'v1.21.40';
/** Version number sent to clients in ping responses. */
public const MINECRAFT_VERSION_NETWORK = '1.21.30';
public const MINECRAFT_VERSION_NETWORK = '1.21.40';

public const BASE_VERSION = '1.18.0';

public const PROTOCOL_748 = 748; // 1.21.40
public const PROTOCOL_729 = 729; // 1.21.30
public const PROTOCOL_712 = 712; // 1.21.20
public const PROTOCOL_686 = 686; // 1.21.2
Expand Down Expand Up @@ -68,6 +69,7 @@ private function __construct(){
public const PROTOCOL_475 = 475; // v1.18.0

public const COMPATIBLE_PROTOCOL = [
self::PROTOCOL_748,
self::PROTOCOL_729,
self::PROTOCOL_712,
// self::PROTOCOL_686,
Expand Down
4 changes: 2 additions & 2 deletions src/ResourcePacksInfoPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function decodePayload(PacketSerializer $in) : void{
}

$this->cdnUrls = [];
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_618){
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_618 && $in->getProtocol() < ProtocolInfo::PROTOCOL_748){
for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; $i++){
$packId = $in->getString();
$cdnUrl = $in->getString();
Expand Down Expand Up @@ -105,7 +105,7 @@ protected function encodePayload(PacketSerializer $out) : void{
foreach($this->resourcePackEntries as $entry){
$entry->write($out);
}
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_618){
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_618 && $out->getProtocol() < ProtocolInfo::PROTOCOL_748){
$out->putUnsignedVarInt(count($this->cdnUrls));
foreach($this->cdnUrls as $packId => $cdnUrl){
$out->putString($packId);
Expand Down
12 changes: 10 additions & 2 deletions src/UpdatePlayerGameTypePacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,23 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->gameMode = $in->getVarInt();
$this->playerActorUniqueId = $in->getActorUniqueId();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_671){
$this->tick = $in->getUnsignedVarInt();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_748){
$this->tick = $in->getUnsignedVarLong();
}else {
$this->tick = $in->getUnsignedVarInt();
}
}
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putVarInt($this->gameMode);
$out->putActorUniqueId($this->playerActorUniqueId);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_671){
$out->putUnsignedVarInt($this->tick);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_748){
$out->putUnsignedVarLong($this->tick);
}else {
$out->putUnsignedVarInt($this->tick);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/types/PlayerAuthInputFlags.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,10 @@ final class PlayerAuthInputFlags{
public const STOP_FLYING = 43;
public const ACK_ACTOR_DATA = 44;
public const IN_CLIENT_PREDICTED_VEHICLE = 45;
public const START_USING_ITEM = 53;
public const IS_CAMERA_RELATIVE_MOVEMENT_ENABLED = 54;
public const IS_ROT_CONTROLLED_BY_MOVE_DIRECTION = 55;
public const START_SPIN_ATTACK = 56;
public const STOP_SPIN_ATTACK = 57;

}
6 changes: 6 additions & 0 deletions src/types/login/ClientData.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ final class ClientData{
/** @required */
public string $LanguageCode;

/** >= PROTOCOL_748 */
public int $MaxViewDistance;

/** >= PROTOCOL_748 */
public int $MemoryTier;

public bool $OverrideSkin;

/**
Expand Down

0 comments on commit cd22875

Please sign in to comment.