diff --git a/src/pocketmine/network/protocol/ContainerSetContentPacket.php b/src/pocketmine/network/protocol/ContainerSetContentPacket.php index ebeabd20d..b47ae3437 100644 --- a/src/pocketmine/network/protocol/ContainerSetContentPacket.php +++ b/src/pocketmine/network/protocol/ContainerSetContentPacket.php @@ -30,6 +30,7 @@ class ContainerSetContentPacket extends DataPacket{ const SPECIAL_INVENTORY = 0; const SPECIAL_ARMOR = 0x78; const SPECIAL_CREATIVE = 0x79; + const SPECIAL_HOTBAR = 0x7a; public $windowid; public $slots = []; @@ -43,14 +44,14 @@ class ContainerSetContentPacket extends DataPacket{ public function decode(){ $this->windowid = $this->getByte(); - $count = $this->getShort(); + $count = $this->getUnsignedVarInt(); for($s = 0; $s < $count and !$this->feof(); ++$s){ $this->slots[$s] = $this->getSlot(); } if($this->windowid === self::SPECIAL_INVENTORY){ - $count = $this->getShort(); + $count = $this->getUnsignedVarInt(); for($s = 0; $s < $count and !$this->feof(); ++$s){ - $this->hotbar[$s] = $this->getInt(); + $this->hotbar[$s] = $this->getVarInt(); } } } @@ -58,17 +59,17 @@ class ContainerSetContentPacket extends DataPacket{ public function encode(){ $this->reset(); $this->putByte($this->windowid); - $this->putShort(count($this->slots)); + $this->putUnsignedVarInt(count($this->slots)); foreach($this->slots as $slot){ $this->putSlot($slot); } if($this->windowid === self::SPECIAL_INVENTORY and count($this->hotbar) > 0){ - $this->putShort(count($this->hotbar)); + $this->putUnsignedVarInt(count($this->hotbar)); foreach($this->hotbar as $slot){ - $this->putInt($slot); + $this->putVarInt($slot); } }else{ - $this->putShort(0); + $this->putUnsignedVarInt(0); } } diff --git a/src/pocketmine/network/protocol/ContainerSetSlotPacket.php b/src/pocketmine/network/protocol/ContainerSetSlotPacket.php index bc385f34c..3e6a42007 100644 --- a/src/pocketmine/network/protocol/ContainerSetSlotPacket.php +++ b/src/pocketmine/network/protocol/ContainerSetSlotPacket.php @@ -36,16 +36,16 @@ class ContainerSetSlotPacket extends DataPacket{ public function decode(){ $this->windowid = $this->getByte(); - $this->slot = $this->getShort(); - $this->hotbarSlot = $this->getShort(); + $this->slot = $this->getVarInt(); + $this->hotbarSlot = $this->getVarInt(); $this->item = $this->getSlot(); } public function encode(){ $this->reset(); $this->putByte($this->windowid); - $this->putShort($this->slot); - $this->putShort($this->hotbarSlot); + $this->putVarInt($this->slot); + $this->putVarInt($this->hotbarSlot); $this->putSlot($this->item); } diff --git a/src/pocketmine/utils/BinaryStream.php b/src/pocketmine/utils/BinaryStream.php index cb5b447dd..cf0c2231d 100644 --- a/src/pocketmine/utils/BinaryStream.php +++ b/src/pocketmine/utils/BinaryStream.php @@ -191,18 +191,16 @@ class BinaryStream extends \stdClass{ } public function getSlot(){ - $id = $this->getSignedShort(); + $id = $this->getVarInt(); if($id <= 0){ return Item::get(0, 0, 0); } - - $cnt = $this->getByte(); - - $data = $this->getShort(); + $auxValue = $this->getVarInt(); + $data = $auxValue >> 8; + $cnt = $auxValue & 0xff; $nbtLen = $this->getLShort(); - $nbt = ""; if($nbtLen > 0){ @@ -217,19 +215,19 @@ class BinaryStream extends \stdClass{ ); } + public function putSlot(Item $item){ if($item->getId() === 0){ - $this->putShort(0); + $this->putVarInt(0); return; } - $this->putShort($item->getId()); - $this->putByte($item->getCount()); - $this->putShort($item->getDamage() === null ? -1 : $item->getDamage()); + $this->putVarInt($item->getId()); + $auxValue = ($item->getDamage() << 8) | $item->getCount(); + $this->putVarInt($auxValue); $nbt = $item->getCompoundTag(); $this->putLShort(strlen($nbt)); $this->put($nbt); - } public function getString(){