mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Base inventory fixes
This commit is contained in:
parent
401de97719
commit
9cde63a327
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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(){
|
||||
|
Loading…
x
Reference in New Issue
Block a user