Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protocol changes for 1.21.40 #277

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/CraftingDataPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CraftingDataPacket extends DataPacket implements ClientboundPacket{
public const ENTRY_FURNACE = 2;
public const ENTRY_FURNACE_DATA = 3;
public const ENTRY_MULTI = 4;
public const ENTRY_SHULKER_BOX = 5;
public const ENTRY_USER_DATA_SHAPELESS = 5;
public const ENTRY_SHAPELESS_CHEMISTRY = 6;
public const ENTRY_SHAPED_CHEMISTRY = 7;
public const ENTRY_SMITHING_TRANSFORM = 8;
Expand Down Expand Up @@ -76,7 +76,7 @@ protected function decodePayload(PacketSerializer $in) : void{
$recipeType = $in->getVarInt();

$this->recipesWithTypeIds[] = match($recipeType){
self::ENTRY_SHAPELESS, self::ENTRY_SHULKER_BOX, self::ENTRY_SHAPELESS_CHEMISTRY => ShapelessRecipe::decode($recipeType, $in),
self::ENTRY_SHAPELESS, self::ENTRY_USER_DATA_SHAPELESS, self::ENTRY_SHAPELESS_CHEMISTRY => ShapelessRecipe::decode($recipeType, $in),
self::ENTRY_SHAPED, self::ENTRY_SHAPED_CHEMISTRY => ShapedRecipe::decode($recipeType, $in),
self::ENTRY_FURNACE, self::ENTRY_FURNACE_DATA => FurnaceRecipe::decode($recipeType, $in),
self::ENTRY_MULTI => MultiRecipe::decode($recipeType, $in),
Expand Down
10 changes: 5 additions & 5 deletions src/InventoryContentPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ class InventoryContentPacket extends DataPacket implements ClientboundPacket{
/** @var ItemStackWrapper[] */
public array $items = [];
public FullContainerName $containerName;
public int $dynamicContainerSize;
public ItemStackWrapper $storage;

/**
* @generate-create-func
* @param ItemStackWrapper[] $items
*/
public static function create(int $windowId, array $items, FullContainerName $containerName, int $dynamicContainerSize) : self{
public static function create(int $windowId, array $items, FullContainerName $containerName, ItemStackWrapper $storage) : self{
$result = new self;
$result->windowId = $windowId;
$result->items = $items;
$result->containerName = $containerName;
$result->dynamicContainerSize = $dynamicContainerSize;
$result->storage = $storage;
return $result;
}

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

protected function encodePayload(PacketSerializer $out) : void{
Expand All @@ -58,7 +58,7 @@ protected function encodePayload(PacketSerializer $out) : void{
$out->putItemStackWrapper($item);
}
$this->containerName->write($out);
$out->putUnsignedVarInt($this->dynamicContainerSize);
$out->putItemStackWrapper($this->storage);
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
10 changes: 5 additions & 5 deletions src/InventorySlotPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ class InventorySlotPacket extends DataPacket implements ClientboundPacket{
public int $windowId;
public int $inventorySlot;
public FullContainerName $containerName;
public int $dynamicContainerSize;
public ItemStackWrapper $storage;
public ItemStackWrapper $item;

/**
* @generate-create-func
*/
public static function create(int $windowId, int $inventorySlot, FullContainerName $containerName, int $dynamicContainerSize, ItemStackWrapper $item) : self{
public static function create(int $windowId, int $inventorySlot, FullContainerName $containerName, ItemStackWrapper $storage, ItemStackWrapper $item) : self{
$result = new self;
$result->windowId = $windowId;
$result->inventorySlot = $inventorySlot;
$result->containerName = $containerName;
$result->dynamicContainerSize = $dynamicContainerSize;
$result->storage = $storage;
$result->item = $item;
return $result;
}
Expand All @@ -44,15 +44,15 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->windowId = $in->getUnsignedVarInt();
$this->inventorySlot = $in->getUnsignedVarInt();
$this->containerName = FullContainerName::read($in);
$this->dynamicContainerSize = $in->getUnsignedVarInt();
$this->storage = $in->getItemStackWrapper();
$this->item = $in->getItemStackWrapper();
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putUnsignedVarInt($this->windowId);
$out->putUnsignedVarInt($this->inventorySlot);
$this->containerName->write($out);
$out->putUnsignedVarInt($this->dynamicContainerSize);
$out->putItemStackWrapper($this->storage);
$out->putItemStackWrapper($this->item);
}

Expand Down
4 changes: 2 additions & 2 deletions src/MobEffectPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->amplifier = $in->getVarInt();
$this->particles = $in->getBool();
$this->duration = $in->getVarInt();
$this->tick = $in->getLLong();
$this->tick = $in->getUnsignedVarLong();
}

protected function encodePayload(PacketSerializer $out) : void{
Expand All @@ -79,7 +79,7 @@ protected function encodePayload(PacketSerializer $out) : void{
$out->putVarInt($this->amplifier);
$out->putBool($this->particles);
$out->putVarInt($this->duration);
$out->putLLong($this->tick);
$out->putUnsignedVarLong($this->tick);
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
65 changes: 65 additions & 0 deletions src/MovementEffectPacket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?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\MovementEffectType;

class MovementEffectPacket extends DataPacket implements ClientboundPacket{
public const NETWORK_ID = ProtocolInfo::MOVEMENT_EFFECT_PACKET;

private int $actorRuntimeId;
private MovementEffectType $effectType;
private int $duration;
private int $tick;

/**
* @generate-create-func
*/
public static function create(int $actorRuntimeId, MovementEffectType $effectType, int $duration, int $tick) : self{
$result = new self;
$result->actorRuntimeId = $actorRuntimeId;
$result->effectType = $effectType;
$result->duration = $duration;
$result->tick = $tick;
return $result;
}

public function getActorRuntimeId() : int{ return $this->actorRuntimeId; }

public function getEffectType() : MovementEffectType{ return $this->effectType; }

public function getDuration() : int{ return $this->duration; }

public function getTick() : int{ return $this->tick; }

protected function decodePayload(PacketSerializer $in) : void{
$this->actorRuntimeId = $in->getActorRuntimeId();
$this->effectType = MovementEffectType::fromPacket($in->getUnsignedVarInt());
$this->duration = $in->getUnsignedVarInt();
$this->tick = $in->getUnsignedVarLong();
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putActorRuntimeId($this->actorRuntimeId);
$out->putUnsignedVarInt($this->effectType->value);
$out->putUnsignedVarInt($this->duration);
$out->putUnsignedVarLong($this->tick);
}

public function handle(PacketHandlerInterface $handler) : bool{
return $handler->handleMovementEffect($this);
}
}
8 changes: 8 additions & 0 deletions src/PacketHandlerDefaultImplTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -829,4 +829,12 @@ public function handleCameraAimAssist(CameraAimAssistPacket $packet) : bool{
public function handleContainerRegistryCleanup(ContainerRegistryCleanupPacket $packet) : bool{
return false;
}

public function handleMovementEffect(MovementEffectPacket $packet) : bool{
return false;
}

public function handleSetMovementAuthority(SetMovementAuthorityPacket $packet) : bool{
return false;
}
}
4 changes: 4 additions & 0 deletions src/PacketHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,8 @@ public function handleServerboundDiagnostics(ServerboundDiagnosticsPacket $packe
public function handleCameraAimAssist(CameraAimAssistPacket $packet) : bool;

public function handleContainerRegistryCleanup(ContainerRegistryCleanupPacket $packet) : bool;

public function handleMovementEffect(MovementEffectPacket $packet) : bool;

public function handleSetMovementAuthority(SetMovementAuthorityPacket $packet) : bool;
}
2 changes: 2 additions & 0 deletions src/PacketPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ public function __construct(){
$this->registerPacket(new ServerboundDiagnosticsPacket());
$this->registerPacket(new CameraAimAssistPacket());
$this->registerPacket(new ContainerRegistryCleanupPacket());
$this->registerPacket(new MovementEffectPacket());
$this->registerPacket(new SetMovementAuthorityPacket());
}

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

namespace pocketmine\network\mcpe\protocol;

use pocketmine\math\Vector2;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\InputMode;
Expand All @@ -26,7 +27,6 @@
use pocketmine\network\mcpe\protocol\types\PlayerBlockActionStopBreak;
use pocketmine\network\mcpe\protocol\types\PlayerBlockActionWithBlockInfo;
use pocketmine\network\mcpe\protocol\types\PlayMode;
use function assert;
use function count;

class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{
Expand All @@ -42,7 +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;
private ?ItemInteractionData $itemInteractionData = null;
Expand All @@ -52,6 +52,7 @@ class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{
private ?PlayerAuthInputVehicleInfo $vehicleInfo = null;
private float $analogMoveVecX;
private float $analogMoveVecZ;
private Vector3 $cameraOrientation;

/**
* @generate-create-func
Expand All @@ -68,7 +69,7 @@ private static function internalCreate(
int $inputMode,
int $playMode,
int $interactionMode,
?Vector3 $vrGazeDirection,
Vector2 $interactRotation,
int $tick,
Vector3 $delta,
?ItemInteractionData $itemInteractionData,
Expand All @@ -77,6 +78,7 @@ private static function internalCreate(
?PlayerAuthInputVehicleInfo $vehicleInfo,
float $analogMoveVecX,
float $analogMoveVecZ,
Vector3 $cameraOrientation,
) : self{
$result = new self;
$result->position = $position;
Expand All @@ -89,7 +91,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;
$result->itemInteractionData = $itemInteractionData;
Expand All @@ -98,6 +100,7 @@ private static function internalCreate(
$result->vehicleInfo = $vehicleInfo;
$result->analogMoveVecX = $analogMoveVecX;
$result->analogMoveVecZ = $analogMoveVecZ;
$result->cameraOrientation = $cameraOrientation;
return $result;
}

Expand All @@ -106,7 +109,6 @@ private static function internalCreate(
* @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 @@ -120,21 +122,17 @@ public static function create(
int $inputMode,
int $playMode,
int $interactionMode,
?Vector3 $vrGazeDirection,
Vector2 $interactRotation,
int $tick,
Vector3 $delta,
?ItemInteractionData $itemInteractionData,
?ItemStackRequest $itemStackRequest,
?array $blockActions,
?PlayerAuthInputVehicleInfo $vehicleInfo,
float $analogMoveVecX,
float $analogMoveVecZ
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 @@ -160,15 +158,16 @@ public static function create(
$inputMode,
$playMode,
$interactionMode,
$vrGazeDirection?->asVector3(),
$interactRotation,
$tick,
$delta,
$itemInteractionData,
$itemStackRequest,
$blockActions,
$vehicleInfo,
$analogMoveVecX,
$analogMoveVecZ
$analogMoveVecZ,
$cameraOrientation
);
}

Expand Down Expand Up @@ -224,9 +223,7 @@ 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{
return $this->tick;
Expand Down Expand Up @@ -257,6 +254,8 @@ public function getAnalogMoveVecX() : float{ return $this->analogMoveVecX; }

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;
}
Expand All @@ -272,9 +271,7 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->inputMode = $in->getUnsignedVarInt();
$this->playMode = $in->getUnsignedVarInt();
$this->interactionMode = $in->getUnsignedVarInt();
if($this->playMode === PlayMode::VR){
$this->vrGazeDirection = $in->getVector3();
}
$this->interactRotation = $in->getVector2();
$this->tick = $in->getUnsignedVarLong();
$this->delta = $in->getVector3();
if($this->hasFlag(PlayerAuthInputFlags::PERFORM_ITEM_INTERACTION)){
Expand All @@ -300,6 +297,7 @@ protected function decodePayload(PacketSerializer $in) : void{
}
$this->analogMoveVecX = $in->getLFloat();
$this->analogMoveVecZ = $in->getLFloat();
$this->cameraOrientation = $in->getVector3();
}

protected function encodePayload(PacketSerializer $out) : void{
Expand All @@ -313,10 +311,7 @@ protected function encodePayload(PacketSerializer $out) : void{
$out->putUnsignedVarInt($this->inputMode);
$out->putUnsignedVarInt($this->playMode);
$out->putUnsignedVarInt($this->interactionMode);
if($this->playMode === PlayMode::VR){
assert($this->vrGazeDirection !== null);
$out->putVector3($this->vrGazeDirection);
}
$out->putVector2($this->interactRotation);
$out->putUnsignedVarLong($this->tick);
$out->putVector3($this->delta);
if($this->itemInteractionData !== null){
Expand All @@ -337,6 +332,7 @@ protected function encodePayload(PacketSerializer $out) : void{
}
$out->putLFloat($this->analogMoveVecX);
$out->putLFloat($this->analogMoveVecZ);
$out->putVector3($this->cameraOrientation);
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
Loading