diff --git a/src/pocketmine/network/mcpe/NetworkBinaryStream.php b/src/pocketmine/network/mcpe/NetworkBinaryStream.php index 2c82dea5a..7e27eaab2 100644 --- a/src/pocketmine/network/mcpe/NetworkBinaryStream.php +++ b/src/pocketmine/network/mcpe/NetworkBinaryStream.php @@ -163,7 +163,7 @@ class NetworkBinaryStream extends BinaryStream{ $value = $this->getVarLong(); break; case Entity::DATA_TYPE_VECTOR3F: - $value = $this->getVector3Obj(); + $value = $this->getVector3(); break; default: $value = []; @@ -219,7 +219,7 @@ class NetworkBinaryStream extends BinaryStream{ $this->putVarLong($d[1]); break; case Entity::DATA_TYPE_VECTOR3F: - $this->putVector3ObjNullable($d[1]); + $this->putVector3Nullable($d[1]); } } } @@ -360,38 +360,11 @@ class NetworkBinaryStream extends BinaryStream{ } /** - * Reads a floating-point vector3 rounded to 4dp. - * - * @param float $x - * @param float $y - * @param float $z - */ - public function getVector3f(&$x, &$y, &$z){ - $x = $this->getRoundedLFloat(4); - $y = $this->getRoundedLFloat(4); - $z = $this->getRoundedLFloat(4); - } - - /** - * Writes a floating-point vector3 - * - * @param float $x - * @param float $y - * @param float $z - */ - public function putVector3f(float $x, float $y, float $z){ - $this->putLFloat($x); - $this->putLFloat($y); - $this->putLFloat($z); - } - - /** - * Reads a floating-point Vector3 object - * TODO: get rid of primitive methods and replace with this + * Reads a floating-point Vector3 object with coordinates rounded to 4 decimal places. * * @return Vector3 */ - public function getVector3Obj() : Vector3{ + public function getVector3() : Vector3{ return new Vector3( $this->getRoundedLFloat(4), $this->getRoundedLFloat(4), @@ -403,13 +376,15 @@ class NetworkBinaryStream extends BinaryStream{ * Writes a floating-point Vector3 object, or 3x zero if null is given. * * Note: ONLY use this where it is reasonable to allow not specifying the vector. - * For all other purposes, use {@link DataPacket#putVector3Obj} + * For all other purposes, use the non-nullable version. + * + * @see NetworkBinaryStream::putVector3() * * @param Vector3|null $vector */ - public function putVector3ObjNullable(Vector3 $vector = null){ + public function putVector3Nullable(Vector3 $vector = null){ if($vector){ - $this->putVector3Obj($vector); + $this->putVector3($vector); }else{ $this->putLFloat(0.0); $this->putLFloat(0.0); @@ -419,11 +394,10 @@ class NetworkBinaryStream extends BinaryStream{ /** * Writes a floating-point Vector3 object - * TODO: get rid of primitive methods and replace with this * * @param Vector3 $vector */ - public function putVector3Obj(Vector3 $vector){ + public function putVector3(Vector3 $vector){ $this->putLFloat($vector->x); $this->putLFloat($vector->y); $this->putLFloat($vector->z); diff --git a/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php b/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php index 6df34a866..8b1f33166 100644 --- a/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php @@ -59,8 +59,8 @@ class AddEntityPacket extends DataPacket{ $this->entityUniqueId = $this->getEntityUniqueId(); $this->entityRuntimeId = $this->getEntityRuntimeId(); $this->type = $this->getUnsignedVarInt(); - $this->position = $this->getVector3Obj(); - $this->motion = $this->getVector3Obj(); + $this->position = $this->getVector3(); + $this->motion = $this->getVector3(); $this->pitch = $this->getLFloat(); $this->yaw = $this->getLFloat(); @@ -93,8 +93,8 @@ class AddEntityPacket extends DataPacket{ $this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); $this->putEntityRuntimeId($this->entityRuntimeId); $this->putUnsignedVarInt($this->type); - $this->putVector3Obj($this->position); - $this->putVector3ObjNullable($this->motion); + $this->putVector3($this->position); + $this->putVector3Nullable($this->motion); $this->putLFloat($this->pitch); $this->putLFloat($this->yaw); diff --git a/src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php b/src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php index c8f059212..a70425e4b 100644 --- a/src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php @@ -49,8 +49,8 @@ class AddItemEntityPacket extends DataPacket{ $this->entityUniqueId = $this->getEntityUniqueId(); $this->entityRuntimeId = $this->getEntityRuntimeId(); $this->item = $this->getSlot(); - $this->position = $this->getVector3Obj(); - $this->motion = $this->getVector3Obj(); + $this->position = $this->getVector3(); + $this->motion = $this->getVector3(); $this->metadata = $this->getEntityMetadata(); } @@ -58,8 +58,8 @@ class AddItemEntityPacket extends DataPacket{ $this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); $this->putEntityRuntimeId($this->entityRuntimeId); $this->putSlot($this->item); - $this->putVector3Obj($this->position); - $this->putVector3ObjNullable($this->motion); + $this->putVector3($this->position); + $this->putVector3Nullable($this->motion); $this->putEntityMetadata($this->metadata); } diff --git a/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php b/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php index 6b58f7ef4..22c7c2263 100644 --- a/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php @@ -74,8 +74,8 @@ class AddPlayerPacket extends DataPacket{ $this->username = $this->getString(); $this->entityUniqueId = $this->getEntityUniqueId(); $this->entityRuntimeId = $this->getEntityRuntimeId(); - $this->position = $this->getVector3Obj(); - $this->motion = $this->getVector3Obj(); + $this->position = $this->getVector3(); + $this->motion = $this->getVector3(); $this->pitch = $this->getLFloat(); $this->yaw = $this->getLFloat(); $this->headYaw = $this->getLFloat(); @@ -101,8 +101,8 @@ class AddPlayerPacket extends DataPacket{ $this->putString($this->username); $this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); $this->putEntityRuntimeId($this->entityRuntimeId); - $this->putVector3Obj($this->position); - $this->putVector3ObjNullable($this->motion); + $this->putVector3($this->position); + $this->putVector3Nullable($this->motion); $this->putLFloat($this->pitch); $this->putLFloat($this->yaw); $this->putLFloat($this->headYaw ?? $this->yaw); diff --git a/src/pocketmine/network/mcpe/protocol/ChangeDimensionPacket.php b/src/pocketmine/network/mcpe/protocol/ChangeDimensionPacket.php index 9e34db177..543cdad95 100644 --- a/src/pocketmine/network/mcpe/protocol/ChangeDimensionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ChangeDimensionPacket.php @@ -41,13 +41,13 @@ class ChangeDimensionPacket extends DataPacket{ protected function decodePayload(){ $this->dimension = $this->getVarInt(); - $this->position = $this->getVector3Obj(); + $this->position = $this->getVector3(); $this->respawn = $this->getBool(); } protected function encodePayload(){ $this->putVarInt($this->dimension); - $this->putVector3Obj($this->position); + $this->putVector3($this->position); $this->putBool($this->respawn); } diff --git a/src/pocketmine/network/mcpe/protocol/ExplodePacket.php b/src/pocketmine/network/mcpe/protocol/ExplodePacket.php index c2a384969..8f98615d4 100644 --- a/src/pocketmine/network/mcpe/protocol/ExplodePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ExplodePacket.php @@ -45,7 +45,7 @@ class ExplodePacket extends DataPacket{ } protected function decodePayload(){ - $this->position = $this->getVector3Obj(); + $this->position = $this->getVector3(); $this->radius = (float) ($this->getVarInt() / 32); $count = $this->getUnsignedVarInt(); for($i = 0; $i < $count; ++$i){ @@ -56,7 +56,7 @@ class ExplodePacket extends DataPacket{ } protected function encodePayload(){ - $this->putVector3Obj($this->position); + $this->putVector3($this->position); $this->putVarInt((int) ($this->radius * 32)); $this->putUnsignedVarInt(count($this->records)); if(count($this->records) > 0){ diff --git a/src/pocketmine/network/mcpe/protocol/InventoryTransactionPacket.php b/src/pocketmine/network/mcpe/protocol/InventoryTransactionPacket.php index 1a732317b..be3c31238 100644 --- a/src/pocketmine/network/mcpe/protocol/InventoryTransactionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/InventoryTransactionPacket.php @@ -83,22 +83,22 @@ class InventoryTransactionPacket extends DataPacket{ $this->trData->face = $this->getVarInt(); $this->trData->hotbarSlot = $this->getVarInt(); $this->trData->itemInHand = $this->getSlot(); - $this->trData->playerPos = $this->getVector3Obj(); - $this->trData->clickPos = $this->getVector3Obj(); + $this->trData->playerPos = $this->getVector3(); + $this->trData->clickPos = $this->getVector3(); break; case self::TYPE_USE_ITEM_ON_ENTITY: $this->trData->entityRuntimeId = $this->getEntityRuntimeId(); $this->trData->actionType = $this->getUnsignedVarInt(); $this->trData->hotbarSlot = $this->getVarInt(); $this->trData->itemInHand = $this->getSlot(); - $this->trData->vector1 = $this->getVector3Obj(); - $this->trData->vector2 = $this->getVector3Obj(); + $this->trData->vector1 = $this->getVector3(); + $this->trData->vector2 = $this->getVector3(); break; case self::TYPE_RELEASE_ITEM: $this->trData->actionType = $this->getUnsignedVarInt(); $this->trData->hotbarSlot = $this->getVarInt(); $this->trData->itemInHand = $this->getSlot(); - $this->trData->headPos = $this->getVector3Obj(); + $this->trData->headPos = $this->getVector3(); break; default: throw new \UnexpectedValueException("Unknown transaction type $this->transactionType"); @@ -123,22 +123,22 @@ class InventoryTransactionPacket extends DataPacket{ $this->putVarInt($this->trData->face); $this->putVarInt($this->trData->hotbarSlot); $this->putSlot($this->trData->itemInHand); - $this->putVector3Obj($this->trData->playerPos); - $this->putVector3Obj($this->trData->clickPos); + $this->putVector3($this->trData->playerPos); + $this->putVector3($this->trData->clickPos); break; case self::TYPE_USE_ITEM_ON_ENTITY: $this->putEntityRuntimeId($this->trData->entityRuntimeId); $this->putUnsignedVarInt($this->trData->actionType); $this->putVarInt($this->trData->hotbarSlot); $this->putSlot($this->trData->itemInHand); - $this->putVector3Obj($this->trData->vector1); - $this->putVector3Obj($this->trData->vector2); + $this->putVector3($this->trData->vector1); + $this->putVector3($this->trData->vector2); break; case self::TYPE_RELEASE_ITEM: $this->putUnsignedVarInt($this->trData->actionType); $this->putVarInt($this->trData->hotbarSlot); $this->putSlot($this->trData->itemInHand); - $this->putVector3Obj($this->trData->headPos); + $this->putVector3($this->trData->headPos); break; default: throw new \UnexpectedValueException("Unknown transaction type $this->transactionType"); diff --git a/src/pocketmine/network/mcpe/protocol/LevelEventPacket.php b/src/pocketmine/network/mcpe/protocol/LevelEventPacket.php index 2f82d0114..3643d2c6f 100644 --- a/src/pocketmine/network/mcpe/protocol/LevelEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LevelEventPacket.php @@ -118,13 +118,13 @@ class LevelEventPacket extends DataPacket{ protected function decodePayload(){ $this->evid = $this->getVarInt(); - $this->position = $this->getVector3Obj(); + $this->position = $this->getVector3(); $this->data = $this->getVarInt(); } protected function encodePayload(){ $this->putVarInt($this->evid); - $this->putVector3ObjNullable($this->position); + $this->putVector3Nullable($this->position); $this->putVarInt($this->data); } diff --git a/src/pocketmine/network/mcpe/protocol/LevelSoundEventPacket.php b/src/pocketmine/network/mcpe/protocol/LevelSoundEventPacket.php index c2fd36650..1afd53ce7 100644 --- a/src/pocketmine/network/mcpe/protocol/LevelSoundEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LevelSoundEventPacket.php @@ -213,7 +213,7 @@ class LevelSoundEventPacket extends DataPacket{ protected function decodePayload(){ $this->sound = $this->getByte(); - $this->position = $this->getVector3Obj(); + $this->position = $this->getVector3(); $this->extraData = $this->getVarInt(); $this->pitch = $this->getVarInt(); $this->unknownBool = $this->getBool(); @@ -222,7 +222,7 @@ class LevelSoundEventPacket extends DataPacket{ protected function encodePayload(){ $this->putByte($this->sound); - $this->putVector3Obj($this->position); + $this->putVector3($this->position); $this->putVarInt($this->extraData); $this->putVarInt($this->pitch); $this->putBool($this->unknownBool); diff --git a/src/pocketmine/network/mcpe/protocol/MoveEntityPacket.php b/src/pocketmine/network/mcpe/protocol/MoveEntityPacket.php index 6e0093cc1..3946d7d03 100644 --- a/src/pocketmine/network/mcpe/protocol/MoveEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MoveEntityPacket.php @@ -49,7 +49,7 @@ class MoveEntityPacket extends DataPacket{ protected function decodePayload(){ $this->entityRuntimeId = $this->getEntityRuntimeId(); - $this->position = $this->getVector3Obj(); + $this->position = $this->getVector3(); $this->pitch = $this->getByteRotation(); $this->headYaw = $this->getByteRotation(); $this->yaw = $this->getByteRotation(); @@ -59,7 +59,7 @@ class MoveEntityPacket extends DataPacket{ protected function encodePayload(){ $this->putEntityRuntimeId($this->entityRuntimeId); - $this->putVector3Obj($this->position); + $this->putVector3($this->position); $this->putByteRotation($this->pitch); $this->putByteRotation($this->headYaw); $this->putByteRotation($this->yaw); diff --git a/src/pocketmine/network/mcpe/protocol/MovePlayerPacket.php b/src/pocketmine/network/mcpe/protocol/MovePlayerPacket.php index 552a090e0..6e91f4885 100644 --- a/src/pocketmine/network/mcpe/protocol/MovePlayerPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MovePlayerPacket.php @@ -60,7 +60,7 @@ class MovePlayerPacket extends DataPacket{ protected function decodePayload(){ $this->entityRuntimeId = $this->getEntityRuntimeId(); - $this->position = $this->getVector3Obj(); + $this->position = $this->getVector3(); $this->pitch = $this->getLFloat(); $this->yaw = $this->getLFloat(); $this->headYaw = $this->getLFloat(); @@ -75,7 +75,7 @@ class MovePlayerPacket extends DataPacket{ protected function encodePayload(){ $this->putEntityRuntimeId($this->entityRuntimeId); - $this->putVector3Obj($this->position); + $this->putVector3($this->position); $this->putLFloat($this->pitch); $this->putLFloat($this->yaw); $this->putLFloat($this->headYaw); //TODO diff --git a/src/pocketmine/network/mcpe/protocol/RespawnPacket.php b/src/pocketmine/network/mcpe/protocol/RespawnPacket.php index d45493b67..c9b4255a5 100644 --- a/src/pocketmine/network/mcpe/protocol/RespawnPacket.php +++ b/src/pocketmine/network/mcpe/protocol/RespawnPacket.php @@ -36,11 +36,11 @@ class RespawnPacket extends DataPacket{ public $position; protected function decodePayload(){ - $this->position = $this->getVector3Obj(); + $this->position = $this->getVector3(); } protected function encodePayload(){ - $this->putVector3Obj($this->position); + $this->putVector3($this->position); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php b/src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php index 2da1e4bd0..1ed0d2f93 100644 --- a/src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php @@ -39,12 +39,12 @@ class SetEntityMotionPacket extends DataPacket{ protected function decodePayload(){ $this->entityRuntimeId = $this->getEntityRuntimeId(); - $this->motion = $this->getVector3Obj(); + $this->motion = $this->getVector3(); } protected function encodePayload(){ $this->putEntityRuntimeId($this->entityRuntimeId); - $this->putVector3Obj($this->motion); + $this->putVector3($this->motion); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/SpawnExperienceOrbPacket.php b/src/pocketmine/network/mcpe/protocol/SpawnExperienceOrbPacket.php index 31b2490fb..cacfc0dd6 100644 --- a/src/pocketmine/network/mcpe/protocol/SpawnExperienceOrbPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SpawnExperienceOrbPacket.php @@ -38,12 +38,12 @@ class SpawnExperienceOrbPacket extends DataPacket{ public $amount; protected function decodePayload(){ - $this->position = $this->getVector3Obj(); + $this->position = $this->getVector3(); $this->amount = $this->getVarInt(); } protected function encodePayload(){ - $this->putVector3Obj($this->position); + $this->putVector3($this->position); $this->putVarInt($this->amount); } diff --git a/src/pocketmine/network/mcpe/protocol/StartGamePacket.php b/src/pocketmine/network/mcpe/protocol/StartGamePacket.php index 20dfcb8f9..075f66c38 100644 --- a/src/pocketmine/network/mcpe/protocol/StartGamePacket.php +++ b/src/pocketmine/network/mcpe/protocol/StartGamePacket.php @@ -115,7 +115,7 @@ class StartGamePacket extends DataPacket{ $this->entityRuntimeId = $this->getEntityRuntimeId(); $this->playerGamemode = $this->getVarInt(); - $this->playerPosition = $this->getVector3Obj(); + $this->playerPosition = $this->getVector3(); $this->pitch = $this->getLFloat(); $this->yaw = $this->getLFloat(); @@ -158,7 +158,7 @@ class StartGamePacket extends DataPacket{ $this->putEntityRuntimeId($this->entityRuntimeId); $this->putVarInt($this->playerGamemode); - $this->putVector3Obj($this->playerPosition); + $this->putVector3($this->playerPosition); $this->putLFloat($this->pitch); $this->putLFloat($this->yaw);