Skip to content

Commit e226413

Browse files
authored
Improvements on 1.21.2 support (#263)
- Added missing `vehicleAngularVelocity` property on `CorrectPlayerMovePredictionPacket` when `predictionType` is `VEHICLE` - Renamed `ServerboundLoadingScreenPacketType` => `LoadingScreenType` - `repetitions` fields are now in a logical sequence on `CraftRecipeAutoStackRequestAction`
1 parent 73def0f commit e226413

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

src/CorrectPlayerMovePredictionPacket.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,37 @@ class CorrectPlayerMovePredictionPacket extends DataPacket implements Clientboun
3030
private int $tick;
3131
private int $predictionType;
3232
private ?Vector2 $vehicleRotation;
33+
private ?float $vehicleAngularVelocity;
3334

3435
/**
3536
* @generate-create-func
3637
*/
37-
private static function internalCreate(Vector3 $position, Vector3 $delta, bool $onGround, int $tick, int $predictionType, ?Vector2 $vehicleRotation) : self{
38+
private static function internalCreate(
39+
Vector3 $position,
40+
Vector3 $delta,
41+
bool $onGround,
42+
int $tick,
43+
int $predictionType,
44+
?Vector2 $vehicleRotation,
45+
?float $vehicleAngularVelocity,
46+
) : self{
3847
$result = new self;
3948
$result->position = $position;
4049
$result->delta = $delta;
4150
$result->onGround = $onGround;
4251
$result->tick = $tick;
4352
$result->predictionType = $predictionType;
4453
$result->vehicleRotation = $vehicleRotation;
54+
$result->vehicleAngularVelocity = $vehicleAngularVelocity;
4555
return $result;
4656
}
4757

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

53-
return self::internalCreate($position, $delta, $onGround, $tick, $predictionType, $vehicleRotation);
63+
return self::internalCreate($position, $delta, $onGround, $tick, $predictionType, $vehicleRotation, $vehicleAngularVelocity);
5464
}
5565

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

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

78+
public function getVehicleAngularVelocity() : ?float{ return $this->vehicleAngularVelocity; }
79+
6880
protected function decodePayload(PacketSerializer $in) : void{
6981
$this->predictionType = $in->getByte();
7082
$this->position = $in->getVector3();
7183
$this->delta = $in->getVector3();
7284
if($this->predictionType === self::PREDICTION_TYPE_VEHICLE){
7385
$this->vehicleRotation = new Vector2($in->getFloat(), $in->getFloat());
86+
$this->vehicleAngularVelocity = $in->readOptional($in->getFloat(...));
7487
}
7588
$this->onGround = $in->getBool();
7689
$this->tick = $in->getUnsignedVarLong();
@@ -87,6 +100,7 @@ protected function encodePayload(PacketSerializer $out) : void{
87100

88101
$out->putFloat($this->vehicleRotation->getX());
89102
$out->putFloat($this->vehicleRotation->getY());
103+
$out->writeOptional($this->vehicleAngularVelocity, $out->putFloat(...));
90104
}
91105
$out->putBool($this->onGround);
92106
$out->putUnsignedVarLong($this->tick);

src/ServerboundLoadingScreenPacket.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@
1515
namespace pocketmine\network\mcpe\protocol;
1616

1717
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
18-
use pocketmine\network\mcpe\protocol\types\hud\ServerboundLoadingScreenPacketType;
18+
use pocketmine\network\mcpe\protocol\types\hud\LoadingScreenType;
1919

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

23-
private ServerboundLoadingScreenPacketType $loadingScreenType;
23+
private LoadingScreenType $loadingScreenType;
2424
private ?int $loadingScreenId = null;
2525

2626
/**
2727
* @generate-create-func
2828
*/
29-
public static function create(ServerboundLoadingScreenPacketType $loadingScreenType, ?int $loadingScreenId) : self{
29+
public static function create(LoadingScreenType $loadingScreenType, ?int $loadingScreenId) : self{
3030
$result = new self;
3131
$result->loadingScreenType = $loadingScreenType;
3232
$result->loadingScreenId = $loadingScreenId;
3333
return $result;
3434
}
3535

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

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

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

src/types/hud/ServerboundLoadingScreenPacketType.php renamed to src/types/hud/LoadingScreenType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

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

19-
enum ServerboundLoadingScreenPacketType : int{
19+
enum LoadingScreenType : int{
2020
use PacketIntEnumTrait;
2121

2222
case UNKNOWN = 0;

src/types/inventory/stackrequest/CraftRecipeAutoStackRequestAction.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ final class CraftRecipeAutoStackRequestAction extends ItemStackRequestAction{
3434
*/
3535
final public function __construct(
3636
private int $recipeId,
37-
private int $repetitions2,
3837
private int $repetitions,
38+
private int $repetitions2,
3939
private array $ingredients
4040
){}
4141

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

5454
public static function read(PacketSerializer $in) : self{
5555
$recipeId = $in->readRecipeNetId();
56-
$repetitions2 = $in->getByte();
5756
$repetitions = $in->getByte();
57+
$repetitions2 = $in->getByte(); //repetitions property is sent twice, mojang...
5858
$ingredients = [];
5959
for($i = 0, $count = $in->getByte(); $i < $count; ++$i){
6060
$ingredients[] = $in->getRecipeIngredient();
6161
}
62-
return new self($recipeId, $repetitions2, $repetitions, $ingredients);
62+
return new self($recipeId, $repetitions, $repetitions2, $ingredients);
6363
}
6464

6565
public function write(PacketSerializer $out) : void{
6666
$out->writeRecipeNetId($this->recipeId);
67-
$out->putByte($this->repetitions2);
6867
$out->putByte($this->repetitions);
68+
$out->putByte($this->repetitions2);
6969
$out->putByte(count($this->ingredients));
7070
foreach($this->ingredients as $ingredient){
7171
$out->putRecipeIngredient($ingredient);

0 commit comments

Comments
 (0)