public function saveNBT() { parent::saveNBT(); $this->namedtag->Inventory = new Enum("Inventory", []); $this->namedtag->Inventory->setTagType(NBT::TAG_Compound); if ($this->inventory !== null) { for ($slot = 0; $slot < 9; ++$slot) { $hotbarSlot = $this->inventory->getHotbarSlotIndex($slot); if ($hotbarSlot !== -1) { $item = $this->inventory->getItem($hotbarSlot); if ($item->getId() !== 0 and $item->getCount() > 0) { $this->namedtag->Inventory[$slot] = new Compound(false, [new Byte("Count", $item->getCount()), new Short("Damage", $item->getDamage()), new Byte("Slot", $slot), new Byte("TrueSlot", $hotbarSlot), new Short("id", $item->getId())]); continue; } } $this->namedtag->Inventory[$slot] = new Compound(false, [new Byte("Count", 0), new Short("Damage", 0), new Byte("Slot", $slot), new Byte("TrueSlot", -1), new Short("id", 0)]); } //Normal inventory $slotCount = Player::SURVIVAL_SLOTS + 9; //$slotCount = (($this instanceof Player and ($this->gamemode & 0x01) === 1) ? Player::CREATIVE_SLOTS : Player::SURVIVAL_SLOTS) + 9; for ($slot = 9; $slot < $slotCount; ++$slot) { $item = $this->inventory->getItem($slot - 9); $this->namedtag->Inventory[$slot] = new Compound(false, [new Byte("Count", $item->getCount()), new Short("Damage", $item->getDamage()), new Byte("Slot", $slot), new Short("id", $item->getId())]); } //Armor 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] = new Compound(false, [new Byte("Count", $item->getCount()), new Short("Damage", $item->getDamage()), new Byte("Slot", $slot), new Short("id", $item->getId())]); } } } }
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())]); } }
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); }
public function saveNBT() { parent::saveNBT(); $this->namedtag->Inventory = new Enum("Inventory", []); $this->namedtag->Inventory->setTagType(NBT::TAG_Compound); if ($this->inventory !== null) { for ($slot = 0; $slot < 9; ++$slot) { $hotbarSlot = $this->inventory->getHotbarSlotIndex($slot); if ($hotbarSlot !== -1) { $item = $this->inventory->getItem($hotbarSlot); if ($item->getId() !== 0 and $item->getCount() > 0) { $tag = NBT::putItemHelper($item, $slot); $tag->TrueSlot = new Byte("TrueSlot", $hotbarSlot); $this->namedtag->Inventory[$slot] = $tag; continue; } } $this->namedtag->Inventory[$slot] = new Compound("", [new Byte("Count", 0), new Short("Damage", 0), new Byte("Slot", $slot), new Byte("TrueSlot", -1), new Short("id", 0)]); } //Normal inventory $slotCount = Player::SURVIVAL_SLOTS + 9; //$slotCount = (($this instanceof Player and ($this->gamemode & 0x01) === 1) ? Player::CREATIVE_SLOTS : Player::SURVIVAL_SLOTS) + 9; for ($slot = 9; $slot < $slotCount; ++$slot) { $item = $this->inventory->getItem($slot - 9); $this->namedtag->Inventory[$slot] = NBT::putItemHelper($item, $slot); } //Armor 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 Compound("Skin", ["Data" => new String("Data", $this->getSkinData()), "Name" => new String("Name", $this->getSkinName()), "Client" => new Byte("Clinet", $this->isOldClient() ? 1 : 0), "Slim" => new Byte("Slim", $this->isSkinSlim() ? 1 : 0), "Transparent" => new Byte("Transparent", $this->isSkinTransparent() ? 1 : 0)]); } }