This commit is contained in:
Dylan K. Taylor 2017-08-02 20:09:43 +01:00
parent 77cd8e7799
commit 63d2b341b9
9 changed files with 168 additions and 15 deletions

View File

@ -444,7 +444,7 @@ abstract class BaseInventory implements Inventory{
}
$pk = new InventorySlotPacket();
$pk->slotIndex = $index;
$pk->inventorySlot = $index;
$pk->item = clone $this->getItem($index);
foreach($target as $player){

View File

@ -475,7 +475,7 @@ class PlayerInventory extends BaseInventory{
$pk2 = new InventorySlotPacket();
$pk2->windowId = ContainerIds::ARMOR;
$pk2->slotIndex = $index - $this->getSize();
$pk2->inventorySlot = $index - $this->getSize();
$pk2->item = $this->getItem($index);
$player->dataPacket($pk2);
}else{
@ -538,7 +538,7 @@ class PlayerInventory extends BaseInventory{
}
$pk = new InventorySlotPacket();
$pk->slotIndex = $index;
$pk->inventorySlot = $index;
$pk->item = clone $this->getItem($index);
foreach($target as $player){

View File

@ -48,6 +48,8 @@ use pocketmine\network\mcpe\protocol\LoginPacket;
use pocketmine\network\mcpe\protocol\MapInfoRequestPacket;
use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket;
use pocketmine\network\mcpe\protocol\MobEquipmentPacket;
use pocketmine\network\mcpe\protocol\ModalFormRequestPacket;
use pocketmine\network\mcpe\protocol\ModalFormResponsePacket;
use pocketmine\network\mcpe\protocol\MovePlayerPacket;
use pocketmine\network\mcpe\protocol\PlayerActionPacket;
use pocketmine\network\mcpe\protocol\PlayerInputPacket;
@ -56,6 +58,8 @@ use pocketmine\network\mcpe\protocol\RemoveBlockPacket;
use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket;
use pocketmine\network\mcpe\protocol\ResourcePackChunkRequestPacket;
use pocketmine\network\mcpe\protocol\ResourcePackClientResponsePacket;
use pocketmine\network\mcpe\protocol\ServerSettingsRequestPacket;
use pocketmine\network\mcpe\protocol\ServerSettingsResponsePacket;
use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket;
use pocketmine\network\mcpe\protocol\ShowCreditsPacket;
use pocketmine\network\mcpe\protocol\SpawnExperienceOrbPacket;
@ -257,4 +261,12 @@ class PlayerNetworkSessionAdapter extends NetworkSession{
public function handlePlayerSkin(PlayerSkinPacket $packet) : bool{
return false; //TODO
}
public function handleModalFormResponse(ModalFormResponsePacket $packet) : bool{
return false; //TODO: GUI stuff
}
public function handleServerSettingsRequest(ServerSettingsRequestPacket $packet) : bool{
return false; //TODO: GUI stuff
}
}

View File

@ -28,6 +28,7 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\entity\Attribute;
use pocketmine\entity\Entity;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\utils\Binary;
use pocketmine\utils\BinaryStream;
@ -379,6 +380,50 @@ abstract class DataPacket extends BinaryStream{
$this->putLFloat($z);
}
/**
* Reads a floating-point Vector3 object
* TODO: get rid of primitive methods and replace with this
*
* @return Vector3
*/
public function getVector3Obj() : Vector3{
return new Vector3(
$this->getRoundedLFloat(4),
$this->getRoundedLFloat(4),
$this->getRoundedLFloat(4)
);
}
/**
* Writes a floating-point Vector3 object, or 3x zero if null is given.
*
* Note: ONLY use this where it is reasonable to allow not specifying the vector.
* For all other purposes, use {@link DataPacket#putVector3Obj}
*
* @param Vector3|null $vector
*/
public function putVector3ObjNullable(Vector3 $vector = null){
if($vector){
$this->putVector3Obj($vector);
}else{
$this->putLFloat(0.0);
$this->putLFloat(0.0);
$this->putLFloat(0.0);
}
}
/**
* Writes a floating-point Vector3 object
* TODO: get rid of primitive methods and replace with this
*
* @param Vector3 $vector
*/
public function putVector3Obj(Vector3 $vector){
$this->putLFloat($vector->x);
$this->putLFloat($vector->y);
$this->putLFloat($vector->z);
}
public function getByteRotation() : float{
return (float) ($this->getByte() * (360 / 256));
}

View File

@ -34,19 +34,19 @@ class InventorySlotPacket extends DataPacket{
/** @var int */
public $windowId;
/** @var int */
public $slotIndex;
public $inventorySlot;
/** @var Item */
public $item;
public function decodePayload(){
$this->windowId = $this->getUnsignedVarInt();
$this->slotIndex = $this->getUnsignedVarInt();
$this->inventorySlot = $this->getUnsignedVarInt();
$this->item = $this->getSlot();
}
public function encodePayload(){
$this->putUnsignedVarInt($this->windowId);
$this->putUnsignedVarInt($this->slotIndex);
$this->putUnsignedVarInt($this->inventorySlot);
$this->putSlot($this->item);
}

View File

@ -34,19 +34,106 @@ class InventoryTransactionPacket extends DataPacket{
const TYPE_USE_ITEM_ON_ENTITY = 3;
const TYPE_RELEASE_ITEM = 4;
const SOURCE_CONTAINER = 0;
const SOURCE_WORLD = 2;
const SOURCE_CREATIVE = 3;
const SOURCE_CRAFTING = 99999;
public $actions = [];
public $transactionData;
public function decodePayload(){
$type = $this->getUnsignedVarInt();
$actionCount = $this->getUnsignedVarInt();
for($i = 0; $i < $actionCount; ++$i){
$this->actions[] = $this->decodeInventoryAction();
}
$this->transactionData = new \stdClass();
$this->transactionData->transactionType = $type;
switch($type){
case 0:
case 1:
//Regular ComplexInventoryTransaction doesn't read any extra data
break;
case self::TYPE_USE_ITEM:
$this->transactionData->useItemActionType = $this->getUnsignedVarInt();
$this->getBlockPosition($this->transactionData->x, $this->transactionData->y, $this->transactionData->z);
$this->transactionData->face = $this->getVarInt();
$this->transactionData->hotbarSlot = $this->getVarInt();
$this->transactionData->itemInHand = $this->getSlot();
$this->transactionData->playerPos = $this->getVector3Obj();
$this->transactionData->clickPos = $this->getVector3Obj();
break;
case self::TYPE_USE_ITEM_ON_ENTITY:
$this->transactionData->entityRuntimeId = $this->getEntityRuntimeId();
$this->transactionData->uvarint1_3 = $this->getUnsignedVarInt();
$this->transactionData->hotbarSlot = $this->getVarInt();
$this->transactionData->itemInHand = $this->getSlot();
$this->transactionData->vector1 = $this->getVector3Obj();
$this->transactionData->vector2 = $this->getVector3Obj();
break;
default:
throw new \UnexpectedValueException("Unknown transaction type $type");
}
//TODO
}
public function encodePayload(){
//TODO
}
protected function decodeInventoryAction(){
$actionBucket = new \stdClass();
$actionBucket->inventorySource = $this->decodeInventorySource();
$actionBucket->inventorySlot = $this->getUnsignedVarInt();
$actionBucket->oldItem = $this->getSlot();
$actionBucket->newItem = $this->getSlot();
return $actionBucket;
}
protected function decodeInventorySource(){
$bucket = new \stdClass();
$bucket->sourceType = $this->getUnsignedVarInt();
switch($bucket->sourceType){
case self::SOURCE_CONTAINER:
$bucket->containerId = $this->getVarInt();
$bucket->field_2 = 0;
break;
case 1: //???
$bucket->containerId = -1;
$bucket->field_2 = 0;
break;
case self::SOURCE_WORLD:
$bucket->containerId = -1;
$bucket->field_2 = $this->getUnsignedVarInt();
break;
case self::SOURCE_CREATIVE:
$bucket->containerId = -1;
$bucket->field_2 = 0;
break;
case self::SOURCE_CRAFTING:
$bucket->containerId = $this->getVarInt();
$bucket->field_2 = 0;
break;
default:
throw new \UnexpectedValueException("Unexpected inventory source type $bucket->sourceType");
}
return $bucket;
}
public function handle(NetworkSession $session) : bool{
return $session->handleInventoryTransaction($this);
}

View File

@ -31,16 +31,18 @@ class ModalFormRequestPacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::MODAL_FORM_REQUEST_PACKET;
/** @var int */
public $uvarint1;
public $formId;
/** @var string */
public $string1;
public $formData; //json
public function decodePayload(){
//TODO
$this->formId = $this->getUnsignedVarInt();
$this->formData = $this->getString();
}
public function encodePayload(){
//TODO
$this->putUnsignedVarInt($this->formId);
$this->putString($this->formData);
}
public function handle(NetworkSession $session) : bool{

View File

@ -31,11 +31,11 @@ class ServerSettingsRequestPacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::SERVER_SETTINGS_REQUEST_PACKET;
public function decodePayload(){
//TODO
//No payload
}
public function encodePayload(){
//TODO
//No payload
}
public function handle(NetworkSession $session) : bool{

View File

@ -30,12 +30,19 @@ use pocketmine\network\mcpe\NetworkSession;
class ServerSettingsResponsePacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::SERVER_SETTINGS_RESPONSE_PACKET;
/** @var int */
public $formId;
/** @var string */
public $formData; //json
public function decodePayload(){
//TODO
$this->formId = $this->getUnsignedVarInt();
$this->formData = $this->getString();
}
public function encodePayload(){
//TODO
$this->putUnsignedVarInt($this->formId);
$this->putString($this->formData);
}
public function handle(NetworkSession $session) : bool{