Found use of extra bytes in Item serialization

No idea why these are separate from the NBT data, but this is what they do.
This commit is contained in:
Dylan K. Taylor 2017-04-02 19:29:14 +01:00
parent f7e959d602
commit 90f1efc667

View File

@ -186,10 +186,10 @@ class BinaryStream extends \stdClass{
public function getSlot(){ public function getSlot(){
$id = $this->getVarInt(); $id = $this->getVarInt();
if($id <= 0){ if($id <= 0){
return Item::get(0, 0, 0); return Item::get(0, 0, 0);
} }
$auxValue = $this->getVarInt(); $auxValue = $this->getVarInt();
$data = $auxValue >> 8; $data = $auxValue >> 8;
$cnt = $auxValue & 0xff; $cnt = $auxValue & 0xff;
@ -201,14 +201,23 @@ class BinaryStream extends \stdClass{
$nbt = $this->get($nbtLen); $nbt = $this->get($nbtLen);
} }
$this->get(2); //??? (TODO) //TODO
$canPlaceOn = $this->getVarInt();
if($canPlaceOn > 0){
for($i = 0; $i < $canPlaceOn; ++$i){
$this->getString();
}
}
return Item::get( //TODO
$id, $canDestroy = $this->getVarInt();
$data, if($canDestroy > 0){
$cnt, for($i = 0; $i < $canDestroy; ++$i){
$nbt $this->getString();
); }
}
return Item::get($id, $data, $cnt, $nbt);
} }
@ -219,12 +228,15 @@ class BinaryStream extends \stdClass{
} }
$this->putVarInt($item->getId()); $this->putVarInt($item->getId());
$auxValue = (($item->getDamage() ?? -1) << 8) | $item->getCount(); $auxValue = ($item->getDamage() << 8) | $item->getCount();
$this->putVarInt($auxValue); $this->putVarInt($auxValue);
$nbt = $item->getCompoundTag(); $nbt = $item->getCompoundTag();
$this->putLShort(strlen($nbt)); $this->putLShort(strlen($nbt));
$this->put($nbt); $this->put($nbt);
$this->put("\x00\x00"); //TODO: find out what these are
$this->putVarInt(0); //CanPlaceOn entry count (TODO)
$this->putVarInt(0); //CanDestroy entry count (TODO)
} }
public function getString(){ public function getString(){