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_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);
}
}

View File

@ -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);
}