Skip to content

Commit

Permalink
1.21.20 support
Browse files Browse the repository at this point in the history
  • Loading branch information
AkmalFairuz committed Aug 15, 2024
1 parent 5984bbd commit de482bc
Show file tree
Hide file tree
Showing 36 changed files with 744 additions and 27 deletions.
15 changes: 14 additions & 1 deletion src/CameraInstructionPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,27 @@
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\camera\CameraFadeInstruction;
use pocketmine\network\mcpe\protocol\types\camera\CameraSetInstruction;
use pocketmine\network\mcpe\protocol\types\camera\CameraTargetInstruction;

class CameraInstructionPacket extends DataPacket implements ClientboundPacket{
public const NETWORK_ID = ProtocolInfo::CAMERA_INSTRUCTION_PACKET;

private ?CameraSetInstruction $set;
private ?bool $clear;
private ?CameraFadeInstruction $fade;
private ?CameraTargetInstruction $target;
private ?bool $removeTarget;

/**
* @generate-create-func
*/
public static function create(?CameraSetInstruction $set, ?bool $clear, ?CameraFadeInstruction $fade) : self{
public static function create(?CameraSetInstruction $set, ?bool $clear, ?CameraFadeInstruction $fade, ?CameraTargetInstruction $target = null, ?bool $removeTarget = null) : self{
$result = new self;
$result->set = $set;
$result->clear = $clear;
$result->fade = $fade;
$result->target = $target;
$result->removeTarget = $removeTarget;
return $result;
}

Expand All @@ -46,12 +51,20 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->set = $in->readOptional(fn() => CameraSetInstruction::read($in));
$this->clear = $in->readOptional(fn() => $in->getBool());
$this->fade = $in->readOptional(fn() => CameraFadeInstruction::read($in));
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$this->target = $in->readOptional(fn() => CameraTargetInstruction::read($in));
$this->removeTarget = $in->readOptional($in->getBool(...));
}
}

protected function encodePayload(PacketSerializer $out) : void{
$out->writeOptional($this->set, fn(CameraSetInstruction $v) => $v->write($out));
$out->writeOptional($this->clear, fn(bool $v) => $out->putBool($v));
$out->writeOptional($this->fade, fn(CameraFadeInstruction $v) => $v->write($out));
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$out->writeOptional($this->target, fn(CameraTargetInstruction $v) => $v->write($out));
$out->writeOptional($this->removeTarget, $out->putBool(...));
}
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
9 changes: 8 additions & 1 deletion src/ChangeDimensionPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ class ChangeDimensionPacket extends DataPacket implements ClientboundPacket{
public int $dimension;
public Vector3 $position;
public bool $respawn = false;
private ?int $loadingScreenId = null;

/**
* @generate-create-func
*/
public static function create(int $dimension, Vector3 $position, bool $respawn) : self{
public static function create(int $dimension, Vector3 $position, bool $respawn, ?int $loadingScreenId = null) : self{
$result = new self;
$result->dimension = $dimension;
$result->position = $position;
Expand All @@ -39,12 +40,18 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->dimension = $in->getVarInt();
$this->position = $in->getVector3();
$this->respawn = $in->getBool();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$this->loadingScreenId = $in->readOptional(fn() => $in->getLInt());
}
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putVarInt($this->dimension);
$out->putVector3($this->position);
$out->putBool($this->respawn);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$out->writeOptional($this->loadingScreenId, $out->putLInt(...));
}
}

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

class ClientboundCloseFormPacket extends DataPacket implements ClientboundPacket{
public const NETWORK_ID = ProtocolInfo::CLIENTBOUND_CLOSE_FORM_PACKET;

/**
* @generate-create-func
*/
public static function create() : self{
return new self;
}

protected function decodePayload(PacketSerializer $in) : void{
//No payload
}

protected function encodePayload(PacketSerializer $out) : void{
//No payload
}

public function handle(PacketHandlerInterface $handler) : bool{
return $handler->handleClientboundCloseForm($this);
}
}
44 changes: 44 additions & 0 deletions src/CurrentStructureFeaturePacket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?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;

class CurrentStructureFeaturePacket extends DataPacket implements ClientboundPacket{
public const NETWORK_ID = ProtocolInfo::CURRENT_STRUCTURE_FEATURE_PACKET;

public string $currentStructureFeature;

/**
* @generate-create-func
*/
public static function create(string $currentStructureFeature) : self{
$result = new self;
$result->currentStructureFeature = $currentStructureFeature;
return $result;
}

protected function decodePayload(PacketSerializer $in) : void{
$this->currentStructureFeature = $in->getString();
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putString($this->currentStructureFeature);
}

public function handle(PacketHandlerInterface $handler) : bool{
return $handler->handleCurrentStructureFeature($this);
}
}
16 changes: 12 additions & 4 deletions src/DisconnectPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ class DisconnectPacket extends DataPacket implements ClientboundPacket, Serverbo

public int $reason; //TODO: add constants / enum
public ?string $message;
public ?string $filteredMessage;

/**
* @generate-create-func
*/
public static function create(int $reason, ?string $message) : self{
public static function create(int $reason, ?string $message, ?string $filteredMessage = null) : self{
$result = new self;
$result->reason = $reason;
$result->message = $message;
$result->filteredMessage = $filteredMessage;
return $result;
}

Expand All @@ -43,16 +45,22 @@ protected function decodePayload(PacketSerializer $in) : void{
$hideDisconnectionScreen = $in->getBool();
if(!$hideDisconnectionScreen){
$this->message = $in->getString();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$this->filteredMessage = $in->getString();
}
}
}

protected function encodePayload(PacketSerializer $out) : void{
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_622){
$out->putVarInt($this->reason);
}
$out->putBool($this->message === null);
if($this->message !== null){
$out->putString($this->message);
$out->putBool($skipMessage = $this->message === null && $this->filteredMessage === null);
if(!$skipMessage){
$out->putString($this->message ?? "");
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$out->putString($this->filteredMessage ?? "");
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/EditorNetworkPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@
class EditorNetworkPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{
public const NETWORK_ID = ProtocolInfo::EDITOR_NETWORK_PACKET;

private bool $isRouteToManager = false;
/** @phpstan-var CacheableNbt<\pocketmine\nbt\tag\CompoundTag> */
private CacheableNbt $payload;

/**
* @generate-create-func
* @phpstan-param CacheableNbt<\pocketmine\nbt\tag\CompoundTag> $payload
*/
public static function create(CacheableNbt $payload) : self{
public static function create(bool $isRouteToManager, CacheableNbt $payload) : self{
$result = new self;
$result->isRouteToManager = $isRouteToManager;
$result->payload = $payload;
return $result;
}
Expand All @@ -40,10 +42,16 @@ public static function create(CacheableNbt $payload) : self{
public function getPayload() : CacheableNbt{ return $this->payload; }

protected function decodePayload(PacketSerializer $in) : void{
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$this->isRouteToManager = $in->getBool();
}
$this->payload = new CacheableNbt($in->getNbtCompoundRoot());
}

protected function encodePayload(PacketSerializer $out) : void{
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$out->putBool($this->isRouteToManager);
}
$out->put($this->payload->getEncodedNbt());
}

Expand Down
10 changes: 9 additions & 1 deletion src/InventoryContentPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ class InventoryContentPacket extends DataPacket implements ClientboundPacket{
public int $windowId;
/** @var ItemStackWrapper[] */
public array $items = [];
public int $dynamicContainerId;

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

Expand All @@ -42,6 +44,9 @@ protected function decodePayload(PacketSerializer $in) : void{
for($i = 0; $i < $count; ++$i){
$this->items[] = ItemStackWrapper::read($in);
}
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$this->dynamicContainerId = $in->getUnsignedVarInt();
}
}

protected function encodePayload(PacketSerializer $out) : void{
Expand All @@ -50,6 +55,9 @@ protected function encodePayload(PacketSerializer $out) : void{
foreach($this->items as $item){
$item->write($out);
}
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$out->putUnsignedVarInt($this->dynamicContainerId);
}
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
10 changes: 9 additions & 1 deletion src/InventorySlotPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,36 @@ class InventorySlotPacket extends DataPacket implements ClientboundPacket{
public int $windowId;
public int $inventorySlot;
public ItemStackWrapper $item;
public int $dynamicContainerId;

/**
* @generate-create-func
*/
public static function create(int $windowId, int $inventorySlot, ItemStackWrapper $item) : self{
public static function create(int $windowId, int $inventorySlot, ItemStackWrapper $item, int $dynamicContainerId) : self{
$result = new self;
$result->windowId = $windowId;
$result->inventorySlot = $inventorySlot;
$result->item = $item;
$result->dynamicContainerId = $dynamicContainerId;
return $result;
}

protected function decodePayload(PacketSerializer $in) : void{
$this->windowId = $in->getUnsignedVarInt();
$this->inventorySlot = $in->getUnsignedVarInt();
$this->item = ItemStackWrapper::read($in);
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$this->dynamicContainerId = $in->getUnsignedVarInt();
}
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putUnsignedVarInt($this->windowId);
$out->putUnsignedVarInt($this->inventorySlot);
$this->item->write($out);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$out->putUnsignedVarInt($this->dynamicContainerId);
}
}

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

class JigsawStructureDataPacket extends DataPacket implements ClientboundPacket{
public const NETWORK_ID = ProtocolInfo::JIGSAW_STRUCTURE_DATA_PACKET;

/** @phpstan-var CacheableNbt<\pocketmine\nbt\tag\CompoundTag> */
private CacheableNbt $nbt;

/**
* @generate-create-func
* @phpstan-param CacheableNbt<\pocketmine\nbt\tag\CompoundTag> $nbt
*/
public static function create(CacheableNbt $nbt) : self{
$result = new self;
$result->nbt = $nbt;
return $result;
}

/** @phpstan-return CacheableNbt<\pocketmine\nbt\tag\CompoundTag> */
public function getNbt() : CacheableNbt{ return $this->nbt; }

protected function decodePayload(PacketSerializer $in) : void{
$this->nbt = new CacheableNbt($in->getNbtCompoundRoot());
}

protected function encodePayload(PacketSerializer $out) : void{
$out->put($this->nbt->getEncodedNbt());
}

public function handle(PacketHandlerInterface $handler) : bool{
return $handler->handleJigsawStructureData($this);
}
}
Loading

0 comments on commit de482bc

Please sign in to comment.