DataPacket now encapsulates NetworkBinaryStream instead of extending it

ultimately the goal is to remove the NetworkBinaryStream crap entirely, but this change has most of the same benefits and is less disruptive.
This commit is contained in:
Dylan K. Taylor 2020-02-24 18:59:54 +00:00
parent 7c2741e4f5
commit ce0af8b040
146 changed files with 1249 additions and 1269 deletions

View File

@ -303,7 +303,7 @@ class NetworkSession{
try{ try{
$this->handleDataPacket($pk); $this->handleDataPacket($pk);
}catch(BadPacketException $e){ }catch(BadPacketException $e){
$this->logger->debug($pk->getName() . ": " . base64_encode($pk->getBuffer())); $this->logger->debug($pk->getName() . ": " . base64_encode($pk->getBinaryStream()->getBuffer()));
throw new BadPacketException("Error processing " . $pk->getName() . ": " . $e->getMessage(), 0, $e); throw new BadPacketException("Error processing " . $pk->getName() . ": " . $e->getMessage(), 0, $e);
} }
} }
@ -315,7 +315,7 @@ class NetworkSession{
public function handleDataPacket(Packet $packet) : void{ public function handleDataPacket(Packet $packet) : void{
if(!($packet instanceof ServerboundPacket)){ if(!($packet instanceof ServerboundPacket)){
if($packet instanceof GarbageServerboundPacket){ if($packet instanceof GarbageServerboundPacket){
$this->logger->debug("Garbage serverbound " . $packet->getName() . ": " . base64_encode($packet->getBuffer())); $this->logger->debug("Garbage serverbound " . $packet->getName() . ": " . base64_encode($packet->getBinaryStream()->getBuffer()));
return; return;
} }
throw new BadPacketException("Unexpected non-serverbound packet"); throw new BadPacketException("Unexpected non-serverbound packet");
@ -326,15 +326,16 @@ class NetworkSession{
try{ try{
$packet->decode(); $packet->decode();
if(!$packet->feof()){ $stream = $packet->getBinaryStream();
$remains = substr($packet->getBuffer(), $packet->getOffset()); if(!$stream->feof()){
$remains = substr($stream->getBuffer(), $stream->getOffset());
$this->logger->debug("Still " . strlen($remains) . " bytes unread in " . $packet->getName() . ": " . bin2hex($remains)); $this->logger->debug("Still " . strlen($remains) . " bytes unread in " . $packet->getName() . ": " . bin2hex($remains));
} }
$ev = new DataPacketReceiveEvent($this, $packet); $ev = new DataPacketReceiveEvent($this, $packet);
$ev->call(); $ev->call();
if(!$ev->isCancelled() and !$packet->handle($this->handler)){ if(!$ev->isCancelled() and !$packet->handle($this->handler)){
$this->logger->debug("Unhandled " . $packet->getName() . ": " . base64_encode($packet->getBuffer())); $this->logger->debug("Unhandled " . $packet->getName() . ": " . base64_encode($stream->getBuffer()));
} }
}finally{ }finally{
$timings->stopTiming(); $timings->stopTiming();

View File

@ -32,7 +32,7 @@ class PacketBatch extends NetworkBinaryStream{
public function putPacket(Packet $packet) : void{ public function putPacket(Packet $packet) : void{
$packet->encode(); $packet->encode();
$this->putString($packet->getBuffer()); $this->putString($packet->getBinaryStream()->getBuffer());
} }
/** /**

View File

@ -98,15 +98,15 @@ class ActorEventPacket extends DataPacket implements ClientboundPacket, Serverbo
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->entityRuntimeId = $this->getEntityRuntimeId(); $this->entityRuntimeId = $this->buf->getEntityRuntimeId();
$this->event = $this->getByte(); $this->event = $this->buf->getByte();
$this->data = $this->getVarInt(); $this->data = $this->buf->getVarInt();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityRuntimeId($this->entityRuntimeId); $this->buf->putEntityRuntimeId($this->entityRuntimeId);
$this->putByte($this->event); $this->buf->putByte($this->event);
$this->putVarInt($this->data); $this->buf->putVarInt($this->data);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -38,15 +38,15 @@ class ActorFallPacket extends DataPacket implements ServerboundPacket{
public $isInVoid; public $isInVoid;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->entityRuntimeId = $this->getEntityRuntimeId(); $this->entityRuntimeId = $this->buf->getEntityRuntimeId();
$this->fallDistance = $this->getLFloat(); $this->fallDistance = $this->buf->getLFloat();
$this->isInVoid = $this->getBool(); $this->isInVoid = $this->buf->getBool();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityRuntimeId($this->entityRuntimeId); $this->buf->putEntityRuntimeId($this->entityRuntimeId);
$this->putLFloat($this->fallDistance); $this->buf->putLFloat($this->fallDistance);
$this->putBool($this->isInVoid); $this->buf->putBool($this->isInVoid);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -36,13 +36,13 @@ class ActorPickRequestPacket extends DataPacket implements ServerboundPacket{
public $hotbarSlot; public $hotbarSlot;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->entityUniqueId = $this->getLLong(); $this->entityUniqueId = $this->buf->getLLong();
$this->hotbarSlot = $this->getByte(); $this->hotbarSlot = $this->buf->getByte();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putLLong($this->entityUniqueId); $this->buf->putLLong($this->entityUniqueId);
$this->putByte($this->hotbarSlot); $this->buf->putByte($this->hotbarSlot);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -174,24 +174,24 @@ class AddActorPacket extends DataPacket implements ClientboundPacket{
public $links = []; public $links = [];
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->entityUniqueId = $this->getEntityUniqueId(); $this->entityUniqueId = $this->buf->getEntityUniqueId();
$this->entityRuntimeId = $this->getEntityRuntimeId(); $this->entityRuntimeId = $this->buf->getEntityRuntimeId();
$this->type = array_search($t = $this->getString(), self::LEGACY_ID_MAP_BC, true); $this->type = array_search($t = $this->buf->getString(), self::LEGACY_ID_MAP_BC, true);
if($this->type === false){ if($this->type === false){
throw new BadPacketException("Can't map ID $t to legacy ID"); throw new BadPacketException("Can't map ID $t to legacy ID");
} }
$this->position = $this->getVector3(); $this->position = $this->buf->getVector3();
$this->motion = $this->getVector3(); $this->motion = $this->buf->getVector3();
$this->pitch = $this->getLFloat(); $this->pitch = $this->buf->getLFloat();
$this->yaw = $this->getLFloat(); $this->yaw = $this->buf->getLFloat();
$this->headYaw = $this->getLFloat(); $this->headYaw = $this->buf->getLFloat();
$attrCount = $this->getUnsignedVarInt(); $attrCount = $this->buf->getUnsignedVarInt();
for($i = 0; $i < $attrCount; ++$i){ for($i = 0; $i < $attrCount; ++$i){
$id = $this->getString(); $id = $this->buf->getString();
$min = $this->getLFloat(); $min = $this->buf->getLFloat();
$current = $this->getLFloat(); $current = $this->buf->getLFloat();
$max = $this->getLFloat(); $max = $this->buf->getLFloat();
$attr = Attribute::get($id); $attr = Attribute::get($id);
if($attr !== null){ if($attr !== null){
@ -208,38 +208,38 @@ class AddActorPacket extends DataPacket implements ClientboundPacket{
} }
} }
$this->metadata = $this->getEntityMetadata(); $this->metadata = $this->buf->getEntityMetadata();
$linkCount = $this->getUnsignedVarInt(); $linkCount = $this->buf->getUnsignedVarInt();
for($i = 0; $i < $linkCount; ++$i){ for($i = 0; $i < $linkCount; ++$i){
$this->links[] = $this->getEntityLink(); $this->links[] = $this->buf->getEntityLink();
} }
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); $this->buf->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId);
$this->putEntityRuntimeId($this->entityRuntimeId); $this->buf->putEntityRuntimeId($this->entityRuntimeId);
if(!isset(self::LEGACY_ID_MAP_BC[$this->type])){ if(!isset(self::LEGACY_ID_MAP_BC[$this->type])){
throw new \InvalidArgumentException("Unknown entity numeric ID $this->type"); throw new \InvalidArgumentException("Unknown entity numeric ID $this->type");
} }
$this->putString(self::LEGACY_ID_MAP_BC[$this->type]); $this->buf->putString(self::LEGACY_ID_MAP_BC[$this->type]);
$this->putVector3($this->position); $this->buf->putVector3($this->position);
$this->putVector3Nullable($this->motion); $this->buf->putVector3Nullable($this->motion);
$this->putLFloat($this->pitch); $this->buf->putLFloat($this->pitch);
$this->putLFloat($this->yaw); $this->buf->putLFloat($this->yaw);
$this->putLFloat($this->headYaw); $this->buf->putLFloat($this->headYaw);
$this->putUnsignedVarInt(count($this->attributes)); $this->buf->putUnsignedVarInt(count($this->attributes));
foreach($this->attributes as $attribute){ foreach($this->attributes as $attribute){
$this->putString($attribute->getId()); $this->buf->putString($attribute->getId());
$this->putLFloat($attribute->getMinValue()); $this->buf->putLFloat($attribute->getMinValue());
$this->putLFloat($attribute->getValue()); $this->buf->putLFloat($attribute->getValue());
$this->putLFloat($attribute->getMaxValue()); $this->buf->putLFloat($attribute->getMaxValue());
} }
$this->putEntityMetadata($this->metadata); $this->buf->putEntityMetadata($this->metadata);
$this->putUnsignedVarInt(count($this->links)); $this->buf->putUnsignedVarInt(count($this->links));
foreach($this->links as $link){ foreach($this->links as $link){
$this->putEntityLink($link); $this->buf->putEntityLink($link);
} }
} }

View File

@ -34,11 +34,11 @@ class AddBehaviorTreePacket extends DataPacket implements ClientboundPacket{
public $behaviorTreeJson; public $behaviorTreeJson;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->behaviorTreeJson = $this->getString(); $this->behaviorTreeJson = $this->buf->getString();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putString($this->behaviorTreeJson); $this->buf->putString($this->behaviorTreeJson);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -44,11 +44,11 @@ class AddEntityPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->uvarint1 = $this->getUnsignedVarInt(); $this->uvarint1 = $this->buf->getUnsignedVarInt();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putUnsignedVarInt($this->uvarint1); $this->buf->putUnsignedVarInt($this->uvarint1);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -52,23 +52,23 @@ class AddItemActorPacket extends DataPacket implements ClientboundPacket{
public $isFromFishing = false; public $isFromFishing = false;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->entityUniqueId = $this->getEntityUniqueId(); $this->entityUniqueId = $this->buf->getEntityUniqueId();
$this->entityRuntimeId = $this->getEntityRuntimeId(); $this->entityRuntimeId = $this->buf->getEntityRuntimeId();
$this->item = $this->getSlot(); $this->item = $this->buf->getSlot();
$this->position = $this->getVector3(); $this->position = $this->buf->getVector3();
$this->motion = $this->getVector3(); $this->motion = $this->buf->getVector3();
$this->metadata = $this->getEntityMetadata(); $this->metadata = $this->buf->getEntityMetadata();
$this->isFromFishing = $this->getBool(); $this->isFromFishing = $this->buf->getBool();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); $this->buf->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId);
$this->putEntityRuntimeId($this->entityRuntimeId); $this->buf->putEntityRuntimeId($this->entityRuntimeId);
$this->putSlot($this->item); $this->buf->putSlot($this->item);
$this->putVector3($this->position); $this->buf->putVector3($this->position);
$this->putVector3Nullable($this->motion); $this->buf->putVector3Nullable($this->motion);
$this->putEntityMetadata($this->metadata); $this->buf->putEntityMetadata($this->metadata);
$this->putBool($this->isFromFishing); $this->buf->putBool($this->isFromFishing);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -43,19 +43,19 @@ class AddPaintingPacket extends DataPacket implements ClientboundPacket{
public $title; public $title;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->entityUniqueId = $this->getEntityUniqueId(); $this->entityUniqueId = $this->buf->getEntityUniqueId();
$this->entityRuntimeId = $this->getEntityRuntimeId(); $this->entityRuntimeId = $this->buf->getEntityRuntimeId();
$this->position = $this->getVector3(); $this->position = $this->buf->getVector3();
$this->direction = $this->getVarInt(); $this->direction = $this->buf->getVarInt();
$this->title = $this->getString(); $this->title = $this->buf->getString();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); $this->buf->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId);
$this->putEntityRuntimeId($this->entityRuntimeId); $this->buf->putEntityRuntimeId($this->entityRuntimeId);
$this->putVector3($this->position); $this->buf->putVector3($this->position);
$this->putVarInt($this->direction); $this->buf->putVarInt($this->direction);
$this->putString($this->title); $this->buf->putString($this->title);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -88,65 +88,65 @@ class AddPlayerPacket extends DataPacket implements ClientboundPacket{
public $buildPlatform = -1; public $buildPlatform = -1;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->uuid = $this->getUUID(); $this->uuid = $this->buf->getUUID();
$this->username = $this->getString(); $this->username = $this->buf->getString();
$this->entityUniqueId = $this->getEntityUniqueId(); $this->entityUniqueId = $this->buf->getEntityUniqueId();
$this->entityRuntimeId = $this->getEntityRuntimeId(); $this->entityRuntimeId = $this->buf->getEntityRuntimeId();
$this->platformChatId = $this->getString(); $this->platformChatId = $this->buf->getString();
$this->position = $this->getVector3(); $this->position = $this->buf->getVector3();
$this->motion = $this->getVector3(); $this->motion = $this->buf->getVector3();
$this->pitch = $this->getLFloat(); $this->pitch = $this->buf->getLFloat();
$this->yaw = $this->getLFloat(); $this->yaw = $this->buf->getLFloat();
$this->headYaw = $this->getLFloat(); $this->headYaw = $this->buf->getLFloat();
$this->item = $this->getSlot(); $this->item = $this->buf->getSlot();
$this->metadata = $this->getEntityMetadata(); $this->metadata = $this->buf->getEntityMetadata();
$this->uvarint1 = $this->getUnsignedVarInt(); $this->uvarint1 = $this->buf->getUnsignedVarInt();
$this->uvarint2 = $this->getUnsignedVarInt(); $this->uvarint2 = $this->buf->getUnsignedVarInt();
$this->uvarint3 = $this->getUnsignedVarInt(); $this->uvarint3 = $this->buf->getUnsignedVarInt();
$this->uvarint4 = $this->getUnsignedVarInt(); $this->uvarint4 = $this->buf->getUnsignedVarInt();
$this->uvarint5 = $this->getUnsignedVarInt(); $this->uvarint5 = $this->buf->getUnsignedVarInt();
$this->long1 = $this->getLLong(); $this->long1 = $this->buf->getLLong();
$linkCount = $this->getUnsignedVarInt(); $linkCount = $this->buf->getUnsignedVarInt();
for($i = 0; $i < $linkCount; ++$i){ for($i = 0; $i < $linkCount; ++$i){
$this->links[$i] = $this->getEntityLink(); $this->links[$i] = $this->buf->getEntityLink();
} }
$this->deviceId = $this->getString(); $this->deviceId = $this->buf->getString();
$this->buildPlatform = $this->getLInt(); $this->buildPlatform = $this->buf->getLInt();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putUUID($this->uuid); $this->buf->putUUID($this->uuid);
$this->putString($this->username); $this->buf->putString($this->username);
$this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); $this->buf->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId);
$this->putEntityRuntimeId($this->entityRuntimeId); $this->buf->putEntityRuntimeId($this->entityRuntimeId);
$this->putString($this->platformChatId); $this->buf->putString($this->platformChatId);
$this->putVector3($this->position); $this->buf->putVector3($this->position);
$this->putVector3Nullable($this->motion); $this->buf->putVector3Nullable($this->motion);
$this->putLFloat($this->pitch); $this->buf->putLFloat($this->pitch);
$this->putLFloat($this->yaw); $this->buf->putLFloat($this->yaw);
$this->putLFloat($this->headYaw ?? $this->yaw); $this->buf->putLFloat($this->headYaw ?? $this->yaw);
$this->putSlot($this->item); $this->buf->putSlot($this->item);
$this->putEntityMetadata($this->metadata); $this->buf->putEntityMetadata($this->metadata);
$this->putUnsignedVarInt($this->uvarint1); $this->buf->putUnsignedVarInt($this->uvarint1);
$this->putUnsignedVarInt($this->uvarint2); $this->buf->putUnsignedVarInt($this->uvarint2);
$this->putUnsignedVarInt($this->uvarint3); $this->buf->putUnsignedVarInt($this->uvarint3);
$this->putUnsignedVarInt($this->uvarint4); $this->buf->putUnsignedVarInt($this->uvarint4);
$this->putUnsignedVarInt($this->uvarint5); $this->buf->putUnsignedVarInt($this->uvarint5);
$this->putLLong($this->long1); $this->buf->putLLong($this->long1);
$this->putUnsignedVarInt(count($this->links)); $this->buf->putUnsignedVarInt(count($this->links));
foreach($this->links as $link){ foreach($this->links as $link){
$this->putEntityLink($link); $this->buf->putEntityLink($link);
} }
$this->putString($this->deviceId); $this->buf->putString($this->deviceId);
$this->putLInt($this->buildPlatform); $this->buf->putLInt($this->buildPlatform);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -76,21 +76,21 @@ class AdventureSettingsPacket extends DataPacket implements ClientboundPacket, S
public $entityUniqueId; //This is a little-endian long, NOT a var-long. (WTF Mojang) public $entityUniqueId; //This is a little-endian long, NOT a var-long. (WTF Mojang)
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->flags = $this->getUnsignedVarInt(); $this->flags = $this->buf->getUnsignedVarInt();
$this->commandPermission = $this->getUnsignedVarInt(); $this->commandPermission = $this->buf->getUnsignedVarInt();
$this->flags2 = $this->getUnsignedVarInt(); $this->flags2 = $this->buf->getUnsignedVarInt();
$this->playerPermission = $this->getUnsignedVarInt(); $this->playerPermission = $this->buf->getUnsignedVarInt();
$this->customFlags = $this->getUnsignedVarInt(); $this->customFlags = $this->buf->getUnsignedVarInt();
$this->entityUniqueId = $this->getLLong(); $this->entityUniqueId = $this->buf->getLLong();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putUnsignedVarInt($this->flags); $this->buf->putUnsignedVarInt($this->flags);
$this->putUnsignedVarInt($this->commandPermission); $this->buf->putUnsignedVarInt($this->commandPermission);
$this->putUnsignedVarInt($this->flags2); $this->buf->putUnsignedVarInt($this->flags2);
$this->putUnsignedVarInt($this->playerPermission); $this->buf->putUnsignedVarInt($this->playerPermission);
$this->putUnsignedVarInt($this->customFlags); $this->buf->putUnsignedVarInt($this->customFlags);
$this->putLLong($this->entityUniqueId); $this->buf->putLLong($this->entityUniqueId);
} }
public function getFlag(int $flag) : bool{ public function getFlag(int $flag) : bool{

View File

@ -58,18 +58,18 @@ class AnimatePacket extends DataPacket implements ClientboundPacket, Serverbound
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->action = $this->getVarInt(); $this->action = $this->buf->getVarInt();
$this->entityRuntimeId = $this->getEntityRuntimeId(); $this->entityRuntimeId = $this->buf->getEntityRuntimeId();
if(($this->action & 0x80) !== 0){ if(($this->action & 0x80) !== 0){
$this->float = $this->getLFloat(); $this->float = $this->buf->getLFloat();
} }
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putVarInt($this->action); $this->buf->putVarInt($this->action);
$this->putEntityRuntimeId($this->entityRuntimeId); $this->buf->putEntityRuntimeId($this->entityRuntimeId);
if(($this->action & 0x80) !== 0){ if(($this->action & 0x80) !== 0){
$this->putLFloat($this->float); $this->buf->putLFloat($this->float);
} }
} }

View File

@ -63,13 +63,13 @@ class AnvilDamagePacket extends DataPacket implements ServerboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->damageAmount = $this->getByte(); $this->damageAmount = $this->buf->getByte();
$this->getBlockPosition($this->x, $this->y, $this->z); $this->buf->getBlockPosition($this->x, $this->y, $this->z);
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putByte($this->damageAmount); $this->buf->putByte($this->damageAmount);
$this->putBlockPosition($this->x, $this->y, $this->z); $this->buf->putBlockPosition($this->x, $this->y, $this->z);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -34,11 +34,11 @@ class AutomationClientConnectPacket extends DataPacket implements ClientboundPac
public $serverUri; public $serverUri;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->serverUri = $this->getString(); $this->serverUri = $this->buf->getString();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putString($this->serverUri); $this->buf->putString($this->serverUri);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -39,11 +39,11 @@ class AvailableActorIdentifiersPacket extends DataPacket implements ClientboundP
public $namedtag; public $namedtag;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->namedtag = $this->getRemaining(); $this->namedtag = $this->buf->getRemaining();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->put( $this->buf->put(
$this->namedtag ?? $this->namedtag ??
self::$DEFAULT_NBT_CACHE ?? self::$DEFAULT_NBT_CACHE ??
(self::$DEFAULT_NBT_CACHE = file_get_contents(\pocketmine\RESOURCE_PATH . '/vanilla/entity_identifiers.nbt')) (self::$DEFAULT_NBT_CACHE = file_get_contents(\pocketmine\RESOURCE_PATH . '/vanilla/entity_identifiers.nbt'))

View File

@ -114,34 +114,34 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{
protected function decodePayload() : void{ protected function decodePayload() : void{
/** @var string[] $enumValues */ /** @var string[] $enumValues */
$enumValues = []; $enumValues = [];
for($i = 0, $enumValuesCount = $this->getUnsignedVarInt(); $i < $enumValuesCount; ++$i){ for($i = 0, $enumValuesCount = $this->buf->getUnsignedVarInt(); $i < $enumValuesCount; ++$i){
$enumValues[] = $this->getString(); $enumValues[] = $this->buf->getString();
} }
/** @var string[] $postfixes */ /** @var string[] $postfixes */
$postfixes = []; $postfixes = [];
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){
$postfixes[] = $this->getString(); $postfixes[] = $this->buf->getString();
} }
/** @var CommandEnum[] $enums */ /** @var CommandEnum[] $enums */
$enums = []; $enums = [];
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){
$enums[] = $enum = $this->getEnum($enumValues); $enums[] = $enum = $this->getEnum($enumValues);
if(isset(self::HARDCODED_ENUM_NAMES[$enum->getName()])){ if(isset(self::HARDCODED_ENUM_NAMES[$enum->getName()])){
$this->hardcodedEnums[] = $enum; $this->hardcodedEnums[] = $enum;
} }
} }
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){
$this->commandData[] = $this->getCommandData($enums, $postfixes); $this->commandData[] = $this->getCommandData($enums, $postfixes);
} }
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){
$this->softEnums[] = $this->getSoftEnum(); $this->softEnums[] = $this->getSoftEnum();
} }
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){
$this->enumConstraints[] = $this->getEnumConstraint($enums, $enumValues); $this->enumConstraints[] = $this->getEnumConstraint($enums, $enumValues);
} }
} }
@ -153,12 +153,12 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{
* @throws BinaryDataException * @throws BinaryDataException
*/ */
protected function getEnum(array $enumValueList) : CommandEnum{ protected function getEnum(array $enumValueList) : CommandEnum{
$enumName = $this->getString(); $enumName = $this->buf->getString();
$enumValues = []; $enumValues = [];
$listSize = count($enumValueList); $listSize = count($enumValueList);
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){
$index = $this->getEnumValueIndex($listSize); $index = $this->getEnumValueIndex($listSize);
if(!isset($enumValueList[$index])){ if(!isset($enumValueList[$index])){
throw new BadPacketException("Invalid enum value index $index"); throw new BadPacketException("Invalid enum value index $index");
@ -174,12 +174,12 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{
* @throws BinaryDataException * @throws BinaryDataException
*/ */
protected function getSoftEnum() : CommandEnum{ protected function getSoftEnum() : CommandEnum{
$enumName = $this->getString(); $enumName = $this->buf->getString();
$enumValues = []; $enumValues = [];
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){
//Get the enum value from the initial pile of mess //Get the enum value from the initial pile of mess
$enumValues[] = $this->getString(); $enumValues[] = $this->buf->getString();
} }
return new CommandEnum($enumName, $enumValues); return new CommandEnum($enumName, $enumValues);
@ -189,10 +189,10 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{
* @param int[] $enumValueMap * @param int[] $enumValueMap
*/ */
protected function putEnum(CommandEnum $enum, array $enumValueMap) : void{ protected function putEnum(CommandEnum $enum, array $enumValueMap) : void{
$this->putString($enum->getName()); $this->buf->putString($enum->getName());
$values = $enum->getValues(); $values = $enum->getValues();
$this->putUnsignedVarInt(count($values)); $this->buf->putUnsignedVarInt(count($values));
$listSize = count($enumValueMap); $listSize = count($enumValueMap);
foreach($values as $value){ foreach($values as $value){
$index = $enumValueMap[$value] ?? -1; $index = $enumValueMap[$value] ?? -1;
@ -204,12 +204,12 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{
} }
protected function putSoftEnum(CommandEnum $enum) : void{ protected function putSoftEnum(CommandEnum $enum) : void{
$this->putString($enum->getName()); $this->buf->putString($enum->getName());
$values = $enum->getValues(); $values = $enum->getValues();
$this->putUnsignedVarInt(count($values)); $this->buf->putUnsignedVarInt(count($values));
foreach($values as $value){ foreach($values as $value){
$this->putString($value); $this->buf->putString($value);
} }
} }
@ -218,21 +218,21 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{
*/ */
protected function getEnumValueIndex(int $valueCount) : int{ protected function getEnumValueIndex(int $valueCount) : int{
if($valueCount < 256){ if($valueCount < 256){
return $this->getByte(); return $this->buf->getByte();
}elseif($valueCount < 65536){ }elseif($valueCount < 65536){
return $this->getLShort(); return $this->buf->getLShort();
}else{ }else{
return $this->getLInt(); return $this->buf->getLInt();
} }
} }
protected function putEnumValueIndex(int $index, int $valueCount) : void{ protected function putEnumValueIndex(int $index, int $valueCount) : void{
if($valueCount < 256){ if($valueCount < 256){
$this->putByte($index); $this->buf->putByte($index);
}elseif($valueCount < 65536){ }elseif($valueCount < 65536){
$this->putLShort($index); $this->buf->putLShort($index);
}else{ }else{
$this->putLInt($index); $this->buf->putLInt($index);
} }
} }
@ -245,11 +245,11 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{
*/ */
protected function getEnumConstraint(array $enums, array $enumValues) : CommandEnumConstraint{ protected function getEnumConstraint(array $enums, array $enumValues) : CommandEnumConstraint{
//wtf, what was wrong with an offset inside the enum? :( //wtf, what was wrong with an offset inside the enum? :(
$valueIndex = $this->getLInt(); $valueIndex = $this->buf->getLInt();
if(!isset($enumValues[$valueIndex])){ if(!isset($enumValues[$valueIndex])){
throw new BadPacketException("Enum constraint refers to unknown enum value index $valueIndex"); throw new BadPacketException("Enum constraint refers to unknown enum value index $valueIndex");
} }
$enumIndex = $this->getLInt(); $enumIndex = $this->buf->getLInt();
if(!isset($enums[$enumIndex])){ if(!isset($enums[$enumIndex])){
throw new BadPacketException("Enum constraint refers to unknown enum index $enumIndex"); throw new BadPacketException("Enum constraint refers to unknown enum index $enumIndex");
} }
@ -260,8 +260,8 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{
} }
$constraintIds = []; $constraintIds = [];
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){
$constraintIds[] = $this->getByte(); $constraintIds[] = $this->buf->getByte();
} }
return new CommandEnumConstraint($enum, $valueOffset, $constraintIds); return new CommandEnumConstraint($enum, $valueOffset, $constraintIds);
@ -272,11 +272,11 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{
* @param int[] $enumValueIndexes string value -> int index * @param int[] $enumValueIndexes string value -> int index
*/ */
protected function putEnumConstraint(CommandEnumConstraint $constraint, array $enumIndexes, array $enumValueIndexes) : void{ protected function putEnumConstraint(CommandEnumConstraint $constraint, array $enumIndexes, array $enumValueIndexes) : void{
$this->putLInt($enumValueIndexes[$constraint->getAffectedValue()]); $this->buf->putLInt($enumValueIndexes[$constraint->getAffectedValue()]);
$this->putLInt($enumIndexes[$constraint->getEnum()->getName()]); $this->buf->putLInt($enumIndexes[$constraint->getEnum()->getName()]);
$this->putUnsignedVarInt(count($constraint->getConstraints())); $this->buf->putUnsignedVarInt(count($constraint->getConstraints()));
foreach($constraint->getConstraints() as $v){ foreach($constraint->getConstraints() as $v){
$this->putByte($v); $this->buf->putByte($v);
} }
} }
@ -288,21 +288,21 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{
* @throws BinaryDataException * @throws BinaryDataException
*/ */
protected function getCommandData(array $enums, array $postfixes) : CommandData{ protected function getCommandData(array $enums, array $postfixes) : CommandData{
$name = $this->getString(); $name = $this->buf->getString();
$description = $this->getString(); $description = $this->buf->getString();
$flags = $this->getByte(); $flags = $this->buf->getByte();
$permission = $this->getByte(); $permission = $this->buf->getByte();
$aliases = $enums[$this->getLInt()] ?? null; $aliases = $enums[$this->buf->getLInt()] ?? null;
$overloads = []; $overloads = [];
for($overloadIndex = 0, $overloadCount = $this->getUnsignedVarInt(); $overloadIndex < $overloadCount; ++$overloadIndex){ for($overloadIndex = 0, $overloadCount = $this->buf->getUnsignedVarInt(); $overloadIndex < $overloadCount; ++$overloadIndex){
$overloads[$overloadIndex] = []; $overloads[$overloadIndex] = [];
for($paramIndex = 0, $paramCount = $this->getUnsignedVarInt(); $paramIndex < $paramCount; ++$paramIndex){ for($paramIndex = 0, $paramCount = $this->buf->getUnsignedVarInt(); $paramIndex < $paramCount; ++$paramIndex){
$parameter = new CommandParameter(); $parameter = new CommandParameter();
$parameter->paramName = $this->getString(); $parameter->paramName = $this->buf->getString();
$parameter->paramType = $this->getLInt(); $parameter->paramType = $this->buf->getLInt();
$parameter->isOptional = $this->getBool(); $parameter->isOptional = $this->buf->getBool();
$parameter->flags = $this->getByte(); $parameter->flags = $this->buf->getByte();
if(($parameter->paramType & self::ARG_FLAG_ENUM) !== 0){ if(($parameter->paramType & self::ARG_FLAG_ENUM) !== 0){
$index = ($parameter->paramType & 0xffff); $index = ($parameter->paramType & 0xffff);
@ -332,23 +332,23 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{
* @param int[] $postfixIndexes * @param int[] $postfixIndexes
*/ */
protected function putCommandData(CommandData $data, array $enumIndexes, array $postfixIndexes) : void{ protected function putCommandData(CommandData $data, array $enumIndexes, array $postfixIndexes) : void{
$this->putString($data->name); $this->buf->putString($data->name);
$this->putString($data->description); $this->buf->putString($data->description);
$this->putByte($data->flags); $this->buf->putByte($data->flags);
$this->putByte($data->permission); $this->buf->putByte($data->permission);
if($data->aliases !== null){ if($data->aliases !== null){
$this->putLInt($enumIndexes[$data->aliases->getName()] ?? -1); $this->buf->putLInt($enumIndexes[$data->aliases->getName()] ?? -1);
}else{ }else{
$this->putLInt(-1); $this->buf->putLInt(-1);
} }
$this->putUnsignedVarInt(count($data->overloads)); $this->buf->putUnsignedVarInt(count($data->overloads));
foreach($data->overloads as $overload){ foreach($data->overloads as $overload){
/** @var CommandParameter[] $overload */ /** @var CommandParameter[] $overload */
$this->putUnsignedVarInt(count($overload)); $this->buf->putUnsignedVarInt(count($overload));
foreach($overload as $parameter){ foreach($overload as $parameter){
$this->putString($parameter->paramName); $this->buf->putString($parameter->paramName);
if($parameter->enum !== null){ if($parameter->enum !== null){
$type = self::ARG_FLAG_ENUM | self::ARG_FLAG_VALID | ($enumIndexes[$parameter->enum->getName()] ?? -1); $type = self::ARG_FLAG_ENUM | self::ARG_FLAG_VALID | ($enumIndexes[$parameter->enum->getName()] ?? -1);
@ -362,9 +362,9 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{
$type = $parameter->paramType; $type = $parameter->paramType;
} }
$this->putLInt($type); $this->buf->putLInt($type);
$this->putBool($parameter->isOptional); $this->buf->putBool($parameter->isOptional);
$this->putByte($parameter->flags); $this->buf->putByte($parameter->flags);
} }
} }
} }
@ -452,32 +452,32 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{
} }
} }
$this->putUnsignedVarInt(count($enumValueIndexes)); $this->buf->putUnsignedVarInt(count($enumValueIndexes));
foreach($enumValueIndexes as $enumValue => $index){ foreach($enumValueIndexes as $enumValue => $index){
$this->putString((string) $enumValue); //stupid PHP key casting D: $this->buf->putString((string) $enumValue); //stupid PHP key casting D:
} }
$this->putUnsignedVarInt(count($postfixIndexes)); $this->buf->putUnsignedVarInt(count($postfixIndexes));
foreach($postfixIndexes as $postfix => $index){ foreach($postfixIndexes as $postfix => $index){
$this->putString((string) $postfix); //stupid PHP key casting D: $this->buf->putString((string) $postfix); //stupid PHP key casting D:
} }
$this->putUnsignedVarInt(count($enums)); $this->buf->putUnsignedVarInt(count($enums));
foreach($enums as $enum){ foreach($enums as $enum){
$this->putEnum($enum, $enumValueIndexes); $this->putEnum($enum, $enumValueIndexes);
} }
$this->putUnsignedVarInt(count($this->commandData)); $this->buf->putUnsignedVarInt(count($this->commandData));
foreach($this->commandData as $data){ foreach($this->commandData as $data){
$this->putCommandData($data, $enumIndexes, $postfixIndexes); $this->putCommandData($data, $enumIndexes, $postfixIndexes);
} }
$this->putUnsignedVarInt(count($this->softEnums)); $this->buf->putUnsignedVarInt(count($this->softEnums));
foreach($this->softEnums as $enum){ foreach($this->softEnums as $enum){
$this->putSoftEnum($enum); $this->putSoftEnum($enum);
} }
$this->putUnsignedVarInt(count($this->enumConstraints)); $this->buf->putUnsignedVarInt(count($this->enumConstraints));
foreach($this->enumConstraints as $constraint){ foreach($this->enumConstraints as $constraint){
$this->putEnumConstraint($constraint, $enumIndexes, $enumValueIndexes); $this->putEnumConstraint($constraint, $enumIndexes, $enumValueIndexes);
} }

View File

@ -38,11 +38,11 @@ class BiomeDefinitionListPacket extends DataPacket implements ClientboundPacket{
public $namedtag; public $namedtag;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->namedtag = $this->getRemaining(); $this->namedtag = $this->buf->getRemaining();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->put( $this->buf->put(
$this->namedtag ?? $this->namedtag ??
self::$DEFAULT_NBT_CACHE ?? self::$DEFAULT_NBT_CACHE ??
(self::$DEFAULT_NBT_CACHE = file_get_contents(\pocketmine\RESOURCE_PATH . '/vanilla/biome_definitions.nbt')) (self::$DEFAULT_NBT_CACHE = file_get_contents(\pocketmine\RESOURCE_PATH . '/vanilla/biome_definitions.nbt'))

View File

@ -47,13 +47,13 @@ class BlockActorDataPacket extends DataPacket implements ClientboundPacket, Serv
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->getBlockPosition($this->x, $this->y, $this->z); $this->buf->getBlockPosition($this->x, $this->y, $this->z);
$this->namedtag = $this->getRemaining(); $this->namedtag = $this->buf->getRemaining();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putBlockPosition($this->x, $this->y, $this->z); $this->buf->putBlockPosition($this->x, $this->y, $this->z);
$this->put($this->namedtag); $this->buf->put($this->namedtag);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -53,15 +53,15 @@ class BlockEventPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->getBlockPosition($this->x, $this->y, $this->z); $this->buf->getBlockPosition($this->x, $this->y, $this->z);
$this->eventType = $this->getVarInt(); $this->eventType = $this->buf->getVarInt();
$this->eventData = $this->getVarInt(); $this->eventData = $this->buf->getVarInt();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putBlockPosition($this->x, $this->y, $this->z); $this->buf->putBlockPosition($this->x, $this->y, $this->z);
$this->putVarInt($this->eventType); $this->buf->putVarInt($this->eventType);
$this->putVarInt($this->eventData); $this->buf->putVarInt($this->eventData);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -42,15 +42,15 @@ class BlockPickRequestPacket extends DataPacket implements ServerboundPacket{
public $hotbarSlot; public $hotbarSlot;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->getSignedBlockPosition($this->blockX, $this->blockY, $this->blockZ); $this->buf->getSignedBlockPosition($this->blockX, $this->blockY, $this->blockZ);
$this->addUserData = $this->getBool(); $this->addUserData = $this->buf->getBool();
$this->hotbarSlot = $this->getByte(); $this->hotbarSlot = $this->buf->getByte();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putSignedBlockPosition($this->blockX, $this->blockY, $this->blockZ); $this->buf->putSignedBlockPosition($this->blockX, $this->blockY, $this->blockZ);
$this->putBool($this->addUserData); $this->buf->putBool($this->addUserData);
$this->putByte($this->hotbarSlot); $this->buf->putByte($this->hotbarSlot);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -59,27 +59,27 @@ class BookEditPacket extends DataPacket implements ServerboundPacket{
public $xuid; public $xuid;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->type = $this->getByte(); $this->type = $this->buf->getByte();
$this->inventorySlot = $this->getByte(); $this->inventorySlot = $this->buf->getByte();
switch($this->type){ switch($this->type){
case self::TYPE_REPLACE_PAGE: case self::TYPE_REPLACE_PAGE:
case self::TYPE_ADD_PAGE: case self::TYPE_ADD_PAGE:
$this->pageNumber = $this->getByte(); $this->pageNumber = $this->buf->getByte();
$this->text = $this->getString(); $this->text = $this->buf->getString();
$this->photoName = $this->getString(); $this->photoName = $this->buf->getString();
break; break;
case self::TYPE_DELETE_PAGE: case self::TYPE_DELETE_PAGE:
$this->pageNumber = $this->getByte(); $this->pageNumber = $this->buf->getByte();
break; break;
case self::TYPE_SWAP_PAGES: case self::TYPE_SWAP_PAGES:
$this->pageNumber = $this->getByte(); $this->pageNumber = $this->buf->getByte();
$this->secondaryPageNumber = $this->getByte(); $this->secondaryPageNumber = $this->buf->getByte();
break; break;
case self::TYPE_SIGN_BOOK: case self::TYPE_SIGN_BOOK:
$this->title = $this->getString(); $this->title = $this->buf->getString();
$this->author = $this->getString(); $this->author = $this->buf->getString();
$this->xuid = $this->getString(); $this->xuid = $this->buf->getString();
break; break;
default: default:
throw new BadPacketException("Unknown book edit type $this->type!"); throw new BadPacketException("Unknown book edit type $this->type!");
@ -87,27 +87,27 @@ class BookEditPacket extends DataPacket implements ServerboundPacket{
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putByte($this->type); $this->buf->putByte($this->type);
$this->putByte($this->inventorySlot); $this->buf->putByte($this->inventorySlot);
switch($this->type){ switch($this->type){
case self::TYPE_REPLACE_PAGE: case self::TYPE_REPLACE_PAGE:
case self::TYPE_ADD_PAGE: case self::TYPE_ADD_PAGE:
$this->putByte($this->pageNumber); $this->buf->putByte($this->pageNumber);
$this->putString($this->text); $this->buf->putString($this->text);
$this->putString($this->photoName); $this->buf->putString($this->photoName);
break; break;
case self::TYPE_DELETE_PAGE: case self::TYPE_DELETE_PAGE:
$this->putByte($this->pageNumber); $this->buf->putByte($this->pageNumber);
break; break;
case self::TYPE_SWAP_PAGES: case self::TYPE_SWAP_PAGES:
$this->putByte($this->pageNumber); $this->buf->putByte($this->pageNumber);
$this->putByte($this->secondaryPageNumber); $this->buf->putByte($this->secondaryPageNumber);
break; break;
case self::TYPE_SIGN_BOOK: case self::TYPE_SIGN_BOOK:
$this->putString($this->title); $this->buf->putString($this->title);
$this->putString($this->author); $this->buf->putString($this->author);
$this->putString($this->xuid); $this->buf->putString($this->xuid);
break; break;
default: default:
throw new \InvalidArgumentException("Unknown book edit type $this->type!"); throw new \InvalidArgumentException("Unknown book edit type $this->type!");

View File

@ -119,29 +119,29 @@ class BossEventPacket extends DataPacket implements ClientboundPacket, Serverbou
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->bossEid = $this->getEntityUniqueId(); $this->bossEid = $this->buf->getEntityUniqueId();
$this->eventType = $this->getUnsignedVarInt(); $this->eventType = $this->buf->getUnsignedVarInt();
switch($this->eventType){ switch($this->eventType){
case self::TYPE_REGISTER_PLAYER: case self::TYPE_REGISTER_PLAYER:
case self::TYPE_UNREGISTER_PLAYER: case self::TYPE_UNREGISTER_PLAYER:
$this->playerEid = $this->getEntityUniqueId(); $this->playerEid = $this->buf->getEntityUniqueId();
break; break;
/** @noinspection PhpMissingBreakStatementInspection */ /** @noinspection PhpMissingBreakStatementInspection */
case self::TYPE_SHOW: case self::TYPE_SHOW:
$this->title = $this->getString(); $this->title = $this->buf->getString();
$this->healthPercent = $this->getLFloat(); $this->healthPercent = $this->buf->getLFloat();
/** @noinspection PhpMissingBreakStatementInspection */ /** @noinspection PhpMissingBreakStatementInspection */
case self::TYPE_UNKNOWN_6: case self::TYPE_UNKNOWN_6:
$this->unknownShort = $this->getLShort(); $this->unknownShort = $this->buf->getLShort();
case self::TYPE_TEXTURE: case self::TYPE_TEXTURE:
$this->color = $this->getUnsignedVarInt(); $this->color = $this->buf->getUnsignedVarInt();
$this->overlay = $this->getUnsignedVarInt(); $this->overlay = $this->buf->getUnsignedVarInt();
break; break;
case self::TYPE_HEALTH_PERCENT: case self::TYPE_HEALTH_PERCENT:
$this->healthPercent = $this->getLFloat(); $this->healthPercent = $this->buf->getLFloat();
break; break;
case self::TYPE_TITLE: case self::TYPE_TITLE:
$this->title = $this->getString(); $this->title = $this->buf->getString();
break; break;
default: default:
break; break;
@ -149,29 +149,29 @@ class BossEventPacket extends DataPacket implements ClientboundPacket, Serverbou
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityUniqueId($this->bossEid); $this->buf->putEntityUniqueId($this->bossEid);
$this->putUnsignedVarInt($this->eventType); $this->buf->putUnsignedVarInt($this->eventType);
switch($this->eventType){ switch($this->eventType){
case self::TYPE_REGISTER_PLAYER: case self::TYPE_REGISTER_PLAYER:
case self::TYPE_UNREGISTER_PLAYER: case self::TYPE_UNREGISTER_PLAYER:
$this->putEntityUniqueId($this->playerEid); $this->buf->putEntityUniqueId($this->playerEid);
break; break;
/** @noinspection PhpMissingBreakStatementInspection */ /** @noinspection PhpMissingBreakStatementInspection */
case self::TYPE_SHOW: case self::TYPE_SHOW:
$this->putString($this->title); $this->buf->putString($this->title);
$this->putLFloat($this->healthPercent); $this->buf->putLFloat($this->healthPercent);
/** @noinspection PhpMissingBreakStatementInspection */ /** @noinspection PhpMissingBreakStatementInspection */
case self::TYPE_UNKNOWN_6: case self::TYPE_UNKNOWN_6:
$this->putLShort($this->unknownShort); $this->buf->putLShort($this->unknownShort);
case self::TYPE_TEXTURE: case self::TYPE_TEXTURE:
$this->putUnsignedVarInt($this->color); $this->buf->putUnsignedVarInt($this->color);
$this->putUnsignedVarInt($this->overlay); $this->buf->putUnsignedVarInt($this->overlay);
break; break;
case self::TYPE_HEALTH_PERCENT: case self::TYPE_HEALTH_PERCENT:
$this->putLFloat($this->healthPercent); $this->buf->putLFloat($this->healthPercent);
break; break;
case self::TYPE_TITLE: case self::TYPE_TITLE:
$this->putString($this->title); $this->buf->putString($this->title);
break; break;
default: default:
break; break;

View File

@ -36,13 +36,13 @@ class CameraPacket extends DataPacket implements ClientboundPacket{
public $playerUniqueId; public $playerUniqueId;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->cameraUniqueId = $this->getEntityUniqueId(); $this->cameraUniqueId = $this->buf->getEntityUniqueId();
$this->playerUniqueId = $this->getEntityUniqueId(); $this->playerUniqueId = $this->buf->getEntityUniqueId();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityUniqueId($this->cameraUniqueId); $this->buf->putEntityUniqueId($this->cameraUniqueId);
$this->putEntityUniqueId($this->playerUniqueId); $this->buf->putEntityUniqueId($this->playerUniqueId);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -39,15 +39,15 @@ class ChangeDimensionPacket extends DataPacket implements ClientboundPacket{
public $respawn = false; public $respawn = false;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->dimension = $this->getVarInt(); $this->dimension = $this->buf->getVarInt();
$this->position = $this->getVector3(); $this->position = $this->buf->getVector3();
$this->respawn = $this->getBool(); $this->respawn = $this->buf->getBool();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putVarInt($this->dimension); $this->buf->putVarInt($this->dimension);
$this->putVector3($this->position); $this->buf->putVector3($this->position);
$this->putBool($this->respawn); $this->buf->putBool($this->respawn);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -40,11 +40,11 @@ class ChunkRadiusUpdatedPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->radius = $this->getVarInt(); $this->radius = $this->buf->getVarInt();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putVarInt($this->radius); $this->buf->putVarInt($this->radius);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -66,24 +66,24 @@ class ClientCacheBlobStatusPacket extends DataPacket implements ServerboundPacke
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$hitCount = $this->getUnsignedVarInt(); $hitCount = $this->buf->getUnsignedVarInt();
$missCount = $this->getUnsignedVarInt(); $missCount = $this->buf->getUnsignedVarInt();
for($i = 0; $i < $hitCount; ++$i){ for($i = 0; $i < $hitCount; ++$i){
$this->hitHashes[] = $this->getLLong(); $this->hitHashes[] = $this->buf->getLLong();
} }
for($i = 0; $i < $missCount; ++$i){ for($i = 0; $i < $missCount; ++$i){
$this->missHashes[] = $this->getLLong(); $this->missHashes[] = $this->buf->getLLong();
} }
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putUnsignedVarInt(count($this->hitHashes)); $this->buf->putUnsignedVarInt(count($this->hitHashes));
$this->putUnsignedVarInt(count($this->missHashes)); $this->buf->putUnsignedVarInt(count($this->missHashes));
foreach($this->hitHashes as $hash){ foreach($this->hitHashes as $hash){
$this->putLLong($hash); $this->buf->putLLong($hash);
} }
foreach($this->missHashes as $hash){ foreach($this->missHashes as $hash){
$this->putLLong($hash); $this->buf->putLLong($hash);
} }
} }

View File

@ -55,18 +55,18 @@ class ClientCacheMissResponsePacket extends DataPacket implements ClientboundPac
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){
$hash = $this->getLLong(); $hash = $this->buf->getLLong();
$payload = $this->getString(); $payload = $this->buf->getString();
$this->blobs[] = new ChunkCacheBlob($hash, $payload); $this->blobs[] = new ChunkCacheBlob($hash, $payload);
} }
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putUnsignedVarInt(count($this->blobs)); $this->buf->putUnsignedVarInt(count($this->blobs));
foreach($this->blobs as $blob){ foreach($this->blobs as $blob){
$this->putLLong($blob->getHash()); $this->buf->putLLong($blob->getHash());
$this->putString($blob->getPayload()); $this->buf->putString($blob->getPayload());
} }
} }

View File

@ -44,11 +44,11 @@ class ClientCacheStatusPacket extends DataPacket implements ServerboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->enabled = $this->getBool(); $this->enabled = $this->buf->getBool();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putBool($this->enabled); $this->buf->putBool($this->enabled);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -73,68 +73,68 @@ class ClientboundMapItemDataPacket extends DataPacket implements ClientboundPack
public $colors = []; public $colors = [];
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->mapId = $this->getEntityUniqueId(); $this->mapId = $this->buf->getEntityUniqueId();
$this->type = $this->getUnsignedVarInt(); $this->type = $this->buf->getUnsignedVarInt();
$this->dimensionId = $this->getByte(); $this->dimensionId = $this->buf->getByte();
$this->isLocked = $this->getBool(); $this->isLocked = $this->buf->getBool();
if(($this->type & 0x08) !== 0){ if(($this->type & 0x08) !== 0){
$count = $this->getUnsignedVarInt(); $count = $this->buf->getUnsignedVarInt();
for($i = 0; $i < $count; ++$i){ for($i = 0; $i < $count; ++$i){
$this->eids[] = $this->getEntityUniqueId(); $this->eids[] = $this->buf->getEntityUniqueId();
} }
} }
if(($this->type & (0x08 | self::BITFLAG_DECORATION_UPDATE | self::BITFLAG_TEXTURE_UPDATE)) !== 0){ //Decoration bitflag or colour bitflag if(($this->type & (0x08 | self::BITFLAG_DECORATION_UPDATE | self::BITFLAG_TEXTURE_UPDATE)) !== 0){ //Decoration bitflag or colour bitflag
$this->scale = $this->getByte(); $this->scale = $this->buf->getByte();
} }
if(($this->type & self::BITFLAG_DECORATION_UPDATE) !== 0){ if(($this->type & self::BITFLAG_DECORATION_UPDATE) !== 0){
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){
$object = new MapTrackedObject(); $object = new MapTrackedObject();
$object->type = $this->getLInt(); $object->type = $this->buf->getLInt();
if($object->type === MapTrackedObject::TYPE_BLOCK){ if($object->type === MapTrackedObject::TYPE_BLOCK){
$this->getBlockPosition($object->x, $object->y, $object->z); $this->buf->getBlockPosition($object->x, $object->y, $object->z);
}elseif($object->type === MapTrackedObject::TYPE_ENTITY){ }elseif($object->type === MapTrackedObject::TYPE_ENTITY){
$object->entityUniqueId = $this->getEntityUniqueId(); $object->entityUniqueId = $this->buf->getEntityUniqueId();
}else{ }else{
throw new BadPacketException("Unknown map object type $object->type"); throw new BadPacketException("Unknown map object type $object->type");
} }
$this->trackedEntities[] = $object; $this->trackedEntities[] = $object;
} }
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){
$icon = $this->getByte(); $icon = $this->buf->getByte();
$rotation = $this->getByte(); $rotation = $this->buf->getByte();
$xOffset = $this->getByte(); $xOffset = $this->buf->getByte();
$yOffset = $this->getByte(); $yOffset = $this->buf->getByte();
$label = $this->getString(); $label = $this->buf->getString();
$color = Color::fromRGBA(Binary::flipIntEndianness($this->getUnsignedVarInt())); $color = Color::fromRGBA(Binary::flipIntEndianness($this->buf->getUnsignedVarInt()));
$this->decorations[] = new MapDecoration($icon, $rotation, $xOffset, $yOffset, $label, $color); $this->decorations[] = new MapDecoration($icon, $rotation, $xOffset, $yOffset, $label, $color);
} }
} }
if(($this->type & self::BITFLAG_TEXTURE_UPDATE) !== 0){ if(($this->type & self::BITFLAG_TEXTURE_UPDATE) !== 0){
$this->width = $this->getVarInt(); $this->width = $this->buf->getVarInt();
$this->height = $this->getVarInt(); $this->height = $this->buf->getVarInt();
$this->xOffset = $this->getVarInt(); $this->xOffset = $this->buf->getVarInt();
$this->yOffset = $this->getVarInt(); $this->yOffset = $this->buf->getVarInt();
$count = $this->getUnsignedVarInt(); $count = $this->buf->getUnsignedVarInt();
if($count !== $this->width * $this->height){ if($count !== $this->width * $this->height){
throw new BadPacketException("Expected colour count of " . ($this->height * $this->width) . " (height $this->height * width $this->width), got $count"); throw new BadPacketException("Expected colour count of " . ($this->height * $this->width) . " (height $this->height * width $this->width), got $count");
} }
for($y = 0; $y < $this->height; ++$y){ for($y = 0; $y < $this->height; ++$y){
for($x = 0; $x < $this->width; ++$x){ for($x = 0; $x < $this->width; ++$x){
$this->colors[$y][$x] = Color::fromRGBA(Binary::flipIntEndianness($this->getUnsignedVarInt())); $this->colors[$y][$x] = Color::fromRGBA(Binary::flipIntEndianness($this->buf->getUnsignedVarInt()));
} }
} }
} }
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityUniqueId($this->mapId); $this->buf->putEntityUniqueId($this->mapId);
$type = 0; $type = 0;
if(($eidsCount = count($this->eids)) > 0){ if(($eidsCount = count($this->eids)) > 0){
@ -147,57 +147,57 @@ class ClientboundMapItemDataPacket extends DataPacket implements ClientboundPack
$type |= self::BITFLAG_TEXTURE_UPDATE; $type |= self::BITFLAG_TEXTURE_UPDATE;
} }
$this->putUnsignedVarInt($type); $this->buf->putUnsignedVarInt($type);
$this->putByte($this->dimensionId); $this->buf->putByte($this->dimensionId);
$this->putBool($this->isLocked); $this->buf->putBool($this->isLocked);
if(($type & 0x08) !== 0){ //TODO: find out what these are for if(($type & 0x08) !== 0){ //TODO: find out what these are for
$this->putUnsignedVarInt($eidsCount); $this->buf->putUnsignedVarInt($eidsCount);
foreach($this->eids as $eid){ foreach($this->eids as $eid){
$this->putEntityUniqueId($eid); $this->buf->putEntityUniqueId($eid);
} }
} }
if(($type & (0x08 | self::BITFLAG_TEXTURE_UPDATE | self::BITFLAG_DECORATION_UPDATE)) !== 0){ if(($type & (0x08 | self::BITFLAG_TEXTURE_UPDATE | self::BITFLAG_DECORATION_UPDATE)) !== 0){
$this->putByte($this->scale); $this->buf->putByte($this->scale);
} }
if(($type & self::BITFLAG_DECORATION_UPDATE) !== 0){ if(($type & self::BITFLAG_DECORATION_UPDATE) !== 0){
$this->putUnsignedVarInt(count($this->trackedEntities)); $this->buf->putUnsignedVarInt(count($this->trackedEntities));
foreach($this->trackedEntities as $object){ foreach($this->trackedEntities as $object){
$this->putLInt($object->type); $this->buf->putLInt($object->type);
if($object->type === MapTrackedObject::TYPE_BLOCK){ if($object->type === MapTrackedObject::TYPE_BLOCK){
$this->putBlockPosition($object->x, $object->y, $object->z); $this->buf->putBlockPosition($object->x, $object->y, $object->z);
}elseif($object->type === MapTrackedObject::TYPE_ENTITY){ }elseif($object->type === MapTrackedObject::TYPE_ENTITY){
$this->putEntityUniqueId($object->entityUniqueId); $this->buf->putEntityUniqueId($object->entityUniqueId);
}else{ }else{
throw new \InvalidArgumentException("Unknown map object type $object->type"); throw new \InvalidArgumentException("Unknown map object type $object->type");
} }
} }
$this->putUnsignedVarInt($decorationCount); $this->buf->putUnsignedVarInt($decorationCount);
foreach($this->decorations as $decoration){ foreach($this->decorations as $decoration){
$this->putByte($decoration->getIcon()); $this->buf->putByte($decoration->getIcon());
$this->putByte($decoration->getRotation()); $this->buf->putByte($decoration->getRotation());
$this->putByte($decoration->getXOffset()); $this->buf->putByte($decoration->getXOffset());
$this->putByte($decoration->getYOffset()); $this->buf->putByte($decoration->getYOffset());
$this->putString($decoration->getLabel()); $this->buf->putString($decoration->getLabel());
$this->putUnsignedVarInt(Binary::flipIntEndianness($decoration->getColor()->toRGBA())); $this->buf->putUnsignedVarInt(Binary::flipIntEndianness($decoration->getColor()->toRGBA()));
} }
} }
if(($type & self::BITFLAG_TEXTURE_UPDATE) !== 0){ if(($type & self::BITFLAG_TEXTURE_UPDATE) !== 0){
$this->putVarInt($this->width); $this->buf->putVarInt($this->width);
$this->putVarInt($this->height); $this->buf->putVarInt($this->height);
$this->putVarInt($this->xOffset); $this->buf->putVarInt($this->xOffset);
$this->putVarInt($this->yOffset); $this->buf->putVarInt($this->yOffset);
$this->putUnsignedVarInt($this->width * $this->height); //list count, but we handle it as a 2D array... thanks for the confusion mojang $this->buf->putUnsignedVarInt($this->width * $this->height); //list count, but we handle it as a 2D array... thanks for the confusion mojang
for($y = 0; $y < $this->height; ++$y){ for($y = 0; $y < $this->height; ++$y){
for($x = 0; $x < $this->width; ++$x){ for($x = 0; $x < $this->width; ++$x){
//if mojang had any sense this would just be a regular LE int //if mojang had any sense this would just be a regular LE int
$this->putUnsignedVarInt(Binary::flipIntEndianness($this->colors[$y][$x]->toRGBA())); $this->buf->putUnsignedVarInt(Binary::flipIntEndianness($this->colors[$y][$x]->toRGBA()));
} }
} }
} }

View File

@ -63,46 +63,46 @@ class CommandBlockUpdatePacket extends DataPacket implements ServerboundPacket{
public $executeOnFirstTick; public $executeOnFirstTick;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->isBlock = $this->getBool(); $this->isBlock = $this->buf->getBool();
if($this->isBlock){ if($this->isBlock){
$this->getBlockPosition($this->x, $this->y, $this->z); $this->buf->getBlockPosition($this->x, $this->y, $this->z);
$this->commandBlockMode = $this->getUnsignedVarInt(); $this->commandBlockMode = $this->buf->getUnsignedVarInt();
$this->isRedstoneMode = $this->getBool(); $this->isRedstoneMode = $this->buf->getBool();
$this->isConditional = $this->getBool(); $this->isConditional = $this->buf->getBool();
}else{ }else{
//Minecart with command block //Minecart with command block
$this->minecartEid = $this->getEntityRuntimeId(); $this->minecartEid = $this->buf->getEntityRuntimeId();
} }
$this->command = $this->getString(); $this->command = $this->buf->getString();
$this->lastOutput = $this->getString(); $this->lastOutput = $this->buf->getString();
$this->name = $this->getString(); $this->name = $this->buf->getString();
$this->shouldTrackOutput = $this->getBool(); $this->shouldTrackOutput = $this->buf->getBool();
$this->tickDelay = $this->getLInt(); $this->tickDelay = $this->buf->getLInt();
$this->executeOnFirstTick = $this->getBool(); $this->executeOnFirstTick = $this->buf->getBool();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putBool($this->isBlock); $this->buf->putBool($this->isBlock);
if($this->isBlock){ if($this->isBlock){
$this->putBlockPosition($this->x, $this->y, $this->z); $this->buf->putBlockPosition($this->x, $this->y, $this->z);
$this->putUnsignedVarInt($this->commandBlockMode); $this->buf->putUnsignedVarInt($this->commandBlockMode);
$this->putBool($this->isRedstoneMode); $this->buf->putBool($this->isRedstoneMode);
$this->putBool($this->isConditional); $this->buf->putBool($this->isConditional);
}else{ }else{
$this->putEntityRuntimeId($this->minecartEid); $this->buf->putEntityRuntimeId($this->minecartEid);
} }
$this->putString($this->command); $this->buf->putString($this->command);
$this->putString($this->lastOutput); $this->buf->putString($this->lastOutput);
$this->putString($this->name); $this->buf->putString($this->name);
$this->putBool($this->shouldTrackOutput); $this->buf->putBool($this->shouldTrackOutput);
$this->putLInt($this->tickDelay); $this->buf->putLInt($this->tickDelay);
$this->putBool($this->executeOnFirstTick); $this->buf->putBool($this->executeOnFirstTick);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -46,16 +46,16 @@ class CommandOutputPacket extends DataPacket implements ClientboundPacket{
public $unknownString; public $unknownString;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->originData = $this->getCommandOriginData(); $this->originData = $this->buf->getCommandOriginData();
$this->outputType = $this->getByte(); $this->outputType = $this->buf->getByte();
$this->successCount = $this->getUnsignedVarInt(); $this->successCount = $this->buf->getUnsignedVarInt();
for($i = 0, $size = $this->getUnsignedVarInt(); $i < $size; ++$i){ for($i = 0, $size = $this->buf->getUnsignedVarInt(); $i < $size; ++$i){
$this->messages[] = $this->getCommandMessage(); $this->messages[] = $this->getCommandMessage();
} }
if($this->outputType === 4){ if($this->outputType === 4){
$this->unknownString = $this->getString(); $this->unknownString = $this->buf->getString();
} }
} }
@ -65,38 +65,38 @@ class CommandOutputPacket extends DataPacket implements ClientboundPacket{
protected function getCommandMessage() : CommandOutputMessage{ protected function getCommandMessage() : CommandOutputMessage{
$message = new CommandOutputMessage(); $message = new CommandOutputMessage();
$message->isInternal = $this->getBool(); $message->isInternal = $this->buf->getBool();
$message->messageId = $this->getString(); $message->messageId = $this->buf->getString();
for($i = 0, $size = $this->getUnsignedVarInt(); $i < $size; ++$i){ for($i = 0, $size = $this->buf->getUnsignedVarInt(); $i < $size; ++$i){
$message->parameters[] = $this->getString(); $message->parameters[] = $this->buf->getString();
} }
return $message; return $message;
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putCommandOriginData($this->originData); $this->buf->putCommandOriginData($this->originData);
$this->putByte($this->outputType); $this->buf->putByte($this->outputType);
$this->putUnsignedVarInt($this->successCount); $this->buf->putUnsignedVarInt($this->successCount);
$this->putUnsignedVarInt(count($this->messages)); $this->buf->putUnsignedVarInt(count($this->messages));
foreach($this->messages as $message){ foreach($this->messages as $message){
$this->putCommandMessage($message); $this->putCommandMessage($message);
} }
if($this->outputType === 4){ if($this->outputType === 4){
$this->putString($this->unknownString); $this->buf->putString($this->unknownString);
} }
} }
protected function putCommandMessage(CommandOutputMessage $message) : void{ protected function putCommandMessage(CommandOutputMessage $message) : void{
$this->putBool($message->isInternal); $this->buf->putBool($message->isInternal);
$this->putString($message->messageId); $this->buf->putString($message->messageId);
$this->putUnsignedVarInt(count($message->parameters)); $this->buf->putUnsignedVarInt(count($message->parameters));
foreach($message->parameters as $parameter){ foreach($message->parameters as $parameter){
$this->putString($parameter); $this->buf->putString($parameter);
} }
} }

View File

@ -39,15 +39,15 @@ class CommandRequestPacket extends DataPacket implements ServerboundPacket{
public $isInternal; public $isInternal;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->command = $this->getString(); $this->command = $this->buf->getString();
$this->originData = $this->getCommandOriginData(); $this->originData = $this->buf->getCommandOriginData();
$this->isInternal = $this->getBool(); $this->isInternal = $this->buf->getBool();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putString($this->command); $this->buf->putString($this->command);
$this->putCommandOriginData($this->originData); $this->buf->putCommandOriginData($this->originData);
$this->putBool($this->isInternal); $this->buf->putBool($this->isInternal);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -53,13 +53,13 @@ class CompletedUsingItemPacket extends DataPacket implements ClientboundPacket{
public $action; public $action;
public function decodePayload() : void{ public function decodePayload() : void{
$this->itemId = $this->getShort(); $this->itemId = $this->buf->getShort();
$this->action = $this->getLInt(); $this->action = $this->buf->getLInt();
} }
public function encodePayload() : void{ public function encodePayload() : void{
$this->putShort($this->itemId); $this->buf->putShort($this->itemId);
$this->putLInt($this->action); $this->buf->putLInt($this->action);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -40,11 +40,11 @@ class ContainerClosePacket extends DataPacket implements ClientboundPacket, Serv
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->windowId = $this->getByte(); $this->windowId = $this->buf->getByte();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putByte($this->windowId); $this->buf->putByte($this->windowId);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -66,17 +66,17 @@ class ContainerOpenPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->windowId = $this->getByte(); $this->windowId = $this->buf->getByte();
$this->type = $this->getByte(); $this->type = $this->buf->getByte();
$this->getBlockPosition($this->x, $this->y, $this->z); $this->buf->getBlockPosition($this->x, $this->y, $this->z);
$this->entityUniqueId = $this->getEntityUniqueId(); $this->entityUniqueId = $this->buf->getEntityUniqueId();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putByte($this->windowId); $this->buf->putByte($this->windowId);
$this->putByte($this->type); $this->buf->putByte($this->type);
$this->putBlockPosition($this->x, $this->y, $this->z); $this->buf->putBlockPosition($this->x, $this->y, $this->z);
$this->putEntityUniqueId($this->entityUniqueId); $this->buf->putEntityUniqueId($this->entityUniqueId);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -56,15 +56,15 @@ class ContainerSetDataPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->windowId = $this->getByte(); $this->windowId = $this->buf->getByte();
$this->property = $this->getVarInt(); $this->property = $this->buf->getVarInt();
$this->value = $this->getVarInt(); $this->value = $this->buf->getVarInt();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putByte($this->windowId); $this->buf->putByte($this->windowId);
$this->putVarInt($this->property); $this->buf->putVarInt($this->property);
$this->putVarInt($this->value); $this->buf->putVarInt($this->value);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -67,60 +67,60 @@ class CraftingDataPacket extends DataPacket implements ClientboundPacket{
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->decodedEntries = []; $this->decodedEntries = [];
$recipeCount = $this->getUnsignedVarInt(); $recipeCount = $this->buf->getUnsignedVarInt();
for($i = 0; $i < $recipeCount; ++$i){ for($i = 0; $i < $recipeCount; ++$i){
$entry = []; $entry = [];
$entry["type"] = $recipeType = $this->getVarInt(); $entry["type"] = $recipeType = $this->buf->getVarInt();
switch($recipeType){ switch($recipeType){
case self::ENTRY_SHAPELESS: case self::ENTRY_SHAPELESS:
case self::ENTRY_SHULKER_BOX: case self::ENTRY_SHULKER_BOX:
case self::ENTRY_SHAPELESS_CHEMISTRY: case self::ENTRY_SHAPELESS_CHEMISTRY:
$entry["recipe_id"] = $this->getString(); $entry["recipe_id"] = $this->buf->getString();
$ingredientCount = $this->getUnsignedVarInt(); $ingredientCount = $this->buf->getUnsignedVarInt();
/** @var Item */ /** @var Item */
$entry["input"] = []; $entry["input"] = [];
for($j = 0; $j < $ingredientCount; ++$j){ for($j = 0; $j < $ingredientCount; ++$j){
$entry["input"][] = $in = $this->getRecipeIngredient(); $entry["input"][] = $in = $this->buf->getRecipeIngredient();
$in->setCount(1); //TODO HACK: they send a useless count field which breaks the PM crafting system because it isn't always 1 $in->setCount(1); //TODO HACK: they send a useless count field which breaks the PM crafting system because it isn't always 1
} }
$resultCount = $this->getUnsignedVarInt(); $resultCount = $this->buf->getUnsignedVarInt();
$entry["output"] = []; $entry["output"] = [];
for($k = 0; $k < $resultCount; ++$k){ for($k = 0; $k < $resultCount; ++$k){
$entry["output"][] = $this->getSlot(); $entry["output"][] = $this->buf->getSlot();
} }
$entry["uuid"] = $this->getUUID()->toString(); $entry["uuid"] = $this->buf->getUUID()->toString();
$entry["block"] = $this->getString(); $entry["block"] = $this->buf->getString();
$entry["priority"] = $this->getVarInt(); $entry["priority"] = $this->buf->getVarInt();
break; break;
case self::ENTRY_SHAPED: case self::ENTRY_SHAPED:
case self::ENTRY_SHAPED_CHEMISTRY: case self::ENTRY_SHAPED_CHEMISTRY:
$entry["recipe_id"] = $this->getString(); $entry["recipe_id"] = $this->buf->getString();
$entry["width"] = $this->getVarInt(); $entry["width"] = $this->buf->getVarInt();
$entry["height"] = $this->getVarInt(); $entry["height"] = $this->buf->getVarInt();
$count = $entry["width"] * $entry["height"]; $count = $entry["width"] * $entry["height"];
$entry["input"] = []; $entry["input"] = [];
for($j = 0; $j < $count; ++$j){ for($j = 0; $j < $count; ++$j){
$entry["input"][] = $in = $this->getRecipeIngredient(); $entry["input"][] = $in = $this->buf->getRecipeIngredient();
$in->setCount(1); //TODO HACK: they send a useless count field which breaks the PM crafting system $in->setCount(1); //TODO HACK: they send a useless count field which breaks the PM crafting system
} }
$resultCount = $this->getUnsignedVarInt(); $resultCount = $this->buf->getUnsignedVarInt();
$entry["output"] = []; $entry["output"] = [];
for($k = 0; $k < $resultCount; ++$k){ for($k = 0; $k < $resultCount; ++$k){
$entry["output"][] = $this->getSlot(); $entry["output"][] = $this->buf->getSlot();
} }
$entry["uuid"] = $this->getUUID()->toString(); $entry["uuid"] = $this->buf->getUUID()->toString();
$entry["block"] = $this->getString(); $entry["block"] = $this->buf->getString();
$entry["priority"] = $this->getVarInt(); $entry["priority"] = $this->buf->getVarInt();
break; break;
case self::ENTRY_FURNACE: case self::ENTRY_FURNACE:
case self::ENTRY_FURNACE_DATA: case self::ENTRY_FURNACE_DATA:
$inputId = $this->getVarInt(); $inputId = $this->buf->getVarInt();
$inputData = -1; $inputData = -1;
if($recipeType === self::ENTRY_FURNACE_DATA){ if($recipeType === self::ENTRY_FURNACE_DATA){
$inputData = $this->getVarInt(); $inputData = $this->buf->getVarInt();
if($inputData === 0x7fff){ if($inputData === 0x7fff){
$inputData = -1; $inputData = -1;
} }
@ -130,34 +130,34 @@ class CraftingDataPacket extends DataPacket implements ClientboundPacket{
}catch(\InvalidArgumentException $e){ }catch(\InvalidArgumentException $e){
throw new BadPacketException($e->getMessage(), 0, $e); throw new BadPacketException($e->getMessage(), 0, $e);
} }
$entry["output"] = $out = $this->getSlot(); $entry["output"] = $out = $this->buf->getSlot();
if($out->getMeta() === 0x7fff){ if($out->getMeta() === 0x7fff){
$entry["output"] = ItemFactory::get($out->getId(), 0); //TODO HACK: some 1.12 furnace recipe outputs have wildcard damage values $entry["output"] = ItemFactory::get($out->getId(), 0); //TODO HACK: some 1.12 furnace recipe outputs have wildcard damage values
} }
$entry["block"] = $this->getString(); $entry["block"] = $this->buf->getString();
break; break;
case self::ENTRY_MULTI: case self::ENTRY_MULTI:
$entry["uuid"] = $this->getUUID()->toString(); $entry["uuid"] = $this->buf->getUUID()->toString();
break; break;
default: default:
throw new BadPacketException("Unhandled recipe type $recipeType!"); //do not continue attempting to decode throw new BadPacketException("Unhandled recipe type $recipeType!"); //do not continue attempting to decode
} }
$this->decodedEntries[] = $entry; $this->decodedEntries[] = $entry;
} }
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){
$input = $this->getVarInt(); $input = $this->buf->getVarInt();
$ingredient = $this->getVarInt(); $ingredient = $this->buf->getVarInt();
$output = $this->getVarInt(); $output = $this->buf->getVarInt();
$this->potionTypeRecipes[] = new PotionTypeRecipe($input, $ingredient, $output); $this->potionTypeRecipes[] = new PotionTypeRecipe($input, $ingredient, $output);
} }
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){
$input = $this->getVarInt(); $input = $this->buf->getVarInt();
$ingredient = $this->getVarInt(); $ingredient = $this->buf->getVarInt();
$output = $this->getVarInt(); $output = $this->buf->getVarInt();
$this->potionContainerRecipes[] = new PotionContainerChangeRecipe($input, $ingredient, $output); $this->potionContainerRecipes[] = new PotionContainerChangeRecipe($input, $ingredient, $output);
} }
$this->cleanRecipes = $this->getBool(); $this->cleanRecipes = $this->buf->getBool();
} }
/** /**
@ -245,35 +245,35 @@ class CraftingDataPacket extends DataPacket implements ClientboundPacket{
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putUnsignedVarInt(count($this->entries)); $this->buf->putUnsignedVarInt(count($this->entries));
$writer = new NetworkBinaryStream(); $writer = new NetworkBinaryStream();
$counter = 0; $counter = 0;
foreach($this->entries as $d){ foreach($this->entries as $d){
$entryType = self::writeEntry($d, $writer, $counter++); $entryType = self::writeEntry($d, $writer, $counter++);
if($entryType >= 0){ if($entryType >= 0){
$this->putVarInt($entryType); $this->buf->putVarInt($entryType);
$this->put($writer->getBuffer()); $this->buf->put($writer->getBuffer());
}else{ }else{
$this->putVarInt(-1); $this->buf->putVarInt(-1);
} }
$writer->reset(); $writer->reset();
} }
$this->putUnsignedVarInt(count($this->potionTypeRecipes)); $this->buf->putUnsignedVarInt(count($this->potionTypeRecipes));
foreach($this->potionTypeRecipes as $recipe){ foreach($this->potionTypeRecipes as $recipe){
$this->putVarInt($recipe->getInputPotionType()); $this->buf->putVarInt($recipe->getInputPotionType());
$this->putVarInt($recipe->getIngredientItemId()); $this->buf->putVarInt($recipe->getIngredientItemId());
$this->putVarInt($recipe->getOutputPotionType()); $this->buf->putVarInt($recipe->getOutputPotionType());
} }
$this->putUnsignedVarInt(count($this->potionContainerRecipes)); $this->buf->putUnsignedVarInt(count($this->potionContainerRecipes));
foreach($this->potionContainerRecipes as $recipe){ foreach($this->potionContainerRecipes as $recipe){
$this->putVarInt($recipe->getInputItemId()); $this->buf->putVarInt($recipe->getInputItemId());
$this->putVarInt($recipe->getIngredientItemId()); $this->buf->putVarInt($recipe->getIngredientItemId());
$this->putVarInt($recipe->getOutputItemId()); $this->buf->putVarInt($recipe->getOutputItemId());
} }
$this->putBool($this->cleanRecipes); $this->buf->putBool($this->cleanRecipes);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -45,34 +45,34 @@ class CraftingEventPacket extends DataPacket implements ServerboundPacket{
public $output = []; public $output = [];
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->windowId = $this->getByte(); $this->windowId = $this->buf->getByte();
$this->type = $this->getVarInt(); $this->type = $this->buf->getVarInt();
$this->id = $this->getUUID(); $this->id = $this->buf->getUUID();
$size = $this->getUnsignedVarInt(); $size = $this->buf->getUnsignedVarInt();
for($i = 0; $i < $size and $i < 128; ++$i){ for($i = 0; $i < $size and $i < 128; ++$i){
$this->input[] = $this->getSlot(); $this->input[] = $this->buf->getSlot();
} }
$size = $this->getUnsignedVarInt(); $size = $this->buf->getUnsignedVarInt();
for($i = 0; $i < $size and $i < 128; ++$i){ for($i = 0; $i < $size and $i < 128; ++$i){
$this->output[] = $this->getSlot(); $this->output[] = $this->buf->getSlot();
} }
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putByte($this->windowId); $this->buf->putByte($this->windowId);
$this->putVarInt($this->type); $this->buf->putVarInt($this->type);
$this->putUUID($this->id); $this->buf->putUUID($this->id);
$this->putUnsignedVarInt(count($this->input)); $this->buf->putUnsignedVarInt(count($this->input));
foreach($this->input as $item){ foreach($this->input as $item){
$this->putSlot($item); $this->buf->putSlot($item);
} }
$this->putUnsignedVarInt(count($this->output)); $this->buf->putUnsignedVarInt(count($this->output));
foreach($this->output as $item){ foreach($this->output as $item){
$this->putSlot($item); $this->buf->putSlot($item);
} }
} }

View File

@ -35,7 +35,7 @@ use function is_object;
use function is_string; use function is_string;
use function method_exists; use function method_exists;
abstract class DataPacket extends NetworkBinaryStream implements Packet{ abstract class DataPacket implements Packet{
public const NETWORK_ID = 0; public const NETWORK_ID = 0;
@ -43,6 +43,17 @@ abstract class DataPacket extends NetworkBinaryStream implements Packet{
public $senderSubId = 0; public $senderSubId = 0;
/** @var int */ /** @var int */
public $recipientSubId = 0; public $recipientSubId = 0;
/** @var NetworkBinaryStream */
protected $buf;
public function __construct(){
$this->buf = new NetworkBinaryStream();
}
public function getBinaryStream() : NetworkBinaryStream{
return $this->buf;
}
public function pid() : int{ public function pid() : int{
return $this::NETWORK_ID; return $this::NETWORK_ID;
@ -60,7 +71,7 @@ abstract class DataPacket extends NetworkBinaryStream implements Packet{
* @throws BadPacketException * @throws BadPacketException
*/ */
final public function decode() : void{ final public function decode() : void{
$this->rewind(); $this->buf->rewind();
try{ try{
$this->decodeHeader(); $this->decodeHeader();
$this->decodePayload(); $this->decodePayload();
@ -74,7 +85,7 @@ abstract class DataPacket extends NetworkBinaryStream implements Packet{
* @throws \UnexpectedValueException * @throws \UnexpectedValueException
*/ */
protected function decodeHeader() : void{ protected function decodeHeader() : void{
$pid = $this->getUnsignedVarInt(); $pid = $this->buf->getUnsignedVarInt();
if($pid !== static::NETWORK_ID){ if($pid !== static::NETWORK_ID){
//TODO: this means a logical error in the code, but how to prevent it from happening? //TODO: this means a logical error in the code, but how to prevent it from happening?
throw new \UnexpectedValueException("Expected " . static::NETWORK_ID . " for packet ID, got $pid"); throw new \UnexpectedValueException("Expected " . static::NETWORK_ID . " for packet ID, got $pid");
@ -90,13 +101,13 @@ abstract class DataPacket extends NetworkBinaryStream implements Packet{
abstract protected function decodePayload() : void; abstract protected function decodePayload() : void;
final public function encode() : void{ final public function encode() : void{
$this->reset(); $this->buf->reset();
$this->encodeHeader(); $this->encodeHeader();
$this->encodePayload(); $this->encodePayload();
} }
protected function encodeHeader() : void{ protected function encodeHeader() : void{
$this->putUnsignedVarInt(static::NETWORK_ID); $this->buf->putUnsignedVarInt(static::NETWORK_ID);
} }
/** /**
@ -104,24 +115,6 @@ abstract class DataPacket extends NetworkBinaryStream implements Packet{
*/ */
abstract protected function encodePayload() : void; abstract protected function encodePayload() : void;
/**
* @return mixed[]
*/
public function __debugInfo() : array{
$data = [];
foreach((array) $this as $k => $v){
if($v === $this->getBuffer()){
$data[$k] = bin2hex($v);
}elseif(is_string($v) or (is_object($v) and method_exists($v, "__toString"))){
$data[$k] = Utils::printable((string) $v);
}else{
$data[$k] = $v;
}
}
return $data;
}
/** /**
* @param string $name * @param string $name
* *

View File

@ -53,16 +53,16 @@ class DisconnectPacket extends DataPacket implements ClientboundPacket, Serverbo
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->hideDisconnectionScreen = $this->getBool(); $this->hideDisconnectionScreen = $this->buf->getBool();
if(!$this->hideDisconnectionScreen){ if(!$this->hideDisconnectionScreen){
$this->message = $this->getString(); $this->message = $this->buf->getString();
} }
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putBool($this->hideDisconnectionScreen); $this->buf->putBool($this->hideDisconnectionScreen);
if(!$this->hideDisconnectionScreen){ if(!$this->hideDisconnectionScreen){
$this->putString($this->message); $this->buf->putString($this->message);
} }
} }

View File

@ -51,13 +51,13 @@ class EducationSettingsPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->codeBuilderDefaultUri = $this->getString(); $this->codeBuilderDefaultUri = $this->buf->getString();
$this->hasQuiz = $this->getBool(); $this->hasQuiz = $this->buf->getBool();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putString($this->codeBuilderDefaultUri); $this->buf->putString($this->codeBuilderDefaultUri);
$this->putBool($this->hasQuiz); $this->buf->putBool($this->hasQuiz);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -63,15 +63,15 @@ class EmotePacket extends DataPacket implements ClientboundPacket, ServerboundPa
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->entityRuntimeId = $this->getEntityRuntimeId(); $this->entityRuntimeId = $this->buf->getEntityRuntimeId();
$this->emoteId = $this->getString(); $this->emoteId = $this->buf->getString();
$this->flags = $this->getByte(); $this->flags = $this->buf->getByte();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityRuntimeId($this->entityRuntimeId); $this->buf->putEntityRuntimeId($this->entityRuntimeId);
$this->putString($this->emoteId); $this->buf->putString($this->emoteId);
$this->putByte($this->flags); $this->buf->putByte($this->flags);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -57,17 +57,17 @@ class EventPacket extends DataPacket implements ClientboundPacket{
public $type; public $type;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->playerRuntimeId = $this->getEntityRuntimeId(); $this->playerRuntimeId = $this->buf->getEntityRuntimeId();
$this->eventData = $this->getVarInt(); $this->eventData = $this->buf->getVarInt();
$this->type = $this->getByte(); $this->type = $this->buf->getByte();
//TODO: nice confusing mess //TODO: nice confusing mess
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityRuntimeId($this->playerRuntimeId); $this->buf->putEntityRuntimeId($this->playerRuntimeId);
$this->putVarInt($this->eventData); $this->buf->putVarInt($this->eventData);
$this->putByte($this->type); $this->buf->putByte($this->type);
//TODO: also nice confusing mess //TODO: also nice confusing mess
} }

View File

@ -37,11 +37,11 @@ class GameRulesChangedPacket extends DataPacket implements ClientboundPacket{
public $gameRules = []; public $gameRules = [];
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->gameRules = $this->getGameRules(); $this->gameRules = $this->buf->getGameRules();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putGameRules($this->gameRules); $this->buf->putGameRules($this->gameRules);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -38,15 +38,15 @@ class GuiDataPickItemPacket extends DataPacket implements ClientboundPacket{
public $hotbarSlot; public $hotbarSlot;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->itemDescription = $this->getString(); $this->itemDescription = $this->buf->getString();
$this->itemEffects = $this->getString(); $this->itemEffects = $this->buf->getString();
$this->hotbarSlot = $this->getLInt(); $this->hotbarSlot = $this->buf->getLInt();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putString($this->itemDescription); $this->buf->putString($this->itemDescription);
$this->putString($this->itemEffects); $this->buf->putString($this->itemEffects);
$this->putLInt($this->hotbarSlot); $this->buf->putLInt($this->hotbarSlot);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -34,11 +34,11 @@ class HurtArmorPacket extends DataPacket implements ClientboundPacket{
public $health; public $health;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->health = $this->getVarInt(); $this->health = $this->buf->getVarInt();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putVarInt($this->health); $this->buf->putVarInt($this->health);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -48,25 +48,25 @@ class InteractPacket extends DataPacket implements ServerboundPacket{
public $z; public $z;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->action = $this->getByte(); $this->action = $this->buf->getByte();
$this->target = $this->getEntityRuntimeId(); $this->target = $this->buf->getEntityRuntimeId();
if($this->action === self::ACTION_MOUSEOVER){ if($this->action === self::ACTION_MOUSEOVER){
//TODO: should this be a vector3? //TODO: should this be a vector3?
$this->x = $this->getLFloat(); $this->x = $this->buf->getLFloat();
$this->y = $this->getLFloat(); $this->y = $this->buf->getLFloat();
$this->z = $this->getLFloat(); $this->z = $this->buf->getLFloat();
} }
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putByte($this->action); $this->buf->putByte($this->action);
$this->putEntityRuntimeId($this->target); $this->buf->putEntityRuntimeId($this->target);
if($this->action === self::ACTION_MOUSEOVER){ if($this->action === self::ACTION_MOUSEOVER){
$this->putLFloat($this->x); $this->buf->putLFloat($this->x);
$this->putLFloat($this->y); $this->buf->putLFloat($this->y);
$this->putLFloat($this->z); $this->buf->putLFloat($this->z);
} }
} }

View File

@ -50,18 +50,18 @@ class InventoryContentPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->windowId = $this->getUnsignedVarInt(); $this->windowId = $this->buf->getUnsignedVarInt();
$count = $this->getUnsignedVarInt(); $count = $this->buf->getUnsignedVarInt();
for($i = 0; $i < $count; ++$i){ for($i = 0; $i < $count; ++$i){
$this->items[] = $this->getSlot(); $this->items[] = $this->buf->getSlot();
} }
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putUnsignedVarInt($this->windowId); $this->buf->putUnsignedVarInt($this->windowId);
$this->putUnsignedVarInt(count($this->items)); $this->buf->putUnsignedVarInt(count($this->items));
foreach($this->items as $item){ foreach($this->items as $item){
$this->putSlot($item); $this->buf->putSlot($item);
} }
} }

View File

@ -47,15 +47,15 @@ class InventorySlotPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->windowId = $this->getUnsignedVarInt(); $this->windowId = $this->buf->getUnsignedVarInt();
$this->inventorySlot = $this->getUnsignedVarInt(); $this->inventorySlot = $this->buf->getUnsignedVarInt();
$this->item = $this->getSlot(); $this->item = $this->buf->getSlot();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putUnsignedVarInt($this->windowId); $this->buf->putUnsignedVarInt($this->windowId);
$this->putUnsignedVarInt($this->inventorySlot); $this->buf->putUnsignedVarInt($this->inventorySlot);
$this->putSlot($this->item); $this->buf->putSlot($this->item);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -50,7 +50,7 @@ class InventoryTransactionPacket extends DataPacket implements ClientboundPacket
public $trData; public $trData;
protected function decodePayload() : void{ protected function decodePayload() : void{
$transactionType = $this->getUnsignedVarInt(); $transactionType = $this->buf->getUnsignedVarInt();
switch($transactionType){ switch($transactionType){
case self::TYPE_NORMAL: case self::TYPE_NORMAL:
@ -72,12 +72,12 @@ class InventoryTransactionPacket extends DataPacket implements ClientboundPacket
throw new BadPacketException("Unknown transaction type $transactionType"); throw new BadPacketException("Unknown transaction type $transactionType");
} }
$this->trData->decode($this); $this->trData->decode($this->buf);
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putUnsignedVarInt($this->trData->getTypeId()); $this->buf->putUnsignedVarInt($this->trData->getTypeId());
$this->trData->encode($this); $this->trData->encode($this->buf);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -39,11 +39,11 @@ class ItemFrameDropItemPacket extends DataPacket implements ServerboundPacket{
public $z; public $z;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->getBlockPosition($this->x, $this->y, $this->z); $this->buf->getBlockPosition($this->x, $this->y, $this->z);
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putBlockPosition($this->x, $this->y, $this->z); $this->buf->putBlockPosition($this->x, $this->y, $this->z);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -44,15 +44,15 @@ class LabTablePacket extends DataPacket implements ClientboundPacket, Serverboun
public $reactionType; public $reactionType;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->uselessByte = $this->getByte(); $this->uselessByte = $this->buf->getByte();
$this->getSignedBlockPosition($this->x, $this->y, $this->z); $this->buf->getSignedBlockPosition($this->x, $this->y, $this->z);
$this->reactionType = $this->getByte(); $this->reactionType = $this->buf->getByte();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putByte($this->uselessByte); $this->buf->putByte($this->uselessByte);
$this->putSignedBlockPosition($this->x, $this->y, $this->z); $this->buf->putSignedBlockPosition($this->x, $this->y, $this->z);
$this->putByte($this->reactionType); $this->buf->putByte($this->reactionType);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -44,17 +44,17 @@ class LecternUpdatePacket extends DataPacket implements ServerboundPacket{
public $dropBook; public $dropBook;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->page = $this->getByte(); $this->page = $this->buf->getByte();
$this->totalPages = $this->getByte(); $this->totalPages = $this->buf->getByte();
$this->getBlockPosition($this->x, $this->y, $this->z); $this->buf->getBlockPosition($this->x, $this->y, $this->z);
$this->dropBook = $this->getBool(); $this->dropBook = $this->buf->getBool();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putByte($this->page); $this->buf->putByte($this->page);
$this->putByte($this->totalPages); $this->buf->putByte($this->totalPages);
$this->putBlockPosition($this->x, $this->y, $this->z); $this->buf->putBlockPosition($this->x, $this->y, $this->z);
$this->putBool($this->dropBook); $this->buf->putBool($this->dropBook);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -101,30 +101,30 @@ class LevelChunkPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->chunkX = $this->getVarInt(); $this->chunkX = $this->buf->getVarInt();
$this->chunkZ = $this->getVarInt(); $this->chunkZ = $this->buf->getVarInt();
$this->subChunkCount = $this->getUnsignedVarInt(); $this->subChunkCount = $this->buf->getUnsignedVarInt();
$this->cacheEnabled = $this->getBool(); $this->cacheEnabled = $this->buf->getBool();
if($this->cacheEnabled){ if($this->cacheEnabled){
for($i = 0, $count = $this->getUnsignedVarInt(); $i < $count; ++$i){ for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){
$this->usedBlobHashes[] = $this->getLLong(); $this->usedBlobHashes[] = $this->buf->getLLong();
} }
} }
$this->extraPayload = $this->getString(); $this->extraPayload = $this->buf->getString();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putVarInt($this->chunkX); $this->buf->putVarInt($this->chunkX);
$this->putVarInt($this->chunkZ); $this->buf->putVarInt($this->chunkZ);
$this->putUnsignedVarInt($this->subChunkCount); $this->buf->putUnsignedVarInt($this->subChunkCount);
$this->putBool($this->cacheEnabled); $this->buf->putBool($this->cacheEnabled);
if($this->cacheEnabled){ if($this->cacheEnabled){
$this->putUnsignedVarInt(count($this->usedBlobHashes)); $this->buf->putUnsignedVarInt(count($this->usedBlobHashes));
foreach($this->usedBlobHashes as $hash){ foreach($this->usedBlobHashes as $hash){
$this->putLLong($hash); $this->buf->putLLong($hash);
} }
} }
$this->putString($this->extraPayload); $this->buf->putString($this->extraPayload);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -54,13 +54,13 @@ class LevelEventGenericPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->eventId = $this->getVarInt(); $this->eventId = $this->buf->getVarInt();
$this->eventData = $this->getRemaining(); $this->eventData = $this->buf->getRemaining();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putVarInt($this->eventId); $this->buf->putVarInt($this->eventId);
$this->put($this->eventData); $this->buf->put($this->eventData);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -134,15 +134,15 @@ class LevelEventPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->evid = $this->getVarInt(); $this->evid = $this->buf->getVarInt();
$this->position = $this->getVector3(); $this->position = $this->buf->getVector3();
$this->data = $this->getVarInt(); $this->data = $this->buf->getVarInt();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putVarInt($this->evid); $this->buf->putVarInt($this->evid);
$this->putVector3Nullable($this->position); $this->buf->putVector3Nullable($this->position);
$this->putVarInt($this->data); $this->buf->putVarInt($this->data);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -336,21 +336,21 @@ class LevelSoundEventPacket extends DataPacket implements ClientboundPacket, Ser
public $disableRelativeVolume = false; public $disableRelativeVolume = false;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->sound = $this->getUnsignedVarInt(); $this->sound = $this->buf->getUnsignedVarInt();
$this->position = $this->getVector3(); $this->position = $this->buf->getVector3();
$this->extraData = $this->getVarInt(); $this->extraData = $this->buf->getVarInt();
$this->entityType = $this->getString(); $this->entityType = $this->buf->getString();
$this->isBabyMob = $this->getBool(); $this->isBabyMob = $this->buf->getBool();
$this->disableRelativeVolume = $this->getBool(); $this->disableRelativeVolume = $this->buf->getBool();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putUnsignedVarInt($this->sound); $this->buf->putUnsignedVarInt($this->sound);
$this->putVector3($this->position); $this->buf->putVector3($this->position);
$this->putVarInt($this->extraData); $this->buf->putVarInt($this->extraData);
$this->putString($this->entityType); $this->buf->putString($this->entityType);
$this->putBool($this->isBabyMob); $this->buf->putBool($this->isBabyMob);
$this->putBool($this->disableRelativeVolume); $this->buf->putBool($this->disableRelativeVolume);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -48,21 +48,21 @@ class LevelSoundEventPacketV1 extends DataPacket{
public $disableRelativeVolume = false; public $disableRelativeVolume = false;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->sound = $this->getByte(); $this->sound = $this->buf->getByte();
$this->position = $this->getVector3(); $this->position = $this->buf->getVector3();
$this->extraData = $this->getVarInt(); $this->extraData = $this->buf->getVarInt();
$this->entityType = $this->getVarInt(); $this->entityType = $this->buf->getVarInt();
$this->isBabyMob = $this->getBool(); $this->isBabyMob = $this->buf->getBool();
$this->disableRelativeVolume = $this->getBool(); $this->disableRelativeVolume = $this->buf->getBool();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putByte($this->sound); $this->buf->putByte($this->sound);
$this->putVector3($this->position); $this->buf->putVector3($this->position);
$this->putVarInt($this->extraData); $this->buf->putVarInt($this->extraData);
$this->putVarInt($this->entityType); $this->buf->putVarInt($this->entityType);
$this->putBool($this->isBabyMob); $this->buf->putBool($this->isBabyMob);
$this->putBool($this->disableRelativeVolume); $this->buf->putBool($this->disableRelativeVolume);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -48,21 +48,21 @@ class LevelSoundEventPacketV2 extends DataPacket{
public $disableRelativeVolume = false; public $disableRelativeVolume = false;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->sound = $this->getByte(); $this->sound = $this->buf->getByte();
$this->position = $this->getVector3(); $this->position = $this->buf->getVector3();
$this->extraData = $this->getVarInt(); $this->extraData = $this->buf->getVarInt();
$this->entityType = $this->getString(); $this->entityType = $this->buf->getString();
$this->isBabyMob = $this->getBool(); $this->isBabyMob = $this->buf->getBool();
$this->disableRelativeVolume = $this->getBool(); $this->disableRelativeVolume = $this->buf->getBool();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putByte($this->sound); $this->buf->putByte($this->sound);
$this->putVector3($this->position); $this->buf->putVector3($this->position);
$this->putVarInt($this->extraData); $this->buf->putVarInt($this->extraData);
$this->putString($this->entityType); $this->buf->putString($this->entityType);
$this->putBool($this->isBabyMob); $this->buf->putBool($this->isBabyMob);
$this->putBool($this->disableRelativeVolume); $this->buf->putBool($this->disableRelativeVolume);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -109,7 +109,7 @@ class LoginPacket extends DataPacket implements ServerboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->protocol = $this->getInt(); $this->protocol = $this->buf->getInt();
$this->decodeConnectionRequest(); $this->decodeConnectionRequest();
} }
@ -134,7 +134,7 @@ class LoginPacket extends DataPacket implements ServerboundPacket{
* @throws BinaryDataException * @throws BinaryDataException
*/ */
protected function decodeConnectionRequest() : void{ protected function decodeConnectionRequest() : void{
$buffer = new BinaryStream($this->getString()); $buffer = new BinaryStream($this->buf->getString());
$chainData = json_decode($buffer->get($buffer->getLInt()), true); $chainData = json_decode($buffer->get($buffer->getLInt()), true);
if(!is_array($chainData)){ if(!is_array($chainData)){

View File

@ -36,13 +36,13 @@ class MapCreateLockedCopyPacket extends DataPacket implements ServerboundPacket{
public $newMapId; public $newMapId;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->originalMapId = $this->getEntityUniqueId(); $this->originalMapId = $this->buf->getEntityUniqueId();
$this->newMapId = $this->getEntityUniqueId(); $this->newMapId = $this->buf->getEntityUniqueId();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityUniqueId($this->originalMapId); $this->buf->putEntityUniqueId($this->originalMapId);
$this->putEntityUniqueId($this->newMapId); $this->buf->putEntityUniqueId($this->newMapId);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -34,11 +34,11 @@ class MapInfoRequestPacket extends DataPacket implements ServerboundPacket{
public $mapId; public $mapId;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->mapId = $this->getEntityUniqueId(); $this->mapId = $this->buf->getEntityUniqueId();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityUniqueId($this->mapId); $this->buf->putEntityUniqueId($this->mapId);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -56,19 +56,19 @@ class MobArmorEquipmentPacket extends DataPacket implements ClientboundPacket, S
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->entityRuntimeId = $this->getEntityRuntimeId(); $this->entityRuntimeId = $this->buf->getEntityRuntimeId();
$this->head = $this->getSlot(); $this->head = $this->buf->getSlot();
$this->chest = $this->getSlot(); $this->chest = $this->buf->getSlot();
$this->legs = $this->getSlot(); $this->legs = $this->buf->getSlot();
$this->feet = $this->getSlot(); $this->feet = $this->buf->getSlot();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityRuntimeId($this->entityRuntimeId); $this->buf->putEntityRuntimeId($this->entityRuntimeId);
$this->putSlot($this->head); $this->buf->putSlot($this->head);
$this->putSlot($this->chest); $this->buf->putSlot($this->chest);
$this->putSlot($this->legs); $this->buf->putSlot($this->legs);
$this->putSlot($this->feet); $this->buf->putSlot($this->feet);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -67,21 +67,21 @@ class MobEffectPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->entityRuntimeId = $this->getEntityRuntimeId(); $this->entityRuntimeId = $this->buf->getEntityRuntimeId();
$this->eventId = $this->getByte(); $this->eventId = $this->buf->getByte();
$this->effectId = $this->getVarInt(); $this->effectId = $this->buf->getVarInt();
$this->amplifier = $this->getVarInt(); $this->amplifier = $this->buf->getVarInt();
$this->particles = $this->getBool(); $this->particles = $this->buf->getBool();
$this->duration = $this->getVarInt(); $this->duration = $this->buf->getVarInt();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityRuntimeId($this->entityRuntimeId); $this->buf->putEntityRuntimeId($this->entityRuntimeId);
$this->putByte($this->eventId); $this->buf->putByte($this->eventId);
$this->putVarInt($this->effectId); $this->buf->putVarInt($this->effectId);
$this->putVarInt($this->amplifier); $this->buf->putVarInt($this->amplifier);
$this->putBool($this->particles); $this->buf->putBool($this->particles);
$this->putVarInt($this->duration); $this->buf->putVarInt($this->duration);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -53,19 +53,19 @@ class MobEquipmentPacket extends DataPacket implements ClientboundPacket, Server
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->entityRuntimeId = $this->getEntityRuntimeId(); $this->entityRuntimeId = $this->buf->getEntityRuntimeId();
$this->item = $this->getSlot(); $this->item = $this->buf->getSlot();
$this->inventorySlot = $this->getByte(); $this->inventorySlot = $this->buf->getByte();
$this->hotbarSlot = $this->getByte(); $this->hotbarSlot = $this->buf->getByte();
$this->windowId = $this->getByte(); $this->windowId = $this->buf->getByte();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityRuntimeId($this->entityRuntimeId); $this->buf->putEntityRuntimeId($this->entityRuntimeId);
$this->putSlot($this->item); $this->buf->putSlot($this->item);
$this->putByte($this->inventorySlot); $this->buf->putByte($this->inventorySlot);
$this->putByte($this->hotbarSlot); $this->buf->putByte($this->hotbarSlot);
$this->putByte($this->windowId); $this->buf->putByte($this->windowId);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -43,13 +43,13 @@ class ModalFormRequestPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->formId = $this->getUnsignedVarInt(); $this->formId = $this->buf->getUnsignedVarInt();
$this->formData = $this->getString(); $this->formData = $this->buf->getString();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putUnsignedVarInt($this->formId); $this->buf->putUnsignedVarInt($this->formId);
$this->putString($this->formData); $this->buf->putString($this->formData);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -36,13 +36,13 @@ class ModalFormResponsePacket extends DataPacket implements ServerboundPacket{
public $formData; //json public $formData; //json
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->formId = $this->getUnsignedVarInt(); $this->formId = $this->buf->getUnsignedVarInt();
$this->formData = $this->getString(); $this->formData = $this->buf->getString();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putUnsignedVarInt($this->formId); $this->buf->putUnsignedVarInt($this->formId);
$this->putString($this->formData); $this->buf->putString($this->formData);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -48,21 +48,21 @@ class MoveActorAbsolutePacket extends DataPacket implements ClientboundPacket, S
public $zRot; public $zRot;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->entityRuntimeId = $this->getEntityRuntimeId(); $this->entityRuntimeId = $this->buf->getEntityRuntimeId();
$this->flags = $this->getByte(); $this->flags = $this->buf->getByte();
$this->position = $this->getVector3(); $this->position = $this->buf->getVector3();
$this->xRot = $this->getByteRotation(); $this->xRot = $this->buf->getByteRotation();
$this->yRot = $this->getByteRotation(); $this->yRot = $this->buf->getByteRotation();
$this->zRot = $this->getByteRotation(); $this->zRot = $this->buf->getByteRotation();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityRuntimeId($this->entityRuntimeId); $this->buf->putEntityRuntimeId($this->entityRuntimeId);
$this->putByte($this->flags); $this->buf->putByte($this->flags);
$this->putVector3($this->position); $this->buf->putVector3($this->position);
$this->putByteRotation($this->xRot); $this->buf->putByteRotation($this->xRot);
$this->putByteRotation($this->yRot); $this->buf->putByteRotation($this->yRot);
$this->putByteRotation($this->zRot); $this->buf->putByteRotation($this->zRot);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -60,7 +60,7 @@ class MoveActorDeltaPacket extends DataPacket implements ClientboundPacket{
*/ */
private function maybeReadCoord(int $flag) : int{ private function maybeReadCoord(int $flag) : int{
if(($this->flags & $flag) !== 0){ if(($this->flags & $flag) !== 0){
return $this->getVarInt(); return $this->buf->getVarInt();
} }
return 0; return 0;
} }
@ -70,14 +70,14 @@ class MoveActorDeltaPacket extends DataPacket implements ClientboundPacket{
*/ */
private function maybeReadRotation(int $flag) : float{ private function maybeReadRotation(int $flag) : float{
if(($this->flags & $flag) !== 0){ if(($this->flags & $flag) !== 0){
return $this->getByteRotation(); return $this->buf->getByteRotation();
} }
return 0.0; return 0.0;
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->entityRuntimeId = $this->getEntityRuntimeId(); $this->entityRuntimeId = $this->buf->getEntityRuntimeId();
$this->flags = $this->getLShort(); $this->flags = $this->buf->getLShort();
$this->xDiff = $this->maybeReadCoord(self::FLAG_HAS_X); $this->xDiff = $this->maybeReadCoord(self::FLAG_HAS_X);
$this->yDiff = $this->maybeReadCoord(self::FLAG_HAS_Y); $this->yDiff = $this->maybeReadCoord(self::FLAG_HAS_Y);
$this->zDiff = $this->maybeReadCoord(self::FLAG_HAS_Z); $this->zDiff = $this->maybeReadCoord(self::FLAG_HAS_Z);
@ -88,19 +88,19 @@ class MoveActorDeltaPacket extends DataPacket implements ClientboundPacket{
private function maybeWriteCoord(int $flag, int $val) : void{ private function maybeWriteCoord(int $flag, int $val) : void{
if(($this->flags & $flag) !== 0){ if(($this->flags & $flag) !== 0){
$this->putVarInt($val); $this->buf->putVarInt($val);
} }
} }
private function maybeWriteRotation(int $flag, float $val) : void{ private function maybeWriteRotation(int $flag, float $val) : void{
if(($this->flags & $flag) !== 0){ if(($this->flags & $flag) !== 0){
$this->putByteRotation($val); $this->buf->putByteRotation($val);
} }
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityRuntimeId($this->entityRuntimeId); $this->buf->putEntityRuntimeId($this->entityRuntimeId);
$this->putLShort($this->flags); $this->buf->putLShort($this->flags);
$this->maybeWriteCoord(self::FLAG_HAS_X, $this->xDiff); $this->maybeWriteCoord(self::FLAG_HAS_X, $this->xDiff);
$this->maybeWriteCoord(self::FLAG_HAS_Y, $this->yDiff); $this->maybeWriteCoord(self::FLAG_HAS_Y, $this->yDiff);
$this->maybeWriteCoord(self::FLAG_HAS_Z, $this->zDiff); $this->maybeWriteCoord(self::FLAG_HAS_Z, $this->zDiff);

View File

@ -58,32 +58,32 @@ class MovePlayerPacket extends DataPacket implements ClientboundPacket, Serverbo
public $teleportItem = 0; public $teleportItem = 0;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->entityRuntimeId = $this->getEntityRuntimeId(); $this->entityRuntimeId = $this->buf->getEntityRuntimeId();
$this->position = $this->getVector3(); $this->position = $this->buf->getVector3();
$this->pitch = $this->getLFloat(); $this->pitch = $this->buf->getLFloat();
$this->yaw = $this->getLFloat(); $this->yaw = $this->buf->getLFloat();
$this->headYaw = $this->getLFloat(); $this->headYaw = $this->buf->getLFloat();
$this->mode = $this->getByte(); $this->mode = $this->buf->getByte();
$this->onGround = $this->getBool(); $this->onGround = $this->buf->getBool();
$this->ridingEid = $this->getEntityRuntimeId(); $this->ridingEid = $this->buf->getEntityRuntimeId();
if($this->mode === MovePlayerPacket::MODE_TELEPORT){ if($this->mode === MovePlayerPacket::MODE_TELEPORT){
$this->teleportCause = $this->getLInt(); $this->teleportCause = $this->buf->getLInt();
$this->teleportItem = $this->getLInt(); $this->teleportItem = $this->buf->getLInt();
} }
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityRuntimeId($this->entityRuntimeId); $this->buf->putEntityRuntimeId($this->entityRuntimeId);
$this->putVector3($this->position); $this->buf->putVector3($this->position);
$this->putLFloat($this->pitch); $this->buf->putLFloat($this->pitch);
$this->putLFloat($this->yaw); $this->buf->putLFloat($this->yaw);
$this->putLFloat($this->headYaw); //TODO $this->buf->putLFloat($this->headYaw); //TODO
$this->putByte($this->mode); $this->buf->putByte($this->mode);
$this->putBool($this->onGround); $this->buf->putBool($this->onGround);
$this->putEntityRuntimeId($this->ridingEid); $this->buf->putEntityRuntimeId($this->ridingEid);
if($this->mode === MovePlayerPacket::MODE_TELEPORT){ if($this->mode === MovePlayerPacket::MODE_TELEPORT){
$this->putLInt($this->teleportCause); $this->buf->putLInt($this->teleportCause);
$this->putLInt($this->teleportItem); $this->buf->putLInt($this->teleportItem);
} }
} }

View File

@ -48,11 +48,11 @@ class MultiplayerSettingsPacket extends DataPacket implements ServerboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->action = $this->getVarInt(); $this->action = $this->buf->getVarInt();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putVarInt($this->action); $this->buf->putVarInt($this->action);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -49,13 +49,13 @@ class NetworkChunkPublisherUpdatePacket extends DataPacket implements Clientboun
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->getSignedBlockPosition($this->x, $this->y, $this->z); $this->buf->getSignedBlockPosition($this->x, $this->y, $this->z);
$this->radius = $this->getUnsignedVarInt(); $this->radius = $this->buf->getUnsignedVarInt();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putSignedBlockPosition($this->x, $this->y, $this->z); $this->buf->putSignedBlockPosition($this->x, $this->y, $this->z);
$this->putUnsignedVarInt($this->radius); $this->buf->putUnsignedVarInt($this->radius);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -47,11 +47,11 @@ class NetworkSettingsPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->compressionThreshold = $this->getLShort(); $this->compressionThreshold = $this->buf->getLShort();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putLShort($this->compressionThreshold); $this->buf->putLShort($this->compressionThreshold);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -36,13 +36,13 @@ class NetworkStackLatencyPacket extends DataPacket implements ClientboundPacket,
public $needResponse; public $needResponse;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->timestamp = $this->getLLong(); $this->timestamp = $this->buf->getLLong();
$this->needResponse = $this->getBool(); $this->needResponse = $this->buf->getBool();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putLLong($this->timestamp); $this->buf->putLLong($this->timestamp);
$this->putBool($this->needResponse); $this->buf->putBool($this->needResponse);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -40,17 +40,17 @@ class NpcRequestPacket extends DataPacket implements ServerboundPacket{
public $actionType; public $actionType;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->entityRuntimeId = $this->getEntityRuntimeId(); $this->entityRuntimeId = $this->buf->getEntityRuntimeId();
$this->requestType = $this->getByte(); $this->requestType = $this->buf->getByte();
$this->commandString = $this->getString(); $this->commandString = $this->buf->getString();
$this->actionType = $this->getByte(); $this->actionType = $this->buf->getByte();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityRuntimeId($this->entityRuntimeId); $this->buf->putEntityRuntimeId($this->entityRuntimeId);
$this->putByte($this->requestType); $this->buf->putByte($this->requestType);
$this->putString($this->commandString); $this->buf->putString($this->commandString);
$this->putByte($this->actionType); $this->buf->putByte($this->actionType);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -34,11 +34,11 @@ class OnScreenTextureAnimationPacket extends DataPacket implements ClientboundPa
public $effectId; public $effectId;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->effectId = $this->getLInt(); //unsigned $this->effectId = $this->buf->getLInt(); //unsigned
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putLInt($this->effectId); $this->buf->putLInt($this->effectId);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -25,27 +25,11 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\network\BadPacketException; use pocketmine\network\BadPacketException;
use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\handler\PacketHandler;
use pocketmine\network\mcpe\serializer\NetworkBinaryStream;
interface Packet{ interface Packet{
public function setOffset(int $offset) : void; public function getBinaryStream() : NetworkBinaryStream;
/**
* TODO: this can't have a native return type yet because of incompatibility with BinaryUtils
* really this should be addressed by making packets not extend BinaryStream, but that's a task for another day.
*
* @return void
*/
public function setBuffer(string $buffer = "", int $offset = 0);
public function getOffset() : int;
public function getBuffer() : string;
/**
* Returns whether the offset has reached the end of the buffer.
*/
public function feof() : bool;
public function pid() : int; public function pid() : int;

View File

@ -191,7 +191,7 @@ class PacketPool{
public static function getPacket(string $buffer) : Packet{ public static function getPacket(string $buffer) : Packet{
$offset = 0; $offset = 0;
$pk = static::getPacketById(Binary::readUnsignedVarInt($buffer, $offset)); $pk = static::getPacketById(Binary::readUnsignedVarInt($buffer, $offset));
$pk->setBuffer($buffer, $offset); $pk->getBinaryStream()->setBuffer($buffer, $offset);
return $pk; return $pk;
} }

View File

@ -38,15 +38,15 @@ class PhotoTransferPacket extends DataPacket implements ClientboundPacket{
public $bookId; //photos are stored in a sibling directory to the games folder (screenshots/(some UUID)/bookID/example.png) public $bookId; //photos are stored in a sibling directory to the games folder (screenshots/(some UUID)/bookID/example.png)
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->photoName = $this->getString(); $this->photoName = $this->buf->getString();
$this->photoData = $this->getString(); $this->photoData = $this->buf->getString();
$this->bookId = $this->getString(); $this->bookId = $this->buf->getString();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putString($this->photoName); $this->buf->putString($this->photoName);
$this->putString($this->photoData); $this->buf->putString($this->photoData);
$this->putString($this->bookId); $this->buf->putString($this->bookId);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -44,20 +44,20 @@ class PlaySoundPacket extends DataPacket implements ClientboundPacket{
public $pitch; public $pitch;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->soundName = $this->getString(); $this->soundName = $this->buf->getString();
$this->getBlockPosition($this->x, $this->y, $this->z); $this->buf->getBlockPosition($this->x, $this->y, $this->z);
$this->x /= 8; $this->x /= 8;
$this->y /= 8; $this->y /= 8;
$this->z /= 8; $this->z /= 8;
$this->volume = $this->getLFloat(); $this->volume = $this->buf->getLFloat();
$this->pitch = $this->getLFloat(); $this->pitch = $this->buf->getLFloat();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putString($this->soundName); $this->buf->putString($this->soundName);
$this->putBlockPosition((int) ($this->x * 8), (int) ($this->y * 8), (int) ($this->z * 8)); $this->buf->putBlockPosition((int) ($this->x * 8), (int) ($this->y * 8), (int) ($this->z * 8));
$this->putLFloat($this->volume); $this->buf->putLFloat($this->volume);
$this->putLFloat($this->pitch); $this->buf->putLFloat($this->pitch);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -49,7 +49,7 @@ class PlayStatusPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->status = $this->getInt(); $this->status = $this->buf->getInt();
} }
public function canBeSentBeforeLogin() : bool{ public function canBeSentBeforeLogin() : bool{
@ -57,7 +57,7 @@ class PlayStatusPacket extends DataPacket implements ClientboundPacket{
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putInt($this->status); $this->buf->putInt($this->status);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -71,17 +71,17 @@ class PlayerActionPacket extends DataPacket implements ServerboundPacket{
public $face; public $face;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->entityRuntimeId = $this->getEntityRuntimeId(); $this->entityRuntimeId = $this->buf->getEntityRuntimeId();
$this->action = $this->getVarInt(); $this->action = $this->buf->getVarInt();
$this->getBlockPosition($this->x, $this->y, $this->z); $this->buf->getBlockPosition($this->x, $this->y, $this->z);
$this->face = $this->getVarInt(); $this->face = $this->buf->getVarInt();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityRuntimeId($this->entityRuntimeId); $this->buf->putEntityRuntimeId($this->entityRuntimeId);
$this->putVarInt($this->action); $this->buf->putVarInt($this->action);
$this->putBlockPosition($this->x, $this->y, $this->z); $this->buf->putBlockPosition($this->x, $this->y, $this->z);
$this->putVarInt($this->face); $this->buf->putVarInt($this->face);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -128,33 +128,33 @@ class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->yaw = $this->getLFloat(); $this->yaw = $this->buf->getLFloat();
$this->pitch = $this->getLFloat(); $this->pitch = $this->buf->getLFloat();
$this->position = $this->getVector3(); $this->position = $this->buf->getVector3();
$this->moveVecX = $this->getLFloat(); $this->moveVecX = $this->buf->getLFloat();
$this->moveVecZ = $this->getLFloat(); $this->moveVecZ = $this->buf->getLFloat();
$this->headYaw = $this->getLFloat(); $this->headYaw = $this->buf->getLFloat();
$this->inputFlags = $this->getUnsignedVarLong(); $this->inputFlags = $this->buf->getUnsignedVarLong();
$this->inputMode = $this->getUnsignedVarInt(); $this->inputMode = $this->buf->getUnsignedVarInt();
$this->playMode = $this->getUnsignedVarInt(); $this->playMode = $this->buf->getUnsignedVarInt();
if($this->playMode === PlayMode::VR){ if($this->playMode === PlayMode::VR){
$this->vrGazeDirection = $this->getVector3(); $this->vrGazeDirection = $this->buf->getVector3();
} }
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putLFloat($this->yaw); $this->buf->putLFloat($this->yaw);
$this->putLFloat($this->pitch); $this->buf->putLFloat($this->pitch);
$this->putVector3($this->position); $this->buf->putVector3($this->position);
$this->putLFloat($this->moveVecX); $this->buf->putLFloat($this->moveVecX);
$this->putLFloat($this->moveVecZ); $this->buf->putLFloat($this->moveVecZ);
$this->putLFloat($this->headYaw); $this->buf->putLFloat($this->headYaw);
$this->putUnsignedVarLong($this->inputFlags); $this->buf->putUnsignedVarLong($this->inputFlags);
$this->putUnsignedVarInt($this->inputMode); $this->buf->putUnsignedVarInt($this->inputMode);
$this->putUnsignedVarInt($this->playMode); $this->buf->putUnsignedVarInt($this->playMode);
if($this->playMode === PlayMode::VR){ if($this->playMode === PlayMode::VR){
assert($this->vrGazeDirection !== null); assert($this->vrGazeDirection !== null);
$this->putVector3($this->vrGazeDirection); $this->buf->putVector3($this->vrGazeDirection);
} }
} }

View File

@ -47,15 +47,15 @@ class PlayerHotbarPacket extends DataPacket implements ClientboundPacket, Server
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->selectedHotbarSlot = $this->getUnsignedVarInt(); $this->selectedHotbarSlot = $this->buf->getUnsignedVarInt();
$this->windowId = $this->getByte(); $this->windowId = $this->buf->getByte();
$this->selectHotbarSlot = $this->getBool(); $this->selectHotbarSlot = $this->buf->getBool();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putUnsignedVarInt($this->selectedHotbarSlot); $this->buf->putUnsignedVarInt($this->selectedHotbarSlot);
$this->putByte($this->windowId); $this->buf->putByte($this->windowId);
$this->putBool($this->selectHotbarSlot); $this->buf->putBool($this->selectHotbarSlot);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -40,17 +40,17 @@ class PlayerInputPacket extends DataPacket implements ServerboundPacket{
public $sneaking; public $sneaking;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->motionX = $this->getLFloat(); $this->motionX = $this->buf->getLFloat();
$this->motionY = $this->getLFloat(); $this->motionY = $this->buf->getLFloat();
$this->jumping = $this->getBool(); $this->jumping = $this->buf->getBool();
$this->sneaking = $this->getBool(); $this->sneaking = $this->buf->getBool();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putLFloat($this->motionX); $this->buf->putLFloat($this->motionX);
$this->putLFloat($this->motionY); $this->buf->putLFloat($this->motionY);
$this->putBool($this->jumping); $this->buf->putBool($this->jumping);
$this->putBool($this->sneaking); $this->buf->putBool($this->sneaking);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -61,23 +61,23 @@ class PlayerListPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->type = $this->getByte(); $this->type = $this->buf->getByte();
$count = $this->getUnsignedVarInt(); $count = $this->buf->getUnsignedVarInt();
for($i = 0; $i < $count; ++$i){ for($i = 0; $i < $count; ++$i){
$entry = new PlayerListEntry(); $entry = new PlayerListEntry();
if($this->type === self::TYPE_ADD){ if($this->type === self::TYPE_ADD){
$entry->uuid = $this->getUUID(); $entry->uuid = $this->buf->getUUID();
$entry->entityUniqueId = $this->getEntityUniqueId(); $entry->entityUniqueId = $this->buf->getEntityUniqueId();
$entry->username = $this->getString(); $entry->username = $this->buf->getString();
$entry->xboxUserId = $this->getString(); $entry->xboxUserId = $this->buf->getString();
$entry->platformChatId = $this->getString(); $entry->platformChatId = $this->buf->getString();
$entry->buildPlatform = $this->getLInt(); $entry->buildPlatform = $this->buf->getLInt();
$entry->skinData = $this->getSkin(); $entry->skinData = $this->buf->getSkin();
$entry->isTeacher = $this->getBool(); $entry->isTeacher = $this->buf->getBool();
$entry->isHost = $this->getBool(); $entry->isHost = $this->buf->getBool();
}else{ }else{
$entry->uuid = $this->getUUID(); $entry->uuid = $this->buf->getUUID();
} }
$this->entries[$i] = $entry; $this->entries[$i] = $entry;
@ -85,21 +85,21 @@ class PlayerListPacket extends DataPacket implements ClientboundPacket{
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putByte($this->type); $this->buf->putByte($this->type);
$this->putUnsignedVarInt(count($this->entries)); $this->buf->putUnsignedVarInt(count($this->entries));
foreach($this->entries as $entry){ foreach($this->entries as $entry){
if($this->type === self::TYPE_ADD){ if($this->type === self::TYPE_ADD){
$this->putUUID($entry->uuid); $this->buf->putUUID($entry->uuid);
$this->putEntityUniqueId($entry->entityUniqueId); $this->buf->putEntityUniqueId($entry->entityUniqueId);
$this->putString($entry->username); $this->buf->putString($entry->username);
$this->putString($entry->xboxUserId); $this->buf->putString($entry->xboxUserId);
$this->putString($entry->platformChatId); $this->buf->putString($entry->platformChatId);
$this->putLInt($entry->buildPlatform); $this->buf->putLInt($entry->buildPlatform);
$this->putSkin($entry->skinData); $this->buf->putSkin($entry->skinData);
$this->putBool($entry->isTeacher); $this->buf->putBool($entry->isTeacher);
$this->putBool($entry->isHost); $this->buf->putBool($entry->isHost);
}else{ }else{
$this->putUUID($entry->uuid); $this->buf->putUUID($entry->uuid);
} }
} }
} }

View File

@ -42,17 +42,17 @@ class PlayerSkinPacket extends DataPacket implements ClientboundPacket, Serverbo
public $skin; public $skin;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->uuid = $this->getUUID(); $this->uuid = $this->buf->getUUID();
$this->skin = $this->getSkin(); $this->skin = $this->buf->getSkin();
$this->newSkinName = $this->getString(); $this->newSkinName = $this->buf->getString();
$this->oldSkinName = $this->getString(); $this->oldSkinName = $this->buf->getString();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putUUID($this->uuid); $this->buf->putUUID($this->uuid);
$this->putSkin($this->skin); $this->buf->putSkin($this->skin);
$this->putString($this->newSkinName); $this->buf->putString($this->newSkinName);
$this->putString($this->oldSkinName); $this->buf->putString($this->oldSkinName);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -35,16 +35,16 @@ class PurchaseReceiptPacket extends DataPacket implements ServerboundPacket{
public $entries = []; public $entries = [];
protected function decodePayload() : void{ protected function decodePayload() : void{
$count = $this->getUnsignedVarInt(); $count = $this->buf->getUnsignedVarInt();
for($i = 0; $i < $count; ++$i){ for($i = 0; $i < $count; ++$i){
$this->entries[] = $this->getString(); $this->entries[] = $this->buf->getString();
} }
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putUnsignedVarInt(count($this->entries)); $this->buf->putUnsignedVarInt(count($this->entries));
foreach($this->entries as $entry){ foreach($this->entries as $entry){
$this->putString($entry); $this->buf->putString($entry);
} }
} }

View File

@ -40,11 +40,11 @@ class RemoveActorPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->entityUniqueId = $this->getEntityUniqueId(); $this->entityUniqueId = $this->buf->getEntityUniqueId();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putEntityUniqueId($this->entityUniqueId); $this->buf->putEntityUniqueId($this->entityUniqueId);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -44,11 +44,11 @@ class RemoveEntityPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->uvarint1 = $this->getUnsignedVarInt(); $this->uvarint1 = $this->buf->getUnsignedVarInt();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putUnsignedVarInt($this->uvarint1); $this->buf->putUnsignedVarInt($this->uvarint1);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -34,11 +34,11 @@ class RemoveObjectivePacket extends DataPacket implements ClientboundPacket{
public $objectiveName; public $objectiveName;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->objectiveName = $this->getString(); $this->objectiveName = $this->buf->getString();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putString($this->objectiveName); $this->buf->putString($this->objectiveName);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -34,11 +34,11 @@ class RequestChunkRadiusPacket extends DataPacket implements ServerboundPacket{
public $radius; public $radius;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->radius = $this->getVarInt(); $this->radius = $this->buf->getVarInt();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putVarInt($this->radius); $this->buf->putVarInt($this->radius);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -50,17 +50,17 @@ class ResourcePackChunkDataPacket extends DataPacket implements ClientboundPacke
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->packId = $this->getString(); $this->packId = $this->buf->getString();
$this->chunkIndex = $this->getLInt(); $this->chunkIndex = $this->buf->getLInt();
$this->progress = $this->getLLong(); $this->progress = $this->buf->getLLong();
$this->data = $this->getString(); $this->data = $this->buf->getString();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putString($this->packId); $this->buf->putString($this->packId);
$this->putLInt($this->chunkIndex); $this->buf->putLInt($this->chunkIndex);
$this->putLLong($this->progress); $this->buf->putLLong($this->progress);
$this->putString($this->data); $this->buf->putString($this->data);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -36,13 +36,13 @@ class ResourcePackChunkRequestPacket extends DataPacket implements ServerboundPa
public $chunkIndex; public $chunkIndex;
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->packId = $this->getString(); $this->packId = $this->buf->getString();
$this->chunkIndex = $this->getLInt(); $this->chunkIndex = $this->buf->getLInt();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putString($this->packId); $this->buf->putString($this->packId);
$this->putLInt($this->chunkIndex); $this->buf->putLInt($this->chunkIndex);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -42,18 +42,18 @@ class ResourcePackClientResponsePacket extends DataPacket implements Serverbound
public $packIds = []; public $packIds = [];
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->status = $this->getByte(); $this->status = $this->buf->getByte();
$entryCount = $this->getLShort(); $entryCount = $this->buf->getLShort();
while($entryCount-- > 0){ while($entryCount-- > 0){
$this->packIds[] = $this->getString(); $this->packIds[] = $this->buf->getString();
} }
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putByte($this->status); $this->buf->putByte($this->status);
$this->putLShort(count($this->packIds)); $this->buf->putLShort(count($this->packIds));
foreach($this->packIds as $id){ foreach($this->packIds as $id){
$this->putString($id); $this->buf->putString($id);
} }
} }

View File

@ -57,23 +57,23 @@ class ResourcePackDataInfoPacket extends DataPacket implements ClientboundPacket
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->packId = $this->getString(); $this->packId = $this->buf->getString();
$this->maxChunkSize = $this->getLInt(); $this->maxChunkSize = $this->buf->getLInt();
$this->chunkCount = $this->getLInt(); $this->chunkCount = $this->buf->getLInt();
$this->compressedPackSize = $this->getLLong(); $this->compressedPackSize = $this->buf->getLLong();
$this->sha256 = $this->getString(); $this->sha256 = $this->buf->getString();
$this->isPremium = $this->getBool(); $this->isPremium = $this->buf->getBool();
$this->packType = $this->getByte(); $this->packType = $this->buf->getByte();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putString($this->packId); $this->buf->putString($this->packId);
$this->putLInt($this->maxChunkSize); $this->buf->putLInt($this->maxChunkSize);
$this->putLInt($this->chunkCount); $this->buf->putLInt($this->chunkCount);
$this->putLLong($this->compressedPackSize); $this->buf->putLLong($this->compressedPackSize);
$this->putString($this->sha256); $this->buf->putString($this->sha256);
$this->putBool($this->isPremium); $this->buf->putBool($this->isPremium);
$this->putByte($this->packType); $this->buf->putByte($this->packType);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -61,36 +61,36 @@ class ResourcePackStackPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->mustAccept = $this->getBool(); $this->mustAccept = $this->buf->getBool();
$behaviorPackCount = $this->getUnsignedVarInt(); $behaviorPackCount = $this->buf->getUnsignedVarInt();
while($behaviorPackCount-- > 0){ while($behaviorPackCount-- > 0){
$this->behaviorPackStack[] = ResourcePackStackEntry::read($this); $this->behaviorPackStack[] = ResourcePackStackEntry::read($this->buf);
} }
$resourcePackCount = $this->getUnsignedVarInt(); $resourcePackCount = $this->buf->getUnsignedVarInt();
while($resourcePackCount-- > 0){ while($resourcePackCount-- > 0){
$this->resourcePackStack[] = ResourcePackStackEntry::read($this); $this->resourcePackStack[] = ResourcePackStackEntry::read($this->buf);
} }
$this->isExperimental = $this->getBool(); $this->isExperimental = $this->buf->getBool();
$this->baseGameVersion = $this->getString(); $this->baseGameVersion = $this->buf->getString();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putBool($this->mustAccept); $this->buf->putBool($this->mustAccept);
$this->putUnsignedVarInt(count($this->behaviorPackStack)); $this->buf->putUnsignedVarInt(count($this->behaviorPackStack));
foreach($this->behaviorPackStack as $entry){ foreach($this->behaviorPackStack as $entry){
$entry->write($this); $entry->write($this->buf);
} }
$this->putUnsignedVarInt(count($this->resourcePackStack)); $this->buf->putUnsignedVarInt(count($this->resourcePackStack));
foreach($this->resourcePackStack as $entry){ foreach($this->resourcePackStack as $entry){
$entry->write($this); $entry->write($this->buf);
} }
$this->putBool($this->isExperimental); $this->buf->putBool($this->isExperimental);
$this->putString($this->baseGameVersion); $this->buf->putString($this->baseGameVersion);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

View File

@ -57,29 +57,29 @@ class ResourcePacksInfoPacket extends DataPacket implements ClientboundPacket{
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->mustAccept = $this->getBool(); $this->mustAccept = $this->buf->getBool();
$this->hasScripts = $this->getBool(); $this->hasScripts = $this->buf->getBool();
$behaviorPackCount = $this->getLShort(); $behaviorPackCount = $this->buf->getLShort();
while($behaviorPackCount-- > 0){ while($behaviorPackCount-- > 0){
$this->behaviorPackEntries[] = ResourcePackInfoEntry::read($this); $this->behaviorPackEntries[] = ResourcePackInfoEntry::read($this->buf);
} }
$resourcePackCount = $this->getLShort(); $resourcePackCount = $this->buf->getLShort();
while($resourcePackCount-- > 0){ while($resourcePackCount-- > 0){
$this->resourcePackEntries[] = ResourcePackInfoEntry::read($this); $this->resourcePackEntries[] = ResourcePackInfoEntry::read($this->buf);
} }
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putBool($this->mustAccept); $this->buf->putBool($this->mustAccept);
$this->putBool($this->hasScripts); $this->buf->putBool($this->hasScripts);
$this->putLShort(count($this->behaviorPackEntries)); $this->buf->putLShort(count($this->behaviorPackEntries));
foreach($this->behaviorPackEntries as $entry){ foreach($this->behaviorPackEntries as $entry){
$entry->write($this); $entry->write($this->buf);
} }
$this->putLShort(count($this->resourcePackEntries)); $this->buf->putLShort(count($this->resourcePackEntries));
foreach($this->resourcePackEntries as $entry){ foreach($this->resourcePackEntries as $entry){
$entry->write($this); $entry->write($this->buf);
} }
} }

View File

@ -51,15 +51,15 @@ class RespawnPacket extends DataPacket implements ClientboundPacket, Serverbound
} }
protected function decodePayload() : void{ protected function decodePayload() : void{
$this->position = $this->getVector3(); $this->position = $this->buf->getVector3();
$this->respawnState = $this->getByte(); $this->respawnState = $this->buf->getByte();
$this->entityRuntimeId = $this->getEntityRuntimeId(); $this->entityRuntimeId = $this->buf->getEntityRuntimeId();
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
$this->putVector3($this->position); $this->buf->putVector3($this->position);
$this->putByte($this->respawnState); $this->buf->putByte($this->respawnState);
$this->putEntityRuntimeId($this->entityRuntimeId); $this->buf->putEntityRuntimeId($this->entityRuntimeId);
} }
public function handle(PacketHandler $handler) : bool{ public function handle(PacketHandler $handler) : bool{

Some files were not shown because too many files have changed in this diff Show More