Network: Remove legacy Vector3 primitive encode/decode methods

This commit is contained in:
Dylan K. Taylor 2018-01-20 10:58:39 +00:00
parent 2eb6e075ae
commit 95d42b9907
15 changed files with 52 additions and 78 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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){

View File

@ -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");

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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{

View File

@ -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{

View File

@ -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);
}

View File

@ -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);