本文整理匯總了PHP中pocketmine\item\Item::nbtDeserialize方法的典型用法代碼示例。如果您正苦於以下問題:PHP Item::nbtDeserialize方法的具體用法?PHP Item::nbtDeserialize怎麽用?PHP Item::nbtDeserialize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pocketmine\item\Item
的用法示例。
在下文中一共展示了Item::nbtDeserialize方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: initEntity
protected function initEntity()
{
parent::initEntity();
$this->setMaxHealth(5);
$this->setHealth($this->namedtag["Health"]);
if (isset($this->namedtag->Age)) {
$this->age = $this->namedtag["Age"];
}
if (isset($this->namedtag->PickupDelay)) {
$this->pickupDelay = $this->namedtag["PickupDelay"];
}
if (isset($this->namedtag->Owner)) {
$this->owner = $this->namedtag["Owner"];
}
if (isset($this->namedtag->Thrower)) {
$this->thrower = $this->namedtag["Thrower"];
}
if (!isset($this->namedtag->Item)) {
$this->close();
return;
}
assert($this->namedtag->Item instanceof CompoundTag);
$this->item = ItemItem::nbtDeserialize($this->namedtag->Item);
$this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
}
示例2: initEntity
protected function initEntity()
{
$this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, false, self::DATA_TYPE_BYTE);
$this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [0, 0, 0], false);
$inventoryContents = $this->namedtag->Inventory ?? null;
$this->inventory = new PlayerInventory($this, $inventoryContents);
//Virtual inventory for desktop GUI crafting and anti-cheat transaction processing
$this->floatingInventory = new FloatingInventory($this);
if ($this instanceof Player) {
$this->addWindow($this->inventory, 0);
} else {
if (isset($this->namedtag->NameTag)) {
$this->setNameTag($this->namedtag["NameTag"]);
}
if (isset($this->namedtag->Skin) and $this->namedtag->Skin instanceof CompoundTag) {
$this->setSkin($this->namedtag->Skin["Data"], $this->namedtag->Skin["Name"]);
}
$this->uuid = UUID::fromData($this->getId(), $this->getSkinData(), $this->getNameTag());
}
if (isset($this->namedtag->Inventory) and $this->namedtag->Inventory instanceof ListTag) {
foreach ($this->namedtag->Inventory as $item) {
if ($item["Slot"] >= 0 and $item["Slot"] < 9) {
//Hotbar
$this->inventory->setHotbarSlotIndex($item["Slot"], isset($item["TrueSlot"]) ? $item["TrueSlot"] : -1);
} elseif ($item["Slot"] >= 100 and $item["Slot"] < 104) {
//Armor
$this->inventory->setItem($this->inventory->getSize() + $item["Slot"] - 100, ItemItem::nbtDeserialize($item));
} else {
$this->inventory->setItem($item["Slot"] - 9, ItemItem::nbtDeserialize($item));
}
}
}
parent::initEntity();
if (!isset($this->namedtag->foodLevel) or !$this->namedtag->foodLevel instanceof IntTag) {
$this->namedtag->foodLevel = new IntTag("foodLevel", $this->getFood());
} else {
$this->setFood($this->namedtag["foodLevel"]);
}
if (!isset($this->namedtag->foodExhaustionLevel) or !$this->namedtag->foodExhaustionLevel instanceof IntTag) {
$this->namedtag->foodExhaustionLevel = new FloatTag("foodExhaustionLevel", $this->getExhaustion());
} else {
$this->setExhaustion($this->namedtag["foodExhaustionLevel"]);
}
if (!isset($this->namedtag->foodSaturationLevel) or !$this->namedtag->foodSaturationLevel instanceof IntTag) {
$this->namedtag->foodSaturationLevel = new FloatTag("foodSaturationLevel", $this->getSaturation());
} else {
$this->setSaturation($this->namedtag["foodSaturationLevel"]);
}
if (!isset($this->namedtag->foodTickTimer) or !$this->namedtag->foodTickTimer instanceof IntTag) {
$this->namedtag->foodTickTimer = new IntTag("foodTickTimer", $this->foodTickTimer);
} else {
$this->foodTickTimer = $this->namedtag["foodTickTimer"];
}
if (!isset($this->namedtag->XpLevel) or !$this->namedtag->XpLevel instanceof IntTag) {
$this->namedtag->XpLevel = new IntTag("XpLevel", $this->getXpLevel());
} else {
$this->setXpLevel($this->namedtag["XpLevel"]);
}
if (!isset($this->namedtag->XpP) or !$this->namedtag->XpP instanceof FloatTag) {
$this->namedtag->XpP = new FloatTag("XpP", $this->getXpProgress());
}
if (!isset($this->namedtag->XpTotal) or !$this->namedtag->XpTotal instanceof IntTag) {
$this->namedtag->XpTotal = new IntTag("XpTotal", $this->totalXp);
} else {
$this->totalXp = $this->namedtag["XpTotal"];
}
if (!isset($this->namedtag->XpSeed) or !$this->namedtag->XpSeed instanceof IntTag) {
$this->namedtag->XpSeed = new IntTag("XpSeed", $this->xpSeed ?? ($this->xpSeed = mt_rand(PHP_INT_MIN, PHP_INT_MAX)));
} else {
$this->xpSeed = $this->namedtag["XpSeed"];
}
}
示例3: getItem
/**
* This method should not be used by plugins, use the Inventory
*
* @param int $index
*
* @return Item
*/
public function getItem($index)
{
$i = $this->getSlotIndex($index);
if ($i < 0) {
return Item::get(Item::AIR, 0, 0);
} else {
return Item::nbtDeserialize($this->namedtag->Items[$i]);
}
}