Skip to content

Commit

Permalink
Improvements on 1.21.2 support (#263)
Browse files Browse the repository at this point in the history
- Added missing `vehicleAngularVelocity` property on `CorrectPlayerMovePredictionPacket` when `predictionType` is `VEHICLE`
- Renamed `ServerboundLoadingScreenPacketType` => `LoadingScreenType`
- `repetitions` fields are now in a logical sequence on `CraftRecipeAutoStackRequestAction`
  • Loading branch information
IvanCraft623 authored Aug 15, 2024
1 parent 73def0f commit e226413
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
20 changes: 17 additions & 3 deletions src/CorrectPlayerMovePredictionPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,37 @@ class CorrectPlayerMovePredictionPacket extends DataPacket implements Clientboun
private int $tick;
private int $predictionType;
private ?Vector2 $vehicleRotation;
private ?float $vehicleAngularVelocity;

/**
* @generate-create-func
*/
private static function internalCreate(Vector3 $position, Vector3 $delta, bool $onGround, int $tick, int $predictionType, ?Vector2 $vehicleRotation) : self{
private static function internalCreate(
Vector3 $position,
Vector3 $delta,
bool $onGround,
int $tick,
int $predictionType,
?Vector2 $vehicleRotation,
?float $vehicleAngularVelocity,
) : self{
$result = new self;
$result->position = $position;
$result->delta = $delta;
$result->onGround = $onGround;
$result->tick = $tick;
$result->predictionType = $predictionType;
$result->vehicleRotation = $vehicleRotation;
$result->vehicleAngularVelocity = $vehicleAngularVelocity;
return $result;
}

public static function create(Vector3 $position, Vector3 $delta, bool $onGround, int $tick, int $predictionType, ?Vector2 $vehicleRotation) : self{
public static function create(Vector3 $position, Vector3 $delta, bool $onGround, int $tick, int $predictionType, ?Vector2 $vehicleRotation, ?float $vehicleAngularVelocity) : self{
if($predictionType === self::PREDICTION_TYPE_VEHICLE && $vehicleRotation === null){
throw new \LogicException("CorrectPlayerMovePredictionPackets with type VEHICLE require a vehicleRotation to be provided");
}

return self::internalCreate($position, $delta, $onGround, $tick, $predictionType, $vehicleRotation);
return self::internalCreate($position, $delta, $onGround, $tick, $predictionType, $vehicleRotation, $vehicleAngularVelocity);
}

public function getPosition() : Vector3{ return $this->position; }
Expand All @@ -65,12 +75,15 @@ public function getPredictionType() : int{ return $this->predictionType; }

public function getVehicleRotation() : ?Vector2{ return $this->vehicleRotation; }

public function getVehicleAngularVelocity() : ?float{ return $this->vehicleAngularVelocity; }

protected function decodePayload(PacketSerializer $in) : void{
$this->predictionType = $in->getByte();
$this->position = $in->getVector3();
$this->delta = $in->getVector3();
if($this->predictionType === self::PREDICTION_TYPE_VEHICLE){
$this->vehicleRotation = new Vector2($in->getFloat(), $in->getFloat());
$this->vehicleAngularVelocity = $in->readOptional($in->getFloat(...));
}
$this->onGround = $in->getBool();
$this->tick = $in->getUnsignedVarLong();
Expand All @@ -87,6 +100,7 @@ protected function encodePayload(PacketSerializer $out) : void{

$out->putFloat($this->vehicleRotation->getX());
$out->putFloat($this->vehicleRotation->getY());
$out->writeOptional($this->vehicleAngularVelocity, $out->putFloat(...));
}
$out->putBool($this->onGround);
$out->putUnsignedVarLong($this->tick);
Expand Down
10 changes: 5 additions & 5 deletions src/ServerboundLoadingScreenPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@
namespace pocketmine\network\mcpe\protocol;

use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\hud\ServerboundLoadingScreenPacketType;
use pocketmine\network\mcpe\protocol\types\hud\LoadingScreenType;

class ServerboundLoadingScreenPacket extends DataPacket implements ServerboundPacket{
public const NETWORK_ID = ProtocolInfo::SERVERBOUND_LOADING_SCREEN_PACKET;

private ServerboundLoadingScreenPacketType $loadingScreenType;
private LoadingScreenType $loadingScreenType;
private ?int $loadingScreenId = null;

/**
* @generate-create-func
*/
public static function create(ServerboundLoadingScreenPacketType $loadingScreenType, ?int $loadingScreenId) : self{
public static function create(LoadingScreenType $loadingScreenType, ?int $loadingScreenId) : self{
$result = new self;
$result->loadingScreenType = $loadingScreenType;
$result->loadingScreenId = $loadingScreenId;
return $result;
}

public function getLoadingScreenType() : ServerboundLoadingScreenPacketType{ return $this->loadingScreenType; }
public function getLoadingScreenType() : LoadingScreenType{ return $this->loadingScreenType; }

public function getLoadingScreenId() : ?int{ return $this->loadingScreenId; }

protected function decodePayload(PacketSerializer $in) : void{
$this->loadingScreenType = ServerboundLoadingScreenPacketType::fromPacket($in->getVarInt());
$this->loadingScreenType = LoadingScreenType::fromPacket($in->getVarInt());
$this->loadingScreenId = $in->readOptional(fn() => $in->getLInt());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use pocketmine\network\mcpe\protocol\types\PacketIntEnumTrait;

enum ServerboundLoadingScreenPacketType : int{
enum LoadingScreenType : int{
use PacketIntEnumTrait;

case UNKNOWN = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ final class CraftRecipeAutoStackRequestAction extends ItemStackRequestAction{
*/
final public function __construct(
private int $recipeId,
private int $repetitions2,
private int $repetitions,
private int $repetitions2,
private array $ingredients
){}

Expand All @@ -53,19 +53,19 @@ public function getIngredients() : array{ return $this->ingredients; }

public static function read(PacketSerializer $in) : self{
$recipeId = $in->readRecipeNetId();
$repetitions2 = $in->getByte();
$repetitions = $in->getByte();
$repetitions2 = $in->getByte(); //repetitions property is sent twice, mojang...
$ingredients = [];
for($i = 0, $count = $in->getByte(); $i < $count; ++$i){
$ingredients[] = $in->getRecipeIngredient();
}
return new self($recipeId, $repetitions2, $repetitions, $ingredients);
return new self($recipeId, $repetitions, $repetitions2, $ingredients);
}

public function write(PacketSerializer $out) : void{
$out->writeRecipeNetId($this->recipeId);
$out->putByte($this->repetitions2);
$out->putByte($this->repetitions);
$out->putByte($this->repetitions2);
$out->putByte(count($this->ingredients));
foreach($this->ingredients as $ingredient){
$out->putRecipeIngredient($ingredient);
Expand Down

0 comments on commit e226413

Please sign in to comment.