Skip to content

Commit

Permalink
Add 1.20.30 support
Browse files Browse the repository at this point in the history
  • Loading branch information
AkmalFairuz committed Sep 19, 2024
1 parent 6664a19 commit deba044
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 21 deletions.
14 changes: 13 additions & 1 deletion src/EmotePacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ class EmotePacket extends DataPacket implements ClientboundPacket, ServerboundPa

private int $actorRuntimeId;
private string $emoteId;
private int $emoteLengthTicks = 0;
private string $xboxUserId;
private string $platformChatId;
private int $flags;

/**
* @generate-create-func
*/
public static function create(int $actorRuntimeId, string $emoteId, string $xboxUserId, string $platformChatId, int $flags) : self{
public static function create(int $actorRuntimeId, string $emoteId, string $xboxUserId, string $platformChatId, int $flags, int $emoteLengthTicks = 0) : self{
$result = new self;
$result->actorRuntimeId = $actorRuntimeId;
$result->emoteId = $emoteId;
$result->emoteLengthTicks = $emoteLengthTicks;
$result->xboxUserId = $xboxUserId;
$result->platformChatId = $platformChatId;
$result->flags = $flags;
Expand All @@ -49,6 +51,10 @@ public function getEmoteId() : string{
return $this->emoteId;
}

public function getEmoteLengthTicks(): int {
return $this->emoteLengthTicks;
}

public function getXboxUserId() : string{ return $this->xboxUserId; }

public function getPlatformChatId() : string{ return $this->platformChatId; }
Expand All @@ -60,6 +66,9 @@ public function getFlags() : int{
protected function decodePayload(PacketSerializer $in) : void{
$this->actorRuntimeId = $in->getActorRuntimeId();
$this->emoteId = $in->getString();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_729){
$this->emoteLengthTicks = $in->getInt();
}
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_589){
$this->xboxUserId = $in->getString();
$this->platformChatId = $in->getString();
Expand All @@ -73,6 +82,9 @@ protected function decodePayload(PacketSerializer $in) : void{
protected function encodePayload(PacketSerializer $out) : void{
$out->putActorRuntimeId($this->actorRuntimeId);
$out->putString($this->emoteId);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_729){
$out->putInt($this->emoteLengthTicks);
}
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_589){
$out->putString($this->xboxUserId);
$out->putString($this->platformChatId);
Expand Down
24 changes: 19 additions & 5 deletions src/InventoryContentPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace pocketmine\network\mcpe\protocol;

use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\inventory\FullContainerName;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;
use function count;

Expand All @@ -24,17 +25,19 @@ class InventoryContentPacket extends DataPacket implements ClientboundPacket{
public int $windowId;
/** @var ItemStackWrapper[] */
public array $items = [];
public int $dynamicContainerId;
public FullContainerName $containerName;
public int $dynamicContainerSize = 0;

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

Expand All @@ -45,7 +48,13 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->items[] = ItemStackWrapper::read($in);
}
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$this->dynamicContainerId = $in->getUnsignedVarInt();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_729){
$this->containerName = FullContainerName::read($in);
$this->dynamicContainerSize = $in->getUnsignedVarInt();
}else {
$dynamicContainerId = $in->getUnsignedVarInt();
$this->containerName = new FullContainerName(0, $dynamicContainerId);
}
}
}

Expand All @@ -56,7 +65,12 @@ protected function encodePayload(PacketSerializer $out) : void{
$item->write($out);
}
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$out->putUnsignedVarInt($this->dynamicContainerId);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_729){
$this->containerName->write($out);
$out->putUnsignedVarInt($this->dynamicContainerSize);
}else {
$out->putUnsignedVarInt($this->containerName->getDynamicId());
}
}
}

Expand Down
23 changes: 18 additions & 5 deletions src/InventorySlotPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,27 @@
namespace pocketmine\network\mcpe\protocol;

use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\inventory\FullContainerName;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;

class InventorySlotPacket extends DataPacket implements ClientboundPacket{
public const NETWORK_ID = ProtocolInfo::INVENTORY_SLOT_PACKET;

public int $windowId;
public int $inventorySlot;
public FullContainerName $containerName;
public int $dynamicContainerSize;
public ItemStackWrapper $item;
public int $dynamicContainerId;

/**
* @generate-create-func
*/
public static function create(int $windowId, int $inventorySlot, ItemStackWrapper $item, int $dynamicContainerId = 0) : self{
public static function create(int $windowId, int $inventorySlot, ItemStackWrapper $item, FullContainerName $containerName, int $dynamicContainerSize) : self{
$result = new self;
$result->windowId = $windowId;
$result->inventorySlot = $inventorySlot;
$result->dynamicContainerId = $dynamicContainerId;
$result->containerName = $containerName;
$result->dynamicContainerSize = $dynamicContainerSize;
$result->item = $item;
return $result;
}
Expand All @@ -41,7 +44,12 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->windowId = $in->getUnsignedVarInt();
$this->inventorySlot = $in->getUnsignedVarInt();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$this->dynamicContainerId = $in->getUnsignedVarInt();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_729){
$this->containerName = FullContainerName::read($in);
$this->dynamicContainerSize = $in->getUnsignedVarInt();
}else{
$this->containerName = new FullContainerName(0, $in->getUnsignedVarInt());
}
}
$this->item = ItemStackWrapper::read($in);
}
Expand All @@ -50,7 +58,12 @@ protected function encodePayload(PacketSerializer $out) : void{
$out->putUnsignedVarInt($this->windowId);
$out->putUnsignedVarInt($this->inventorySlot);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_712){
$out->putUnsignedVarInt($this->dynamicContainerId);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_729){
$this->containerName->write($out);
$out->putUnsignedVarInt($this->dynamicContainerSize);
}else{
$out->putUnsignedVarInt($this->containerName->getDynamicId());
}
}
$this->item->write($out);
}
Expand Down
4 changes: 3 additions & 1 deletion src/ProtocolInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ private function __construct(){
*/

/** Actual Minecraft: PE protocol version */
public const CURRENT_PROTOCOL = 712;
public const CURRENT_PROTOCOL = 729;
/** Current Minecraft PE version reported by the server. This is usually the earliest currently supported version. */
public const MINECRAFT_VERSION = 'v1.21.20';
/** Version number sent to clients in ping responses. */
public const MINECRAFT_VERSION_NETWORK = '1.21.20';

public const BASE_VERSION = '1.18.0';

public const PROTOCOL_729 = 729; // 1.21.30
public const PROTOCOL_712 = 712; // 1.21.20
public const PROTOCOL_686 = 686; // 1.21.2
public const PROTOCOL_685 = 685; // 1.21.0
Expand Down Expand Up @@ -67,6 +68,7 @@ private function __construct(){
public const PROTOCOL_475 = 475; // v1.18.0

public const COMPATIBLE_PROTOCOL = [
self::PROTOCOL_729,
self::PROTOCOL_712,
// self::PROTOCOL_686,
self::PROTOCOL_685,
Expand Down
24 changes: 16 additions & 8 deletions src/ResourcePacksInfoPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,14 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->hasAddons = $in->getBool();
}
$this->hasScripts = $in->getBool();
$this->forceServerPacks = $in->getBool();
$behaviorPackCount = $in->getLShort();
while($behaviorPackCount-- > 0){
$this->behaviorPackEntries[] = BehaviorPackInfoEntry::read($in);
if($in->getProtocol() < ProtocolInfo::PROTOCOL_729) {
$this->forceServerPacks = $in->getBool();
}
if($in->getProtocol() < ProtocolInfo::PROTOCOL_729) {
$behaviorPackCount = $in->getLShort();
while($behaviorPackCount-- > 0) {
$this->behaviorPackEntries[] = BehaviorPackInfoEntry::read($in);
}
}

$resourcePackCount = $in->getLShort();
Expand All @@ -88,10 +92,14 @@ protected function encodePayload(PacketSerializer $out) : void{
$out->putBool($this->hasAddons);
}
$out->putBool($this->hasScripts);
$out->putBool($this->forceServerPacks);
$out->putLShort(count($this->behaviorPackEntries));
foreach($this->behaviorPackEntries as $entry){
$entry->write($out);
if($out->getProtocol() < ProtocolInfo::PROTOCOL_729) {
$out->putBool($this->forceServerPacks);
}
if($out->getProtocol() < ProtocolInfo::PROTOCOL_729) {
$out->putLShort(count($this->behaviorPackEntries));
foreach($this->behaviorPackEntries as $entry) {
$entry->write($out);
}
}
$out->putLShort(count($this->resourcePackEntries));
foreach($this->resourcePackEntries as $entry){
Expand Down
10 changes: 9 additions & 1 deletion src/TransferPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,33 @@ class TransferPacket extends DataPacket implements ClientboundPacket{

public string $address;
public int $port = 19132;
public bool $reloadWorld = true;

/**
* @generate-create-func
*/
public static function create(string $address, int $port) : self{
public static function create(string $address, int $port, bool $reloadWorld = true) : self{
$result = new self;
$result->address = $address;
$result->port = $port;
$result->reloadWorld = $reloadWorld;
return $result;
}

protected function decodePayload(PacketSerializer $in) : void{
$this->address = $in->getString();
$this->port = $in->getLShort();
if($in->getProtocol() >= ProtocolInfo::PROTOCOL_729){
$this->reloadWorld = $in->getBool();
}
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putString($this->address);
$out->putLShort($this->port);
if($out->getProtocol() >= ProtocolInfo::PROTOCOL_729){
$this->reloadWorld = $out->getBool();
}
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
5 changes: 5 additions & 0 deletions src/serializer/PacketSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,11 @@ public function putAttributeList(Attribute ...$attributes) : void{
$this->putLFloat($attribute->getMin());
$this->putLFloat($attribute->getMax());
$this->putLFloat($attribute->getCurrent());
if($this->getProtocol() >= ProtocolInfo::PROTOCOL_729) {
// TODO: implement default min & max
$this->putLFloat($attribute->getMin()); // default min
$this->putLFloat($attribute->getMax()); // default max
}
$this->putLFloat($attribute->getDefault());
$this->putString($attribute->getId());

Expand Down

0 comments on commit deba044

Please sign in to comment.