From 86ed0f1397566c33a970743500904d09f34c74e1 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 4 Oct 2016 15:07:53 +0100 Subject: [PATCH] Updated existing packets and added new ones --- src/pocketmine/Player.php | 5 +- src/pocketmine/level/Level.php | 11 ++- src/pocketmine/network/Network.php | 99 +++++++++++-------- src/pocketmine/network/RakLibInterface.php | 1 + .../network/protocol/AddEntityPacket.php | 25 +++-- .../protocol/AddHangingEntityPacket.php | 48 +++++++++ .../network/protocol/AddItemEntityPacket.php | 11 +-- .../network/protocol/AddItemPacket.php | 41 ++++++++ .../network/protocol/AddPaintingPacket.php | 9 +- .../network/protocol/AddPlayerPacket.php | 18 ++-- .../network/protocol/AnimatePacket.php | 4 +- .../protocol/BlockEntityDataPacket.php | 8 +- .../network/protocol/BlockEventPacket.php | 8 +- .../protocol/ChangeDimensionPacket.php | 8 +- .../network/protocol/ContainerOpenPacket.php | 8 +- .../protocol/ContainerSetDataPacket.php | 4 +- .../network/protocol/EntityEventPacket.php | 7 +- .../network/protocol/ExplodePacket.php | 12 +-- .../network/protocol/HurtArmorPacket.php | 2 +- .../network/protocol/InteractPacket.php | 4 +- .../protocol/InventoryActionPacket.php | 40 ++++++++ .../protocol/ItemFrameDropItemPacket.php | 44 +++++++++ .../network/protocol/LevelEventPacket.php | 15 ++- .../protocol/LevelSoundEventPacket.php | 50 ++++++++++ .../protocol/MobArmorEquipmentPacket.php | 4 +- .../network/protocol/MobEffectPacket.php | 10 +- .../network/protocol/MobEquipmentPacket.php | 7 +- .../network/protocol/MoveEntityPacket.php | 12 +-- .../network/protocol/PlayerActionPacket.php | 22 ++--- .../network/protocol/PlayerInputPacket.php | 46 +++++++++ .../network/protocol/PlayerListPacket.php | 4 +- .../network/protocol/RemoveBlockPacket.php | 6 +- .../network/protocol/RemoveEntityPacket.php | 2 +- .../protocol/ReplaceSelectedItemPacket.php | 41 ++++++++ .../network/protocol/RespawnPacket.php | 14 +-- .../protocol/SetCommandsEnabledPacket.php | 41 ++++++++ .../network/protocol/SetDifficultyPacket.php | 2 +- .../network/protocol/SetEntityDataPacket.php | 2 +- .../network/protocol/SetEntityLinkPacket.php | 4 +- .../protocol/SetEntityMotionPacket.php | 17 ++-- .../network/protocol/SetHealthPacket.php | 2 +- .../protocol/SetPlayerGameTypePacket.php | 2 +- .../protocol/SetSpawnPositionPacket.php | 6 +- .../network/protocol/SetTimePacket.php | 4 +- .../protocol/SpawnExperienceOrbPacket.php | 44 +++++++++ .../network/protocol/TakeItemEntityPacket.php | 4 +- .../protocol/UpdateAttributesPacket.php | 14 ++- .../network/protocol/UpdateBlockPacket.php | 8 +- .../network/protocol/UseItemPacket.php | 17 +--- 49 files changed, 597 insertions(+), 220 deletions(-) create mode 100644 src/pocketmine/network/protocol/AddHangingEntityPacket.php create mode 100644 src/pocketmine/network/protocol/AddItemPacket.php create mode 100644 src/pocketmine/network/protocol/InventoryActionPacket.php create mode 100644 src/pocketmine/network/protocol/ItemFrameDropItemPacket.php create mode 100644 src/pocketmine/network/protocol/LevelSoundEventPacket.php create mode 100644 src/pocketmine/network/protocol/PlayerInputPacket.php create mode 100644 src/pocketmine/network/protocol/ReplaceSelectedItemPacket.php create mode 100644 src/pocketmine/network/protocol/SetCommandsEnabledPacket.php create mode 100644 src/pocketmine/network/protocol/SpawnExperienceOrbPacket.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 7a0ed285e..100454e22 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1451,7 +1451,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade if($this->chunk !== null){ $this->level->addEntityMotion($this->chunk->getX(), $this->chunk->getZ(), $this->getId(), $this->motionX, $this->motionY, $this->motionZ); $pk = new SetEntityMotionPacket(); - $pk->entities[] = [0, $mot->x, $mot->y, $mot->z]; + $pk->eid = 0; + $pk->motionX = $mot->x; + $pk->motionY = $mot->y; + $pk->motionZ = $mot->z; $this->dataPacket($pk); } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 7b1cd8eb8..be46f930c 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -723,9 +723,14 @@ class Level implements ChunkManager, Metadatable{ foreach($this->motionToSend as $index => $entry){ Level::getXZ($index, $chunkX, $chunkZ); - $pk = new SetEntityMotionPacket(); - $pk->entities = $entry; - $this->addChunkPacket($chunkX, $chunkZ, $pk); + foreach($entry as $entity){ + $pk = new SetEntityMotionPacket(); + $pk->eid = $entity[0]; + $pk->motionX = $entity[1]; + $pk->motionY = $entity[2]; + $pk->motionZ = $entity[3]; + $this->addChunkPacket($chunkX, $chunkZ, $pk); + } } $this->motionToSend = []; diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 7eb375226..6cb10f2cf 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -25,7 +25,9 @@ namespace pocketmine\network; use pocketmine\network\protocol\AddEntityPacket; +use pocketmine\network\protocol\AddHangingEntityPacket; use pocketmine\network\protocol\AddItemEntityPacket; +use pocketmine\network\protocol\AddItemPacket; use pocketmine\network\protocol\AddPaintingPacket; use pocketmine\network\protocol\AddPlayerPacket; use pocketmine\network\protocol\AdventureSettingsPacket; @@ -52,19 +54,25 @@ use pocketmine\network\protocol\HurtArmorPacket; use pocketmine\network\protocol\Info as ProtocolInfo; use pocketmine\network\protocol\Info; use pocketmine\network\protocol\InteractPacket; +use pocketmine\network\protocol\InventoryActionPacket; +use pocketmine\network\protocol\ItemFrameDropItemPacket; use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\protocol\LevelSoundEventPacket; use pocketmine\network\protocol\LoginPacket; use pocketmine\network\protocol\MobArmorEquipmentPacket; use pocketmine\network\protocol\MobEquipmentPacket; use pocketmine\network\protocol\MoveEntityPacket; use pocketmine\network\protocol\MovePlayerPacket; use pocketmine\network\protocol\PlayerActionPacket; +use pocketmine\network\protocol\PlayerInputPacket; use pocketmine\network\protocol\PlayerListPacket; use pocketmine\network\protocol\PlayStatusPacket; use pocketmine\network\protocol\RemoveBlockPacket; use pocketmine\network\protocol\RemoveEntityPacket; +use pocketmine\network\protocol\ReplaceSelectedItemPacket; use pocketmine\network\protocol\RequestChunkRadiusPacket; use pocketmine\network\protocol\RespawnPacket; +use pocketmine\network\protocol\SetCommandsEnabledPacket; use pocketmine\network\protocol\SetDifficultyPacket; use pocketmine\network\protocol\SetEntityDataPacket; use pocketmine\network\protocol\SetEntityLinkPacket; @@ -73,6 +81,7 @@ use pocketmine\network\protocol\SetHealthPacket; use pocketmine\network\protocol\SetPlayerGameTypePacket; use pocketmine\network\protocol\SetSpawnPositionPacket; use pocketmine\network\protocol\SetTimePacket; +use pocketmine\network\protocol\SpawnExperienceOrbPacket; use pocketmine\network\protocol\StartGamePacket; use pocketmine\network\protocol\TakeItemEntityPacket; use pocketmine\network\protocol\TextPacket; @@ -230,6 +239,7 @@ class Network{ $pk->setBuffer($buf, 1); $pk->decode(); + assert($pk->feof(), "Still " . strlen(substr($pk->buffer, $pk->offset)) . " bytes unread in " . get_class($pk)); $p->handleDataPacket($pk); } } @@ -283,56 +293,65 @@ class Network{ private function registerPackets(){ $this->packetPool = new \SplFixedArray(256); - $this->registerPacket(ProtocolInfo::LOGIN_PACKET, LoginPacket::class); - $this->registerPacket(ProtocolInfo::PLAY_STATUS_PACKET, PlayStatusPacket::class); - $this->registerPacket(ProtocolInfo::DISCONNECT_PACKET, DisconnectPacket::class); - $this->registerPacket(ProtocolInfo::BATCH_PACKET, BatchPacket::class); - $this->registerPacket(ProtocolInfo::TEXT_PACKET, TextPacket::class); - $this->registerPacket(ProtocolInfo::SET_TIME_PACKET, SetTimePacket::class); - $this->registerPacket(ProtocolInfo::START_GAME_PACKET, StartGamePacket::class); - $this->registerPacket(ProtocolInfo::ADD_PLAYER_PACKET, AddPlayerPacket::class); $this->registerPacket(ProtocolInfo::ADD_ENTITY_PACKET, AddEntityPacket::class); - $this->registerPacket(ProtocolInfo::REMOVE_ENTITY_PACKET, RemoveEntityPacket::class); + $this->registerPacket(ProtocolInfo::ADD_HANGING_ENTITY_PACKET, AddHangingEntityPacket::class); $this->registerPacket(ProtocolInfo::ADD_ITEM_ENTITY_PACKET, AddItemEntityPacket::class); - $this->registerPacket(ProtocolInfo::TAKE_ITEM_ENTITY_PACKET, TakeItemEntityPacket::class); - $this->registerPacket(ProtocolInfo::MOVE_ENTITY_PACKET, MoveEntityPacket::class); - $this->registerPacket(ProtocolInfo::MOVE_PLAYER_PACKET, MovePlayerPacket::class); - $this->registerPacket(ProtocolInfo::REMOVE_BLOCK_PACKET, RemoveBlockPacket::class); - $this->registerPacket(ProtocolInfo::UPDATE_BLOCK_PACKET, UpdateBlockPacket::class); + $this->registerPacket(ProtocolInfo::ADD_ITEM_PACKET, AddItemPacket::class); $this->registerPacket(ProtocolInfo::ADD_PAINTING_PACKET, AddPaintingPacket::class); - $this->registerPacket(ProtocolInfo::EXPLODE_PACKET, ExplodePacket::class); - $this->registerPacket(ProtocolInfo::LEVEL_EVENT_PACKET, LevelEventPacket::class); - $this->registerPacket(ProtocolInfo::BLOCK_EVENT_PACKET, BlockEventPacket::class); - $this->registerPacket(ProtocolInfo::ENTITY_EVENT_PACKET, EntityEventPacket::class); - $this->registerPacket(ProtocolInfo::MOB_EQUIPMENT_PACKET, MobEquipmentPacket::class); - $this->registerPacket(ProtocolInfo::MOB_ARMOR_EQUIPMENT_PACKET, MobArmorEquipmentPacket::class); - $this->registerPacket(ProtocolInfo::INTERACT_PACKET, InteractPacket::class); - $this->registerPacket(ProtocolInfo::USE_ITEM_PACKET, UseItemPacket::class); - $this->registerPacket(ProtocolInfo::PLAYER_ACTION_PACKET, PlayerActionPacket::class); - $this->registerPacket(ProtocolInfo::HURT_ARMOR_PACKET, HurtArmorPacket::class); - $this->registerPacket(ProtocolInfo::SET_ENTITY_DATA_PACKET, SetEntityDataPacket::class); - $this->registerPacket(ProtocolInfo::SET_ENTITY_MOTION_PACKET, SetEntityMotionPacket::class); - $this->registerPacket(ProtocolInfo::SET_ENTITY_LINK_PACKET, SetEntityLinkPacket::class); - $this->registerPacket(ProtocolInfo::SET_HEALTH_PACKET, SetHealthPacket::class); - $this->registerPacket(ProtocolInfo::SET_SPAWN_POSITION_PACKET, SetSpawnPositionPacket::class); + $this->registerPacket(ProtocolInfo::ADD_PLAYER_PACKET, AddPlayerPacket::class); + $this->registerPacket(ProtocolInfo::ADVENTURE_SETTINGS_PACKET, AdventureSettingsPacket::class); $this->registerPacket(ProtocolInfo::ANIMATE_PACKET, AnimatePacket::class); - $this->registerPacket(ProtocolInfo::RESPAWN_PACKET, RespawnPacket::class); - $this->registerPacket(ProtocolInfo::DROP_ITEM_PACKET, DropItemPacket::class); - $this->registerPacket(ProtocolInfo::CONTAINER_OPEN_PACKET, ContainerOpenPacket::class); + $this->registerPacket(ProtocolInfo::BATCH_PACKET, BatchPacket::class); + $this->registerPacket(ProtocolInfo::BLOCK_ENTITY_DATA_PACKET, BlockEntityDataPacket::class); + $this->registerPacket(ProtocolInfo::BLOCK_EVENT_PACKET, BlockEventPacket::class); + $this->registerPacket(ProtocolInfo::CHANGE_DIMENSION_PACKET, ChangeDimensionPacket::class); + $this->registerPacket(ProtocolInfo::CHUNK_RADIUS_UPDATED_PACKET, ChunkRadiusUpdatedPacket::class); $this->registerPacket(ProtocolInfo::CONTAINER_CLOSE_PACKET, ContainerClosePacket::class); - $this->registerPacket(ProtocolInfo::CONTAINER_SET_SLOT_PACKET, ContainerSetSlotPacket::class); - $this->registerPacket(ProtocolInfo::CONTAINER_SET_DATA_PACKET, ContainerSetDataPacket::class); + $this->registerPacket(ProtocolInfo::CONTAINER_OPEN_PACKET, ContainerOpenPacket::class); $this->registerPacket(ProtocolInfo::CONTAINER_SET_CONTENT_PACKET, ContainerSetContentPacket::class); + $this->registerPacket(ProtocolInfo::CONTAINER_SET_DATA_PACKET, ContainerSetDataPacket::class); + $this->registerPacket(ProtocolInfo::CONTAINER_SET_SLOT_PACKET, ContainerSetSlotPacket::class); $this->registerPacket(ProtocolInfo::CRAFTING_DATA_PACKET, CraftingDataPacket::class); $this->registerPacket(ProtocolInfo::CRAFTING_EVENT_PACKET, CraftingEventPacket::class); - $this->registerPacket(ProtocolInfo::ADVENTURE_SETTINGS_PACKET, AdventureSettingsPacket::class); - $this->registerPacket(ProtocolInfo::BLOCK_ENTITY_DATA_PACKET, BlockEntityDataPacket::class); + $this->registerPacket(ProtocolInfo::DISCONNECT_PACKET, DisconnectPacket::class); + $this->registerPacket(ProtocolInfo::DROP_ITEM_PACKET, DropItemPacket::class); + $this->registerPacket(ProtocolInfo::ENTITY_EVENT_PACKET, EntityEventPacket::class); + $this->registerPacket(ProtocolInfo::EXPLODE_PACKET, ExplodePacket::class); $this->registerPacket(ProtocolInfo::FULL_CHUNK_DATA_PACKET, FullChunkDataPacket::class); - $this->registerPacket(ProtocolInfo::SET_DIFFICULTY_PACKET, SetDifficultyPacket::class); - $this->registerPacket(ProtocolInfo::SET_PLAYER_GAMETYPE_PACKET, SetPlayerGameTypePacket::class); - $this->registerPacket(ProtocolInfo::CHANGE_DIMENSION_PACKET, ChangeDimensionPacket::class); + $this->registerPacket(ProtocolInfo::HURT_ARMOR_PACKET, HurtArmorPacket::class); + $this->registerPacket(ProtocolInfo::INTERACT_PACKET, InteractPacket::class); + $this->registerPacket(ProtocolInfo::INVENTORY_ACTION_PACKET, InventoryActionPacket::class); + $this->registerPacket(ProtocolInfo::ITEM_FRAME_DROP_ITEM_PACKET, ItemFrameDropItemPacket::class); + $this->registerPacket(ProtocolInfo::LEVEL_EVENT_PACKET, LevelEventPacket::class); + $this->registerPacket(ProtocolInfo::LEVEL_SOUND_EVENT_PACKET, LevelSoundEventPacket::class); + $this->registerPacket(ProtocolInfo::LOGIN_PACKET, LoginPacket::class); + $this->registerPacket(ProtocolInfo::MOB_ARMOR_EQUIPMENT_PACKET, MobArmorEquipmentPacket::class); + $this->registerPacket(ProtocolInfo::MOB_EQUIPMENT_PACKET, MobEquipmentPacket::class); + $this->registerPacket(ProtocolInfo::MOVE_ENTITY_PACKET, MoveEntityPacket::class); + $this->registerPacket(ProtocolInfo::MOVE_PLAYER_PACKET, MovePlayerPacket::class); + $this->registerPacket(ProtocolInfo::PLAYER_ACTION_PACKET, PlayerActionPacket::class); + $this->registerPacket(ProtocolInfo::PLAYER_INPUT_PACKET, PlayerInputPacket::class); $this->registerPacket(ProtocolInfo::PLAYER_LIST_PACKET, PlayerListPacket::class); + $this->registerPacket(ProtocolInfo::PLAY_STATUS_PACKET, PlayStatusPacket::class); + $this->registerPacket(ProtocolInfo::REMOVE_BLOCK_PACKET, RemoveBlockPacket::class); + $this->registerPacket(ProtocolInfo::REMOVE_ENTITY_PACKET, RemoveEntityPacket::class); + $this->registerPacket(ProtocolInfo::REPLACE_SELECTED_ITEM_PACKET, ReplaceSelectedItemPacket::class); $this->registerPacket(ProtocolInfo::REQUEST_CHUNK_RADIUS_PACKET, RequestChunkRadiusPacket::class); - $this->registerPacket(ProtocolInfo::CHUNK_RADIUS_UPDATED_PACKET, ChunkRadiusUpdatedPacket::class); + $this->registerPacket(ProtocolInfo::RESPAWN_PACKET, RespawnPacket::class); + $this->registerPacket(ProtocolInfo::SET_COMMANDS_ENABLED_PACKET, SetCommandsEnabledPacket::class); + $this->registerPacket(ProtocolInfo::SET_DIFFICULTY_PACKET, SetDifficultyPacket::class); + $this->registerPacket(ProtocolInfo::SET_ENTITY_DATA_PACKET, SetEntityDataPacket::class); + $this->registerPacket(ProtocolInfo::SET_ENTITY_LINK_PACKET, SetEntityLinkPacket::class); + $this->registerPacket(ProtocolInfo::SET_ENTITY_MOTION_PACKET, SetEntityMotionPacket::class); + $this->registerPacket(ProtocolInfo::SET_HEALTH_PACKET, SetHealthPacket::class); + $this->registerPacket(ProtocolInfo::SET_PLAYER_GAMETYPE_PACKET, SetPlayerGameTypePacket::class); + $this->registerPacket(ProtocolInfo::SET_SPAWN_POSITION_PACKET, SetSpawnPositionPacket::class); + $this->registerPacket(ProtocolInfo::SET_TIME_PACKET, SetTimePacket::class); + $this->registerPacket(ProtocolInfo::SPAWN_EXPERIENCE_ORB_PACKET, SpawnExperienceOrbPacket::class); + $this->registerPacket(ProtocolInfo::START_GAME_PACKET, StartGamePacket::class); + $this->registerPacket(ProtocolInfo::TAKE_ITEM_ENTITY_PACKET, TakeItemEntityPacket::class); + $this->registerPacket(ProtocolInfo::TEXT_PACKET, TextPacket::class); + $this->registerPacket(ProtocolInfo::UPDATE_BLOCK_PACKET, UpdateBlockPacket::class); + $this->registerPacket(ProtocolInfo::USE_ITEM_PACKET, UseItemPacket::class); } } diff --git a/src/pocketmine/network/RakLibInterface.php b/src/pocketmine/network/RakLibInterface.php index 02cbc9a9e..24ab4ec78 100644 --- a/src/pocketmine/network/RakLibInterface.php +++ b/src/pocketmine/network/RakLibInterface.php @@ -132,6 +132,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ $pk = $this->getPacket($packet->buffer); if($pk !== null){ $pk->decode(); + assert($pk->feof(), "Still " . strlen(substr($pk->buffer, $pk->offset)) . " bytes unread!"); $this->players[$identifier]->handleDataPacket($pk); } } diff --git a/src/pocketmine/network/protocol/AddEntityPacket.php b/src/pocketmine/network/protocol/AddEntityPacket.php index d1da7c8fd..1ed2a77c3 100644 --- a/src/pocketmine/network/protocol/AddEntityPacket.php +++ b/src/pocketmine/network/protocol/AddEntityPacket.php @@ -51,23 +51,20 @@ class AddEntityPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putLong($this->eid); - $this->putInt($this->type); - $this->putFloat($this->x); - $this->putFloat($this->y); - $this->putFloat($this->z); - $this->putFloat($this->speedX); - $this->putFloat($this->speedY); - $this->putFloat($this->speedZ); - $this->putFloat($this->yaw * (256 / 360)); - $this->putFloat($this->pitch * (256 / 360)); - $this->putInt($this->modifiers); + $this->putEntityId($this->eid); //EntityUniqueID - TODO: verify this + $this->putEntityId($this->eid); + $this->putUnsignedVarInt($this->type); + $this->putVector3f($this->x, $this->y, $this->z); + $this->putVector3f($this->speedX, $this->speedY, $this->speedZ); + $this->putLFloat($this->yaw * (256 / 360)); + $this->putLFloat($this->pitch * (256 / 360)); + $this->putUnsignedVarInt($this->modifiers); //attributes? $meta = Binary::writeMetadata($this->metadata); $this->put($meta); - $this->putShort(count($this->links)); + $this->putUnsignedVarInt(count($this->links)); foreach($this->links as $link){ - $this->putLong($link[0]); - $this->putLong($link[1]); + $this->putEntityId($link[0]); + $this->putEntityId($link[1]); $this->putByte($link[2]); } } diff --git a/src/pocketmine/network/protocol/AddHangingEntityPacket.php b/src/pocketmine/network/protocol/AddHangingEntityPacket.php new file mode 100644 index 000000000..0f179863f --- /dev/null +++ b/src/pocketmine/network/protocol/AddHangingEntityPacket.php @@ -0,0 +1,48 @@ + + +class AddHangingEntityPacket extends DataPacket{ + const NETWORK_ID = Info::ADD_HANGING_ENTITY_PACKET; + + public $entityUniqueId; + public $entityRuntimeId; + public $x; + public $y; + public $z; + public $unknown; + + public function decode(){ + + } + + public function encode(){ + $this->reset(); + $this->putEntityId($this->entityUniqueId); + $this->putEntityId($this->entityRuntimeId); + $this->putBlockCoords($this->x, $this->y, $this->z); + $this->putVarInt($this->unknown); + } + +} \ No newline at end of file diff --git a/src/pocketmine/network/protocol/AddItemEntityPacket.php b/src/pocketmine/network/protocol/AddItemEntityPacket.php index 86509e5b0..7357b4538 100644 --- a/src/pocketmine/network/protocol/AddItemEntityPacket.php +++ b/src/pocketmine/network/protocol/AddItemEntityPacket.php @@ -42,14 +42,11 @@ class AddItemEntityPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putLong($this->eid); + $this->putEntityId($this->eid); //EntityUniqueID + $this->putEntityId($this->eid); //EntityRuntimeID $this->putSlot($this->item); - $this->putFloat($this->x); - $this->putFloat($this->y); - $this->putFloat($this->z); - $this->putFloat($this->speedX); - $this->putFloat($this->speedY); - $this->putFloat($this->speedZ); + $this->putVector3f($this->x, $this->y, $this->z); + $this->putVector3f($this->speedX, $this->speedY, $this->speedZ); } } diff --git a/src/pocketmine/network/protocol/AddItemPacket.php b/src/pocketmine/network/protocol/AddItemPacket.php new file mode 100644 index 000000000..cf688795a --- /dev/null +++ b/src/pocketmine/network/protocol/AddItemPacket.php @@ -0,0 +1,41 @@ + + + +class AddItemPacket extends DataPacket{ + const NETWORK_ID = Info::ADD_ITEM_PACKET; + + public $item; + + public function decode(){ + + } + + public function encode(){ + $this->reset(); + $this->putSlot($this->item); + } + +} \ No newline at end of file diff --git a/src/pocketmine/network/protocol/AddPaintingPacket.php b/src/pocketmine/network/protocol/AddPaintingPacket.php index 7b2276185..3c2f20c22 100644 --- a/src/pocketmine/network/protocol/AddPaintingPacket.php +++ b/src/pocketmine/network/protocol/AddPaintingPacket.php @@ -40,11 +40,10 @@ class AddPaintingPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putLong($this->eid); - $this->putInt($this->x); - $this->putInt($this->y); - $this->putInt($this->z); - $this->putInt($this->direction); + $this->putEntityId($this->eid); //EntityUniqueID + $this->putEntityId($this->eid); //EntityRuntimeID + $this->putBlockCoords($this->x, $this->y, $this->z); + $this->putVarInt($this->direction); $this->putString($this->title); } diff --git a/src/pocketmine/network/protocol/AddPlayerPacket.php b/src/pocketmine/network/protocol/AddPlayerPacket.php index afa1eb833..2027bdab3 100644 --- a/src/pocketmine/network/protocol/AddPlayerPacket.php +++ b/src/pocketmine/network/protocol/AddPlayerPacket.php @@ -53,16 +53,14 @@ class AddPlayerPacket extends DataPacket{ $this->reset(); $this->putUUID($this->uuid); $this->putString($this->username); - $this->putLong($this->eid); - $this->putFloat($this->x); - $this->putFloat($this->y); - $this->putFloat($this->z); - $this->putFloat($this->speedX); - $this->putFloat($this->speedY); - $this->putFloat($this->speedZ); - $this->putFloat($this->yaw); - $this->putFloat($this->yaw); //TODO headrot - $this->putFloat($this->pitch); + $this->putEntityId($this->eid); //EntityUniqueID + $this->putEntityId($this->eid); //EntityRuntimeID + $this->putVector3f($this->x, $this->y, $this->z); + $this->putVector3f($this->speedX, $this->speedY, $this->speedZ); + //TODO: check these are in the right order + $this->putLFloat($this->yaw); + $this->putLFloat($this->yaw); //TODO headrot + $this->putLFloat($this->pitch); $this->putSlot($this->item); $meta = Binary::writeMetadata($this->metadata); diff --git a/src/pocketmine/network/protocol/AnimatePacket.php b/src/pocketmine/network/protocol/AnimatePacket.php index f6d5ba624..857582062 100644 --- a/src/pocketmine/network/protocol/AnimatePacket.php +++ b/src/pocketmine/network/protocol/AnimatePacket.php @@ -32,13 +32,13 @@ class AnimatePacket extends DataPacket{ public function decode(){ $this->action = $this->getByte(); - $this->eid = $this->getLong(); + $this->eid = $this->getEntityId(); } public function encode(){ $this->reset(); $this->putByte($this->action); - $this->putLong($this->eid); + $this->putEntityId($this->eid); } } diff --git a/src/pocketmine/network/protocol/BlockEntityDataPacket.php b/src/pocketmine/network/protocol/BlockEntityDataPacket.php index 668da2eea..df01e6142 100644 --- a/src/pocketmine/network/protocol/BlockEntityDataPacket.php +++ b/src/pocketmine/network/protocol/BlockEntityDataPacket.php @@ -33,17 +33,13 @@ class BlockEntityDataPacket extends DataPacket{ public $namedtag; public function decode(){ - $this->x = $this->getInt(); - $this->y = $this->getInt(); - $this->z = $this->getInt(); + $this->getBlockCoords($this->x, $this->y, $this->z); $this->namedtag = $this->get(true); } public function encode(){ $this->reset(); - $this->putInt($this->x); - $this->putInt($this->y); - $this->putInt($this->z); + $this->putBlockCoords($this->x, $this->y, $this->z); $this->put($this->namedtag); } diff --git a/src/pocketmine/network/protocol/BlockEventPacket.php b/src/pocketmine/network/protocol/BlockEventPacket.php index 1399cfc4d..14b4ca274 100644 --- a/src/pocketmine/network/protocol/BlockEventPacket.php +++ b/src/pocketmine/network/protocol/BlockEventPacket.php @@ -39,11 +39,9 @@ class BlockEventPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->x); - $this->putInt($this->y); - $this->putInt($this->z); - $this->putInt($this->case1); - $this->putInt($this->case2); + $this->putBlockCoords($this->x, $this->y, $this->z); + $this->putVarInt($this->case1); + $this->putVarInt($this->case2); } } diff --git a/src/pocketmine/network/protocol/ChangeDimensionPacket.php b/src/pocketmine/network/protocol/ChangeDimensionPacket.php index cd26241f2..2ce2a03c3 100644 --- a/src/pocketmine/network/protocol/ChangeDimensionPacket.php +++ b/src/pocketmine/network/protocol/ChangeDimensionPacket.php @@ -34,7 +34,7 @@ class ChangeDimensionPacket extends DataPacket{ public $x; public $y; public $z; - public $unknown; + public $unknown; //bool public function decode(){ @@ -42,10 +42,8 @@ class ChangeDimensionPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putByte($this->dimension); - $this->putFloat($this->x); - $this->putFloat($this->y); - $this->putFloat($this->z); + $this->putVarInt($this->dimension); + $this->putVector3f($this->x, $this->y, $this->z); $this->putByte($this->unknown); } diff --git a/src/pocketmine/network/protocol/ContainerOpenPacket.php b/src/pocketmine/network/protocol/ContainerOpenPacket.php index 5b5923adc..895947c6d 100644 --- a/src/pocketmine/network/protocol/ContainerOpenPacket.php +++ b/src/pocketmine/network/protocol/ContainerOpenPacket.php @@ -33,6 +33,7 @@ class ContainerOpenPacket extends DataPacket{ public $x; public $y; public $z; + public $entityId = -1; public function decode(){ @@ -42,10 +43,9 @@ class ContainerOpenPacket extends DataPacket{ $this->reset(); $this->putByte($this->windowid); $this->putByte($this->type); - $this->putShort($this->slots); - $this->putInt($this->x); - $this->putInt($this->y); - $this->putInt($this->z); + $this->putVarInt($this->slots); + $this->putBlockCoords($this->x, $this->y, $this->z); + $this->putEntityId($this->entityId); } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/ContainerSetDataPacket.php b/src/pocketmine/network/protocol/ContainerSetDataPacket.php index 750accdce..45f886e81 100644 --- a/src/pocketmine/network/protocol/ContainerSetDataPacket.php +++ b/src/pocketmine/network/protocol/ContainerSetDataPacket.php @@ -38,8 +38,8 @@ class ContainerSetDataPacket extends DataPacket{ public function encode(){ $this->reset(); $this->putByte($this->windowid); - $this->putShort($this->property); - $this->putShort($this->value); + $this->putVarInt($this->property); + $this->putVarInt($this->value); } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/EntityEventPacket.php b/src/pocketmine/network/protocol/EntityEventPacket.php index 53aba2365..1baf47c30 100644 --- a/src/pocketmine/network/protocol/EntityEventPacket.php +++ b/src/pocketmine/network/protocol/EntityEventPacket.php @@ -47,16 +47,19 @@ class EntityEventPacket extends DataPacket{ public $eid; public $event; + public $unknown; public function decode(){ - $this->eid = $this->getLong(); + $this->eid = $this->getEntityId(); $this->event = $this->getByte(); + $this->unknown = $this->getVarInt(); } public function encode(){ $this->reset(); - $this->putLong($this->eid); + $this->putEntityId($this->eid); $this->putByte($this->event); + $this->putVarInt($this->unknown); } } diff --git a/src/pocketmine/network/protocol/ExplodePacket.php b/src/pocketmine/network/protocol/ExplodePacket.php index 6b0f660d5..5e11d27b6 100644 --- a/src/pocketmine/network/protocol/ExplodePacket.php +++ b/src/pocketmine/network/protocol/ExplodePacket.php @@ -44,16 +44,12 @@ class ExplodePacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putFloat($this->x); - $this->putFloat($this->y); - $this->putFloat($this->z); - $this->putFloat($this->radius); - $this->putInt(count($this->records)); + $this->putVector3f($this->x, $this->y, $this->z); + $this->putLFloat($this->radius); + $this->putUnsignedVarInt(count($this->records)); if(count($this->records) > 0){ foreach($this->records as $record){ - $this->putByte($record->x); - $this->putByte($record->y); - $this->putByte($record->z); + $this->putBlockCoords($record->x, $record->y, $record->z); } } } diff --git a/src/pocketmine/network/protocol/HurtArmorPacket.php b/src/pocketmine/network/protocol/HurtArmorPacket.php index 2f5896c87..6118dc20d 100644 --- a/src/pocketmine/network/protocol/HurtArmorPacket.php +++ b/src/pocketmine/network/protocol/HurtArmorPacket.php @@ -35,7 +35,7 @@ class HurtArmorPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putByte($this->health); + $this->putVarInt($this->health); } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/InteractPacket.php b/src/pocketmine/network/protocol/InteractPacket.php index 58f5a8067..07cb3d076 100644 --- a/src/pocketmine/network/protocol/InteractPacket.php +++ b/src/pocketmine/network/protocol/InteractPacket.php @@ -39,13 +39,13 @@ class InteractPacket extends DataPacket{ public function decode(){ $this->action = $this->getByte(); - $this->target = $this->getLong(); + $this->target = $this->getEntityId(); } public function encode(){ $this->reset(); $this->putByte($this->action); - $this->putLong($this->target); + $this->putEntityId($this->target); } } diff --git a/src/pocketmine/network/protocol/InventoryActionPacket.php b/src/pocketmine/network/protocol/InventoryActionPacket.php new file mode 100644 index 000000000..79d7924d3 --- /dev/null +++ b/src/pocketmine/network/protocol/InventoryActionPacket.php @@ -0,0 +1,40 @@ + + +class InventoryActionPacket extends DataPacket{ + const NETWORK_ID = Info::INVENTORY_ACTION_PACKET; + + public $unknown; + public $item; + + public function decode(){ + + } + + public function encode(){ + $this->putUnsignedVarInt($this->unknown); + $this->putSlot($this->item); + } +} \ No newline at end of file diff --git a/src/pocketmine/network/protocol/ItemFrameDropItemPacket.php b/src/pocketmine/network/protocol/ItemFrameDropItemPacket.php new file mode 100644 index 000000000..b7932ae50 --- /dev/null +++ b/src/pocketmine/network/protocol/ItemFrameDropItemPacket.php @@ -0,0 +1,44 @@ + + +class ItemFrameDropItemPacket extends DataPacket{ + + const NETWORK_ID = Info::ITEM_FRAME_DROP_ITEM_PACKET; + + public $x; + public $y; + public $z; + public $item; + + public function decode(){ + $this->getBlockCoords($this->x, $this->y, $this->z); + $this->item = $this->getSlot(); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/pocketmine/network/protocol/LevelEventPacket.php b/src/pocketmine/network/protocol/LevelEventPacket.php index b8b59f150..0187c4b20 100644 --- a/src/pocketmine/network/protocol/LevelEventPacket.php +++ b/src/pocketmine/network/protocol/LevelEventPacket.php @@ -23,7 +23,6 @@ namespace pocketmine\network\protocol; #include - class LevelEventPacket extends DataPacket{ const NETWORK_ID = Info::LEVEL_EVENT_PACKET; @@ -67,9 +66,9 @@ class LevelEventPacket extends DataPacket{ const EVENT_ADD_PARTICLE_MASK = 0x4000; public $evid; - public $x; - public $y; - public $z; + public $x = 0; //Weather effects don't have coordinates + public $y = 0; + public $z = 0; public $data; public function decode(){ @@ -78,11 +77,9 @@ class LevelEventPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putShort($this->evid); - $this->putFloat($this->x); - $this->putFloat($this->y); - $this->putFloat($this->z); - $this->putInt($this->data); + $this->putVarInt($this->evid); + $this->putVector3f($this->x, $this->y, $this->z); + $this->putVarInt($this->data); } } diff --git a/src/pocketmine/network/protocol/LevelSoundEventPacket.php b/src/pocketmine/network/protocol/LevelSoundEventPacket.php new file mode 100644 index 000000000..44610940b --- /dev/null +++ b/src/pocketmine/network/protocol/LevelSoundEventPacket.php @@ -0,0 +1,50 @@ + + +class LevelSoundEventPacket extends DataPacket{ + const NETWORK_ID = Info::LEVEL_SOUND_EVENT_PACKET; + + //TODO: find unknowns + public $unknownByte; + public $x; + public $y; + public $z; + public $unknownVarInt1; + public $unknownVarInt2; + public $unknownBool; + + public function decode(){ + + } + + public function encode(){ + $this->reset(); + $this->putByte($this->unknownByte); + $this->putVector3f($this->x, $this->y, $this->z); + $this->putVarInt($this->unknownVarInt1); + $this->putVarInt($this->unknownVarInt2); + $this->putByte($this->unknownBool); + } +} \ No newline at end of file diff --git a/src/pocketmine/network/protocol/MobArmorEquipmentPacket.php b/src/pocketmine/network/protocol/MobArmorEquipmentPacket.php index 0fb13e577..a629c9040 100644 --- a/src/pocketmine/network/protocol/MobArmorEquipmentPacket.php +++ b/src/pocketmine/network/protocol/MobArmorEquipmentPacket.php @@ -31,7 +31,7 @@ class MobArmorEquipmentPacket extends DataPacket{ public $slots = []; public function decode(){ - $this->eid = $this->getLong(); + $this->eid = $this->getEntityId(); $this->slots[0] = $this->getSlot(); $this->slots[1] = $this->getSlot(); $this->slots[2] = $this->getSlot(); @@ -40,7 +40,7 @@ class MobArmorEquipmentPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putLong($this->eid); + $this->putEntityId($this->eid); $this->putSlot($this->slots[0]); $this->putSlot($this->slots[1]); $this->putSlot($this->slots[2]); diff --git a/src/pocketmine/network/protocol/MobEffectPacket.php b/src/pocketmine/network/protocol/MobEffectPacket.php index f38112551..80fa0fa1f 100644 --- a/src/pocketmine/network/protocol/MobEffectPacket.php +++ b/src/pocketmine/network/protocol/MobEffectPacket.php @@ -44,12 +44,12 @@ class MobEffectPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putLong($this->eid); + $this->putEntityId($this->eid); $this->putByte($this->eventId); - $this->putByte($this->effectId); - $this->putByte($this->amplifier); - $this->putByte($this->particles ? 1 : 0); - $this->putInt($this->duration); + $this->putVarInt($this->effectId); + $this->putVarInt($this->amplifier); + $this->putByte($this->particles); + $this->putVarInt($this->duration); } } diff --git a/src/pocketmine/network/protocol/MobEquipmentPacket.php b/src/pocketmine/network/protocol/MobEquipmentPacket.php index fa897b06b..b0dfc584f 100644 --- a/src/pocketmine/network/protocol/MobEquipmentPacket.php +++ b/src/pocketmine/network/protocol/MobEquipmentPacket.php @@ -31,20 +31,23 @@ class MobEquipmentPacket extends DataPacket{ public $item; public $slot; public $selectedSlot; + public $unknownByte; public function decode(){ - $this->eid = $this->getLong(); + $this->eid = $this->getEntityId(); //EntityRuntimeID $this->item = $this->getSlot(); $this->slot = $this->getByte(); $this->selectedSlot = $this->getByte(); + $this->unknownByte = $this->getByte(); } public function encode(){ $this->reset(); - $this->putLong($this->eid); + $this->putEntityId($this->eid); //EntityRuntimeID $this->putSlot($this->item); $this->putByte($this->slot); $this->putByte($this->selectedSlot); + $this->putByte($this->unknownByte); } } diff --git a/src/pocketmine/network/protocol/MoveEntityPacket.php b/src/pocketmine/network/protocol/MoveEntityPacket.php index ffcb4aa61..f13490236 100644 --- a/src/pocketmine/network/protocol/MoveEntityPacket.php +++ b/src/pocketmine/network/protocol/MoveEntityPacket.php @@ -36,10 +36,8 @@ class MoveEntityPacket extends DataPacket{ public $pitch; public function decode(){ - $this->eid = $this->getLong(); - $this->x = $this->getFloat(); - $this->y = $this->getFloat(); - $this->z = $this->getFloat(); + $this->eid = $this->getEntityId(); + $this->getVector3f($this->x, $this->y, $this->z); $this->pitch = $this->getByte() * (360.0 / 256); $this->yaw = $this->getByte() * (360.0 / 256); $this->headYaw = $this->getByte() * (360.0 / 256); @@ -47,10 +45,8 @@ class MoveEntityPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putLong($this->eid); - $this->putFloat($this->x); - $this->putFloat($this->y); - $this->putFloat($this->z); + $this->putEntityId($this->eid); + $this->putVector3f($this->x, $this->y, $this->z); $this->putByte($this->pitch / (360.0 / 256)); $this->putByte($this->yaw / (360.0 / 256)); $this->putByte($this->headYaw / (360.0 / 256)); diff --git a/src/pocketmine/network/protocol/PlayerActionPacket.php b/src/pocketmine/network/protocol/PlayerActionPacket.php index c4186dcb4..c31d46949 100644 --- a/src/pocketmine/network/protocol/PlayerActionPacket.php +++ b/src/pocketmine/network/protocol/PlayerActionPacket.php @@ -40,7 +40,7 @@ class PlayerActionPacket extends DataPacket{ const ACTION_STOP_SPRINT = 10; const ACTION_START_SNEAK = 11; const ACTION_STOP_SNEAK = 12; - const ACTION_DIMENSION_CHANGE = 13; + const ACTION_DIMENSION_CHANGE = 13; //TODO: correct these public $eid; public $action; @@ -50,22 +50,18 @@ class PlayerActionPacket extends DataPacket{ public $face; public function decode(){ - $this->eid = $this->getLong(); - $this->action = $this->getInt(); - $this->x = $this->getInt(); - $this->y = $this->getInt(); - $this->z = $this->getInt(); - $this->face = $this->getInt(); + $this->eid = $this->getEntityId(); + $this->action = $this->getVarInt(); + $this->getBlockCoords($this->x, $this->y, $this->z); + $this->face = $this->getVarInt(); } public function encode(){ $this->reset(); - $this->putLong($this->eid); - $this->putInt($this->action); - $this->putInt($this->x); - $this->putInt($this->y); - $this->putInt($this->z); - $this->putInt($this->face); + $this->putEntityId($this->eid); + $this->putVarInt($this->action); + $this->putBlockCoords($this->x, $this->y, $this->z); + $this->putVarInt($this->face); } } diff --git a/src/pocketmine/network/protocol/PlayerInputPacket.php b/src/pocketmine/network/protocol/PlayerInputPacket.php new file mode 100644 index 000000000..90913ef77 --- /dev/null +++ b/src/pocketmine/network/protocol/PlayerInputPacket.php @@ -0,0 +1,46 @@ + + + +class PlayerInputPacket extends DataPacket{ + const NETWORK_ID = Info::PLAYER_INPUT_PACKET; + + public $motionX; + public $motionY; + public $unknownBool1; + public $unknownBool2; + + public function decode(){ + $this->motionX = $this->getLFloat(); + $this->motionY = $this->getLFloat(); + $this->unknownBool1 = $this->getByte(); + $this->unknownBool2 = $this->getByte(); + } + + public function encode(){ + + } + +} diff --git a/src/pocketmine/network/protocol/PlayerListPacket.php b/src/pocketmine/network/protocol/PlayerListPacket.php index c9f65a664..f74741a82 100644 --- a/src/pocketmine/network/protocol/PlayerListPacket.php +++ b/src/pocketmine/network/protocol/PlayerListPacket.php @@ -30,7 +30,7 @@ class PlayerListPacket extends DataPacket{ const TYPE_ADD = 0; const TYPE_REMOVE = 1; - //REMOVE: UUID, ADD: UUID, entity id, name, isSlim, skin + //REMOVE: UUID, ADD: UUID, entity id, name, skinId, skin /** @var array[] */ public $entries = []; public $type; @@ -51,7 +51,7 @@ class PlayerListPacket extends DataPacket{ foreach($this->entries as $d){ if($this->type === self::TYPE_ADD){ $this->putUUID($d[0]); - $this->putLong($d[1]); + $this->putEntityId($d[1]); $this->putString($d[2]); $this->putString($d[3]); $this->putString($d[4]); diff --git a/src/pocketmine/network/protocol/RemoveBlockPacket.php b/src/pocketmine/network/protocol/RemoveBlockPacket.php index 2f503f11e..5b2591565 100644 --- a/src/pocketmine/network/protocol/RemoveBlockPacket.php +++ b/src/pocketmine/network/protocol/RemoveBlockPacket.php @@ -27,16 +27,12 @@ namespace pocketmine\network\protocol; class RemoveBlockPacket extends DataPacket{ const NETWORK_ID = Info::REMOVE_BLOCK_PACKET; - public $eid; public $x; public $y; public $z; public function decode(){ - $this->eid = $this->getLong(); - $this->x = $this->getInt(); - $this->z = $this->getInt(); - $this->y = $this->getByte(); + $this->getBlockCoords($this->x, $this->y, $this->z); } public function encode(){ diff --git a/src/pocketmine/network/protocol/RemoveEntityPacket.php b/src/pocketmine/network/protocol/RemoveEntityPacket.php index f4b5b4c91..ac4cf9054 100644 --- a/src/pocketmine/network/protocol/RemoveEntityPacket.php +++ b/src/pocketmine/network/protocol/RemoveEntityPacket.php @@ -35,7 +35,7 @@ class RemoveEntityPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putLong($this->eid); + $this->putEntityId($this->eid); } } diff --git a/src/pocketmine/network/protocol/ReplaceSelectedItemPacket.php b/src/pocketmine/network/protocol/ReplaceSelectedItemPacket.php new file mode 100644 index 000000000..46c524d10 --- /dev/null +++ b/src/pocketmine/network/protocol/ReplaceSelectedItemPacket.php @@ -0,0 +1,41 @@ + + + +class ReplaceSelectedItemPacket extends DataPacket{ + const NETWORK_ID = Info::REPLACE_SELECTED_ITEM_PACKET; + + public $item; + + public function decode(){ + + } + + public function encode(){ + $this->reset(); + $this->putSlot($this->item); + } + +} \ No newline at end of file diff --git a/src/pocketmine/network/protocol/RespawnPacket.php b/src/pocketmine/network/protocol/RespawnPacket.php index ee8121c90..ad1279dde 100644 --- a/src/pocketmine/network/protocol/RespawnPacket.php +++ b/src/pocketmine/network/protocol/RespawnPacket.php @@ -32,16 +32,16 @@ class RespawnPacket extends DataPacket{ public $z; public function decode(){ - $this->x = $this->getFloat(); - $this->y = $this->getFloat(); - $this->z = $this->getFloat(); + $this->x = $this->getLFloat(); + $this->y = $this->getLFloat(); + $this->z = $this->getLFloat(); } public function encode(){ $this->reset(); - $this->putFloat($this->x); - $this->putFloat($this->y); - $this->putFloat($this->z); + $this->putLFloat($this->x); + $this->putLFloat($this->y); + $this->putLFloat($this->z); } -} +} \ No newline at end of file diff --git a/src/pocketmine/network/protocol/SetCommandsEnabledPacket.php b/src/pocketmine/network/protocol/SetCommandsEnabledPacket.php new file mode 100644 index 000000000..ad9a92672 --- /dev/null +++ b/src/pocketmine/network/protocol/SetCommandsEnabledPacket.php @@ -0,0 +1,41 @@ + + + +class SetCommandsEnabledPacket extends DataPacket{ + const NETWORK_ID = Info::SET_COMMANDS_ENABLED_PACKET; + + public $enabled; + + public function decode(){ + + } + + public function encode(){ + $this->reset(); + $this->putByte($this->enabled); + } + +} \ No newline at end of file diff --git a/src/pocketmine/network/protocol/SetDifficultyPacket.php b/src/pocketmine/network/protocol/SetDifficultyPacket.php index 23179171d..1b0beb653 100644 --- a/src/pocketmine/network/protocol/SetDifficultyPacket.php +++ b/src/pocketmine/network/protocol/SetDifficultyPacket.php @@ -35,7 +35,7 @@ class SetDifficultyPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->difficulty); + $this->putUnsignedVarInt($this->difficulty); } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/SetEntityDataPacket.php b/src/pocketmine/network/protocol/SetEntityDataPacket.php index ae7b89175..814d2a150 100644 --- a/src/pocketmine/network/protocol/SetEntityDataPacket.php +++ b/src/pocketmine/network/protocol/SetEntityDataPacket.php @@ -40,7 +40,7 @@ class SetEntityDataPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putLong($this->eid); + $this->putEntityId($this->eid); $meta = Binary::writeMetadata($this->metadata); $this->put($meta); } diff --git a/src/pocketmine/network/protocol/SetEntityLinkPacket.php b/src/pocketmine/network/protocol/SetEntityLinkPacket.php index 8533fae82..297b91eec 100644 --- a/src/pocketmine/network/protocol/SetEntityLinkPacket.php +++ b/src/pocketmine/network/protocol/SetEntityLinkPacket.php @@ -37,8 +37,8 @@ class SetEntityLinkPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putLong($this->from); - $this->putLong($this->to); + $this->putEntityId($this->from); + $this->putEntityId($this->to); $this->putByte($this->type); } diff --git a/src/pocketmine/network/protocol/SetEntityMotionPacket.php b/src/pocketmine/network/protocol/SetEntityMotionPacket.php index aa7dbe02f..964f20d15 100644 --- a/src/pocketmine/network/protocol/SetEntityMotionPacket.php +++ b/src/pocketmine/network/protocol/SetEntityMotionPacket.php @@ -27,10 +27,10 @@ namespace pocketmine\network\protocol; class SetEntityMotionPacket extends DataPacket{ const NETWORK_ID = Info::SET_ENTITY_MOTION_PACKET; - - // eid, motX, motY, motZ - /** @var array[] */ - public $entities = []; + public $eid; + public $motionX; + public $motionY; + public $motionZ; public function clean(){ $this->entities = []; @@ -43,13 +43,8 @@ class SetEntityMotionPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt(count($this->entities)); - foreach($this->entities as $d){ - $this->putLong($d[0]); //eid - $this->putFloat($d[1]); //motX - $this->putFloat($d[2]); //motY - $this->putFloat($d[3]); //motZ - } + $this->putEntityId($this->eid); + $this->putVector3f($this->motionX, $this->motionY, $this->motionZ); } } diff --git a/src/pocketmine/network/protocol/SetHealthPacket.php b/src/pocketmine/network/protocol/SetHealthPacket.php index 60fd1687c..7ce8895b4 100644 --- a/src/pocketmine/network/protocol/SetHealthPacket.php +++ b/src/pocketmine/network/protocol/SetHealthPacket.php @@ -35,7 +35,7 @@ class SetHealthPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->health); + $this->putVarInt($this->health); } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/SetPlayerGameTypePacket.php b/src/pocketmine/network/protocol/SetPlayerGameTypePacket.php index 46e0ad72e..98cde80d7 100644 --- a/src/pocketmine/network/protocol/SetPlayerGameTypePacket.php +++ b/src/pocketmine/network/protocol/SetPlayerGameTypePacket.php @@ -35,7 +35,7 @@ class SetPlayerGameTypePacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->gamemode); + $this->putVarInt($this->gamemode); } } diff --git a/src/pocketmine/network/protocol/SetSpawnPositionPacket.php b/src/pocketmine/network/protocol/SetSpawnPositionPacket.php index cf9571bb7..a220671e0 100644 --- a/src/pocketmine/network/protocol/SetSpawnPositionPacket.php +++ b/src/pocketmine/network/protocol/SetSpawnPositionPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\protocol; class SetSpawnPositionPacket extends DataPacket{ const NETWORK_ID = Info::SET_SPAWN_POSITION_PACKET; + public $unknown; public $x; public $y; public $z; @@ -37,9 +38,8 @@ class SetSpawnPositionPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->x); - $this->putInt($this->y); - $this->putInt($this->z); + $this->putVarInt($this->unknown); + $this->putBlockCoords($this->x, $this->y, $this->z); } } diff --git a/src/pocketmine/network/protocol/SetTimePacket.php b/src/pocketmine/network/protocol/SetTimePacket.php index 0d1fcca58..5ea5bf205 100644 --- a/src/pocketmine/network/protocol/SetTimePacket.php +++ b/src/pocketmine/network/protocol/SetTimePacket.php @@ -35,8 +35,8 @@ class SetTimePacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->time); - $this->putByte($this->started ? 1 : 0); + $this->putVarInt($this->time); + $this->putByte((int) $this->started); } } diff --git a/src/pocketmine/network/protocol/SpawnExperienceOrbPacket.php b/src/pocketmine/network/protocol/SpawnExperienceOrbPacket.php new file mode 100644 index 000000000..6f38d86c2 --- /dev/null +++ b/src/pocketmine/network/protocol/SpawnExperienceOrbPacket.php @@ -0,0 +1,44 @@ + + + +class SpawnExperienceOrbPacket extends DataPacket{ + const NETWORK_ID = Info::SPAWN_EXPERIENCE_ORB_PACKET; + + public $x; + public $y; + public $z; + public $amount; + + public function decode(){ + + } + + public function encode(){ + $this->reset(); + $this->putVector3f($this->x, $this->y, $this->z); + $this->putVarInt($this->amount); + } +} \ No newline at end of file diff --git a/src/pocketmine/network/protocol/TakeItemEntityPacket.php b/src/pocketmine/network/protocol/TakeItemEntityPacket.php index 09b0f2c0c..887477d71 100644 --- a/src/pocketmine/network/protocol/TakeItemEntityPacket.php +++ b/src/pocketmine/network/protocol/TakeItemEntityPacket.php @@ -36,8 +36,8 @@ class TakeItemEntityPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putLong($this->target); - $this->putLong($this->eid); + $this->putEntityId($this->target); + $this->putEntityId($this->eid); } } diff --git a/src/pocketmine/network/protocol/UpdateAttributesPacket.php b/src/pocketmine/network/protocol/UpdateAttributesPacket.php index 46bc3cf6e..53c723aaf 100644 --- a/src/pocketmine/network/protocol/UpdateAttributesPacket.php +++ b/src/pocketmine/network/protocol/UpdateAttributesPacket.php @@ -40,15 +40,13 @@ class UpdateAttributesPacket extends DataPacket{ public function encode(){ $this->reset(); - - $this->putLong($this->entityId); - - $this->putShort(count($this->entries)); - + $this->putEntityId($this->entityId); + $this->putUnsignedVarInt(count($this->entries)); foreach($this->entries as $entry){ - $this->putFloat($entry->getMinValue()); - $this->putFloat($entry->getMaxValue()); - $this->putFloat($entry->getValue()); + $this->putLFloat($entry->getMinValue()); + $this->putLFloat($entry->getMaxValue()); + $this->putLFloat($entry->getValue()); + $this->putLFloat($entry->getDefaultValue()); $this->putString($entry->getName()); } } diff --git a/src/pocketmine/network/protocol/UpdateBlockPacket.php b/src/pocketmine/network/protocol/UpdateBlockPacket.php index 673e066bd..70fc5e01d 100644 --- a/src/pocketmine/network/protocol/UpdateBlockPacket.php +++ b/src/pocketmine/network/protocol/UpdateBlockPacket.php @@ -49,11 +49,9 @@ class UpdateBlockPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->x); - $this->putInt($this->z); - $this->putByte($this->y); - $this->putByte($this->blockId); - $this->putByte(($this->flags << 4) | $this->blockData); + $this->putBlockCoords($this->x, $this->y, $this->z); + $this->putUnsignedVarInt($this->blockId); + $this->putUnsignedVarInt(($this->flags << 4) | $this->blockData); } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/UseItemPacket.php b/src/pocketmine/network/protocol/UseItemPacket.php index 42752c138..c909f3eb4 100644 --- a/src/pocketmine/network/protocol/UseItemPacket.php +++ b/src/pocketmine/network/protocol/UseItemPacket.php @@ -41,18 +41,11 @@ class UseItemPacket extends DataPacket{ public $slot; public function decode(){ - $this->x = $this->getInt(); - $this->y = $this->getInt(); - $this->z = $this->getInt(); - $this->face = $this->getByte(); - $this->fx = $this->getFloat(); - $this->fy = $this->getFloat(); - $this->fz = $this->getFloat(); - $this->posX = $this->getFloat(); - $this->posY = $this->getFloat(); - $this->posZ = $this->getFloat(); - $this->slot = $this->getInt(); - + $this->getBlockCoords($this->x, $this->y, $this->z); + $this->face = $this->getVarInt(); + $this->getVector3f($this->fx, $this->fy, $this->fz); + $this->getVector3f($this->posX, $this->posY, $this->posZ); + $this->slot = $this->getVarInt(); $this->item = $this->getSlot(); }