mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
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:
@ -412,7 +412,7 @@ class Binary{
|
||||
* Reads a 64-bit zigzag-encoded variable-length integer from the supplied stream.
|
||||
* @param \pocketmine\nbt\NBT|BinaryStream $stream
|
||||
*
|
||||
* @return int
|
||||
* @return int|string
|
||||
*/
|
||||
public static function readVarLong($stream){
|
||||
if(PHP_INT_SIZE === 8){
|
||||
@ -476,7 +476,6 @@ class Binary{
|
||||
for($i = 0; $i <= 63; $i += 7){
|
||||
$b = $stream->getByte();
|
||||
$value = bcadd($value, bcmul($b & 0x7f, bcpow("2", "$i")));
|
||||
var_dump($value);
|
||||
|
||||
if(($b & 0x80) === 0){
|
||||
return $value;
|
||||
@ -497,7 +496,6 @@ class Binary{
|
||||
for($i = 0; $i <= 63; $i += 7){
|
||||
$b = $stream->getByte();
|
||||
$value |= (($b & 0x7f) << $i);
|
||||
var_dump($value);
|
||||
|
||||
if(($b & 0x80) === 0){
|
||||
return $value;
|
||||
|
@ -233,66 +233,68 @@ class BinaryStream extends \stdClass{
|
||||
$this->put($v);
|
||||
}
|
||||
|
||||
//TODO: varint64
|
||||
|
||||
/**
|
||||
* Reads an unsigned varint32 from the stream.
|
||||
* Reads a 32-bit variable-length unsigned integer from the buffer and returns it.
|
||||
* @return int
|
||||
*/
|
||||
public function getUnsignedVarInt(){
|
||||
return Binary::readUnsignedVarInt($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an unsigned varint32 to the stream.
|
||||
* Writes a 32-bit variable-length unsigned integer to the end of the buffer.
|
||||
* @param int $v
|
||||
*/
|
||||
public function putUnsignedVarInt($v){
|
||||
$this->put(Binary::writeUnsignedVarInt($v));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a signed varint32 from the stream.
|
||||
* Reads a 32-bit zigzag-encoded variable-length integer from the buffer and returns it.
|
||||
* @return int
|
||||
*/
|
||||
public function getVarInt(){
|
||||
return Binary::readVarInt($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a signed varint32 to the stream.
|
||||
* Writes a 32-bit zigzag-encoded variable-length integer to the end of the buffer.
|
||||
* @param int $v
|
||||
*/
|
||||
public function putVarInt($v){
|
||||
$this->put(Binary::writeVarInt($v));
|
||||
}
|
||||
|
||||
public function getEntityId(){
|
||||
return $this->getVarInt();
|
||||
/**
|
||||
* Reads a 64-bit variable-length integer from the buffer and returns it.
|
||||
* @return int|string int, or the string representation of an int64 on 32-bit platforms
|
||||
*/
|
||||
public function getUnsignedVarLong(){
|
||||
return Binary::readUnsignedVarLong($this);
|
||||
}
|
||||
|
||||
public function putEntityId($v){
|
||||
$this->putVarInt($v);
|
||||
/**
|
||||
* Writes a 64-bit variable-length integer to the end of the buffer.
|
||||
* @param int|string $v int, or the string representation of an int64 on 32-bit platforms
|
||||
*/
|
||||
public function putUnsignedVarLong($v){
|
||||
$this->buffer .= Binary::writeUnsignedVarLong($v);
|
||||
}
|
||||
|
||||
public function getBlockCoords(&$x, &$y, &$z){
|
||||
$x = $this->getVarInt();
|
||||
$y = $this->getUnsignedVarInt();
|
||||
$z = $this->getVarInt();
|
||||
/**
|
||||
* Reads a 64-bit zigzag-encoded variable-length integer from the buffer and returns it.
|
||||
* @return int|string int, or the string representation of an int64 on 32-bit platforms
|
||||
*/
|
||||
public function getVarLong(){
|
||||
return Binary::readVarLong($this);
|
||||
}
|
||||
|
||||
public function putBlockCoords($x, $y, $z){
|
||||
$this->putVarInt($x);
|
||||
$this->putUnsignedVarInt($y);
|
||||
$this->putVarInt($z);
|
||||
}
|
||||
|
||||
public function getVector3f(&$x, &$y, &$z){
|
||||
$x = $this->getLFloat(4);
|
||||
$y = $this->getLFloat(4);
|
||||
$z = $this->getLFloat(4);
|
||||
}
|
||||
|
||||
public function putVector3f($x, $y, $z){
|
||||
$this->putLFloat($x);
|
||||
$this->putLFloat($y);
|
||||
$this->putLFloat($z);
|
||||
/**
|
||||
* Writes a 64-bit zigzag-encoded variable-length integer to the end of the buffer.
|
||||
* @param int|string $v int, or the string representation of an int64 on 32-bit platforms
|
||||
*/
|
||||
public function putVarLong($v){
|
||||
$this->buffer .= Binary::writeVarLong($v);
|
||||
}
|
||||
|
||||
public function feof(){
|
||||
|
Reference in New Issue
Block a user