Skip to content

Commit 43d2711

Browse files
committed
Protocol changes for 1.21.40
1 parent 440c807 commit 43d2711

21 files changed

+266
-70
lines changed

src/CraftingDataPacket.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CraftingDataPacket extends DataPacket implements ClientboundPacket{
3636
public const ENTRY_FURNACE = 2;
3737
public const ENTRY_FURNACE_DATA = 3;
3838
public const ENTRY_MULTI = 4;
39-
public const ENTRY_SHULKER_BOX = 5;
39+
public const ENTRY_USER_DATA_SHAPELESS = 5;
4040
public const ENTRY_SHAPELESS_CHEMISTRY = 6;
4141
public const ENTRY_SHAPED_CHEMISTRY = 7;
4242
public const ENTRY_SMITHING_TRANSFORM = 8;
@@ -76,7 +76,7 @@ protected function decodePayload(PacketSerializer $in) : void{
7676
$recipeType = $in->getVarInt();
7777

7878
$this->recipesWithTypeIds[] = match($recipeType){
79-
self::ENTRY_SHAPELESS, self::ENTRY_SHULKER_BOX, self::ENTRY_SHAPELESS_CHEMISTRY => ShapelessRecipe::decode($recipeType, $in),
79+
self::ENTRY_SHAPELESS, self::ENTRY_USER_DATA_SHAPELESS, self::ENTRY_SHAPELESS_CHEMISTRY => ShapelessRecipe::decode($recipeType, $in),
8080
self::ENTRY_SHAPED, self::ENTRY_SHAPED_CHEMISTRY => ShapedRecipe::decode($recipeType, $in),
8181
self::ENTRY_FURNACE, self::ENTRY_FURNACE_DATA => FurnaceRecipe::decode($recipeType, $in),
8282
self::ENTRY_MULTI => MultiRecipe::decode($recipeType, $in),

src/InventoryContentPacket.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ class InventoryContentPacket extends DataPacket implements ClientboundPacket{
2626
/** @var ItemStackWrapper[] */
2727
public array $items = [];
2828
public FullContainerName $containerName;
29-
public int $dynamicContainerSize;
29+
public ItemStackWrapper $storage;
3030

3131
/**
3232
* @generate-create-func
3333
* @param ItemStackWrapper[] $items
3434
*/
35-
public static function create(int $windowId, array $items, FullContainerName $containerName, int $dynamicContainerSize) : self{
35+
public static function create(int $windowId, array $items, FullContainerName $containerName, ItemStackWrapper $storage) : self{
3636
$result = new self;
3737
$result->windowId = $windowId;
3838
$result->items = $items;
3939
$result->containerName = $containerName;
40-
$result->dynamicContainerSize = $dynamicContainerSize;
40+
$result->storage = $storage;
4141
return $result;
4242
}
4343

@@ -48,7 +48,7 @@ protected function decodePayload(PacketSerializer $in) : void{
4848
$this->items[] = $in->getItemStackWrapper();
4949
}
5050
$this->containerName = FullContainerName::read($in);
51-
$this->dynamicContainerSize = $in->getUnsignedVarInt();
51+
$this->storage = $in->getItemStackWrapper();
5252
}
5353

5454
protected function encodePayload(PacketSerializer $out) : void{
@@ -58,7 +58,7 @@ protected function encodePayload(PacketSerializer $out) : void{
5858
$out->putItemStackWrapper($item);
5959
}
6060
$this->containerName->write($out);
61-
$out->putUnsignedVarInt($this->dynamicContainerSize);
61+
$out->putItemStackWrapper($this->storage);
6262
}
6363

6464
public function handle(PacketHandlerInterface $handler) : bool{

src/InventorySlotPacket.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ class InventorySlotPacket extends DataPacket implements ClientboundPacket{
2424
public int $windowId;
2525
public int $inventorySlot;
2626
public FullContainerName $containerName;
27-
public int $dynamicContainerSize;
27+
public ItemStackWrapper $storage;
2828
public ItemStackWrapper $item;
2929

3030
/**
3131
* @generate-create-func
3232
*/
33-
public static function create(int $windowId, int $inventorySlot, FullContainerName $containerName, int $dynamicContainerSize, ItemStackWrapper $item) : self{
33+
public static function create(int $windowId, int $inventorySlot, FullContainerName $containerName, ItemStackWrapper $storage, ItemStackWrapper $item) : self{
3434
$result = new self;
3535
$result->windowId = $windowId;
3636
$result->inventorySlot = $inventorySlot;
3737
$result->containerName = $containerName;
38-
$result->dynamicContainerSize = $dynamicContainerSize;
38+
$result->storage = $storage;
3939
$result->item = $item;
4040
return $result;
4141
}
@@ -44,15 +44,15 @@ protected function decodePayload(PacketSerializer $in) : void{
4444
$this->windowId = $in->getUnsignedVarInt();
4545
$this->inventorySlot = $in->getUnsignedVarInt();
4646
$this->containerName = FullContainerName::read($in);
47-
$this->dynamicContainerSize = $in->getUnsignedVarInt();
47+
$this->storage = $in->getItemStackWrapper();
4848
$this->item = $in->getItemStackWrapper();
4949
}
5050

5151
protected function encodePayload(PacketSerializer $out) : void{
5252
$out->putUnsignedVarInt($this->windowId);
5353
$out->putUnsignedVarInt($this->inventorySlot);
5454
$this->containerName->write($out);
55-
$out->putUnsignedVarInt($this->dynamicContainerSize);
55+
$out->putItemStackWrapper($this->storage);
5656
$out->putItemStackWrapper($this->item);
5757
}
5858

src/MobEffectPacket.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected function decodePayload(PacketSerializer $in) : void{
6969
$this->amplifier = $in->getVarInt();
7070
$this->particles = $in->getBool();
7171
$this->duration = $in->getVarInt();
72-
$this->tick = $in->getLLong();
72+
$this->tick = $in->getUnsignedVarLong();
7373
}
7474

7575
protected function encodePayload(PacketSerializer $out) : void{
@@ -79,7 +79,7 @@ protected function encodePayload(PacketSerializer $out) : void{
7979
$out->putVarInt($this->amplifier);
8080
$out->putBool($this->particles);
8181
$out->putVarInt($this->duration);
82-
$out->putLLong($this->tick);
82+
$out->putUnsignedVarLong($this->tick);
8383
}
8484

8585
public function handle(PacketHandlerInterface $handler) : bool{

src/MovementEffectPacket.php

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
/*
4+
* This file is part of BedrockProtocol.
5+
* Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6+
*
7+
* BedrockProtocol is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*/
12+
13+
declare(strict_types=1);
14+
15+
namespace pocketmine\network\mcpe\protocol;
16+
17+
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
18+
use pocketmine\network\mcpe\protocol\types\MovementEffectType;
19+
20+
class MovementEffectPacket extends DataPacket implements ClientboundPacket{
21+
public const NETWORK_ID = ProtocolInfo::MOVEMENT_EFFECT_PACKET;
22+
23+
private int $actorRuntimeId;
24+
private MovementEffectType $effectType;
25+
private int $duration;
26+
private int $tick;
27+
28+
/**
29+
* @generate-create-func
30+
*/
31+
public static function create(int $actorRuntimeId, MovementEffectType $effectType, int $duration, int $tick) : self{
32+
$result = new self;
33+
$result->actorRuntimeId = $actorRuntimeId;
34+
$result->effectType = $effectType;
35+
$result->duration = $duration;
36+
$result->tick = $tick;
37+
return $result;
38+
}
39+
40+
public function getActorRuntimeId() : int{ return $this->actorRuntimeId; }
41+
42+
public function getEffectType() : MovementEffectType{ return $this->effectType; }
43+
44+
public function getDuration() : int{ return $this->duration; }
45+
46+
public function getTick() : int{ return $this->tick; }
47+
48+
protected function decodePayload(PacketSerializer $in) : void{
49+
$this->actorRuntimeId = $in->getActorRuntimeId();
50+
$this->effectType = MovementEffectType::fromPacket($in->getUnsignedVarInt());
51+
$this->duration = $in->getUnsignedVarInt();
52+
$this->tick = $in->getUnsignedVarLong();
53+
}
54+
55+
protected function encodePayload(PacketSerializer $out) : void{
56+
$out->putActorRuntimeId($this->actorRuntimeId);
57+
$out->putUnsignedVarInt($this->effectType->value);
58+
$out->putUnsignedVarInt($this->duration);
59+
$out->putUnsignedVarLong($this->tick);
60+
}
61+
62+
public function handle(PacketHandlerInterface $handler) : bool{
63+
return $handler->handleMovementEffect($this);
64+
}
65+
}

src/PacketHandlerDefaultImplTrait.php

+8
Original file line numberDiff line numberDiff line change
@@ -829,4 +829,12 @@ public function handleCameraAimAssist(CameraAimAssistPacket $packet) : bool{
829829
public function handleContainerRegistryCleanup(ContainerRegistryCleanupPacket $packet) : bool{
830830
return false;
831831
}
832+
833+
public function handleMovementEffect(MovementEffectPacket $packet) : bool{
834+
return false;
835+
}
836+
837+
public function handleSetMovementAuthority(SetMovementAuthorityPacket $packet) : bool{
838+
return false;
839+
}
832840
}

src/PacketHandlerInterface.php

+4
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,8 @@ public function handleServerboundDiagnostics(ServerboundDiagnosticsPacket $packe
421421
public function handleCameraAimAssist(CameraAimAssistPacket $packet) : bool;
422422

423423
public function handleContainerRegistryCleanup(ContainerRegistryCleanupPacket $packet) : bool;
424+
425+
public function handleMovementEffect(MovementEffectPacket $packet) : bool;
426+
427+
public function handleSetMovementAuthority(SetMovementAuthorityPacket $packet) : bool;
424428
}

src/PlayerAuthInputPacket.php

+20-24
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace pocketmine\network\mcpe\protocol;
1616

17+
use pocketmine\math\Vector2;
1718
use pocketmine\math\Vector3;
1819
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
1920
use pocketmine\network\mcpe\protocol\types\InputMode;
@@ -26,7 +27,6 @@
2627
use pocketmine\network\mcpe\protocol\types\PlayerBlockActionStopBreak;
2728
use pocketmine\network\mcpe\protocol\types\PlayerBlockActionWithBlockInfo;
2829
use pocketmine\network\mcpe\protocol\types\PlayMode;
29-
use function assert;
3030
use function count;
3131

3232
class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{
@@ -42,7 +42,7 @@ class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{
4242
private int $inputMode;
4343
private int $playMode;
4444
private int $interactionMode;
45-
private ?Vector3 $vrGazeDirection = null;
45+
private Vector2 $interactRotation;
4646
private int $tick;
4747
private Vector3 $delta;
4848
private ?ItemInteractionData $itemInteractionData = null;
@@ -52,6 +52,7 @@ class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{
5252
private ?PlayerAuthInputVehicleInfo $vehicleInfo = null;
5353
private float $analogMoveVecX;
5454
private float $analogMoveVecZ;
55+
private Vector3 $cameraOrientation;
5556

5657
/**
5758
* @generate-create-func
@@ -68,7 +69,7 @@ private static function internalCreate(
6869
int $inputMode,
6970
int $playMode,
7071
int $interactionMode,
71-
?Vector3 $vrGazeDirection,
72+
Vector2 $interactRotation,
7273
int $tick,
7374
Vector3 $delta,
7475
?ItemInteractionData $itemInteractionData,
@@ -77,6 +78,7 @@ private static function internalCreate(
7778
?PlayerAuthInputVehicleInfo $vehicleInfo,
7879
float $analogMoveVecX,
7980
float $analogMoveVecZ,
81+
Vector3 $cameraOrientation,
8082
) : self{
8183
$result = new self;
8284
$result->position = $position;
@@ -89,7 +91,7 @@ private static function internalCreate(
8991
$result->inputMode = $inputMode;
9092
$result->playMode = $playMode;
9193
$result->interactionMode = $interactionMode;
92-
$result->vrGazeDirection = $vrGazeDirection;
94+
$result->interactRotation = $interactRotation;
9395
$result->tick = $tick;
9496
$result->delta = $delta;
9597
$result->itemInteractionData = $itemInteractionData;
@@ -98,6 +100,7 @@ private static function internalCreate(
98100
$result->vehicleInfo = $vehicleInfo;
99101
$result->analogMoveVecX = $analogMoveVecX;
100102
$result->analogMoveVecZ = $analogMoveVecZ;
103+
$result->cameraOrientation = $cameraOrientation;
101104
return $result;
102105
}
103106

@@ -106,7 +109,6 @@ private static function internalCreate(
106109
* @param int $inputMode @see InputMode
107110
* @param int $playMode @see PlayMode
108111
* @param int $interactionMode @see InteractionMode
109-
* @param Vector3|null $vrGazeDirection only used when PlayMode::VR
110112
* @param PlayerBlockAction[]|null $blockActions Blocks that the client has interacted with
111113
*/
112114
public static function create(
@@ -120,21 +122,17 @@ public static function create(
120122
int $inputMode,
121123
int $playMode,
122124
int $interactionMode,
123-
?Vector3 $vrGazeDirection,
125+
Vector2 $interactRotation,
124126
int $tick,
125127
Vector3 $delta,
126128
?ItemInteractionData $itemInteractionData,
127129
?ItemStackRequest $itemStackRequest,
128130
?array $blockActions,
129131
?PlayerAuthInputVehicleInfo $vehicleInfo,
130132
float $analogMoveVecX,
131-
float $analogMoveVecZ
133+
float $analogMoveVecZ,
134+
Vector3 $cameraOrientation
132135
) : self{
133-
if($playMode === PlayMode::VR and $vrGazeDirection === null){
134-
//yuck, can we get a properly written packet just once? ...
135-
throw new \InvalidArgumentException("Gaze direction must be provided for VR play mode");
136-
}
137-
138136
$realInputFlags = $inputFlags & ~((1 << PlayerAuthInputFlags::PERFORM_ITEM_STACK_REQUEST) | (1 << PlayerAuthInputFlags::PERFORM_ITEM_INTERACTION) | (1 << PlayerAuthInputFlags::PERFORM_BLOCK_ACTIONS));
139137
if($itemStackRequest !== null){
140138
$realInputFlags |= 1 << PlayerAuthInputFlags::PERFORM_ITEM_STACK_REQUEST;
@@ -160,15 +158,16 @@ public static function create(
160158
$inputMode,
161159
$playMode,
162160
$interactionMode,
163-
$vrGazeDirection?->asVector3(),
161+
$interactRotation,
164162
$tick,
165163
$delta,
166164
$itemInteractionData,
167165
$itemStackRequest,
168166
$blockActions,
169167
$vehicleInfo,
170168
$analogMoveVecX,
171-
$analogMoveVecZ
169+
$analogMoveVecZ,
170+
$cameraOrientation
172171
);
173172
}
174173

@@ -224,9 +223,7 @@ public function getInteractionMode() : int{
224223
return $this->interactionMode;
225224
}
226225

227-
public function getVrGazeDirection() : ?Vector3{
228-
return $this->vrGazeDirection;
229-
}
226+
public function getInteractRotation() : Vector2{ return $this->interactRotation; }
230227

231228
public function getTick() : int{
232229
return $this->tick;
@@ -257,6 +254,8 @@ public function getAnalogMoveVecX() : float{ return $this->analogMoveVecX; }
257254

258255
public function getAnalogMoveVecZ() : float{ return $this->analogMoveVecZ; }
259256

257+
public function getCameraOrientation() : Vector3{ return $this->cameraOrientation; }
258+
260259
public function hasFlag(int $flag) : bool{
261260
return ($this->inputFlags & (1 << $flag)) !== 0;
262261
}
@@ -272,9 +271,7 @@ protected function decodePayload(PacketSerializer $in) : void{
272271
$this->inputMode = $in->getUnsignedVarInt();
273272
$this->playMode = $in->getUnsignedVarInt();
274273
$this->interactionMode = $in->getUnsignedVarInt();
275-
if($this->playMode === PlayMode::VR){
276-
$this->vrGazeDirection = $in->getVector3();
277-
}
274+
$this->interactRotation = $in->getVector2();
278275
$this->tick = $in->getUnsignedVarLong();
279276
$this->delta = $in->getVector3();
280277
if($this->hasFlag(PlayerAuthInputFlags::PERFORM_ITEM_INTERACTION)){
@@ -300,6 +297,7 @@ protected function decodePayload(PacketSerializer $in) : void{
300297
}
301298
$this->analogMoveVecX = $in->getLFloat();
302299
$this->analogMoveVecZ = $in->getLFloat();
300+
$this->cameraOrientation = $in->getVector3();
303301
}
304302

305303
protected function encodePayload(PacketSerializer $out) : void{
@@ -313,10 +311,7 @@ protected function encodePayload(PacketSerializer $out) : void{
313311
$out->putUnsignedVarInt($this->inputMode);
314312
$out->putUnsignedVarInt($this->playMode);
315313
$out->putUnsignedVarInt($this->interactionMode);
316-
if($this->playMode === PlayMode::VR){
317-
assert($this->vrGazeDirection !== null);
318-
$out->putVector3($this->vrGazeDirection);
319-
}
314+
$out->putVector2($this->interactRotation);
320315
$out->putUnsignedVarLong($this->tick);
321316
$out->putVector3($this->delta);
322317
if($this->itemInteractionData !== null){
@@ -337,6 +332,7 @@ protected function encodePayload(PacketSerializer $out) : void{
337332
}
338333
$out->putLFloat($this->analogMoveVecX);
339334
$out->putLFloat($this->analogMoveVecZ);
335+
$out->putVector3($this->cameraOrientation);
340336
}
341337

342338
public function handle(PacketHandlerInterface $handler) : bool{

0 commit comments

Comments
 (0)