mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 10:19:39 +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:
parent
3a044f0154
commit
295d9bc80b
@ -50,8 +50,8 @@ class AddEntityPacket extends DataPacket{
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->eid); //EntityUniqueID - TODO: verify this
|
||||
$this->putEntityId($this->eid);
|
||||
$this->putEntityUniqueId($this->eid);
|
||||
$this->putEntityRuntimeId($this->eid);
|
||||
$this->putUnsignedVarInt($this->type);
|
||||
$this->putVector3f($this->x, $this->y, $this->z);
|
||||
$this->putVector3f($this->speedX, $this->speedY, $this->speedZ);
|
||||
@ -67,8 +67,8 @@ class AddEntityPacket extends DataPacket{
|
||||
$this->putEntityMetadata($this->metadata);
|
||||
$this->putUnsignedVarInt(count($this->links));
|
||||
foreach($this->links as $link){
|
||||
$this->putEntityId($link[0]);
|
||||
$this->putEntityId($link[1]);
|
||||
$this->putEntityUniqueId($link[0]);
|
||||
$this->putEntityUniqueId($link[1]);
|
||||
$this->putByte($link[2]);
|
||||
}
|
||||
}
|
||||
|
@ -41,9 +41,9 @@ class AddHangingEntityPacket extends DataPacket{
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->entityUniqueId);
|
||||
$this->putEntityId($this->entityRuntimeId);
|
||||
$this->putBlockCoords($this->x, $this->y, $this->z);
|
||||
$this->putEntityUniqueId($this->entityUniqueId);
|
||||
$this->putEntityRuntimeId($this->entityRuntimeId);
|
||||
$this->putBlockPosition($this->x, $this->y, $this->z);
|
||||
$this->putVarInt($this->unknown);
|
||||
}
|
||||
|
||||
|
@ -44,8 +44,8 @@ class AddItemEntityPacket extends DataPacket{
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->eid); //EntityUniqueID
|
||||
$this->putEntityId($this->eid); //EntityRuntimeID
|
||||
$this->putEntityUniqueId($this->eid);
|
||||
$this->putEntityRuntimeId($this->eid);
|
||||
$this->putSlot($this->item);
|
||||
$this->putVector3f($this->x, $this->y, $this->z);
|
||||
$this->putVector3f($this->speedX, $this->speedY, $this->speedZ);
|
||||
|
@ -42,9 +42,9 @@ class AddPaintingPacket extends DataPacket{
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->eid); //EntityUniqueID
|
||||
$this->putEntityId($this->eid); //EntityRuntimeID
|
||||
$this->putBlockCoords($this->x, $this->y, $this->z);
|
||||
$this->putEntityUniqueId($this->eid);
|
||||
$this->putEntityRuntimeId($this->eid);
|
||||
$this->putBlockPosition($this->x, $this->y, $this->z);
|
||||
$this->putVarInt($this->direction);
|
||||
$this->putString($this->title);
|
||||
}
|
||||
|
@ -51,8 +51,8 @@ class AddPlayerPacket extends DataPacket{
|
||||
$this->reset();
|
||||
$this->putUUID($this->uuid);
|
||||
$this->putString($this->username);
|
||||
$this->putEntityId($this->eid); //EntityUniqueID
|
||||
$this->putEntityId($this->eid); //EntityRuntimeID
|
||||
$this->putEntityUniqueId($this->eid);
|
||||
$this->putEntityRuntimeId($this->eid);
|
||||
$this->putVector3f($this->x, $this->y, $this->z);
|
||||
$this->putVector3f($this->speedX, $this->speedY, $this->speedZ);
|
||||
$this->putLFloat($this->pitch);
|
||||
|
@ -34,13 +34,13 @@ class AnimatePacket extends DataPacket{
|
||||
|
||||
public function decode(){
|
||||
$this->action = $this->getVarInt();
|
||||
$this->eid = $this->getEntityId();
|
||||
$this->eid = $this->getEntityRuntimeId();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putVarInt($this->action);
|
||||
$this->putEntityId($this->eid);
|
||||
$this->putEntityRuntimeId($this->eid);
|
||||
}
|
||||
|
||||
public function handle(NetworkSession $session) : bool{
|
||||
|
@ -35,13 +35,13 @@ class BlockEntityDataPacket extends DataPacket{
|
||||
public $namedtag;
|
||||
|
||||
public function decode(){
|
||||
$this->getBlockCoords($this->x, $this->y, $this->z);
|
||||
$this->getBlockPosition($this->x, $this->y, $this->z);
|
||||
$this->namedtag = $this->get(true);
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putBlockCoords($this->x, $this->y, $this->z);
|
||||
$this->putBlockPosition($this->x, $this->y, $this->z);
|
||||
$this->put($this->namedtag);
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ class BlockEventPacket extends DataPacket{
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putBlockCoords($this->x, $this->y, $this->z);
|
||||
$this->putBlockPosition($this->x, $this->y, $this->z);
|
||||
$this->putVarInt($this->case1);
|
||||
$this->putVarInt($this->case2);
|
||||
}
|
||||
|
@ -28,25 +28,13 @@ use pocketmine\network\mcpe\NetworkSession;
|
||||
class CommandStepPacket extends DataPacket{
|
||||
const NETWORK_ID = ProtocolInfo::COMMAND_STEP_PACKET;
|
||||
|
||||
/**
|
||||
* unknown (string)
|
||||
* unknown (string)
|
||||
* unknown (uvarint)
|
||||
* unknown (uvarint)
|
||||
* unknown (bool)
|
||||
* unknown (uvarint64)
|
||||
* unknown (string)
|
||||
* unknown (string)
|
||||
* https://gist.github.com/dktapps/8285b93af4ca38e0104bfeb9a6c87afd
|
||||
*/
|
||||
|
||||
public $command;
|
||||
public $overload;
|
||||
public $uvarint1;
|
||||
public $uvarint2;
|
||||
public $bool;
|
||||
public $uvarint64;
|
||||
public $args; //JSON formatted command arguments
|
||||
public $args;
|
||||
public $string4;
|
||||
|
||||
public function decode(){
|
||||
@ -55,12 +43,11 @@ class CommandStepPacket extends DataPacket{
|
||||
$this->uvarint1 = $this->getUnsignedVarInt();
|
||||
$this->uvarint2 = $this->getUnsignedVarInt();
|
||||
$this->bool = (bool) $this->getByte();
|
||||
$this->uvarint64 = $this->getUnsignedVarInt(); //TODO: varint64
|
||||
$this->uvarint64 = $this->getUnsignedVarLong();
|
||||
$this->args = json_decode($this->getString());
|
||||
$this->string4 = $this->getString();
|
||||
while(!$this->feof()){
|
||||
$this->getByte(); //prevent assertion errors. TODO: find out why there are always 3 extra bytes at the end of this packet.
|
||||
}
|
||||
|
||||
$this->get(true); //TODO: read command origin data
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
@ -46,8 +46,8 @@ class ContainerOpenPacket extends DataPacket{
|
||||
$this->putByte($this->windowid);
|
||||
$this->putByte($this->type);
|
||||
$this->putVarInt($this->slots);
|
||||
$this->putBlockCoords($this->x, $this->y, $this->z);
|
||||
$this->putEntityId($this->entityId);
|
||||
$this->putBlockPosition($this->x, $this->y, $this->z);
|
||||
$this->putEntityUniqueId($this->entityId);
|
||||
}
|
||||
|
||||
public function handle(NetworkSession $session) : bool{
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -52,14 +52,14 @@ class EntityEventPacket extends DataPacket{
|
||||
public $unknown;
|
||||
|
||||
public function decode(){
|
||||
$this->eid = $this->getEntityId();
|
||||
$this->eid = $this->getEntityRuntimeId();
|
||||
$this->event = $this->getByte();
|
||||
$this->unknown = $this->getVarInt();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->eid);
|
||||
$this->putEntityRuntimeId($this->eid);
|
||||
$this->putByte($this->event);
|
||||
$this->putVarInt($this->unknown);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class ExplodePacket extends DataPacket{
|
||||
$this->putUnsignedVarInt(count($this->records));
|
||||
if(count($this->records) > 0){
|
||||
foreach($this->records as $record){
|
||||
$this->putBlockCoords($record->x, $record->y, $record->z);
|
||||
$this->putBlockPosition($record->x, $record->y, $record->z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,13 +39,13 @@ class InteractPacket extends DataPacket{
|
||||
|
||||
public function decode(){
|
||||
$this->action = $this->getByte();
|
||||
$this->target = $this->getEntityId();
|
||||
$this->target = $this->getEntityRuntimeId();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putByte($this->action);
|
||||
$this->putEntityId($this->target);
|
||||
$this->putEntityRuntimeId($this->target);
|
||||
}
|
||||
|
||||
public function handle(NetworkSession $session) : bool{
|
||||
|
@ -34,7 +34,7 @@ class ItemFrameDropItemPacket extends DataPacket{
|
||||
public $z;
|
||||
|
||||
public function decode(){
|
||||
$this->getBlockCoords($this->x, $this->y, $this->z);
|
||||
$this->getBlockPosition($this->x, $this->y, $this->z);
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
@ -33,7 +33,7 @@ class MobArmorEquipmentPacket extends DataPacket{
|
||||
public $slots = [];
|
||||
|
||||
public function decode(){
|
||||
$this->eid = $this->getEntityId();
|
||||
$this->eid = $this->getEntityRuntimeId();
|
||||
$this->slots[0] = $this->getSlot();
|
||||
$this->slots[1] = $this->getSlot();
|
||||
$this->slots[2] = $this->getSlot();
|
||||
@ -42,7 +42,7 @@ class MobArmorEquipmentPacket extends DataPacket{
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->eid);
|
||||
$this->putEntityRuntimeId($this->eid);
|
||||
$this->putSlot($this->slots[0]);
|
||||
$this->putSlot($this->slots[1]);
|
||||
$this->putSlot($this->slots[2]);
|
||||
|
@ -46,7 +46,7 @@ class MobEffectPacket extends DataPacket{
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->eid);
|
||||
$this->putEntityRuntimeId($this->eid);
|
||||
$this->putByte($this->eventId);
|
||||
$this->putVarInt($this->effectId);
|
||||
$this->putVarInt($this->amplifier);
|
||||
|
@ -36,7 +36,7 @@ class MobEquipmentPacket extends DataPacket{
|
||||
public $unknownByte;
|
||||
|
||||
public function decode(){
|
||||
$this->eid = $this->getEntityId(); //EntityRuntimeID
|
||||
$this->eid = $this->getEntityRuntimeId();
|
||||
$this->item = $this->getSlot();
|
||||
$this->slot = $this->getByte();
|
||||
$this->selectedSlot = $this->getByte();
|
||||
@ -45,7 +45,7 @@ class MobEquipmentPacket extends DataPacket{
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->eid); //EntityRuntimeID
|
||||
$this->putEntityRuntimeId($this->eid);
|
||||
$this->putSlot($this->item);
|
||||
$this->putByte($this->slot);
|
||||
$this->putByte($this->selectedSlot);
|
||||
|
@ -38,7 +38,7 @@ class MoveEntityPacket extends DataPacket{
|
||||
public $pitch;
|
||||
|
||||
public function decode(){
|
||||
$this->eid = $this->getEntityId();
|
||||
$this->eid = $this->getEntityRuntimeId();
|
||||
$this->getVector3f($this->x, $this->y, $this->z);
|
||||
$this->pitch = $this->getByte() * (360.0 / 256);
|
||||
$this->yaw = $this->getByte() * (360.0 / 256);
|
||||
@ -47,7 +47,7 @@ class MoveEntityPacket extends DataPacket{
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->eid);
|
||||
$this->putEntityRuntimeId($this->eid);
|
||||
$this->putVector3f($this->x, $this->y, $this->z);
|
||||
$this->putByte($this->pitch / (360.0 / 256));
|
||||
$this->putByte($this->yaw / (360.0 / 256));
|
||||
|
@ -44,7 +44,7 @@ class MovePlayerPacket extends DataPacket{
|
||||
public $onGround;
|
||||
|
||||
public function decode(){
|
||||
$this->eid = $this->getEntityId(); //EntityRuntimeID
|
||||
$this->eid = $this->getEntityRuntimeId();
|
||||
$this->getVector3f($this->x, $this->y, $this->z);
|
||||
$this->pitch = $this->getLFloat();
|
||||
$this->yaw = $this->getLFloat();
|
||||
@ -55,7 +55,7 @@ class MovePlayerPacket extends DataPacket{
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->eid); //EntityRuntimeID
|
||||
$this->putEntityRuntimeId($this->eid);
|
||||
$this->putVector3f($this->x, $this->y, $this->z);
|
||||
$this->putLFloat($this->pitch);
|
||||
$this->putLFloat($this->yaw);
|
||||
|
@ -55,17 +55,17 @@ class PlayerActionPacket extends DataPacket{
|
||||
public $face;
|
||||
|
||||
public function decode(){
|
||||
$this->eid = $this->getEntityId();
|
||||
$this->eid = $this->getEntityRuntimeId();
|
||||
$this->action = $this->getVarInt();
|
||||
$this->getBlockCoords($this->x, $this->y, $this->z);
|
||||
$this->getBlockPosition($this->x, $this->y, $this->z);
|
||||
$this->face = $this->getVarInt();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->eid);
|
||||
$this->putEntityRuntimeId($this->eid);
|
||||
$this->putVarInt($this->action);
|
||||
$this->putBlockCoords($this->x, $this->y, $this->z);
|
||||
$this->putBlockPosition($this->x, $this->y, $this->z);
|
||||
$this->putVarInt($this->face);
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ class PlayerListPacket extends DataPacket{
|
||||
foreach($this->entries as $d){
|
||||
if($this->type === self::TYPE_ADD){
|
||||
$this->putUUID($d[0]);
|
||||
$this->putEntityId($d[1]);
|
||||
$this->putEntityUniqueId($d[1]);
|
||||
$this->putString($d[2]);
|
||||
$this->putString($d[3]);
|
||||
$this->putString($d[4]);
|
||||
|
@ -34,7 +34,7 @@ class RemoveBlockPacket extends DataPacket{
|
||||
public $z;
|
||||
|
||||
public function decode(){
|
||||
$this->getBlockCoords($this->x, $this->y, $this->z);
|
||||
$this->getBlockPosition($this->x, $this->y, $this->z);
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
@ -37,7 +37,7 @@ class RemoveEntityPacket extends DataPacket{
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->eid);
|
||||
$this->putEntityUniqueId($this->eid);
|
||||
}
|
||||
|
||||
public function handle(NetworkSession $session) : bool{
|
||||
|
@ -38,7 +38,7 @@ class SetEntityDataPacket extends DataPacket{
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->eid);
|
||||
$this->putEntityRuntimeId($this->eid);
|
||||
$this->putEntityMetadata($this->metadata);
|
||||
}
|
||||
|
||||
|
@ -39,8 +39,8 @@ class SetEntityLinkPacket extends DataPacket{
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->from);
|
||||
$this->putEntityId($this->to);
|
||||
$this->putEntityUniqueId($this->from);
|
||||
$this->putEntityUniqueId($this->to);
|
||||
$this->putByte($this->type);
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ class SetEntityMotionPacket extends DataPacket{
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->eid);
|
||||
$this->putEntityRuntimeId($this->eid);
|
||||
$this->putVector3f($this->motionX, $this->motionY, $this->motionZ);
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ class SetSpawnPositionPacket extends DataPacket{
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putVarInt($this->unknown);
|
||||
$this->putBlockCoords($this->x, $this->y, $this->z);
|
||||
$this->putBlockPosition($this->x, $this->y, $this->z);
|
||||
$this->putBool($this->unknownBool);
|
||||
}
|
||||
|
||||
|
@ -37,13 +37,13 @@ class ShowCreditsPacket extends DataPacket{
|
||||
public $status;
|
||||
|
||||
public function decode(){
|
||||
$this->playerEid = $this->getEntityId();
|
||||
$this->playerEid = $this->getEntityRuntimeId();
|
||||
$this->status = $this->getVarInt();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->playerEid);
|
||||
$this->putEntityRuntimeId($this->playerEid);
|
||||
$this->putVarInt($this->status);
|
||||
}
|
||||
|
||||
|
@ -58,8 +58,8 @@ class StartGamePacket extends DataPacket{
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->entityUniqueId); //EntityUniqueID
|
||||
$this->putEntityId($this->entityRuntimeId); //EntityRuntimeID
|
||||
$this->putEntityUniqueId($this->entityUniqueId); //EntityUniqueID
|
||||
$this->putEntityRuntimeId($this->entityRuntimeId); //EntityRuntimeID
|
||||
$this->putVector3f($this->x, $this->y, $this->z);
|
||||
$this->putLFloat(0); //TODO: find out what these are (yaw/pitch?)
|
||||
$this->putLFloat(0);
|
||||
@ -68,7 +68,7 @@ class StartGamePacket extends DataPacket{
|
||||
$this->putVarInt($this->generator);
|
||||
$this->putVarInt($this->gamemode);
|
||||
$this->putVarInt($this->difficulty);
|
||||
$this->putBlockCoords($this->spawnX, $this->spawnY, $this->spawnZ);
|
||||
$this->putBlockPosition($this->spawnX, $this->spawnY, $this->spawnZ);
|
||||
$this->putBool($this->hasAchievementsDisabled);
|
||||
$this->putVarInt($this->dayCycleStopTime);
|
||||
$this->putBool($this->eduMode);
|
||||
|
@ -38,8 +38,8 @@ class TakeItemEntityPacket extends DataPacket{
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->target);
|
||||
$this->putEntityId($this->eid);
|
||||
$this->putEntityRuntimeId($this->target);
|
||||
$this->putEntityRuntimeId($this->eid);
|
||||
}
|
||||
|
||||
public function handle(NetworkSession $session) : bool{
|
||||
|
@ -41,7 +41,7 @@ class UpdateAttributesPacket extends DataPacket{
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putEntityId($this->entityId);
|
||||
$this->putEntityRuntimeId($this->entityId);
|
||||
$this->putUnsignedVarInt(count($this->entries));
|
||||
foreach($this->entries as $entry){
|
||||
$this->putLFloat($entry->getMinValue());
|
||||
|
@ -51,7 +51,7 @@ class UpdateBlockPacket extends DataPacket{
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->putBlockCoords($this->x, $this->y, $this->z);
|
||||
$this->putBlockPosition($this->x, $this->y, $this->z);
|
||||
$this->putUnsignedVarInt($this->blockId);
|
||||
$this->putUnsignedVarInt(($this->flags << 4) | $this->blockData);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ class UseItemPacket extends DataPacket{
|
||||
public $slot;
|
||||
|
||||
public function decode(){
|
||||
$this->getBlockCoords($this->x, $this->y, $this->z);
|
||||
$this->getBlockPosition($this->x, $this->y, $this->z);
|
||||
$this->blockId = $this->getUnsignedVarInt();
|
||||
$this->face = $this->getVarInt();
|
||||
$this->getVector3f($this->fx, $this->fy, $this->fz);
|
||||
|
@ -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(){
|
||||
|
Loading…
x
Reference in New Issue
Block a user