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 22, 2024
1 parent 2140246 commit ed2b47d
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions src/PlayerAuthInputPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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 +70,7 @@ private static function internalCreate(
int $inputMode,
int $playMode,
int $interactionMode,
?Vector3 $vrGazeDirection,
Vector2 $interactRotation,
int $tick,
Vector3 $delta,
Expand All @@ -91,6 +93,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,8 +112,9 @@ private static function internalCreate(
* @param int $inputMode @see InputMode
* @param int $playMode @see PlayMode
* @param int $interactionMode @see InteractionMode
* @param PlayerBlockAction[]|null $blockActions Blocks that the client has interacted with
* @param Vector3|null $vrGazeDirection only used when PlayMode::VR
*/
* @param PlayerBlockAction[]|null $blockActions Blocks that the client has interacted with

Check failure on line 117 in src/PlayerAuthInputPacket.php

View workflow job for this annotation

GitHub Actions / Tests (PHP 8.1)

Syntax error, unexpected '*' on line 117

Check failure on line 117 in src/PlayerAuthInputPacket.php

View workflow job for this annotation

GitHub Actions / Tests (PHP 8.2)

Syntax error, unexpected '*' on line 117

Check failure on line 117 in src/PlayerAuthInputPacket.php

View workflow job for this annotation

GitHub Actions / Tests (PHP 8.3)

Syntax error, unexpected '*' on line 117
public static function create(
Vector3 $position,
float $pitch,
Expand All @@ -122,6 +126,7 @@ public static function create(
int $inputMode,
int $playMode,
int $interactionMode,
?Vector3 $vrGazeDirection,
Vector2 $interactRotation,
int $tick,
Vector3 $delta,
Expand All @@ -133,6 +138,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 +165,7 @@ public static function create(
$inputMode,
$playMode,
$interactionMode,
$vrGazeDirection?->asVector3(),
$interactRotation,
$tick,
$delta,
Expand Down Expand Up @@ -220,6 +231,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 +283,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 +313,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 +335,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 +361,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

0 comments on commit ed2b47d

Please sign in to comment.