Skip to content

Commit

Permalink
Protocol changes for 1.19.40
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Oct 25, 2022
1 parent 8da4c73 commit b455a74
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/AddActorPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use pocketmine\network\mcpe\protocol\types\entity\Attribute;
use pocketmine\network\mcpe\protocol\types\entity\EntityLink;
use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty;
use pocketmine\network\mcpe\protocol\types\entity\PropertySyncData;
use function count;

class AddActorPacket extends DataPacket implements ClientboundPacket{
Expand All @@ -41,6 +42,7 @@ class AddActorPacket extends DataPacket implements ClientboundPacket{
* @phpstan-var array<int, MetadataProperty>
*/
public array $metadata = [];
public PropertySyncData $syncedProperties;
/** @var EntityLink[] */
public array $links = [];

Expand All @@ -63,6 +65,7 @@ public static function create(
float $bodyYaw,
array $attributes,
array $metadata,
PropertySyncData $syncedProperties,
array $links,
) : self{
$result = new self;
Expand All @@ -77,6 +80,7 @@ public static function create(
$result->bodyYaw = $bodyYaw;
$result->attributes = $attributes;
$result->metadata = $metadata;
$result->syncedProperties = $syncedProperties;
$result->links = $links;
return $result;
}
Expand All @@ -102,6 +106,8 @@ protected function decodePayload(PacketSerializer $in) : void{
}

$this->metadata = $in->getEntityMetadata();
$this->syncedProperties = PropertySyncData::read($in);

$linkCount = $in->getUnsignedVarInt();
for($i = 0; $i < $linkCount; ++$i){
$this->links[] = $in->getEntityLink();
Expand All @@ -128,6 +134,8 @@ protected function encodePayload(PacketSerializer $out) : void{
}

$out->putEntityMetadata($this->metadata);
$this->syncedProperties->write($out);

$out->putUnsignedVarInt(count($this->links));
foreach($this->links as $link){
$out->putEntityLink($link);
Expand Down
6 changes: 6 additions & 0 deletions src/AddPlayerPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use pocketmine\network\mcpe\protocol\types\DeviceOS;
use pocketmine\network\mcpe\protocol\types\entity\EntityLink;
use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty;
use pocketmine\network\mcpe\protocol\types\entity\PropertySyncData;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;
use Ramsey\Uuid\UuidInterface;
use function count;
Expand All @@ -42,6 +43,7 @@ class AddPlayerPacket extends DataPacket implements ClientboundPacket{
* @phpstan-var array<int, MetadataProperty>
*/
public array $metadata = [];
public PropertySyncData $syncedProperties;

public UpdateAbilitiesPacket $abilitiesPacket;

Expand Down Expand Up @@ -69,6 +71,7 @@ public static function create(
ItemStackWrapper $item,
int $gameMode,
array $metadata,
PropertySyncData $syncedProperties,
UpdateAbilitiesPacket $abilitiesPacket,
array $links,
string $deviceId,
Expand All @@ -87,6 +90,7 @@ public static function create(
$result->item = $item;
$result->gameMode = $gameMode;
$result->metadata = $metadata;
$result->syncedProperties = $syncedProperties;
$result->abilitiesPacket = $abilitiesPacket;
$result->links = $links;
$result->deviceId = $deviceId;
Expand All @@ -107,6 +111,7 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->item = ItemStackWrapper::read($in);
$this->gameMode = $in->getVarInt();
$this->metadata = $in->getEntityMetadata();
$this->syncedProperties = PropertySyncData::read($in);

$this->abilitiesPacket = new UpdateAbilitiesPacket();
$this->abilitiesPacket->decodePayload($in);
Expand All @@ -133,6 +138,7 @@ protected function encodePayload(PacketSerializer $out) : void{
$this->item->write($out);
$out->putVarInt($this->gameMode);
$out->putEntityMetadata($this->metadata);
$this->syncedProperties->write($out);

$this->abilitiesPacket->encodePayload($out);

Expand Down
6 changes: 3 additions & 3 deletions src/ProtocolInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ private function __construct(){
*/

/** Actual Minecraft: PE protocol version */
public const CURRENT_PROTOCOL = 554;
public const CURRENT_PROTOCOL = 557;
/** Current Minecraft PE version reported by the server. This is usually the earliest currently supported version. */
public const MINECRAFT_VERSION = 'v1.19.30';
public const MINECRAFT_VERSION = 'v1.19.40';
/** Version number sent to clients in ping responses. */
public const MINECRAFT_VERSION_NETWORK = '1.19.30';
public const MINECRAFT_VERSION_NETWORK = '1.19.40';

public const LOGIN_PACKET = 0x01;
public const PLAY_STATUS_PACKET = 0x02;
Expand Down
7 changes: 6 additions & 1 deletion src/SetActorDataPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty;
use pocketmine\network\mcpe\protocol\types\entity\PropertySyncData;

class SetActorDataPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ //TODO: check why this is serverbound
public const NETWORK_ID = ProtocolInfo::SET_ACTOR_DATA_PACKET;
Expand All @@ -26,30 +27,34 @@ class SetActorDataPacket extends DataPacket implements ClientboundPacket, Server
* @phpstan-var array<int, MetadataProperty>
*/
public array $metadata;
public PropertySyncData $syncedProperties;
public int $tick = 0;

/**
* @generate-create-func
* @param MetadataProperty[] $metadata
* @phpstan-param array<int, MetadataProperty> $metadata
*/
public static function create(int $actorRuntimeId, array $metadata, int $tick) : self{
public static function create(int $actorRuntimeId, array $metadata, PropertySyncData $syncedProperties, int $tick) : self{
$result = new self;
$result->actorRuntimeId = $actorRuntimeId;
$result->metadata = $metadata;
$result->syncedProperties = $syncedProperties;
$result->tick = $tick;
return $result;
}

protected function decodePayload(PacketSerializer $in) : void{
$this->actorRuntimeId = $in->getActorRuntimeId();
$this->metadata = $in->getEntityMetadata();
$this->syncedProperties = PropertySyncData::read($in);
$this->tick = $in->getUnsignedVarLong();
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putActorRuntimeId($this->actorRuntimeId);
$out->putEntityMetadata($this->metadata);
$this->syncedProperties->write($out);
$out->putUnsignedVarLong($this->tick);
}

Expand Down
1 change: 1 addition & 0 deletions src/types/UpdateAbilitiesPacketLayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ final class UpdateAbilitiesPacketLayer{
public const LAYER_BASE = 1;
public const LAYER_SPECTATOR = 2;
public const LAYER_COMMANDS = 3;
public const LAYER_EDITOR = 4;

public const ABILITY_BUILD = 0;
public const ABILITY_MINE = 1;
Expand Down
74 changes: 74 additions & 0 deletions src/types/entity/PropertySyncData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?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\types\entity;

use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use function count;

final class PropertySyncData{
/**
* @param int[] $intProperties
* @param float[] $floatProperties
* @phpstan-param array<int, int> $intProperties
* @phpstan-param array<int, float> $floatProperties
*/
public function __construct(
private array $intProperties,
private array $floatProperties,
){}

/**
* @return int[]
* @phpstan-return array<int, int>
*/
public function getIntProperties() : array{
return $this->intProperties;
}

/**
* @return float[]
* @phpstan-return array<int, float>
*/
public function getFloatProperties() : array{
return $this->floatProperties;
}

public static function read(PacketSerializer $in) : self{
$intProperties = [];
$floatProperties = [];

for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){
$intProperties[$in->getUnsignedVarInt()] = $in->getVarInt();
}
for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){
$floatProperties[$in->getUnsignedVarInt()] = $in->getLFloat();
}

return new self($intProperties, $floatProperties);
}

public function write(PacketSerializer $out) : void{
$out->putUnsignedVarInt(count($this->intProperties));
foreach($this->intProperties as $key => $value){
$out->putUnsignedVarInt($key);
$out->putVarInt($value);
}
$out->putUnsignedVarInt(count($this->floatProperties));
foreach($this->floatProperties as $key => $value){
$out->putUnsignedVarInt($key);
$out->putLFloat($value);
}
}
}

0 comments on commit b455a74

Please sign in to comment.