Skip to content

Commit

Permalink
feat: protocol improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedikt05 committed Sep 21, 2024
1 parent 7ff81e7 commit c61f4b6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,23 @@ class ChangeDimensionPacket extends DataPacket{
public int $dimension;
public Vector3 $position;
public bool $respawn = false;
public ?int $loadingScreenId = null;

protected function decodePayload() : void{
$this->dimension = $this->getVarInt();
$this->position = $this->getVector3();
$this->respawn = $this->getBool();
$this->loadingScreenId = $this->getBool() ? $this->getLInt() : null;
}

protected function encodePayload() : void{
$this->putVarInt($this->dimension);
$this->putVector3($this->position);
$this->putBool($this->respawn);
$this->putBool(false);
$this->putBool($this->loadingScreenId !== null);
if($this->loadingScreenId !== null){
$this->putLInt($this->loadingScreenId);
}
}

public function handle(NetworkSession $session) : bool{
Expand Down
23 changes: 11 additions & 12 deletions src/pocketmine/network/mcpe/protocol/MobArmorEquipmentPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,23 @@

#include <rules/DataPacket.h>

use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;

class MobArmorEquipmentPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::MOB_ARMOR_EQUIPMENT_PACKET;

/** @var int */
public $entityRuntimeId;
public int $entityRuntimeId;

//this intentionally doesn't use an array because we don't want any implicit dependencies on internal order

/** @var ItemStackWrapper */
public $head;
/** @var ItemStackWrapper */
public $chest;
/** @var ItemStackWrapper */
public $legs;
/** @var ItemStackWrapper */
public $feet;
/** @var ItemStackWrapper */
public $body;
public ItemStackWrapper $head;
public ItemStackWrapper $chest;
public ItemStackWrapper $legs;
public ItemStackWrapper $feet;
public ?ItemStackWrapper $body = null;

protected function decodePayload() : void{
$this->entityRuntimeId = $this->getEntityRuntimeId();
Expand All @@ -62,6 +58,9 @@ protected function encodePayload() : void{
$this->chest->write($this);
$this->legs->write($this);
$this->feet->write($this);
if($this->body === null){
$this->body = ItemStackWrapper::legacy(ItemFactory::get(Item::AIR));
}
$this->body->write($this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ protected function decodePayload() : void{
}

protected function encodePayload() : void{
$this->putVarInt($this->leftTab->value);
$this->putVarInt($this->rightTab->value);
$this->putVarInt($this->leftTab);
$this->putVarInt($this->rightTab);
$this->putBool($this->filtering);
$this->putVarInt($this->inventoryLayout->value);
$this->putVarInt($this->craftingLayout->value);
$this->putVarInt($this->inventoryLayout);
$this->putVarInt($this->craftingLayout);
}

public function handle(NetworkSession $session) : bool{
Expand Down

0 comments on commit c61f4b6

Please sign in to comment.