Cleaned up muddled varint/varlong mess, added separate methods for entity unique and runtime ids, moved some MCPE-protocol-specific methods out of BinaryStream

This commit is contained in:
Dylan K. Taylor
2017-03-08 19:34:12 +00:00
parent 3a044f0154
commit 295d9bc80b
36 changed files with 177 additions and 110 deletions

View File

@ -122,7 +122,7 @@ abstract class DataPacket extends BinaryStream{
$value[2] = $this->getVarInt(); //z
break;
case Entity::DATA_TYPE_LONG:
$value = $this->getVarInt(); //TODO: varint64 proper support
$value = $this->getVarLong();
break;
case Entity::DATA_TYPE_VECTOR3F:
$value = [0.0, 0.0, 0.0];
@ -178,7 +178,7 @@ abstract class DataPacket extends BinaryStream{
$this->putVarInt($d[1][2]); //z
break;
case Entity::DATA_TYPE_LONG:
$this->putVarInt($d[1]); //TODO: varint64 support
$this->putVarLong($d[1]);
break;
case Entity::DATA_TYPE_VECTOR3F:
//TODO: change this implementation (use objects)
@ -186,4 +186,84 @@ abstract class DataPacket extends BinaryStream{
}
}
}
/**
* Reads and returns an EntityUniqueID
* @return int|string
*/
public function getEntityUniqueId(){
return $this->getVarLong();
}
/**
* Writes an EntityUniqueID
* @param int|string $eid
*/
public function putEntityUniqueId($eid){
$this->putVarLong($eid);
}
/**
* Reads and returns an EntityRuntimeID
* @return int|string
*/
public function getEntityRuntimeId(){
return $this->getUnsignedVarLong();
}
/**
* Writes an EntityUniqueID
* @param int|string $eid
*/
public function putEntityRuntimeId($eid){
$this->putUnsignedVarLong($eid);
}
/**
* Writes an block position with unsigned Y coordinate.
* @param int $x
* @param int $y 0-255
* @param int $z
*/
public function getBlockPosition(&$x, &$y, &$z){
$x = $this->getVarInt();
$y = $this->getUnsignedVarInt();
$z = $this->getVarInt();
}
/**
* Reads a block position with unsigned Y coordinate.
* @param int &$x
* @param int &$y
* @param int &$z
*/
public function putBlockPosition($x, $y, $z){
$this->putVarInt($x);
$this->putUnsignedVarInt($y);
$this->putVarInt($z);
}
/**
* 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->getLFloat(4);
$y = $this->getLFloat(4);
$z = $this->getLFloat(4);
}
/**
* Writes a floating-point vector3
* @param float $x
* @param float $y
* @param float $z
*/
public function putVector3f($x, $y, $z){
$this->putLFloat($x);
$this->putLFloat($y);
$this->putLFloat($z);
}
}