public function saveNBT()
{
parent::saveNBT();
$this->namedtag->Inventory = new ListTag("Inventory", []);
$this->namedtag->Inventory->setTagType(NBT::TAG_Compound);
if ($this->inventory !== null) {
//Hotbar
for ($slot = 0; $slot < $this->inventory->getHotbarSize(); ++$slot) {
$inventorySlotIndex = $this->inventory->getHotbarSlotIndex($slot);
$item = $this->inventory->getItem($inventorySlotIndex);
$tag = NBT::putItemHelper($item, $slot);
$tag->TrueSlot = new ByteTag("TrueSlot", $inventorySlotIndex);
$this->namedtag->Inventory[$slot] = $tag;
}
//Normal inventory
$slotCount = $this->inventory->getSize() + $this->inventory->getHotbarSize();
for ($slot = $this->inventory->getHotbarSize(); $slot < $slotCount; ++$slot) {
$item = $this->inventory->getItem($slot - $this->inventory->getHotbarSize());
//As NBT, real inventory slots are slots 9-44, NOT 0-35
$this->namedtag->Inventory[$slot] = NBT::putItemHelper($item, $slot);
}
//Armour
for ($slot = 100; $slot < 104; ++$slot) {
$item = $this->inventory->getItem($this->inventory->getSize() + $slot - 100);
if ($item instanceof ItemItem and $item->getId() !== ItemItem::AIR) {
$this->namedtag->Inventory[$slot] = NBT::putItemHelper($item, $slot);
}
}
}
if (strlen($this->getSkinData()) > 0) {
$this->namedtag->Skin = new CompoundTag("Skin", ["Data" => new StringTag("Data", $this->getSkinData()), "Name" => new StringTag("Name", $this->getSkinId())]);
}
//Xp
$this->namedtag->XpLevel = new IntTag("XpLevel", $this->getXpLevel());
$this->namedtag->XpTotal = new IntTag("XpTotal", $this->getTotalXp());
$this->namedtag->XpP = new FloatTag("XpP", $this->getXpProgress());
$this->namedtag->XpSeed = new IntTag("XpSeed", $this->getXpSeed());
//Food
$this->namedtag->foodLevel = new IntTag("foodLevel", $this->getFood());
$this->namedtag->foodExhaustionLevel = new FloatTag("foodExhaustionLevel", $this->getExhaustion());
$this->namedtag->foodSaturationLevel = new FloatTag("foodSaturationLevel", $this->getSaturation());
$this->namedtag->foodTickTimer = new IntTag("foodTickTimer", $this->foodTickTimer);
}