From 0a4d62b4053e518594f811df210a72a51877230c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 15 May 2017 15:56:59 +0100 Subject: [PATCH] Added encode and decode methods for more packets --- src/pocketmine/Player.php | 2 ++ src/pocketmine/entity/Arrow.php | 2 +- src/pocketmine/entity/FallingSand.php | 2 +- src/pocketmine/entity/Human.php | 2 +- src/pocketmine/entity/Item.php | 2 +- src/pocketmine/entity/PrimedTNT.php | 2 +- src/pocketmine/entity/Snowball.php | 2 +- src/pocketmine/entity/Squid.php | 2 +- src/pocketmine/entity/Villager.php | 2 +- src/pocketmine/entity/Zombie.php | 2 +- .../level/particle/FloatingTextParticle.php | 2 +- .../network/mcpe/protocol/AddEntityPacket.php | 23 ++++++++++++--- .../mcpe/protocol/AddHangingEntityPacket.php | 7 +++-- .../mcpe/protocol/AddItemEntityPacket.php | 14 ++++++--- .../network/mcpe/protocol/AddItemPacket.php | 2 +- .../mcpe/protocol/AddPaintingPacket.php | 13 ++++++--- .../network/mcpe/protocol/AddPlayerPacket.php | 19 +++++++++--- .../network/mcpe/protocol/AnimatePacket.php | 2 +- .../mcpe/protocol/AvailableCommandsPacket.php | 3 +- .../mcpe/protocol/BlockEventPacket.php | 4 ++- .../mcpe/protocol/ChangeDimensionPacket.php | 4 ++- .../protocol/ChunkRadiusUpdatedPacket.php | 1 + .../mcpe/protocol/CommandStepPacket.php | 12 +++++++- .../mcpe/protocol/ContainerOpenPacket.php | 9 ++++-- .../mcpe/protocol/ContainerSetDataPacket.php | 4 ++- .../mcpe/protocol/CraftingEventPacket.php | 15 ++++++++++ .../network/mcpe/protocol/DropItemPacket.php | 4 ++- .../mcpe/protocol/EntityFallPacket.php | 9 ++++-- .../network/mcpe/protocol/ExplodePacket.php | 11 ++++++- .../mcpe/protocol/FullChunkDataPacket.php | 4 ++- .../network/mcpe/protocol/HurtArmorPacket.php | 2 +- .../mcpe/protocol/InventoryActionPacket.php | 6 +++- .../mcpe/protocol/ItemFrameDropItemPacket.php | 3 +- .../mcpe/protocol/LevelEventPacket.php | 4 ++- .../network/mcpe/protocol/LoginPacket.php | 2 +- .../mcpe/protocol/MapInfoRequestPacket.php | 4 +-- .../mcpe/protocol/MobArmorEquipmentPacket.php | 1 + .../network/mcpe/protocol/MobEffectPacket.php | 7 ++++- .../mcpe/protocol/PlayerInputPacket.php | 6 +++- .../mcpe/protocol/PlayerListPacket.php | 14 ++++++++- .../mcpe/protocol/RemoveBlockPacket.php | 3 +- .../mcpe/protocol/RemoveEntityPacket.php | 2 +- .../mcpe/protocol/ReplaceItemInSlotPacket.php | 2 +- .../protocol/RequestChunkRadiusPacket.php | 3 +- .../network/mcpe/protocol/RespawnPacket.php | 8 ++--- .../protocol/SetCommandsEnabledPacket.php | 2 +- .../mcpe/protocol/SetEntityDataPacket.php | 3 +- .../mcpe/protocol/SetEntityLinkPacket.php | 4 ++- .../mcpe/protocol/SetEntityMotionPacket.php | 3 +- .../mcpe/protocol/SetSpawnPositionPacket.php | 4 ++- .../network/mcpe/protocol/SetTimePacket.php | 2 +- .../protocol/SpawnExperienceOrbPacket.php | 3 +- .../network/mcpe/protocol/StartGamePacket.php | 29 +++++++++++++++++-- .../network/mcpe/protocol/TransferPacket.php | 3 +- .../mcpe/protocol/UpdateAttributesPacket.php | 3 +- .../mcpe/protocol/UpdateBlockPacket.php | 6 +++- .../network/mcpe/protocol/UseItemPacket.php | 11 +++++-- 57 files changed, 244 insertions(+), 78 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 5bbff9b9d..058a27d04 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1866,6 +1866,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; + $pk->pitch = $this->pitch; + $pk->yaw = $this->yaw; $pk->seed = -1; $pk->dimension = 0; //TODO: implement this properly $pk->worldGamemode = Player::getClientFriendlyGamemode($this->server->getGamemode()); diff --git a/src/pocketmine/entity/Arrow.php b/src/pocketmine/entity/Arrow.php index 75c401a65..8e78ff197 100644 --- a/src/pocketmine/entity/Arrow.php +++ b/src/pocketmine/entity/Arrow.php @@ -86,7 +86,7 @@ class Arrow extends Projectile{ public function spawnTo(Player $player){ $pk = new AddEntityPacket(); $pk->type = Arrow::NETWORK_ID; - $pk->eid = $this->getId(); + $pk->entityRuntimeId = $this->getId(); $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; diff --git a/src/pocketmine/entity/FallingSand.php b/src/pocketmine/entity/FallingSand.php index 9467dd013..edcf579aa 100644 --- a/src/pocketmine/entity/FallingSand.php +++ b/src/pocketmine/entity/FallingSand.php @@ -145,7 +145,7 @@ class FallingSand extends Entity{ public function spawnTo(Player $player){ $pk = new AddEntityPacket(); $pk->type = FallingSand::NETWORK_ID; - $pk->eid = $this->getId(); + $pk->entityRuntimeId = $this->getId(); $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 9797ead87..8668d9b5c 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -511,7 +511,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ $pk = new AddPlayerPacket(); $pk->uuid = $this->getUniqueId(); $pk->username = $this->getName(); - $pk->eid = $this->getId(); + $pk->entityRuntimeId = $this->getId(); $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; diff --git a/src/pocketmine/entity/Item.php b/src/pocketmine/entity/Item.php index 71a1549ce..602288460 100644 --- a/src/pocketmine/entity/Item.php +++ b/src/pocketmine/entity/Item.php @@ -228,7 +228,7 @@ class Item extends Entity{ public function spawnTo(Player $player){ $pk = new AddItemEntityPacket(); - $pk->eid = $this->getId(); + $pk->entityRuntimeId = $this->getId(); $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; diff --git a/src/pocketmine/entity/PrimedTNT.php b/src/pocketmine/entity/PrimedTNT.php index 9eb7825d1..9e133a360 100644 --- a/src/pocketmine/entity/PrimedTNT.php +++ b/src/pocketmine/entity/PrimedTNT.php @@ -146,7 +146,7 @@ class PrimedTNT extends Entity implements Explosive{ public function spawnTo(Player $player){ $pk = new AddEntityPacket(); $pk->type = PrimedTNT::NETWORK_ID; - $pk->eid = $this->getId(); + $pk->entityRuntimeId = $this->getId(); $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; diff --git a/src/pocketmine/entity/Snowball.php b/src/pocketmine/entity/Snowball.php index e7d4cc4a6..e38f6f219 100644 --- a/src/pocketmine/entity/Snowball.php +++ b/src/pocketmine/entity/Snowball.php @@ -62,7 +62,7 @@ class Snowball extends Projectile{ public function spawnTo(Player $player){ $pk = new AddEntityPacket(); $pk->type = Snowball::NETWORK_ID; - $pk->eid = $this->getId(); + $pk->entityRuntimeId = $this->getId(); $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; diff --git a/src/pocketmine/entity/Squid.php b/src/pocketmine/entity/Squid.php index 50a398360..c55591c29 100644 --- a/src/pocketmine/entity/Squid.php +++ b/src/pocketmine/entity/Squid.php @@ -148,7 +148,7 @@ class Squid extends WaterAnimal implements Ageable{ public function spawnTo(Player $player){ $pk = new AddEntityPacket(); - $pk->eid = $this->getId(); + $pk->entityRuntimeId = $this->getId(); $pk->type = Squid::NETWORK_ID; $pk->x = $this->x; $pk->y = $this->y; diff --git a/src/pocketmine/entity/Villager.php b/src/pocketmine/entity/Villager.php index dff059ef4..3f876ba56 100644 --- a/src/pocketmine/entity/Villager.php +++ b/src/pocketmine/entity/Villager.php @@ -52,7 +52,7 @@ class Villager extends Creature implements NPC, Ageable{ public function spawnTo(Player $player){ $pk = new AddEntityPacket(); - $pk->eid = $this->getId(); + $pk->entityRuntimeId = $this->getId(); $pk->type = Villager::NETWORK_ID; $pk->x = $this->x; $pk->y = $this->y; diff --git a/src/pocketmine/entity/Zombie.php b/src/pocketmine/entity/Zombie.php index 633631cdc..5e50e1526 100644 --- a/src/pocketmine/entity/Zombie.php +++ b/src/pocketmine/entity/Zombie.php @@ -39,7 +39,7 @@ class Zombie extends Monster{ public function spawnTo(Player $player){ $pk = new AddEntityPacket(); - $pk->eid = $this->getId(); + $pk->entityRuntimeId = $this->getId(); $pk->type = Zombie::NETWORK_ID; $pk->x = $this->x; $pk->y = $this->y; diff --git a/src/pocketmine/level/particle/FloatingTextParticle.php b/src/pocketmine/level/particle/FloatingTextParticle.php index 9ef93bc50..d4f44f8b3 100644 --- a/src/pocketmine/level/particle/FloatingTextParticle.php +++ b/src/pocketmine/level/particle/FloatingTextParticle.php @@ -77,7 +77,7 @@ class FloatingTextParticle extends Particle{ if(!$this->invisible){ $pk = new AddEntityPacket(); - $pk->eid = $this->entityId; + $pk->entityRuntimeId = $this->entityId; $pk->type = ItemEntity::NETWORK_ID; $pk->x = $this->x; $pk->y = $this->y - 0.75; diff --git a/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php b/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php index b3e0c63c0..7e071ada8 100644 --- a/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php @@ -29,7 +29,8 @@ use pocketmine\network\mcpe\NetworkSession; class AddEntityPacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::ADD_ENTITY_PACKET; - public $eid; + public $entityUniqueId = null; //TODO + public $entityRuntimeId; public $type; public $x; public $y; @@ -45,13 +46,27 @@ class AddEntityPacket extends DataPacket{ public $links = []; public function decode(){ - + $this->entityUniqueId = $this->getEntityUniqueId(); + $this->entityRuntimeId = $this->getEntityRuntimeId(); + $this->type = $this->getUnsignedVarInt(); + $this->getVector3f($this->x, $this->y, $this->z); + $this->getVector3f($this->speedX, $this->speedY, $this->speedZ); + $this->pitch = $this->getLFloat(); + $this->yaw = $this->getLFloat(); + $this->attributes = $this->getAttributeList(); + $this->metadata = $this->getEntityMetadata(); + $linkCount = $this->getUnsignedVarInt(); + for($i = 0; $i < $linkCount; ++$i){ + $this->links[$i][0] = $this->getEntityUniqueId(); + $this->links[$i][1] = $this->getEntityUniqueId(); + $this->links[$i][2] = $this->getByte(); + } } public function encode(){ $this->reset(); - $this->putEntityUniqueId($this->eid); - $this->putEntityRuntimeId($this->eid); + $this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); + $this->putEntityRuntimeId($this->entityRuntimeId); $this->putUnsignedVarInt($this->type); $this->putVector3f($this->x, $this->y, $this->z); $this->putVector3f($this->speedX, $this->speedY, $this->speedZ); diff --git a/src/pocketmine/network/mcpe/protocol/AddHangingEntityPacket.php b/src/pocketmine/network/mcpe/protocol/AddHangingEntityPacket.php index 5d2d4310e..73cf5178c 100644 --- a/src/pocketmine/network/mcpe/protocol/AddHangingEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddHangingEntityPacket.php @@ -33,10 +33,13 @@ class AddHangingEntityPacket extends DataPacket{ public $x; public $y; public $z; - public $unknown; + public $unknown; //TODO (rotation?) public function decode(){ - + $this->entityUniqueId = $this->getEntityUniqueId(); + $this->entityRuntimeId = $this->getEntityRuntimeId(); + $this->getBlockPosition($this->x, $this->y, $this->z); + $this->unknown = $this->getVarInt(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php b/src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php index 455890fd0..e5d55d988 100644 --- a/src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php @@ -29,7 +29,8 @@ use pocketmine\network\mcpe\NetworkSession; class AddItemEntityPacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::ADD_ITEM_ENTITY_PACKET; - public $eid; + public $entityUniqueId = null; //TODO + public $entityRuntimeId; public $item; public $x; public $y; @@ -40,13 +41,18 @@ class AddItemEntityPacket extends DataPacket{ public $metadata = []; public function decode(){ - + $this->entityUniqueId = $this->getEntityUniqueId(); + $this->entityRuntimeId = $this->getEntityRuntimeId(); + $this->item = $this->getSlot(); + $this->getVector3f($this->x, $this->y, $this->z); + $this->getVector3f($this->speedX, $this->speedY, $this->speedZ); + $this->metadata = $this->getEntityMetadata(); } public function encode(){ $this->reset(); - $this->putEntityUniqueId($this->eid); - $this->putEntityRuntimeId($this->eid); + $this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); + $this->putEntityRuntimeId($this->entityRuntimeId); $this->putSlot($this->item); $this->putVector3f($this->x, $this->y, $this->z); $this->putVector3f($this->speedX, $this->speedY, $this->speedZ); diff --git a/src/pocketmine/network/mcpe/protocol/AddItemPacket.php b/src/pocketmine/network/mcpe/protocol/AddItemPacket.php index 397d87f9d..b79e2fd0c 100644 --- a/src/pocketmine/network/mcpe/protocol/AddItemPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddItemPacket.php @@ -32,7 +32,7 @@ class AddItemPacket extends DataPacket{ public $item; public function decode(){ - + $this->item = $this->getSlot(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/AddPaintingPacket.php b/src/pocketmine/network/mcpe/protocol/AddPaintingPacket.php index 9ae5b2988..e4f34d19e 100644 --- a/src/pocketmine/network/mcpe/protocol/AddPaintingPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddPaintingPacket.php @@ -29,7 +29,8 @@ use pocketmine\network\mcpe\NetworkSession; class AddPaintingPacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::ADD_PAINTING_PACKET; - public $eid; + public $entityUniqueId = null; //TODO + public $entityRuntimeId; public $x; public $y; public $z; @@ -37,13 +38,17 @@ class AddPaintingPacket extends DataPacket{ public $title; public function decode(){ - + $this->entityUniqueId = $this->getEntityUniqueId(); + $this->entityRuntimeId = $this->getEntityRuntimeId(); + $this->getBlockPosition($this->x, $this->y, $this->z); + $this->direction = $this->getVarInt(); + $this->title = $this->getString(); } public function encode(){ $this->reset(); - $this->putEntityUniqueId($this->eid); - $this->putEntityRuntimeId($this->eid); + $this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); + $this->putEntityRuntimeId($this->entityRuntimeId); $this->putBlockPosition($this->x, $this->y, $this->z); $this->putVarInt($this->direction); $this->putString($this->title); diff --git a/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php b/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php index b64c3b428..a2ffad7c1 100644 --- a/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php @@ -30,7 +30,8 @@ class AddPlayerPacket extends DataPacket{ public $uuid; public $username; - public $eid; + public $entityUniqueId = null; //TODO + public $entityRuntimeId; public $x; public $y; public $z; @@ -44,15 +45,25 @@ class AddPlayerPacket extends DataPacket{ public $metadata = []; public function decode(){ - + $this->uuid = $this->getUUID(); + $this->username = $this->getString(); + $this->entityUniqueId = $this->getEntityUniqueId(); + $this->entityRuntimeId = $this->getEntityRuntimeId(); + $this->getVector3f($this->x, $this->y, $this->z); + $this->getVector3f($this->speedX, $this->speedY, $this->speedZ); + $this->pitch = $this->getLFloat(); + $this->headYaw = $this->getLFloat(); + $this->yaw = $this->getLFloat(); + $this->item = $this->getSlot(); + $this->metadata = $this->getEntityMetadata(); } public function encode(){ $this->reset(); $this->putUUID($this->uuid); $this->putString($this->username); - $this->putEntityUniqueId($this->eid); - $this->putEntityRuntimeId($this->eid); + $this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); + $this->putEntityRuntimeId($this->entityRuntimeId); $this->putVector3f($this->x, $this->y, $this->z); $this->putVector3f($this->speedX, $this->speedY, $this->speedZ); $this->putLFloat($this->pitch); diff --git a/src/pocketmine/network/mcpe/protocol/AnimatePacket.php b/src/pocketmine/network/mcpe/protocol/AnimatePacket.php index 1614043c7..68e3784c2 100644 --- a/src/pocketmine/network/mcpe/protocol/AnimatePacket.php +++ b/src/pocketmine/network/mcpe/protocol/AnimatePacket.php @@ -31,7 +31,7 @@ class AnimatePacket extends DataPacket{ public $action; public $eid; - public $float; //Boat rowing time? + public $float; //TODO (Boat rowing time?) public function decode(){ $this->action = $this->getVarInt(); diff --git a/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php b/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php index fc458e074..2c1fe007e 100644 --- a/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php @@ -32,7 +32,8 @@ class AvailableCommandsPacket extends DataPacket{ public $unknown; public function decode(){ - + $this->commands = $this->getString(); + $this->unknown = $this->getString(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/BlockEventPacket.php b/src/pocketmine/network/mcpe/protocol/BlockEventPacket.php index ba0667a4a..f2c78bc4d 100644 --- a/src/pocketmine/network/mcpe/protocol/BlockEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/BlockEventPacket.php @@ -36,7 +36,9 @@ class BlockEventPacket extends DataPacket{ public $case2; public function decode(){ - + $this->getBlockPosition($this->x, $this->y, $this->z); + $this->case1 = $this->getVarInt(); + $this->case2 = $this->getVarInt(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/ChangeDimensionPacket.php b/src/pocketmine/network/mcpe/protocol/ChangeDimensionPacket.php index 93f85494d..d80b4fff1 100644 --- a/src/pocketmine/network/mcpe/protocol/ChangeDimensionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ChangeDimensionPacket.php @@ -39,7 +39,9 @@ class ChangeDimensionPacket extends DataPacket{ public $unknown; //bool public function decode(){ - + $this->dimension = $this->getVarInt(); + $this->getVector3f($this->x, $this->y, $this->z); + $this->unknown = $this->getBool(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/ChunkRadiusUpdatedPacket.php b/src/pocketmine/network/mcpe/protocol/ChunkRadiusUpdatedPacket.php index 9c6b6dc7c..5d30c282f 100644 --- a/src/pocketmine/network/mcpe/protocol/ChunkRadiusUpdatedPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ChunkRadiusUpdatedPacket.php @@ -32,6 +32,7 @@ class ChunkRadiusUpdatedPacket extends DataPacket{ public $radius; public function decode(){ + $this->radius = $this->getVarInt(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/CommandStepPacket.php b/src/pocketmine/network/mcpe/protocol/CommandStepPacket.php index a7a3acc9b..45549d21e 100644 --- a/src/pocketmine/network/mcpe/protocol/CommandStepPacket.php +++ b/src/pocketmine/network/mcpe/protocol/CommandStepPacket.php @@ -45,13 +45,23 @@ class CommandStepPacket extends DataPacket{ $this->done = $this->getBool(); $this->clientId = $this->getUnsignedVarLong(); $this->inputJson = json_decode($this->getString()); - $this->outputJson = $this->getString(); + $this->outputJson = json_decode($this->getString()); $this->get(true); //TODO: read command origin data } public function encode(){ + $this->reset(); + $this->putString($this->command); + $this->putString($this->overload); + $this->putUnsignedVarInt($this->uvarint1); + $this->putUnsignedVarInt($this->currentStep); + $this->putBool($this->done); + $this->putUnsignedVarLong($this->clientId); + $this->putString(json_encode($this->inputJson)); + $this->putString(json_encode($this->outputJson)); + $this->put("\x00\x00\x00"); //TODO: command origin data } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php b/src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php index af221ec79..6b46a61d7 100644 --- a/src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php @@ -34,10 +34,13 @@ class ContainerOpenPacket extends DataPacket{ public $x; public $y; public $z; - public $entityId = -1; + public $entityUniqueId = -1; public function decode(){ - + $this->windowid = $this->getByte(); + $this->type = $this->getByte(); + $this->getBlockPosition($this->x, $this->y, $this->z); + $this->entityUniqueId = $this->getEntityUniqueId(); } public function encode(){ @@ -45,7 +48,7 @@ class ContainerOpenPacket extends DataPacket{ $this->putByte($this->windowid); $this->putByte($this->type); $this->putBlockPosition($this->x, $this->y, $this->z); - $this->putEntityUniqueId($this->entityId); + $this->putEntityUniqueId($this->entityUniqueId); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/ContainerSetDataPacket.php b/src/pocketmine/network/mcpe/protocol/ContainerSetDataPacket.php index a8faaeab4..bd8db150c 100644 --- a/src/pocketmine/network/mcpe/protocol/ContainerSetDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ContainerSetDataPacket.php @@ -34,7 +34,9 @@ class ContainerSetDataPacket extends DataPacket{ public $value; public function decode(){ - + $this->windowid = $this->getByte(); + $this->property = $this->getVarInt(); + $this->value = $this->getVarInt(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/CraftingEventPacket.php b/src/pocketmine/network/mcpe/protocol/CraftingEventPacket.php index e45d42410..4572a1199 100644 --- a/src/pocketmine/network/mcpe/protocol/CraftingEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/CraftingEventPacket.php @@ -25,12 +25,14 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\item\Item; use pocketmine\network\mcpe\NetworkSession; +use pocketmine\utils\UUID; class CraftingEventPacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::CRAFTING_EVENT_PACKET; public $windowId; public $type; + /** @var UUID */ public $id; /** @var Item[] */ public $input = []; @@ -60,7 +62,20 @@ class CraftingEventPacket extends DataPacket{ } public function encode(){ + $this->reset(); + $this->putByte($this->windowId); + $this->putVarInt($this->type); + $this->putUUID($this->id); + $this->putUnsignedVarInt(count($this->input)); + foreach($this->input as $item){ + $this->putSlot($item); + } + + $this->putUnsignedVarInt(count($this->output)); + foreach($this->output as $item){ + $this->putSlot($item); + } } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/DropItemPacket.php b/src/pocketmine/network/mcpe/protocol/DropItemPacket.php index be25e0c7b..3938d7430 100644 --- a/src/pocketmine/network/mcpe/protocol/DropItemPacket.php +++ b/src/pocketmine/network/mcpe/protocol/DropItemPacket.php @@ -40,7 +40,9 @@ class DropItemPacket extends DataPacket{ } public function encode(){ - + $this->reset(); + $this->putByte($this->type); + $this->putByte($this->item); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/EntityFallPacket.php b/src/pocketmine/network/mcpe/protocol/EntityFallPacket.php index e97259945..fb102788a 100644 --- a/src/pocketmine/network/mcpe/protocol/EntityFallPacket.php +++ b/src/pocketmine/network/mcpe/protocol/EntityFallPacket.php @@ -29,18 +29,21 @@ use pocketmine\network\mcpe\NetworkSession; class EntityFallPacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::ENTITY_FALL_PACKET; - public $eid; + public $entityRuntimeId; public $fallDistance; public $bool1; public function decode(){ - $this->eid = $this->getEntityRuntimeId(); + $this->entityRuntimeId = $this->getEntityRuntimeId(); $this->fallDistance = $this->getLFloat(); $this->bool1 = $this->getBool(); } public function encode(){ - + $this->reset(); + $this->putEntityRuntimeId($this->entityRuntimeId); + $this->putLFloat($this->fallDistance); + $this->putBool($this->bool1); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/ExplodePacket.php b/src/pocketmine/network/mcpe/protocol/ExplodePacket.php index c298e6351..de1685bff 100644 --- a/src/pocketmine/network/mcpe/protocol/ExplodePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ExplodePacket.php @@ -24,6 +24,7 @@ namespace pocketmine\network\mcpe\protocol; #include +use pocketmine\math\Vector3; use pocketmine\network\mcpe\NetworkSession; class ExplodePacket extends DataPacket{ @@ -33,6 +34,7 @@ class ExplodePacket extends DataPacket{ public $y; public $z; public $radius; + /** @var Vector3[] */ public $records = []; public function clean(){ @@ -41,7 +43,14 @@ class ExplodePacket extends DataPacket{ } public function decode(){ - + $this->getVector3f($this->x, $this->y, $this->z); + $this->radius = $this->getLFloat(); + $count = $this->getUnsignedVarInt(); + for($i = 0; $i < $count; ++$i){ + $x = $y = $z = null; + $this->getBlockPosition($x, $y, $z); + $this->records[$i] = new Vector3($x, $y, $z); + } } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/FullChunkDataPacket.php b/src/pocketmine/network/mcpe/protocol/FullChunkDataPacket.php index 6610492b6..4d854d4d7 100644 --- a/src/pocketmine/network/mcpe/protocol/FullChunkDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/FullChunkDataPacket.php @@ -34,7 +34,9 @@ class FullChunkDataPacket extends DataPacket{ public $data; public function decode(){ - + $this->chunkX = $this->getVarInt(); + $this->chunkZ = $this->getVarInt(); + $this->data = $this->getString(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/HurtArmorPacket.php b/src/pocketmine/network/mcpe/protocol/HurtArmorPacket.php index 644c0bf82..3cde53856 100644 --- a/src/pocketmine/network/mcpe/protocol/HurtArmorPacket.php +++ b/src/pocketmine/network/mcpe/protocol/HurtArmorPacket.php @@ -32,7 +32,7 @@ class HurtArmorPacket extends DataPacket{ public $health; public function decode(){ - + $this->health = $this->getVarInt(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/InventoryActionPacket.php b/src/pocketmine/network/mcpe/protocol/InventoryActionPacket.php index 46fb5802f..1208952f8 100644 --- a/src/pocketmine/network/mcpe/protocol/InventoryActionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/InventoryActionPacket.php @@ -34,10 +34,14 @@ class InventoryActionPacket extends DataPacket{ public $varint2; public function decode(){ - + $this->uvarint0 = $this->getUnsignedVarInt(); + $this->item = $this->getSlot(); + $this->varint1 = $this->getVarInt(); + $this->varint2 = $this->getVarInt(); } public function encode(){ + $this->reset(); $this->putUnsignedVarInt($this->uvarint0); $this->putSlot($this->item); $this->putVarInt($this->varint1); diff --git a/src/pocketmine/network/mcpe/protocol/ItemFrameDropItemPacket.php b/src/pocketmine/network/mcpe/protocol/ItemFrameDropItemPacket.php index 9a101c420..7e4106cb5 100644 --- a/src/pocketmine/network/mcpe/protocol/ItemFrameDropItemPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ItemFrameDropItemPacket.php @@ -38,7 +38,8 @@ class ItemFrameDropItemPacket extends DataPacket{ } public function encode(){ - + $this->reset(); + $this->putBlockPosition($this->x, $this->y, $this->z); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/LevelEventPacket.php b/src/pocketmine/network/mcpe/protocol/LevelEventPacket.php index e57e42a1a..4a1276c25 100644 --- a/src/pocketmine/network/mcpe/protocol/LevelEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LevelEventPacket.php @@ -104,7 +104,9 @@ class LevelEventPacket extends DataPacket{ public $data; public function decode(){ - + $this->evid = $this->getVarInt(); + $this->getVector3f($this->x, $this->y, $this->z); + $this->data = $this->getVarInt(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/LoginPacket.php b/src/pocketmine/network/mcpe/protocol/LoginPacket.php index 7413711e4..ccaf923fe 100644 --- a/src/pocketmine/network/mcpe/protocol/LoginPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LoginPacket.php @@ -85,7 +85,7 @@ class LoginPacket extends DataPacket{ } public function encode(){ - + //TODO } public function decodeToken($token){ diff --git a/src/pocketmine/network/mcpe/protocol/MapInfoRequestPacket.php b/src/pocketmine/network/mcpe/protocol/MapInfoRequestPacket.php index 98b65a970..bd2fb1a3e 100644 --- a/src/pocketmine/network/mcpe/protocol/MapInfoRequestPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MapInfoRequestPacket.php @@ -33,12 +33,12 @@ class MapInfoRequestPacket extends DataPacket{ public $mapId; public function decode(){ - $this->mapId = $this->getVarInt(); //signed var-long, actually entity ID (needs fixing) + $this->mapId = $this->getEntityUniqueId(); } public function encode(){ $this->reset(); - $this->putVarInt($this->mapId); + $this->putEntityUniqueId($this->mapId); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/MobArmorEquipmentPacket.php b/src/pocketmine/network/mcpe/protocol/MobArmorEquipmentPacket.php index 63cf63587..31f112899 100644 --- a/src/pocketmine/network/mcpe/protocol/MobArmorEquipmentPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MobArmorEquipmentPacket.php @@ -30,6 +30,7 @@ class MobArmorEquipmentPacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::MOB_ARMOR_EQUIPMENT_PACKET; public $eid; + /** @var Item[] */ public $slots = []; public function decode(){ diff --git a/src/pocketmine/network/mcpe/protocol/MobEffectPacket.php b/src/pocketmine/network/mcpe/protocol/MobEffectPacket.php index be64a6c25..8b7337e6e 100644 --- a/src/pocketmine/network/mcpe/protocol/MobEffectPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MobEffectPacket.php @@ -41,7 +41,12 @@ class MobEffectPacket extends DataPacket{ public $duration; public function decode(){ - + $this->eid = $this->getEntityRuntimeId(); + $this->eventId = $this->getByte(); + $this->effectId = $this->getVarInt(); + $this->amplifier = $this->getVarInt(); + $this->particles = $this->getBool(); + $this->duration = $this->getVarInt(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/PlayerInputPacket.php b/src/pocketmine/network/mcpe/protocol/PlayerInputPacket.php index f80d636c4..69e9bac23 100644 --- a/src/pocketmine/network/mcpe/protocol/PlayerInputPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayerInputPacket.php @@ -42,7 +42,11 @@ class PlayerInputPacket extends DataPacket{ } public function encode(){ - + $this->reset(); + $this->putLFloat($this->motionX); + $this->putLFloat($this->motionY); + $this->putBool($this->unknownBool1); + $this->putBool($this->unknownBool2); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/PlayerListPacket.php b/src/pocketmine/network/mcpe/protocol/PlayerListPacket.php index 07e95483f..31183efb2 100644 --- a/src/pocketmine/network/mcpe/protocol/PlayerListPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayerListPacket.php @@ -43,7 +43,19 @@ class PlayerListPacket extends DataPacket{ } public function decode(){ - + $this->type = $this->getByte(); + $count = $this->getUnsignedVarInt(); + for($i = 0; $i < $count; ++$i){ + if($this->type === self::TYPE_ADD){ + $this->entries[$i][0] = $this->getUUID(); + $this->entries[$i][1] = $this->getEntityUniqueId(); + $this->entries[$i][2] = $this->getString(); + $this->entries[$i][3] = $this->getString(); + $this->entries[$i][4] = $this->getString(); + }else{ + $this->entries[$i][0] = $this->getUUID(); + } + } } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/RemoveBlockPacket.php b/src/pocketmine/network/mcpe/protocol/RemoveBlockPacket.php index 65025be1e..377cb1dea 100644 --- a/src/pocketmine/network/mcpe/protocol/RemoveBlockPacket.php +++ b/src/pocketmine/network/mcpe/protocol/RemoveBlockPacket.php @@ -38,7 +38,8 @@ class RemoveBlockPacket extends DataPacket{ } public function encode(){ - + $this->reset(); + $this->putBlockPosition($this->x, $this->y, $this->z); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/RemoveEntityPacket.php b/src/pocketmine/network/mcpe/protocol/RemoveEntityPacket.php index a75da9742..9f2b0ab24 100644 --- a/src/pocketmine/network/mcpe/protocol/RemoveEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/RemoveEntityPacket.php @@ -32,7 +32,7 @@ class RemoveEntityPacket extends DataPacket{ public $eid; public function decode(){ - + $this->eid = $this->getEntityUniqueId(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/ReplaceItemInSlotPacket.php b/src/pocketmine/network/mcpe/protocol/ReplaceItemInSlotPacket.php index 1a2c9317b..28e9039d5 100644 --- a/src/pocketmine/network/mcpe/protocol/ReplaceItemInSlotPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ReplaceItemInSlotPacket.php @@ -32,7 +32,7 @@ class ReplaceItemInSlotPacket extends DataPacket{ public $item; public function decode(){ - + $this->item = $this->getSlot(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/RequestChunkRadiusPacket.php b/src/pocketmine/network/mcpe/protocol/RequestChunkRadiusPacket.php index 5a3d1bbe6..390e99150 100644 --- a/src/pocketmine/network/mcpe/protocol/RequestChunkRadiusPacket.php +++ b/src/pocketmine/network/mcpe/protocol/RequestChunkRadiusPacket.php @@ -36,7 +36,8 @@ class RequestChunkRadiusPacket extends DataPacket{ } public function encode(){ - + $this->reset(); + $this->putVarInt($this->radius); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/RespawnPacket.php b/src/pocketmine/network/mcpe/protocol/RespawnPacket.php index 1af41d7e8..b14a29344 100644 --- a/src/pocketmine/network/mcpe/protocol/RespawnPacket.php +++ b/src/pocketmine/network/mcpe/protocol/RespawnPacket.php @@ -34,16 +34,12 @@ class RespawnPacket extends DataPacket{ public $z; public function decode(){ - $this->x = $this->getLFloat(); - $this->y = $this->getLFloat(); - $this->z = $this->getLFloat(); + $this->getVector3f($this->x, $this->y, $this->z); } public function encode(){ $this->reset(); - $this->putLFloat($this->x); - $this->putLFloat($this->y); - $this->putLFloat($this->z); + $this->putVector3f($this->x, $this->y, $this->z); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/SetCommandsEnabledPacket.php b/src/pocketmine/network/mcpe/protocol/SetCommandsEnabledPacket.php index 7c7529bcb..564ca7f8a 100644 --- a/src/pocketmine/network/mcpe/protocol/SetCommandsEnabledPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetCommandsEnabledPacket.php @@ -32,7 +32,7 @@ class SetCommandsEnabledPacket extends DataPacket{ public $enabled; public function decode(){ - + $this->enabled = $this->getBool(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/SetEntityDataPacket.php b/src/pocketmine/network/mcpe/protocol/SetEntityDataPacket.php index 25b5437b5..8de054bdf 100644 --- a/src/pocketmine/network/mcpe/protocol/SetEntityDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetEntityDataPacket.php @@ -33,7 +33,8 @@ class SetEntityDataPacket extends DataPacket{ public $metadata; public function decode(){ - + $this->eid = $this->getEntityRuntimeId(); + $this->metadata = $this->getEntityMetadata(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php b/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php index 486df6b17..74e48e3eb 100644 --- a/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php @@ -34,7 +34,9 @@ class SetEntityLinkPacket extends DataPacket{ public $type; public function decode(){ - + $this->from = $this->getEntityUniqueId(); + $this->to = $this->getEntityUniqueId(); + $this->type = $this->getByte(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php b/src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php index ec66b3953..57d7d867c 100644 --- a/src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php @@ -35,7 +35,8 @@ class SetEntityMotionPacket extends DataPacket{ public $motionZ; public function decode(){ - + $this->eid = $this->getEntityRuntimeId(); + $this->getVector3f($this->motionX, $this->motionY, $this->motionZ); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/SetSpawnPositionPacket.php b/src/pocketmine/network/mcpe/protocol/SetSpawnPositionPacket.php index 0c1acd0bc..98ca3d027 100644 --- a/src/pocketmine/network/mcpe/protocol/SetSpawnPositionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetSpawnPositionPacket.php @@ -36,7 +36,9 @@ class SetSpawnPositionPacket extends DataPacket{ public $unknownBool; public function decode(){ - + $this->unknown = $this->getVarInt(); + $this->getBlockPosition($this->x, $this->y, $this->z); + $this->unknownBool = $this->getBool(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/SetTimePacket.php b/src/pocketmine/network/mcpe/protocol/SetTimePacket.php index e94c4206e..6368a064b 100644 --- a/src/pocketmine/network/mcpe/protocol/SetTimePacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetTimePacket.php @@ -31,7 +31,7 @@ class SetTimePacket extends DataPacket{ public $time; public function decode(){ - + $this->time = $this->getVarInt(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/SpawnExperienceOrbPacket.php b/src/pocketmine/network/mcpe/protocol/SpawnExperienceOrbPacket.php index a29fc4bd9..4b1271432 100644 --- a/src/pocketmine/network/mcpe/protocol/SpawnExperienceOrbPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SpawnExperienceOrbPacket.php @@ -35,7 +35,8 @@ class SpawnExperienceOrbPacket extends DataPacket{ public $amount; public function decode(){ - + $this->getVector3f($this->x, $this->y, $this->z); + $this->amount = $this->getVarInt(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/StartGamePacket.php b/src/pocketmine/network/mcpe/protocol/StartGamePacket.php index 1367de51a..ff6cc4b21 100644 --- a/src/pocketmine/network/mcpe/protocol/StartGamePacket.php +++ b/src/pocketmine/network/mcpe/protocol/StartGamePacket.php @@ -35,6 +35,8 @@ class StartGamePacket extends DataPacket{ public $x; public $y; public $z; + public $pitch; + public $yaw; public $seed; public $dimension; public $generator = 1; //default infinite - 0 old, 1 infinite, 2 flat @@ -55,6 +57,29 @@ class StartGamePacket extends DataPacket{ public $premiumWorldTemplateId = ""; public function decode(){ + $this->entityUniqueId = $this->getEntityUniqueId(); + $this->entityRuntimeId = $this->getEntityRuntimeId(); + $this->playerGamemode = $this->getVarInt(); + $this->getVector3f($this->x, $this->y, $this->z); + $this->pitch = $this->getLFloat(); + $this->yaw = $this->getLFloat(); + $this->seed = $this->getVarInt(); + $this->dimension = $this->getVarInt(); + $this->generator = $this->getVarInt(); + $this->worldGamemode = $this->getVarInt(); + $this->difficulty = $this->getVarInt(); + $this->getBlockPosition($this->spawnX, $this->spawnY, $this->spawnZ); + $this->hasAchievementsDisabled = $this->getBool(); + $this->dayCycleStopTime = $this->getVarInt(); + $this->eduMode = $this->getBool(); + $this->rainLevel = $this->getLFloat(); + $this->lightningLevel = $this->getLFloat(); + $this->commandsEnabled = $this->getBool(); + $this->isTexturePacksRequired = $this->getBool(); + /*$gameRulesCount = */$this->getUnsignedVarInt(); //TODO + $this->levelId = $this->getString(); + $this->worldName = $this->getString(); + $this->premiumWorldTemplateId = $this->getString(); } @@ -64,8 +89,8 @@ class StartGamePacket extends DataPacket{ $this->putEntityRuntimeId($this->entityRuntimeId); $this->putVarInt($this->playerGamemode); //client gamemode, other field is world gamemode $this->putVector3f($this->x, $this->y, $this->z); - $this->putLFloat(0); //TODO: yaw/pitch - $this->putLFloat(0); + $this->putLFloat($this->pitch); + $this->putLFloat($this->yaw); $this->putVarInt($this->seed); $this->putVarInt($this->dimension); $this->putVarInt($this->generator); diff --git a/src/pocketmine/network/mcpe/protocol/TransferPacket.php b/src/pocketmine/network/mcpe/protocol/TransferPacket.php index 1e6da8000..44a0c1b97 100644 --- a/src/pocketmine/network/mcpe/protocol/TransferPacket.php +++ b/src/pocketmine/network/mcpe/protocol/TransferPacket.php @@ -32,7 +32,8 @@ class TransferPacket extends DataPacket{ public $port = 19132; public function decode(){ - + $this->address = $this->getString(); + $this->port = $this->getLShort(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/UpdateAttributesPacket.php b/src/pocketmine/network/mcpe/protocol/UpdateAttributesPacket.php index 68cd90e72..dcb03b088 100644 --- a/src/pocketmine/network/mcpe/protocol/UpdateAttributesPacket.php +++ b/src/pocketmine/network/mcpe/protocol/UpdateAttributesPacket.php @@ -35,7 +35,8 @@ class UpdateAttributesPacket extends DataPacket{ public $entries = []; public function decode(){ - + $this->entityId = $this->getEntityRuntimeId(); + $this->entries = $this->getAttributeList(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php b/src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php index b7ac09198..8f35ca61c 100644 --- a/src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php +++ b/src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php @@ -46,7 +46,11 @@ class UpdateBlockPacket extends DataPacket{ public $flags; public function decode(){ - + $this->getBlockPosition($this->x, $this->y, $this->z); + $this->blockId = $this->getUnsignedVarInt(); + $aux = $this->getUnsignedVarInt(); + $this->blockData = $aux & 0x0f; + $this->flags = $aux >> 4; } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/UseItemPacket.php b/src/pocketmine/network/mcpe/protocol/UseItemPacket.php index 505123d02..f9f61a220 100644 --- a/src/pocketmine/network/mcpe/protocol/UseItemPacket.php +++ b/src/pocketmine/network/mcpe/protocol/UseItemPacket.php @@ -34,7 +34,6 @@ class UseItemPacket extends DataPacket{ public $z; public $blockId; public $face; - public $item; public $fx; public $fy; public $fz; @@ -42,6 +41,8 @@ class UseItemPacket extends DataPacket{ public $posY; public $posZ; public $slot; + /** @var Item */ + public $item; public function decode(){ $this->getBlockPosition($this->x, $this->y, $this->z); @@ -54,7 +55,13 @@ class UseItemPacket extends DataPacket{ } public function encode(){ - + $this->reset(); + $this->putUnsignedVarInt($this->blockId); + $this->putUnsignedVarInt($this->face); + $this->putVector3f($this->fx, $this->fy, $this->fz); + $this->putVector3f($this->posX, $this->posY, $this->posZ); + $this->putVarInt($this->slot); + $this->putSlot($this->item); } public function handle(NetworkSession $session) : bool{