Base inventory fixes

This commit is contained in:
Dylan K. Taylor 2016-10-04 12:54:38 +01:00
parent 401de97719
commit 9cde63a327
3 changed files with 21 additions and 22 deletions

View File

@ -30,6 +30,7 @@ class ContainerSetContentPacket extends DataPacket{
const SPECIAL_INVENTORY = 0; const SPECIAL_INVENTORY = 0;
const SPECIAL_ARMOR = 0x78; const SPECIAL_ARMOR = 0x78;
const SPECIAL_CREATIVE = 0x79; const SPECIAL_CREATIVE = 0x79;
const SPECIAL_HOTBAR = 0x7a;
public $windowid; public $windowid;
public $slots = []; public $slots = [];
@ -43,14 +44,14 @@ class ContainerSetContentPacket extends DataPacket{
public function decode(){ public function decode(){
$this->windowid = $this->getByte(); $this->windowid = $this->getByte();
$count = $this->getShort(); $count = $this->getUnsignedVarInt();
for($s = 0; $s < $count and !$this->feof(); ++$s){ for($s = 0; $s < $count and !$this->feof(); ++$s){
$this->slots[$s] = $this->getSlot(); $this->slots[$s] = $this->getSlot();
} }
if($this->windowid === self::SPECIAL_INVENTORY){ if($this->windowid === self::SPECIAL_INVENTORY){
$count = $this->getShort(); $count = $this->getUnsignedVarInt();
for($s = 0; $s < $count and !$this->feof(); ++$s){ 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(){ public function encode(){
$this->reset(); $this->reset();
$this->putByte($this->windowid); $this->putByte($this->windowid);
$this->putShort(count($this->slots)); $this->putUnsignedVarInt(count($this->slots));
foreach($this->slots as $slot){ foreach($this->slots as $slot){
$this->putSlot($slot); $this->putSlot($slot);
} }
if($this->windowid === self::SPECIAL_INVENTORY and count($this->hotbar) > 0){ 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){ foreach($this->hotbar as $slot){
$this->putInt($slot); $this->putVarInt($slot);
} }
}else{ }else{
$this->putShort(0); $this->putUnsignedVarInt(0);
} }
} }

View File

@ -36,16 +36,16 @@ class ContainerSetSlotPacket extends DataPacket{
public function decode(){ public function decode(){
$this->windowid = $this->getByte(); $this->windowid = $this->getByte();
$this->slot = $this->getShort(); $this->slot = $this->getVarInt();
$this->hotbarSlot = $this->getShort(); $this->hotbarSlot = $this->getVarInt();
$this->item = $this->getSlot(); $this->item = $this->getSlot();
} }
public function encode(){ public function encode(){
$this->reset(); $this->reset();
$this->putByte($this->windowid); $this->putByte($this->windowid);
$this->putShort($this->slot); $this->putVarInt($this->slot);
$this->putShort($this->hotbarSlot); $this->putVarInt($this->hotbarSlot);
$this->putSlot($this->item); $this->putSlot($this->item);
} }

View File

@ -191,18 +191,16 @@ class BinaryStream extends \stdClass{
} }
public function getSlot(){ public function getSlot(){
$id = $this->getSignedShort(); $id = $this->getVarInt();
if($id <= 0){ if($id <= 0){
return Item::get(0, 0, 0); return Item::get(0, 0, 0);
} }
$auxValue = $this->getVarInt();
$cnt = $this->getByte(); $data = $auxValue >> 8;
$cnt = $auxValue & 0xff;
$data = $this->getShort();
$nbtLen = $this->getLShort(); $nbtLen = $this->getLShort();
$nbt = ""; $nbt = "";
if($nbtLen > 0){ if($nbtLen > 0){
@ -217,19 +215,19 @@ class BinaryStream extends \stdClass{
); );
} }
public function putSlot(Item $item){ public function putSlot(Item $item){
if($item->getId() === 0){ if($item->getId() === 0){
$this->putShort(0); $this->putVarInt(0);
return; return;
} }
$this->putShort($item->getId()); $this->putVarInt($item->getId());
$this->putByte($item->getCount()); $auxValue = ($item->getDamage() << 8) | $item->getCount();
$this->putShort($item->getDamage() === null ? -1 : $item->getDamage()); $this->putVarInt($auxValue);
$nbt = $item->getCompoundTag(); $nbt = $item->getCompoundTag();
$this->putLShort(strlen($nbt)); $this->putLShort(strlen($nbt));
$this->put($nbt); $this->put($nbt);
} }
public function getString(){ public function getString(){