Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/bedrock-1.21.50'
Browse files Browse the repository at this point in the history
  • Loading branch information
dries-c committed Dec 3, 2024
2 parents b1ad8fa + d55b7fc commit 48d512e
Show file tree
Hide file tree
Showing 28 changed files with 1,413 additions and 48 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/team-pr-auto-approve.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#Due to GitHub awkwardness, it's not easy to reduce the review requirement for collaborators.
#Our policy is that 2 collaborators should be aware of every change.
#For outside PRs, this means 2 collaborator reviews.
#For PRs made by collaborators, this means 1 reviewer + the author.
#We trust that collaborators don't need as much oversight.
name: Auto approve collaborator PRs

on:
pull_request_target:
types:
- opened
- synchronize
- reopened
- ready_for_review

jobs:
dispatch:
name: Request approval
runs-on: ubuntu-latest

steps:
- name: Generate access token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.RESTRICTED_ACTIONS_DISPATCH_ID }}
private-key: ${{ secrets.RESTRICTED_ACTIONS_DISPATCH_KEY }}
owner: ${{ github.repository_owner }}
repositories: RestrictedActions

- name: Dispatch restricted action
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ steps.generate-token.outputs.token }}
repository: ${{ github.repository_owner }}/RestrictedActions
event-type: auto_approve_collaborator_pr
client-payload: '{"repo": "${{ github.repository }}", "pull_request_id": "${{ github.event.pull_request.number }}" }'
8 changes: 7 additions & 1 deletion src/CameraAimAssistPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
class CameraAimAssistPacket extends DataPacket implements ClientboundPacket{
public const NETWORK_ID = ProtocolInfo::CAMERA_AIM_ASSIST_PACKET;

private string $presetId;
private Vector2 $viewAngle;
private float $distance;
private CameraAimAssistTargetMode $targetMode;
Expand All @@ -30,15 +31,18 @@ class CameraAimAssistPacket extends DataPacket implements ClientboundPacket{
/**
* @generate-create-func
*/
public static function create(Vector2 $viewAngle, float $distance, CameraAimAssistTargetMode $targetMode, CameraAimAssistActionType $actionType) : self{
public static function create(string $presetId, Vector2 $viewAngle, float $distance, CameraAimAssistTargetMode $targetMode, CameraAimAssistActionType $actionType) : self{
$result = new self;
$result->presetId = $presetId;
$result->viewAngle = $viewAngle;
$result->distance = $distance;
$result->targetMode = $targetMode;
$result->actionType = $actionType;
return $result;
}

public function getPresetId() : string{ return $this->presetId; }

public function getViewAngle() : Vector2{ return $this->viewAngle; }

public function getDistance() : float{ return $this->distance; }
Expand All @@ -48,13 +52,15 @@ public function getTargetMode() : CameraAimAssistTargetMode{ return $this->targe
public function getActionType() : CameraAimAssistActionType{ return $this->actionType; }

protected function decodePayload(PacketSerializer $in) : void{
$this->presetId = $in->getString();
$this->viewAngle = $in->getVector2();
$this->distance = $in->getLFloat();
$this->targetMode = CameraAimAssistTargetMode::fromPacket($in->getByte());
$this->actionType = CameraAimAssistActionType::fromPacket($in->getByte());
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putString($this->presetId);
$out->putVector2($this->viewAngle);
$out->putLFloat($this->distance);
$out->putByte($this->targetMode->value);
Expand Down
79 changes: 79 additions & 0 deletions src/CameraAimAssistPresetsPacket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

/*
* This file is part of BedrockProtocol.
* Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
*
* BedrockProtocol is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/

declare(strict_types=1);

namespace pocketmine\network\mcpe\protocol;

use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\camera\CameraAimAssistCategories;
use pocketmine\network\mcpe\protocol\types\camera\CameraAimAssistPreset;
use function count;

class CameraAimAssistPresetsPacket extends DataPacket implements ClientboundPacket{
public const NETWORK_ID = ProtocolInfo::CAMERA_AIM_ASSIST_PRESETS_PACKET;

/** @var CameraAimAssistCategories[] */
private array $categories;
/** @var CameraAimAssistPreset[] */
private array $presets;

/**
* @generate-create-func
* @param CameraAimAssistCategories[] $categories
* @param CameraAimAssistPreset[] $presets
*/
public static function create(array $categories, array $presets) : self{
$result = new self;
$result->categories = $categories;
$result->presets = $presets;
return $result;
}

/**
* @return CameraAimAssistCategories[]
*/
public function getCategories() : array{ return $this->categories; }

/**
* @return CameraAimAssistPreset[]
*/
public function getPresets() : array{ return $this->presets; }

protected function decodePayload(PacketSerializer $in) : void{
$this->categories = [];
for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){
$this->categories[] = CameraAimAssistCategories::read($in);
}

$this->presets = [];
for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){
$this->presets[] = CameraAimAssistPreset::read($in);
}
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putUnsignedVarInt(count($this->categories));
foreach($this->categories as $category){
$category->write($out);
}

$out->putUnsignedVarInt(count($this->presets));
foreach($this->presets as $preset){
$preset->write($out);
}
}

public function handle(PacketHandlerInterface $handler) : bool{
return $handler->handleCameraAimAssistPresets($this);
}
}
2 changes: 2 additions & 0 deletions src/PacketHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,4 +429,6 @@ public function handleContainerRegistryCleanup(ContainerRegistryCleanupPacket $p
public function handleMovementEffect(MovementEffectPacket $packet) : bool;

public function handleSetMovementAuthority(SetMovementAuthorityPacket $packet) : bool;

public function handleCameraAimAssistPresets(CameraAimAssistPresetsPacket $packet) : bool;
}
1 change: 1 addition & 0 deletions src/PacketPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public function __construct(){
$this->registerPacket(new ContainerRegistryCleanupPacket());
$this->registerPacket(new MovementEffectPacket());
$this->registerPacket(new SetMovementAuthorityPacket());
$this->registerPacket(new CameraAimAssistPresetsPacket());
}

public function registerPacket(Packet $packet) : void{
Expand Down
65 changes: 32 additions & 33 deletions src/PlayerAuthInputPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use pocketmine\math\Vector2;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\serializer\BitSet;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\InputMode;
use pocketmine\network\mcpe\protocol\types\InteractionMode;
Expand All @@ -39,7 +40,7 @@ class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{
private float $headYaw;
private float $moveVecX;
private float $moveVecZ;
private int $inputFlags;
private BitSet $inputFlags;
private int $inputMode;
private int $playMode;
private int $interactionMode;
Expand All @@ -55,6 +56,7 @@ class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{
private float $analogMoveVecX;
private float $analogMoveVecZ;
private Vector3 $cameraOrientation;
private Vector2 $rawMove;

/**
* @generate-create-func
Expand All @@ -67,7 +69,7 @@ private static function internalCreate(
float $headYaw,
float $moveVecX,
float $moveVecZ,
int $inputFlags,
BitSet $inputFlags,
int $inputMode,
int $playMode,
int $interactionMode,
Expand All @@ -82,6 +84,7 @@ private static function internalCreate(
float $analogMoveVecX,
float $analogMoveVecZ,
Vector3 $cameraOrientation,
Vector2 $rawMove,
) : self{
$result = new self;
$result->position = $position;
Expand All @@ -105,15 +108,15 @@ private static function internalCreate(
$result->analogMoveVecX = $analogMoveVecX;
$result->analogMoveVecZ = $analogMoveVecZ;
$result->cameraOrientation = $cameraOrientation;
$result->rawMove = $rawMove;
return $result;
}

/**
* @param int $inputFlags @see PlayerAuthInputFlags
* @param BitSet $inputFlags @see PlayerAuthInputFlags
* @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 @@ -123,7 +126,7 @@ public static function create(
float $headYaw,
float $moveVecX,
float $moveVecZ,
int $inputFlags,
BitSet $inputFlags,
int $inputMode,
int $playMode,
int $interactionMode,
Expand All @@ -137,23 +140,18 @@ public static function create(
?PlayerAuthInputVehicleInfo $vehicleInfo,
float $analogMoveVecX,
float $analogMoveVecZ,
Vector3 $cameraOrientation
Vector3 $cameraOrientation,
Vector2 $rawMove
) : 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;
}
if($itemInteractionData !== null){
$realInputFlags |= 1 << PlayerAuthInputFlags::PERFORM_ITEM_INTERACTION;
}
if($blockActions !== null){
$realInputFlags |= 1 << PlayerAuthInputFlags::PERFORM_BLOCK_ACTIONS;
}
$inputFlags->set(PlayerAuthInputFlags::PERFORM_ITEM_STACK_REQUEST, $itemStackRequest !== null);
$inputFlags->set(PlayerAuthInputFlags::PERFORM_ITEM_INTERACTION, $itemInteractionData !== null);
$inputFlags->set(PlayerAuthInputFlags::PERFORM_BLOCK_ACTIONS, $blockActions !== null);
$inputFlags->set(PlayerAuthInputFlags::IN_CLIENT_PREDICTED_VEHICLE, $vehicleInfo !== null);

return self::internalCreate(
$position,
Expand All @@ -162,7 +160,7 @@ public static function create(
$headYaw,
$moveVecX,
$moveVecZ,
$realInputFlags,
$inputFlags,
$inputMode,
$playMode,
$interactionMode,
Expand All @@ -176,7 +174,8 @@ public static function create(
$vehicleInfo,
$analogMoveVecX,
$analogMoveVecZ,
$cameraOrientation
$cameraOrientation,
$rawMove
);
}

Expand Down Expand Up @@ -207,7 +206,7 @@ public function getMoveVecZ() : float{
/**
* @see PlayerAuthInputFlags
*/
public function getInputFlags() : int{
public function getInputFlags() : BitSet{
return $this->inputFlags;
}

Expand All @@ -232,10 +231,6 @@ 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 @@ -269,9 +264,7 @@ 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;
}
public function getRawMove() : Vector2{ return $this->rawMove; }

protected function decodePayload(PacketSerializer $in) : void{
$this->pitch = $in->getLFloat();
Expand All @@ -280,7 +273,7 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->moveVecX = $in->getLFloat();
$this->moveVecZ = $in->getLFloat();
$this->headYaw = $in->getLFloat();
$this->inputFlags = $in->getUnsignedVarLong();
$this->inputFlags = BitSet::read($in, $in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_50 ? 65 : 64);
$this->inputMode = $in->getUnsignedVarInt();
$this->playMode = $in->getUnsignedVarInt();
$this->interactionMode = $in->getUnsignedVarInt();
Expand All @@ -291,13 +284,13 @@ protected function decodePayload(PacketSerializer $in) : void{
}
$this->tick = $in->getUnsignedVarLong();
$this->delta = $in->getVector3();
if($this->hasFlag(PlayerAuthInputFlags::PERFORM_ITEM_INTERACTION)){
if($this->inputFlags->get(PlayerAuthInputFlags::PERFORM_ITEM_INTERACTION)){
$this->itemInteractionData = ItemInteractionData::read($in);
}
if($this->hasFlag(PlayerAuthInputFlags::PERFORM_ITEM_STACK_REQUEST)){
if($this->inputFlags->get(PlayerAuthInputFlags::PERFORM_ITEM_STACK_REQUEST)){
$this->itemStackRequest = ItemStackRequest::read($in);
}
if($this->hasFlag(PlayerAuthInputFlags::PERFORM_BLOCK_ACTIONS)){
if($this->inputFlags->get(PlayerAuthInputFlags::PERFORM_BLOCK_ACTIONS)){
$this->blockActions = [];
$max = $in->getVarInt();
for($i = 0; $i < $max; ++$i){
Expand All @@ -309,21 +302,24 @@ protected function decodePayload(PacketSerializer $in) : void{
};
}
}
if($this->hasFlag(PlayerAuthInputFlags::IN_CLIENT_PREDICTED_VEHICLE) && $in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_20_60){
if($this->inputFlags->get(PlayerAuthInputFlags::IN_CLIENT_PREDICTED_VEHICLE) && $in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_20_60){
$this->vehicleInfo = PlayerAuthInputVehicleInfo::read($in);
}
$this->analogMoveVecX = $in->getLFloat();
$this->analogMoveVecZ = $in->getLFloat();
if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_40){
$this->cameraOrientation = $in->getVector3();
if($in->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_50){
$this->rawMove = $in->getVector2();
}
}
}

protected function encodePayload(PacketSerializer $out) : void{
$inputFlags = $this->inputFlags;

if($this->vehicleInfo !== null && $out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_20_60){
$inputFlags |= 1 << PlayerAuthInputFlags::IN_CLIENT_PREDICTED_VEHICLE;
$inputFlags->set(PlayerAuthInputFlags::IN_CLIENT_PREDICTED_VEHICLE, true);
}

$out->putLFloat($this->pitch);
Expand All @@ -332,7 +328,7 @@ protected function encodePayload(PacketSerializer $out) : void{
$out->putLFloat($this->moveVecX);
$out->putLFloat($this->moveVecZ);
$out->putLFloat($this->headYaw);
$out->putUnsignedVarLong($inputFlags);
$this->inputFlags->write($out, $out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_50 ? 65 : 64);
$out->putUnsignedVarInt($this->inputMode);
$out->putUnsignedVarInt($this->playMode);
$out->putUnsignedVarInt($this->interactionMode);
Expand Down Expand Up @@ -364,6 +360,9 @@ protected function encodePayload(PacketSerializer $out) : void{
$out->putLFloat($this->analogMoveVecZ);
if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_40){
$out->putVector3($this->cameraOrientation);
if($out->getProtocolId() >= ProtocolInfo::PROTOCOL_1_21_50){
$out->putVector2($this->rawMove);
}
}
}

Expand Down
Loading

0 comments on commit 48d512e

Please sign in to comment.