Skip to content

Commit

Permalink
Add 1.21.30 BC support
Browse files Browse the repository at this point in the history
  • Loading branch information
dries-c committed Oct 23, 2024
1 parent 2140246 commit b03df4c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
37 changes: 33 additions & 4 deletions src/PlayerAuthInputPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use pocketmine\network\mcpe\protocol\types\PlayerBlockActionStopBreak;
use pocketmine\network\mcpe\protocol\types\PlayerBlockActionWithBlockInfo;
use pocketmine\network\mcpe\protocol\types\PlayMode;
use function assert;
use function count;

class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{
Expand All @@ -42,6 +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;
Expand Down Expand Up @@ -69,6 +71,7 @@ private static function internalCreate(
int $inputMode,
int $playMode,
int $interactionMode,
?Vector3 $vrGazeDirection,
Vector2 $interactRotation,
int $tick,
Vector3 $delta,
Expand All @@ -91,6 +94,7 @@ private static function internalCreate(
$result->inputMode = $inputMode;
$result->playMode = $playMode;
$result->interactionMode = $interactionMode;
$result->vrGazeDirection = $vrGazeDirection;
$result->interactRotation = $interactRotation;
$result->tick = $tick;
$result->delta = $delta;
Expand All @@ -109,6 +113,7 @@ private static function internalCreate(
* @param int $inputMode @see InputMode
* @param int $playMode @see PlayMode
* @param int $interactionMode @see InteractionMode
* @param Vector3|null $vrGazeDirection only used when PlayMode::VR
* @param PlayerBlockAction[]|null $blockActions Blocks that the client has interacted with
*/
public static function create(
Expand All @@ -122,6 +127,7 @@ public static function create(
int $inputMode,
int $playMode,
int $interactionMode,
?Vector3 $vrGazeDirection,
Vector2 $interactRotation,
int $tick,
Vector3 $delta,
Expand All @@ -133,6 +139,11 @@ public static function create(
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");
}

$realInputFlags = $inputFlags & ~((1 << PlayerAuthInputFlags::PERFORM_ITEM_STACK_REQUEST) | (1 << PlayerAuthInputFlags::PERFORM_ITEM_INTERACTION) | (1 << PlayerAuthInputFlags::PERFORM_BLOCK_ACTIONS));
if($itemStackRequest !== null){
$realInputFlags |= 1 << PlayerAuthInputFlags::PERFORM_ITEM_STACK_REQUEST;
Expand All @@ -155,6 +166,7 @@ public static function create(
$inputMode,
$playMode,
$interactionMode,
$vrGazeDirection?->asVector3(),
$interactRotation,
$tick,
$delta,
Expand Down Expand Up @@ -220,6 +232,10 @@ 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 @@ -268,7 +284,11 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->inputMode = $in->getUnsignedVarInt();
$this->playMode = $in->getUnsignedVarInt();
$this->interactionMode = $in->getUnsignedVarInt();
$this->interactRotation = $in->getVector2();
if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_40){
$this->interactRotation = $in->getVector2();
}elseif($this->playMode === PlayMode::VR){
$this->vrGazeDirection = $in->getVector3();
}
$this->tick = $in->getUnsignedVarLong();
$this->delta = $in->getVector3();
if($this->hasFlag(PlayerAuthInputFlags::PERFORM_ITEM_INTERACTION)){
Expand All @@ -294,7 +314,9 @@ protected function decodePayload(PacketSerializer $in) : void{
}
$this->analogMoveVecX = $in->getLFloat();
$this->analogMoveVecZ = $in->getLFloat();
$this->cameraOrientation = $in->getVector3();
if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_40){
$this->cameraOrientation = $in->getVector3();
}
}

protected function encodePayload(PacketSerializer $out) : void{
Expand All @@ -314,7 +336,12 @@ protected function encodePayload(PacketSerializer $out) : void{
$out->putUnsignedVarInt($this->inputMode);
$out->putUnsignedVarInt($this->playMode);
$out->putUnsignedVarInt($this->interactionMode);
$out->putVector2($this->interactRotation);
if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_40){
$out->putVector2($this->interactRotation);
}elseif($this->playMode === PlayMode::VR){
assert($this->vrGazeDirection !== null);
$out->putVector3($this->vrGazeDirection);
}
$out->putUnsignedVarLong($this->tick);
$out->putVector3($this->delta);
if($this->itemInteractionData !== null){
Expand All @@ -335,7 +362,9 @@ protected function encodePayload(PacketSerializer $out) : void{
}
$out->putLFloat($this->analogMoveVecX);
$out->putLFloat($this->analogMoveVecZ);
$out->putVector3($this->cameraOrientation);
if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_40){
$out->putVector3($this->cameraOrientation);
}
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
4 changes: 2 additions & 2 deletions src/ResourcePacksInfoPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->resourcePackEntries[] = ResourcePackInfoEntry::read($in);
}

if($in->getProtocolId() === ProtocolInfo::PROTOCOL_1_20_30){
if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_20_30 && $in->getProtocolId() < ProtocolInfo::PROTOCOL_1_21_40){
$this->cdnUrls = [];
for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; $i++){
$packId = $in->getString();
Expand All @@ -109,7 +109,7 @@ protected function encodePayload(PacketSerializer $out) : void{
foreach($this->resourcePackEntries as $entry){
$entry->write($out);
}
if($out->getProtocolId() === ProtocolInfo::PROTOCOL_1_20_30){
if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_20_30 && $out->getProtocolId() < ProtocolInfo::PROTOCOL_1_21_40){
$out->putUnsignedVarInt(count($this->cdnUrls));
foreach($this->cdnUrls as $packId => $cdnUrl){
$out->putString($packId);
Expand Down

0 comments on commit b03df4c

Please sign in to comment.