public function saveNBT()
{
parent::saveNBT();
$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);
$this->namedtag->XpLevel = new IntTag("XpLevel", $this->getXpLevel());
$this->namedtag->XpP = new FloatTag("XpP", $this->getXpProgress());
$this->namedtag->XpTotal = new IntTag("XpTotal", $this->totalXp);
$this->namedtag->XpSeed = new IntTag("XpSeed", $this->xpSeed ?? ($this->xpSeed = mt_rand(PHP_INT_MIN, PHP_INT_MAX)));
$this->namedtag->Inventory = new ListTag("Inventory", []);
$this->namedtag->Inventory->setTagType(NBT::TAG_Compound);
if ($this->inventory !== null) {
for ($slot = 0; $slot < $this->inventory->getHotbarSize(); ++$slot) {
$hotbarSlot = $this->inventory->getHotbarSlotIndex($slot);
if ($hotbarSlot !== -1) {
$item = $this->inventory->getItem($hotbarSlot);
if ($item->getId() !== 0 and $item->getCount() > 0) {
$tag = $item->nbtSerialize($slot);
$tag->TrueSlot = new ByteTag("TrueSlot", $hotbarSlot);
$this->namedtag->Inventory[$slot] = $tag;
continue;
}
}
$this->namedtag->Inventory[$slot] = new CompoundTag("", [new ByteTag("Count", 0), new ShortTag("Damage", 0), new ByteTag("Slot", $slot), new ByteTag("TrueSlot", -1), new ShortTag("id", 0)]);
}
//Normal inventory
$slotCount = $this->inventory->getSize() + $this->inventory->getHotbarSize();
for ($slot = $this->inventory->getHotbarSize(); $slot < $slotCount; ++$slot) {
$item = $this->inventory->getItem($slot - 9);
$this->namedtag->Inventory[$slot] = $item->nbtSerialize($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] = $item->nbtSerialize($slot);
}
}
}
if (strlen($this->getSkinData()) > 0) {
$this->namedtag->Skin = new CompoundTag("Skin", ["Data" => new StringTag("Data", $this->getSkinData()), "Name" => new StringTag("Name", $this->getSkinId())]);
}
}